Skip to content

Commit 75a6900

Browse files
committed
fix(marker): Solved a bug with the popup message not showing when the marker is moved, thanks to @bosiakov for reporting here:
#1019
1 parent b006748 commit 75a6900

File tree

3 files changed

+74
-3
lines changed

3 files changed

+74
-3
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<!DOCTYPE html>
2+
<html ng-app="demoapp">
3+
<head>
4+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
5+
<script src="../bower_components/angular/angular.min.js"></script>
6+
<script src="../bower_components/leaflet/dist/leaflet.js"></script>
7+
<script src="../dist/angular-leaflet-directive.min.js"></script>
8+
<link rel="stylesheet" href="../bower_components/leaflet/dist/leaflet.css" />
9+
<script>
10+
var app = angular.module("demoapp", ["leaflet-directive"]);
11+
app.controller('MarkersCompiledWithoutIconController', [ '$scope', function($scope) {
12+
$scope.setSourceMarker = function () {
13+
alert($scope.markers.popup.lat + " " + $scope.markers.popup.lng)
14+
}
15+
16+
$scope.setDestinationMarker = function () {
17+
alert($scope.markers.popup.lat + " " + $scope.markers.popup.lng)
18+
};
19+
20+
var getNewPopupMarker = function(lat, lng) {
21+
return {
22+
lat: lat,
23+
lng: lng,
24+
focus: true,
25+
opacity: 1,
26+
icon: {
27+
iconUrl: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3wsIFR0j2j5hUQAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJTVBkLmUHAAAADElEQVQI12P4//8/AAX+Av7czFnnAAAAAElFTkSuQmCC', // Transparent pixel
28+
iconSize: [0, 0], // size of the icon
29+
popupAnchor: [0, 0] // point from which the popup should open relative to the iconAnchor
30+
},
31+
message: "<button ' \
32+
ng-click='setSourceMarker()'>First button</button> \
33+
<button class='btn btn-danger btn-block' \
34+
ng-click='setDestinationMarker()'>Second button</button>",
35+
getMessageScope: function () {
36+
return $scope;
37+
},
38+
};
39+
};
40+
41+
$scope.$on("leafletDirectiveMap.click", function (event, args) {
42+
var leafEvent = args.leafletEvent;
43+
var lat = leafEvent.latlng.lat;
44+
var lng = leafEvent.latlng.lng;
45+
46+
$scope.markers.popup.lat = lat;
47+
$scope.markers.popup.lng = lng;
48+
$scope.markers.popup.focus = true;
49+
50+
});
51+
52+
angular.extend($scope, {
53+
chicago: {
54+
lat: 41.85,
55+
lng: -87.65,
56+
zoom: 8
57+
},
58+
markers: {
59+
popup: getNewPopupMarker(41.85, -87.65)
60+
}
61+
});
62+
}]);
63+
64+
</script>
65+
</head>
66+
<body ng-controller="MarkersCompiledWithoutIconController">
67+
<leaflet lf-center="chicago" lf-markers="markers" height="480px" width="100%"></leaflet>
68+
<h1>Changing Icon Rotation</h1>
69+
</div>
70+
</body>
71+
</html>

src/directives/events.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ angular.module('leaflet-directive').directive('lfEvents', function(leafletLogger
1010
var isObject = leafletHelpers.isObject;
1111
var isDefined = leafletHelpers.isDefined;
1212
var leafletScope = controller.getLeafletScope();
13-
var eventBroadcast = leafletScope.eventBroadcast;
13+
var eventBroadcast = leafletScope.lfEvents;
1414
var availableMapEvents = leafletMapEvents.getAvailableMapEvents();
1515
var addEvents = leafletMapEvents.addEvents;
1616

@@ -20,7 +20,7 @@ angular.module('leaflet-directive').directive('lfEvents', function(leafletLogger
2020
var logic = 'broadcast';
2121

2222
// We have a possible valid object
23-
if (!isDefined(eventBroadcast.map)) {
23+
if (!isDefined(eventBroadcast) || !isDefined(eventBroadcast.map)) {
2424
// We do not have events enable/disable do we do nothing (all enabled by default)
2525
mapEvents = availableMapEvents;
2626
} else if (!isObject(eventBroadcast.map)) {

src/services/leafletMarkersHelpers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ angular.module('leaflet-directive').service('leafletMarkersHelpers', function($r
385385
}
386386

387387
// The markerData.focus property must be true so we update if there wasn't a previous value or it wasn't true
388-
if (markerData.focus === true && (!isDefined(oldMarkerData.focus) || oldMarkerData.focus === false) || (isInitializing && markerData.focus === true)) {
388+
if (markerData.focus === true && (markerData.lat !== oldMarkerData.lat || markerData.lng !== oldMarkerData.lng || !isDefined(oldMarkerData.focus) || oldMarkerData.focus === false) || (isInitializing && markerData.focus === true)) {
389389
// Reopen the popup when focus is still true
390390
marker.openPopup();
391391
updatedFocus = true;

0 commit comments

Comments
 (0)