arthur-e / Wicket

A modest library for moving between Well-Known Text (WKT) and various framework geometries
https://arthur-e.github.io/Wicket/
Other
586 stars 226 forks source link

How to send to google.maps.Polygon #116

Closed neilm813 closed 6 years ago

neilm813 commented 6 years ago

Hello and thanks for this tool! I could use a little help please:

I tried following the provided example and am successfully able to log wkt.components and execute wkt.toObject(), but I'm unsure how to proceed and send the object to google.maps.Polygon

I've used google.maps.Polygon before so I only need to know how / where to extract the properly formatted coordinates regardless of wkt polygon type. Thanks.

arthur-e commented 6 years ago

Hi @neilm813, it is toObject() that gives you an instance of the google.maps.Polygon class (or could be said "gives you a google.maps.Polygon object"). To get this on a map, let's assume you have a google.maps.Map object assigned to a variable map.

Every google.maps.Polygon has a method called setMap() which accepts, as its only argument, the map, in this case (see reference). So:

// Create a google.maps.Polygon
myPolygon = wkt.toObject()

// Show the polygon on the map
myPolygon.setMap(map)
neilm813 commented 6 years ago

Appreciate the help, thanks @arthur-e