ng-change () inside a marker (ngMap) in Angularjs

1

I'm working with sockets, where I send coordinates every time (lat, lon) and to show these coordinates I use ngMap, when I have a first coordinate it is shown on my map but if I get a second coordinate the marker is duplicated, is where I want to use ng-change () so that when there are new coordinates remove the marker and always create a single one. Below I share my code:

<ng-map id="mapa_inicio" center= "-3.989785, -79.205805" zoom="13">        
   <marker ng-repeat = "u in ubicacion track by $index"
      position="{{conversion(u.latitud)}},{{conversion(u.longitud)}}" tittle={{u.id_ruta}} ng-change="remover_marker()">
    </marker> 
</ng-map>

js:

$scope.remover_marker = function(){
console.log("aqui haré el control deseado")
}

My mistake is that the ng-change () does not work, how can I solve it? I thank you in advance

    
asked by Dimoreno 02.08.2017 в 17:58
source

1 answer

0

The most convenient thing is to remove it and make it appear in the new coordinates, this is an example of a driver to add, show, delete markers.

var app = angular.module('myApp', ['ngMap']);
app.controller('MarkerRemoveCtrl', function(NgMap) {
  var vm = this;
  NgMap.getMap().then(map => vm.map = map);
  vm.positions = [{lat:37.7699298,lng:-122.4469157}];

  vm.addMarker = function(event) {
    var ll = event.latLng;
    vm.positions.push({lat:ll.lat(), lng: ll.lng()});
  }
  vm.deleteMarkers = function() {
    vm.positions = [];
  };
  vm.showMarkers = function() {
    for (var key in vm.map.markers) {
      vm.map.markers[key].setMap(vm.map);
    };
  };
  vm.hideMarkers = function() {
    for (var key in vm.map.markers) {
      vm.map.markers[key].setMap(null);
    };
  };
});

On this website you can find all the uses of ng-map.

link

    
answered by 03.08.2017 в 15:19