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

Commit 0adacda

Browse files
committed
feat(build): Added a new createBoundsFromArray helper, proposed by @lukasz-zak here:
tombatossals/angular-leaflet-directive#228
1 parent 901259a commit 0adacda

File tree

2 files changed

+24
-28
lines changed

2 files changed

+24
-28
lines changed

examples/bounds-example.html

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,33 @@
11
<!DOCTYPE html>
22
<html ng-app="demoapp">
33
<head>
4-
<script src="http://cdn.leafletjs.com/leaflet-0.7/leaflet.js"></script>
5-
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.2/angular.min.js"></script>
4+
<script src="http://cdn.leafletjs.com/leaflet-0.7.1/leaflet.js"></script>
5+
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.min.js"></script>
66
<script src="../dist/angular-leaflet-directive.min.js"></script>
7-
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7/leaflet.css" />
7+
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.1/leaflet.css" />
88
<script>
99
var app = angular.module("demoapp", ["leaflet-directive"]);
10-
app.controller("DemoController", [ "$scope", "leafletData", function($scope, leafletData) {
11-
angular.extend($scope, {
12-
london: {
13-
lat: 51.505,
14-
lng: -0.09,
15-
zoom: 4
16-
},
17-
bounds: {
18-
southWest: {
19-
lat:51.508742458803326,
20-
lng: -0.087890625,
21-
},
22-
northEast: {
23-
lat:51.508742458803326,
24-
lng:-0.087890625,
25-
}
26-
}
27-
});
28-
leafletData.getMap().then(function(map){
10+
app.controller("DemoController", [ "$scope", "leafletData", "leafletBoundsHelpers", function($scope, leafletData, leafletBoundsHelpers) {
11+
12+
var bounds = leafletBoundsHelpers.createBoundsFromArray([
13+
[ 51.508742458803326, -0.087890625 ],
14+
[ 51.508742458803326, -0.087890625 ]
15+
]);
16+
17+
angular.extend($scope, {
18+
london: {
19+
lat: 51.505,
20+
lng: -0.09,
21+
zoom: 4
22+
},
23+
bounds: bounds
24+
});
25+
26+
leafletData.getMap().then(function(map){
2927
var bounds = map.getBounds();
3028
console.log('northwest=' + bounds.getNorthWest().toString() + '&northeast=' + bounds.getNorthEast().toString() + '&southeast=' + bounds.getSouthEast().toString() + '&southwest=' + bounds.getSouthWest().toString());
31-
});
32-
}]);
29+
});
30+
}]);
3331
</script>
3432
<style>
3533
input {

src/services/leafletBoundsHelpers.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ angular.module("leaflet-directive").factory('leafletBoundsHelpers', function ($l
2525
createBoundsFromArray: function(boundsArray) {
2626
if (!(isArray(boundsArray) && boundsArray.length === 2 &&
2727
isArray(boundsArray[0]) && isArray(boundsArray[1]) &&
28-
boundsArray[0].length === 2 && boundsArray[1].lenth === 2 &&
28+
boundsArray[0].length === 2 && boundsArray[1].length === 2 &&
2929
isNumber(boundsArray[0][0]) && isNumber(boundsArray[0][1]) &&
3030
isNumber(boundsArray[1][0]) && isNumber(boundsArray[1][1]))) {
31-
$log.warn("[AngularJS - Leaflet] The bounds array is not valid.");
31+
$log.error("[AngularJS - Leaflet] The bounds array is not valid.");
3232
return;
3333
}
3434

@@ -46,8 +46,6 @@ angular.module("leaflet-directive").factory('leafletBoundsHelpers', function ($l
4646
},
4747

4848
updateBoundsInScope: function(leafletScope, map) {
49-
if(!leafletScope.bounds) { return; }
50-
5149
var mapBounds = map.getBounds();
5250
var newScopeBounds = {
5351
northEast: {

0 commit comments

Comments
 (0)