angular-google-maps marker removal removes all markers

489 Views Asked by At

I am using angular-google-maps to add markers to my map. I have followed all the best practices for loading the Maps API, and I have a set of items I display on the map. Everything works well except item removal. When I remove an item from the array of items, all of the markers disappear. I am clearly doing something wrong, but I don't understand what exactly. Another strange part of this: when I add another item, the marker successfully gets added to the map, but it's the only marker I can see. Furthermore, the angular-google-map-marker elements are still in the dom, so I'm not sure why they aren't displayed (I tried setting visibility to visible, display to anything but none). My code is as follows (Jade/LiveScript).


index.jade

ui-gmap-google-map(center="map.center", zoom="map.zoom")
  ui-gmap-marker(ng-repeat="item in items", idKey="item._id", coords="item.location")

app.ls

angular.module("appName", ["uiGmapgoogle-maps", "appController"])
  .config (uiGmapGoogleMapApiProvider) ->
    uiGmapGoogleMapApiProvider.configure({
        v: "3.17",
        libraries: "weather,geometry,visualization"
    })

appController.ls

appController = ($scope, $timeout, $mdSidenav, $http, $log, $mdDialog) ->
  ...
  $scope.items =
    "id1":
      _id: "id1"
      location:
        type: "Point"
        coordinates: [-71, 42]
    ...

  $scope.sendItemReq = (ev) ->
    $http($scope.itemReq)
      .success (data, status, headers, config) ->
        currentItemId = $scope.currentItem._id
        delete $scope.items[currentItemId]

Any ideas what I am doing wrong here? Let me know if I should provide any more information.

P.S. I understand that I will have to do a setMap(null) to actually remove the marker, I'd just like to deal with this step first.

0

There are 0 best solutions below