How to remove data from a Google Maps Data Layer?

前端 未结 4 1808
深忆病人
深忆病人 2020-12-23 22:51

I see Google Maps support geojson. Looking at the docs here: https://developers.google.com/maps/documentation/javascript/datalayer#load_geojson

Given the last exampl

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-23 23:27

    As a follow-up to @mensi's answer, it can be important to keep track of different sets of features loaded from different data sources. You could do that by adding a property to each feature:

    feature.setProperty('kind', 'region');
    feature.setProperty('kind', 'lake');
    

    However, it may be easier to create multiple data layers. A Google Map by default starts out with a single data layer, but you are not limited to that. You can do:

    var datalayer = new google.maps.Data({ map: mymap });
    

    (It's important to set a map option, or your data layer will not show up.)

    This way, it's easier to group features by layer, and turn entire layers on or off.

提交回复
热议问题