Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have multiple data layers in Google Maps?

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/

like image 918
kaoscify Avatar asked Mar 21 '17 22:03

kaoscify


People also ask

Can you combine layers in Google maps?

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.

How do Layers work in Google maps?

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.

What is the Layers button on Google maps?

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.


1 Answers

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/

like image 72
ffflabs Avatar answered Oct 29 '22 09:10

ffflabs