0

I'm using leaflet.awesome-markers card markers. When you change the color of the icon it immediately closes the pop-up message.

Is it possible to change the color without closing the pop-up?

$scope.$on('leafletDirectiveMarker.viewMap.click', function(e, args){
    $scope.selectedPoint = $scope.points.filter( function(spoint){ return spoint._id ===  args.modelName; })[0];
    $scope.waypoints[$scope.selectedPoint._id].icon.markerColor = 'green'; 
});
Charlie
  • 2,004
  • 6
  • 20
  • 40

2 Answers2

1

Use L.Marker.setIcon() instead, and stop propagation of the event, preferably with L.DomEvent.stop() as it will stop propagation of click events from the marker to the map (through any L.LayerGroups, if any).

In plain Javascript (no angular) this would be:

marker.on('click', function(ev) {
    marker.setIcon(L.icon({ iconUrl: 'some-green-icon.png' }));
    // Also this.setIcon(...)

    L.DomEvent.stop(ev);    
});
IvanSanchez
  • 18,272
  • 3
  • 30
  • 45
0

For myself, I solved the problem of the so - add and display pop-ups when necessary without using a standard mechanism angular (specified for a message marker). You can of course was immediately initialize the pop-up messages when loading data, but in my project it easier to implement on-demand.

//popup's store
$scope.popups = {};

$scope._setViewMarker = function(pId, showPopup){
var wp = $scope.waypoints;
wp[pId].icon.markerColor = 'red';

//set unselected markers color
for (var i in wp)
    if(i != pId){
        wp[i].icon.markerColor = 'blue';
    };  
// close other popups
for (var i in $scope.popups)
    if(i != pId)
        $scope.map.closePopup($scope.popups[i]);        
// show or create poupap
if(showPopup)
    if($scope.popups[pId] ){
        if(!$scope.popups[pId]._isOpen)
            $scope.map.openPopup($scope.popups[pId]);
    } else {
        var ind = $scope.points.map(function(e) { return e._id; }).indexOf(pId);   
        var c = angular.element('<popup point="points['+ind+']" note-click="showDetailPoint(points['+ind+'])"></popup>');
        var linkFn = $compile(c);
        var element = linkFn($scope);
        $scope.popups[pId] = L.popup({offset:[0, -30]}).setLatLng( [wp[pId].lat, wp[pId].lng] ).setContent(element[0]).openOn($scope.map);
        $scope.popups[pId].pointId = pId;
    };
};    
$scope.$on('leafletDirectiveMarker.viewMap.click', function(e, args){
    $scope._setViewMarker(args.modelName, true);
});