Search code examples
google-maps-api-3geojson

Google maps v3 data.feature Editable?


I have polygons loaded using method

map.data.loadGeoJson('geo.json',{ idPropertyName: 'ID' });

Now I want to make editable one of loaded from geojson polygons.

I was tried:

map.data.getFeatureById(1).setProperty('editable', true);

But it seems that data.feature don't have editable property?

Any ideas how to make it in easiest way? Only one idea that I have in this moment is to make my own parser from geoJson and draw all shapes as google.maps.Polygon().


Solution

  • Maybe it isn't best solution but it works for me now. I'm duplicating shape geometry from feature and creating new polygon in place.

    var shape = [];
    for (var i = 0; i < map.data.getFeatureById(ID).getGeometry().getLength(); i++) {
            var shapeData = map.data.getFeatureById(ID).getGeometry().getAt(i).getArray();
            shape.push(shapeData);
        }
    
        nowEditingShape = new google.maps.Polygon({
          paths: shape,
          strokeColor: '#FF0000',
          strokeOpacity: 0.8,
          strokeWeight: 2,
          fillColor: '#FF0000',
          fillOpacity: 0.35,
        editable: true
        });
        map.data.remove(map.data.getFeatureById(ID));
        nowEditingShape.setMap(map);