Skip to content
This repository was archived by the owner on Sep 20, 2019. It is now read-only.

Commit ebad626

Browse files
committed
feat(url-center-hash): Listen for URL changes to update the center.
As a suggestion by @peterm95018 here: tombatossals/angular-leaflet-directive#283
1 parent 4a6d755 commit ebad626

File tree

4 files changed

+31
-26
lines changed

4 files changed

+31
-26
lines changed

dist/angular-leaflet-directive.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -172,21 +172,20 @@
172172
}
173173
return centerParam;
174174
};
175-
urlCenterHash = extractCenterFromUrl(); /*
176-
leafletScope.$on('$locationChangeSuccess', function(event) {
177-
var scope = event.currentScope;
178-
//$log.debug("updated location...");
179-
var urlCenter = extractCenterFromUrl();
180-
if (isDefined(urlCenter) && !isSameCenterOnMap(urlCenter, map)) {
181-
//$log.debug("updating center model...", urlCenter);
182-
scope.center = {
183-
lat: urlCenter.lat,
184-
lng: urlCenter.lng,
185-
zoom: urlCenter.zoom
186-
};
187-
}
188-
});
189-
*/
175+
urlCenterHash = extractCenterFromUrl();
176+
leafletScope.$on('$locationChangeSuccess', function (event) {
177+
var scope = event.currentScope;
178+
//$log.debug("updated location...");
179+
var urlCenter = extractCenterFromUrl();
180+
if (isDefined(urlCenter) && !isSameCenterOnMap(urlCenter, map)) {
181+
//$log.debug("updating center model...", urlCenter);
182+
scope.center = {
183+
lat: urlCenter.lat,
184+
lng: urlCenter.lng,
185+
zoom: urlCenter.zoom
186+
};
187+
}
188+
});
190189
}
191190
leafletScope.$watch('center', function (center) {
192191
//$log.debug("updated center model...");

dist/angular-leaflet-directive.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/url-hash-center-example.html

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,20 @@
3030
</head>
3131
<body ng-controller="DemoController">
3232
<h1>Center map with URL synchronization example</h1>
33-
<p>This demo syncs the map center position with the URL, and viceversa, using the <strong>center-url-params</strong> property.</p>
34-
<form>
35-
Latitude : <input type="number" step="any" ng-model="london.lat" />
36-
Longitude : <input type="number" step="any" ng-model="london.lng" />
37-
Zoom : <input type="number" step="any" ng-model="london.zoom" />
38-
</form>
39-
<leaflet center="london" url-hash-center="yes" width="640" height="400"></leaflet>
33+
<div style="float: left;">
34+
<p>This demo syncs the map center position with the URL, and viceversa, using the <strong>center-url-params</strong> property.</p>
35+
<form>
36+
Latitude : <input type="number" step="any" ng-model="london.lat" />
37+
Longitude : <input type="number" step="any" ng-model="london.lng" />
38+
Zoom : <input type="number" step="any" ng-model="london.zoom" />
39+
</form>
40+
<leaflet center="london" url-hash-center="yes" width="640" height="400"></leaflet>
41+
</div>
42+
<ul style="float: left;">
43+
<li><a href="#/?c=36.8899:-121.8008:12">Watsonville</a>
44+
<li><a href="#/?c=34.0078:-118.8060:14">Malibu</a>
45+
<li><a href="#/?c=33.7717:-117.9458:12">Garden Grove</a>
46+
<li><a href="#/?c=32.5290:-117.0442:13">Tijuana</a>
47+
</ul>
4048
</body>
4149
</html>

src/directives/center.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ angular.module("leaflet-directive").directive('center',
7070
};
7171
urlCenterHash = extractCenterFromUrl();
7272

73-
/*
7473
leafletScope.$on('$locationChangeSuccess', function(event) {
7574
var scope = event.currentScope;
7675
//$log.debug("updated location...");
@@ -84,7 +83,6 @@ angular.module("leaflet-directive").directive('center',
8483
};
8584
}
8685
});
87-
*/
8886
}
8987

9088
leafletScope.$watch("center", function(center) {

0 commit comments

Comments
 (0)