Is it possible to have multiple data layers using Google Maps API? The only existing related question I could find was this.
Here's my problem.
I want to have a data layer for showcasing polygons on map that are being drawn by the user. At the same time I want to have another data layer that displays polygons that already exist in a database.
I figured I would do this by creating 2 data layers:
drawLayer = new google.maps.Data();
savedLayer = new google.maps.Data();
But when I initialize the drawing tools using drawLayer.setControls(['Polygon'])
, it doesn't work. If I replace the drawLayer
with map.data
, then the drawing tools works fine. Why is that?
JSFiddle: http://jsfiddle.net/pjaLdz6w/
Go to first map and select "Add a New Layer" Go to the second map and in the top menu ( three dots) and choose Export to kml-->save the file to your computer. Go to first map, click into the new layer and choose Import--> import the kml file you previously saved. The two maps are combined.
Layers are objects on the map that consist of one or more separate items, but are manipulated as a single unit. Layers generally reflect collections of objects that you add on top of the map to designate a common association.
You can organize your map features with map layers. For example, you can put color-coded restaurants on one layer and coffee shops on another.
In your fiddle you aren't declaring drawLayer
as a google.maps.Data
object. But even if you do, you still need to give it a map attribute:
drawLayer = new google.maps.Data({map:map});
JSFiddle: http://jsfiddle.net/jbyd815y/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With