How to have multiple layers of data in Google Maps?

Is it possible to have multiple layers of data using the Google Maps API? The only existing related question I could find was this .

Here is my problem.

I want to have a data layer to showcase polygons on a map that are drawn by the user. At the same time, I want to have another layer of data that displays polygons that already exist in the database.

I figured I would do it by creating 2 data layers:

drawLayer = new google.maps.Data();
savedLayer = new google.maps.Data();

      

But when I initialize the painting tools with drawLayer.setControls(['Polygon'])

, it doesn't work. If I replace drawLayer

with map.data

, the drawing tools work fine. Why is this?

JSFiddle: http://jsfiddle.net/pjaLdz6w/

+3


source to share


1 answer


In your script, you are not declaring drawLayer

as an object google.maps.Data

. But even if you do, you still need to assign a map attribute to it:

drawLayer = new google.maps.Data({map:map});

      



JSFiddle: http://jsfiddle.net/jbyd815y/

+3


source







All Articles