tombatossals / angular-leaflet-directive

AngularJS directive to embed an interact with maps managed by Leaflet library
http://tombatossals.github.io/angular-leaflet-directive
MIT License
1.5k stars 635 forks source link

Marker click event stops working when Map ID is assigned #1084

Open teknotica opened 8 years ago

teknotica commented 8 years ago

Hello!

I've implemented some functionality for when the markers in the map are clicked. All worked fine until I had to get the map object, so I added an ID to my map. The click events won't trigger anymore :( am I missing something? Thanks in advance.

My code looks like this:

<!-- Map -->
<leaflet id="citymap" class="leaflet-map" event-broadcast="events"
    layers="mapbox.layers"
    lf-center="mapbox.center"
    markers="markers"
    defaults="mapbox.defaults"
    maxbounds="mapbox.maxbounds"></leaflet>
'use strict';
angular.module('club', ['leaflet-directive'])
.controller('clubCtrl', function ($scope, leafletData, leafletMarkerEvents) {

    // Get current map zoom
    var getCurrentMapZoom = function() {
        leafletData.getMap('citymap').then(function(map) {
            console.log(map.zoom);
        });
    };

    // Event listener when markers get clicked
    $scope.$on('leafletDirectiveMarker.click', function (event, args) {
        // console.log("Marker clicked");
        getCurrentMapZoom();
    });

});
teknotica commented 8 years ago

Found the issue (for someone stumbling upon the same case):

The click event needs to reference the current map id, instead of:

$scope.$on('leafletDirectiveMarker.click', function (event, args) { ... }

use the following:

$scope.$on('leafletDirectiveMarker.citymap.click', function (event, args) { ... }

Note the .citymap (ID of the map clicked)

DDroll commented 8 years ago

Looks like as breaking change! Example in "events" section on exaples page doesn't work too old way) All events in my app stop working after update to new version, thank you, teknotica, i fixed it with adding map id after leafletDirectiveMarker, leafletDirectiveMap etc. It should be mentioned in docs..

aretw0 commented 6 years ago

@DDroll I was smashing my head on keyboard! Thanks!