javascript - Removing a particular polygon from maps data -
i generating polygons using addgeojson method not sure how can remove particular polygon later when needed. here code
var __layers; var layer = new google.maps.data(); $.ajax({ url: url, type: 'post', success:function(data) { __layers = layer.addgeojson(data); layer.setmap(map1); layer.setstyle(style); } });
i trying remove data not working
map1.data.remove(__layers[0]);
the way _layers has been initialized looks culprit here. may either try layer.setmap(null) or modify code following
var __layers = []; var layer = new google.maps.data(); $.ajax({ url: url, type: 'post', success:function(data) { __layers.push(layer.addgeojson(data)); layer.setmap(map1); layer.setstyle(style); } });
and use
map1.data.remove(__layers.pop());
Comments
Post a Comment