Google maps GeoJSON- toggle marker layers?

后端 未结 2 1045
-上瘾入骨i
-上瘾入骨i 2021-02-04 14:23

I have some GeoJSON returned from a call to a PostGIS database. I\'d like to be able to add a marker for each feature, and be able to toggle different types of marker/feature. C

相关标签:
2条回答
  • 2021-02-04 14:23

    To Add: var layer_1 = new google.maps.Data(); should be done inside map initialization function, as:

    var map;
    
      var data_layer_for_ramps;
    
    
    
      function initialize() {
    
                map = new google.maps.Map(document.getElementById('map'), {
                  zoom: 12,
                  center: new google.maps.LatLng(-33.897907, 151.179138),//-33.8151,151.0032 
                  mapTypeId: 'roadmap'
                });
    
                data_layer_for_ramps = new google.maps.Data();
            }   
    
    0 讨论(0)
  • 2021-02-04 14:33

    You can also create separate layers

    var layer_1 = new google.maps.Data();
    var layer_2 = new google.maps.Data();
    

    then populate it, e.g. with json data

    layer_1.loadGeoJson('/path/to/data.json');
    layer_2.loadGeoJson('/path/to/data2.json');
    

    then add / remove them on the map

    layer_1.setMap(map);
    layer_2.setMap(map);
    layer_1.setMap(null);
    
    0 讨论(0)
提交回复
热议问题