admin 管理员组文章数量: 1086019
I want to synchronize google-maps with angular.js, so I created custom directive for google-maps.
CODE
var map;
map = new google.maps.Map(document.getElementById('map'),
mapOptions);
scope.$watch('geojson', function(newVal, oldVal) {
if (newVal !== oldVal) {
map.data.setMap(null);
map = new google.maps.Map(document.getElementById('map'),
mapOptions);
map.data.addGeoJson(scope.geojson);
}
}, true);
My solution works but it is not what i would like to achieve, when data is changing, map is loaded each time with new scope.geojson, unfortunately i couldn't find any good solution how to remove just data, I assume there is not some option to add geojson data as layer? and then just clear this layer before adding new geojson, so map will be stable and only geojson data will change?
I want to synchronize google-maps with angular.js, so I created custom directive for google-maps.
CODE
var map;
map = new google.maps.Map(document.getElementById('map'),
mapOptions);
scope.$watch('geojson', function(newVal, oldVal) {
if (newVal !== oldVal) {
map.data.setMap(null);
map = new google.maps.Map(document.getElementById('map'),
mapOptions);
map.data.addGeoJson(scope.geojson);
}
}, true);
My solution works but it is not what i would like to achieve, when data is changing, map is loaded each time with new scope.geojson, unfortunately i couldn't find any good solution how to remove just data, I assume there is not some option to add geojson data as layer? and then just clear this layer before adding new geojson, so map will be stable and only geojson data will change?
Share Improve this question edited Feb 28, 2015 at 14:21 Pankaj Parkar 136k23 gold badges240 silver badges303 bronze badges asked Feb 28, 2015 at 13:40 IgorIgor 1,4343 gold badges18 silver badges36 bronze badges1 Answer
Reset to default 8Use the forEach
method of the data
class to loop over the features and remove them using the remove
method:
map.data.forEach(function (feature) {
map.data.remove(feature);
});
data
reference: https://developers.google./maps/documentation/javascript/reference#Data
本文标签: javascriptClear google map from previously addGeoJson(scopedata) after watchStack Overflow
版权声明:本文标题:javascript - Clear google map from previously addGeoJson(scope.data) after watch - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744091341a2532092.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论