简体   繁体   中英

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/

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM