I have 2 function, 1 to add markers and 1 to remove markers.

What I am doing to add markers

$scope.getMapData = function (msg, passedIndex) {

msg = L.layerGroup();
for (var i= 0; i < $scope.apiResult.length; i++) {
if ($scope.apiResult[i].Type == "Point"){
L.marker([$scope.Lat[i], $scope.Lng[i]], {icon: greenIcon}).bindPopup($scope.apiResult[i].DESCRIPTION).addTo(msg);

Remove marker:

        $scope.removeMarker = function (msg, passedIndex) {
          absolute_index = passedIndex + ($scope.currentPage) * $scope.pageSize;

              $scope.community[absolute_index].visibility = false;
              // cities.removeLayer(a);
            } else {
               $scope.community[absolute_index].visibility = true;

When I console log map.hasLayer in my "add marker" function, it returns me the value, but when I console log that in my remove marker function, i am not returned anything.

PS: My "msg" all has a unique name like "express_speed". I tried using removeLayer on msg but it doesn't work.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.