Skip to content

Commit bb04624

Browse files
committed
feat(code): Follow strictly the AirBNB code style guide
https://github.com/airbnb/javascript
1 parent cb3e58e commit bb04624

35 files changed

+5037
-4780
lines changed

src/directives/bounds.js

Lines changed: 77 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,86 @@
1-
angular.module("leaflet-directive").directive('bounds', function ($log, $timeout, $http, leafletHelpers, nominatimService, leafletBoundsHelpers) {
1+
angular.module('leaflet-directive').directive('bounds', function($log, $timeout, $http, leafletHelpers, nominatimService, leafletBoundsHelpers) {
22

3-
return {
4-
restrict: "A",
5-
scope: false,
6-
replace: false,
7-
require: [ 'leaflet' ],
3+
return {
4+
restrict: 'A',
5+
scope: false,
6+
replace: false,
7+
require: ['leaflet'],
88

9-
link: function(scope, element, attrs, controller) {
10-
var isDefined = leafletHelpers.isDefined;
11-
var createLeafletBounds = leafletBoundsHelpers.createLeafletBounds;
12-
var leafletScope = controller[0].getLeafletScope();
13-
var mapController = controller[0];
14-
var errorHeader = leafletHelpers.errorHeader + ' [Bounds] ';
9+
link: function(scope, element, attrs, controller) {
10+
var isDefined = leafletHelpers.isDefined;
11+
var createLeafletBounds = leafletBoundsHelpers.createLeafletBounds;
12+
var leafletScope = controller[0].getLeafletScope();
13+
var mapController = controller[0];
14+
var errorHeader = leafletHelpers.errorHeader + ' [Bounds] ';
1515

16-
var emptyBounds = function(bounds) {
17-
return (bounds._southWest.lat === 0 && bounds._southWest.lng === 0 &&
18-
bounds._northEast.lat === 0 && bounds._northEast.lng === 0);
19-
};
16+
var emptyBounds = function(bounds) {
17+
return (bounds._southWest.lat === 0 && bounds._southWest.lng === 0 &&
18+
bounds._northEast.lat === 0 && bounds._northEast.lng === 0);
19+
};
2020

21-
mapController.getMap().then(function (map) {
22-
leafletScope.$on('boundsChanged', function (event) {
23-
var scope = event.currentScope;
24-
var bounds = map.getBounds();
21+
mapController.getMap().then(function(map) {
22+
leafletScope.$on('boundsChanged', function(event) {
23+
var scope = event.currentScope;
24+
var bounds = map.getBounds();
2525

26-
if (emptyBounds(bounds) || scope.settingBoundsFromScope) {
27-
return;
28-
}
29-
scope.settingBoundsFromLeaflet = true;
30-
var newScopeBounds = {
31-
northEast: {
32-
lat: bounds._northEast.lat,
33-
lng: bounds._northEast.lng
34-
},
35-
southWest: {
36-
lat: bounds._southWest.lat,
37-
lng: bounds._southWest.lng
38-
},
39-
options: bounds.options
40-
};
41-
if (!angular.equals(scope.bounds, newScopeBounds)) {
42-
scope.bounds = newScopeBounds;
43-
}
44-
$timeout( function() {
45-
scope.settingBoundsFromLeaflet = false;
46-
});
47-
});
26+
if (emptyBounds(bounds) || scope.settingBoundsFromScope) {
27+
return;
28+
}
4829

49-
var lastNominatimQuery;
50-
leafletScope.$watch('bounds', function (bounds) {
51-
if (scope.settingBoundsFromLeaflet)
52-
return;
53-
if (isDefined(bounds.address) && bounds.address !== lastNominatimQuery) {
54-
scope.settingBoundsFromScope = true;
55-
nominatimService.query(bounds.address, attrs.id).then(function(data) {
56-
var b = data.boundingbox;
57-
var newBounds = [ [ b[0], b[2]], [ b[1], b[3]] ];
58-
map.fitBounds(newBounds);
59-
}, function(errMsg) {
60-
$log.error(errorHeader + ' ' + errMsg + '.');
61-
});
62-
lastNominatimQuery = bounds.address;
63-
$timeout( function() {
64-
scope.settingBoundsFromScope = false;
65-
});
66-
return;
67-
}
30+
scope.settingBoundsFromLeaflet = true;
31+
var newScopeBounds = {
32+
northEast: {
33+
lat: bounds._northEast.lat,
34+
lng: bounds._northEast.lng,
35+
},
36+
southWest: {
37+
lat: bounds._southWest.lat,
38+
lng: bounds._southWest.lng,
39+
},
40+
options: bounds.options,
41+
};
42+
if (!angular.equals(scope.bounds, newScopeBounds)) {
43+
scope.bounds = newScopeBounds;
44+
}
6845

69-
var leafletBounds = createLeafletBounds(bounds);
70-
if (leafletBounds && !map.getBounds().equals(leafletBounds)) {
71-
scope.settingBoundsFromScope = true;
72-
map.fitBounds(leafletBounds, bounds.options);
73-
$timeout( function() {
74-
scope.settingBoundsFromScope = false;
75-
});
76-
}
77-
}, true);
46+
$timeout(function() {
47+
scope.settingBoundsFromLeaflet = false;
48+
});
49+
});
50+
51+
var lastNominatimQuery;
52+
leafletScope.$watch('bounds', function(bounds) {
53+
if (scope.settingBoundsFromLeaflet)
54+
return;
55+
if (isDefined(bounds.address) && bounds.address !== lastNominatimQuery) {
56+
scope.settingBoundsFromScope = true;
57+
nominatimService.query(bounds.address, attrs.id).then(function(data) {
58+
var b = data.boundingbox;
59+
var newBounds = [[b[0], b[2]], [b[1], b[3]]];
60+
map.fitBounds(newBounds);
61+
}, function(errMsg) {
62+
63+
$log.error(errorHeader + ' ' + errMsg + '.');
64+
});
65+
66+
lastNominatimQuery = bounds.address;
67+
$timeout(function() {
68+
scope.settingBoundsFromScope = false;
69+
});
70+
71+
return;
72+
}
73+
74+
var leafletBounds = createLeafletBounds(bounds);
75+
if (leafletBounds && !map.getBounds().equals(leafletBounds)) {
76+
scope.settingBoundsFromScope = true;
77+
map.fitBounds(leafletBounds, bounds.options);
78+
$timeout(function() {
79+
scope.settingBoundsFromScope = false;
7880
});
79-
}
80-
};
81+
}
82+
}, true);
83+
});
84+
},
85+
};
8186
});

0 commit comments

Comments
 (0)