Add and remove several layers to map leaflet

المشرف العام

Administrator
طاقم الإدارة
I 'm trying to add objects to a map I get from an asynchronous call, what I have:

var objetosLayer;var overlays = {};$scope.showItems = function (content) { var showItems = function (item, next) { ItemsService.findById(item._id, { filter: { within: { geometry: $scope.layout.geometry.features[0].geometry }, itemType: 'Objeto' } }, function (err, item) { if (err) { //console.log(err); } if(item !== undefined) { item = GeoService.toGeoJSON(item, { idKey: '_id', geometryKey: 'lastLocation' }); $scope.objetosGeoJson = item; objetosLayer = L.geoJson(item); leafletData.getMap().then(function (map) { objetosLayer.addTo(map); }); overlays['showItems'] = objetosLayer; console.log(overlays['showItems']); } }); $scope.disableFirstButton = true; $scope.activeFirstButton = true; next(); }; var onFinish = function (err) { if (err) { //console.log(err); } }; async.each(content, showItems, onFinish);};$scope.showOutsideItems = function (content) { _.forEach(content, function(item) { ItemsService.findById(item._id, { filter: { within: { geometry: $scope.layout.geometry.features[0].geometry }, itemType: 'Objeto' } }, function (err) { if(err) { if (err.message === 'no item') { ItemsService.findById(err.details.itemId, function (err, item) { console.log(item); if(item.lastLocation) { item = GeoService.toGeoJSON(item, { idKey: '_id', geometryKey: 'lastLocation' }); $scope.objetosGeoJson = item; objetosLayer = L.geoJson(item); leafletData.getMap().then(function (map) { objetosLayer.addTo(map); }); overlays['outsideItems'] = objetosLayer; } else { alert('err'); } }); } } }); $scope.disableSecondButton = true; $scope.activeSecondButton = true; });};$scope.hidePoints = function (layerType, disableButton, activeButton) { leafletData.getMap().then(function(map) { map.removeLayer(overlays[layerType]); });};The function showItems shows all points, but when I try to remove them it just remove the last point showed.

How can I put all points in the same overlay so when a clic remove it's remove all points.



أكثر...
 
أعلى