Skip to content

Commit

Permalink
feat(url-center-hash): Listen for URL changes to update the center.
Browse files Browse the repository at this point in the history
As a suggestion by @peterm95018 here:
#283
  • Loading branch information
tombatossals committed Mar 19, 2014
1 parent 4a6d755 commit ebad626
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 26 deletions.
29 changes: 14 additions & 15 deletions dist/angular-leaflet-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,21 +172,20 @@
}
return centerParam;
};
urlCenterHash = extractCenterFromUrl(); /*
leafletScope.$on('$locationChangeSuccess', function(event) {
var scope = event.currentScope;
//$log.debug("updated location...");
var urlCenter = extractCenterFromUrl();
if (isDefined(urlCenter) && !isSameCenterOnMap(urlCenter, map)) {
//$log.debug("updating center model...", urlCenter);
scope.center = {
lat: urlCenter.lat,
lng: urlCenter.lng,
zoom: urlCenter.zoom
};
}
});
*/
urlCenterHash = extractCenterFromUrl();
leafletScope.$on('$locationChangeSuccess', function (event) {
var scope = event.currentScope;
//$log.debug("updated location...");
var urlCenter = extractCenterFromUrl();
if (isDefined(urlCenter) && !isSameCenterOnMap(urlCenter, map)) {
//$log.debug("updating center model...", urlCenter);
scope.center = {
lat: urlCenter.lat,
lng: urlCenter.lng,
zoom: urlCenter.zoom
};
}
});
}
leafletScope.$watch('center', function (center) {
//$log.debug("updated center model...");
Expand Down
4 changes: 2 additions & 2 deletions dist/angular-leaflet-directive.min.js

Large diffs are not rendered by default.

22 changes: 15 additions & 7 deletions examples/url-hash-center-example.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,20 @@
</head>
<body ng-controller="DemoController">
<h1>Center map with URL synchronization example</h1>
<p>This demo syncs the map center position with the URL, and viceversa, using the <strong>center-url-params</strong> property.</p>
<form>
Latitude : <input type="number" step="any" ng-model="london.lat" />
Longitude : <input type="number" step="any" ng-model="london.lng" />
Zoom : <input type="number" step="any" ng-model="london.zoom" />
</form>
<leaflet center="london" url-hash-center="yes" width="640" height="400"></leaflet>
<div style="float: left;">
<p>This demo syncs the map center position with the URL, and viceversa, using the <strong>center-url-params</strong> property.</p>
<form>
Latitude : <input type="number" step="any" ng-model="london.lat" />
Longitude : <input type="number" step="any" ng-model="london.lng" />
Zoom : <input type="number" step="any" ng-model="london.zoom" />
</form>
<leaflet center="london" url-hash-center="yes" width="640" height="400"></leaflet>
</div>
<ul style="float: left;">
<li><a href="#/?c=36.8899:-121.8008:12">Watsonville</a>
<li><a href="#/?c=34.0078:-118.8060:14">Malibu</a>
<li><a href="#/?c=33.7717:-117.9458:12">Garden Grove</a>
<li><a href="#/?c=32.5290:-117.0442:13">Tijuana</a>
</ul>
</body>
</html>
2 changes: 0 additions & 2 deletions src/directives/center.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ angular.module("leaflet-directive").directive('center',
};
urlCenterHash = extractCenterFromUrl();

/*
leafletScope.$on('$locationChangeSuccess', function(event) {
var scope = event.currentScope;
//$log.debug("updated location...");
Expand All @@ -84,7 +83,6 @@ angular.module("leaflet-directive").directive('center',
};
}
});
*/
}

leafletScope.$watch("center", function(center) {
Expand Down

0 comments on commit ebad626

Please sign in to comment.