How to remove data from a Google Maps Data Layer?

前端 未结 4 1814
深忆病人
深忆病人 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条回答
  •  萌比男神i
    2020-12-23 23:48

    While map.data is designed as a placeholder for the common case of a single datasource, you can have multiple, and still use addGeoJSon using something like:

    // load data - do the same for data2, data3 or whatever
    data1 = new google.maps.Data();
    data1.loadGeoJson(url1);
    
    // create some layer control logic for turning on data1
    data1.setMap(map) // or restyle or whatever
    
    // turn off data1 and turn on data2
    data1.setMap(null) // hides it
    data2.setMap(map) // displays data2
    

提交回复
热议问题