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

Commit f0dadaf

Browse files
committed
feat(build): Added a new service leafletMarkerHelpers with the methods needed to manage the marker attribute
1 parent afa17e5 commit f0dadaf

File tree

7 files changed

+74
-80
lines changed

7 files changed

+74
-80
lines changed

Gruntfile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ module.exports = function(grunt) {
262262
'src/services/leafletMapDefaults.js',
263263
'src/services/leafletEvents.js',
264264
'src/services/leafletLayerHelpers.js',
265+
'src/services/leafletMarkerHelpers.js',
265266
'src/services/leafletHelpers.js'
266267
],
267268
dest: 'dist/angular-leaflet-directive.js',

dist/angular-leaflet-directive.js

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ angular.module("leaflet-directive").directive('bounds', function ($log, leafletH
593593
};
594594
});
595595

596-
angular.module("leaflet-directive").directive('markers', function ($log, $rootScope, $q, leafletData, leafletHelpers, leafletMapDefaults, leafletEvents) {
596+
angular.module("leaflet-directive").directive('markers', function ($log, $rootScope, $q, leafletData, leafletHelpers, leafletMapDefaults, leafletMarkerHelpers, leafletEvents) {
597597
return {
598598
restrict: "A",
599599
scope: false,
@@ -611,11 +611,11 @@ angular.module("leaflet-directive").directive('markers', function ($log, $rootSc
611611
safeApply = leafletHelpers.safeApply,
612612
leafletScope = mapController.getLeafletScope(),
613613
markers = leafletScope.markers,
614+
getLeafletIcon = leafletMarkerHelpers.getLeafletIcon,
614615
availableMarkerEvents = leafletEvents.getAvailableMarkerEvents();
615616

616617
mapController.getMap().then(function(map) {
617-
var defaults = leafletMapDefaults.getDefaults(attrs.id),
618-
leafletMarkers = {},
618+
var leafletMarkers = {},
619619
groups = {},
620620
getLayers;
621621

@@ -629,22 +629,6 @@ angular.module("leaflet-directive").directive('markers', function ($log, $rootSc
629629
};
630630
}
631631

632-
// Default leaflet icon object used in all markers as a default
633-
var LeafletIcon = L.Icon.extend({
634-
options: {
635-
iconUrl: defaults.icon.url,
636-
iconRetinaUrl: defaults.icon.retinaUrl,
637-
iconSize: defaults.icon.size,
638-
iconAnchor: defaults.icon.anchor,
639-
labelAnchor: defaults.icon.labelAnchor,
640-
popupAnchor: defaults.icon.popup,
641-
shadowUrl: defaults.icon.shadow.url,
642-
shadowRetinaUrl: defaults.icon.shadow.retinaUrl,
643-
shadowSize: defaults.icon.shadow.size,
644-
shadowAnchor: defaults.icon.shadow.anchor
645-
}
646-
});
647-
648632
if (!isDefined(markers)) {
649633
return;
650634
}
@@ -1034,7 +1018,7 @@ angular.module("leaflet-directive").directive('markers', function ($log, $rootSc
10341018
// If there is no icon property or it's not an object
10351019
if (old_data.icon !== undefined && old_data.icon !== null && typeof old_data.icon === 'object') {
10361020
// If there was an icon before restore to the default
1037-
marker.setIcon(new LeafletIcon());
1021+
marker.setIcon(getLeafletIcon());
10381022
marker.closePopup();
10391023
marker.unbindPopup();
10401024
if (data.message !== undefined && data.message !== null && typeof data.message === 'string' && data.message !== "") {
@@ -1056,7 +1040,7 @@ angular.module("leaflet-directive").directive('markers', function ($log, $rootSc
10561040
marker.setIcon(data.icon);
10571041
} else {
10581042
// This icon is a icon set in the model trough options
1059-
marker.setIcon(new LeafletIcon(data.icon));
1043+
marker.setIcon(getLeafletIcon(data.icon));
10601044
}
10611045
if (dragA) {
10621046
marker.dragging.enable();
@@ -1132,7 +1116,7 @@ angular.module("leaflet-directive").directive('markers', function ($log, $rootSc
11321116
if (marker.dragging) {
11331117
dragG = marker.dragging.enabled();
11341118
}
1135-
marker.setIcon(new LeafletIcon(data.icon));
1119+
marker.setIcon(getLeafletIcon(data.icon));
11361120
if (dragG) {
11371121
marker.dragging.enable();
11381122
}
@@ -1236,7 +1220,7 @@ angular.module("leaflet-directive").directive('markers', function ($log, $rootSc
12361220
if (data.icon) {
12371221
micon = data.icon;
12381222
} else {
1239-
micon = new LeafletIcon();
1223+
micon = getLeafletIcon();
12401224
}
12411225
var moptions = {
12421226
icon: micon,
@@ -1692,20 +1676,6 @@ angular.module("leaflet-directive").factory('leafletMapDefaults', function ($q,
16921676
tileLayerOptions: {
16931677
attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
16941678
},
1695-
icon: {
1696-
url: 'http://cdn.leafletjs.com/leaflet-0.7/images/marker-icon.png',
1697-
retinaUrl: 'http://cdn.leafletjs.com/leaflet-0.7/images/marker-icon-2x.png',
1698-
size: [25, 41],
1699-
anchor: [12, 40],
1700-
labelAnchor: [10, -20],
1701-
popup: [0, -40],
1702-
shadow: {
1703-
url: 'http://cdn.leafletjs.com/leaflet-0.7/images/marker-shadow.png',
1704-
retinaUrl: 'http://cdn.leafletjs.com/leaflet-0.7/images/marker-shadow.png',
1705-
size: [41, 41],
1706-
anchor: [12, 40]
1707-
}
1708-
},
17091679
path: {
17101680
weight: 10,
17111681
opacity: 1,
@@ -1775,7 +1745,7 @@ angular.module("leaflet-directive").factory('leafletMapDefaults', function ($q,
17751745
newDefaults.zoomControlPosition = isDefined(userDefaults.zoomControlPosition) ? userDefaults.zoomControlPosition : newDefaults.zoomControlPosition;
17761746
newDefaults.keyboard = isDefined(userDefaults.keyboard) ? userDefaults.keyboard : newDefaults.keyboard;
17771747
newDefaults.dragging = isDefined(userDefaults.dragging) ? userDefaults.dragging : newDefaults.dragging;
1778-
1748+
17791749
newDefaults.controlLayersPosition = isDefined(userDefaults.controlLayersPosition) ? userDefaults.controlLayersPosition : newDefaults.controlLayersPosition;
17801750

17811751
if (isDefined(userDefaults.crs) && isDefined(L.CRS[userDefaults.crs])) {
@@ -1923,7 +1893,7 @@ angular.module("leaflet-directive").factory('leafletEvents', function ($rootScop
19231893
});
19241894

19251895

1926-
angular.module("leaflet-directive").factory('leafletLayerHelpers', function ($rootScope, $q, $log, leafletHelpers) {
1896+
angular.module("leaflet-directive").factory('leafletLayerHelpers', function ($rootScope, $log, leafletHelpers) {
19271897
var Helpers = leafletHelpers,
19281898
isString = leafletHelpers.isString,
19291899
isObject = leafletHelpers.isObject,
@@ -2096,6 +2066,33 @@ angular.module("leaflet-directive").factory('leafletLayerHelpers', function ($ro
20962066
};
20972067
});
20982068

2069+
angular.module("leaflet-directive").factory('leafletMarkerHelpers', function () {
2070+
2071+
var LeafletDefaultIcon = L.Icon.extend({
2072+
options: {
2073+
iconUrl: 'http://cdn.leafletjs.com/leaflet-0.7/images/marker-icon.png',
2074+
iconRetinaUrl: 'http://cdn.leafletjs.com/leaflet-0.7/images/marker-icon-2x.png',
2075+
iconSize: [25, 41],
2076+
iconAnchor: [12, 40],
2077+
labelAnchor: [10, -20],
2078+
popupAnchor: [0, -40],
2079+
shadow: {
2080+
url: 'http://cdn.leafletjs.com/leaflet-0.7/images/marker-shadow.png',
2081+
retinaUrl: 'http://cdn.leafletjs.com/leaflet-0.7/images/marker-shadow.png',
2082+
size: [41, 41],
2083+
anchor: [12, 40]
2084+
}
2085+
}
2086+
});
2087+
2088+
return {
2089+
getLeafletIcon: function(data) {
2090+
return new LeafletDefaultIcon(data);
2091+
}
2092+
};
2093+
2094+
});
2095+
20992096
angular.module("leaflet-directive").factory('leafletHelpers', function ($q, $log) {
21002097

21012098
function _obtainEffectiveMapId(d, mapId) {

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.

src/directives/markers.js

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
angular.module("leaflet-directive").directive('markers', function ($log, $rootScope, $q, leafletData, leafletHelpers, leafletMapDefaults, leafletEvents) {
1+
angular.module("leaflet-directive").directive('markers', function ($log, $rootScope, $q, leafletData, leafletHelpers, leafletMapDefaults, leafletMarkerHelpers, leafletEvents) {
22
return {
33
restrict: "A",
44
scope: false,
@@ -16,11 +16,11 @@ angular.module("leaflet-directive").directive('markers', function ($log, $rootSc
1616
safeApply = leafletHelpers.safeApply,
1717
leafletScope = mapController.getLeafletScope(),
1818
markers = leafletScope.markers,
19+
getLeafletIcon = leafletMarkerHelpers.getLeafletIcon,
1920
availableMarkerEvents = leafletEvents.getAvailableMarkerEvents();
2021

2122
mapController.getMap().then(function(map) {
22-
var defaults = leafletMapDefaults.getDefaults(attrs.id),
23-
leafletMarkers = {},
23+
var leafletMarkers = {},
2424
groups = {},
2525
getLayers;
2626

@@ -34,22 +34,6 @@ angular.module("leaflet-directive").directive('markers', function ($log, $rootSc
3434
};
3535
}
3636

37-
// Default leaflet icon object used in all markers as a default
38-
var LeafletIcon = L.Icon.extend({
39-
options: {
40-
iconUrl: defaults.icon.url,
41-
iconRetinaUrl: defaults.icon.retinaUrl,
42-
iconSize: defaults.icon.size,
43-
iconAnchor: defaults.icon.anchor,
44-
labelAnchor: defaults.icon.labelAnchor,
45-
popupAnchor: defaults.icon.popup,
46-
shadowUrl: defaults.icon.shadow.url,
47-
shadowRetinaUrl: defaults.icon.shadow.retinaUrl,
48-
shadowSize: defaults.icon.shadow.size,
49-
shadowAnchor: defaults.icon.shadow.anchor
50-
}
51-
});
52-
5337
if (!isDefined(markers)) {
5438
return;
5539
}
@@ -439,7 +423,7 @@ angular.module("leaflet-directive").directive('markers', function ($log, $rootSc
439423
// If there is no icon property or it's not an object
440424
if (old_data.icon !== undefined && old_data.icon !== null && typeof old_data.icon === 'object') {
441425
// If there was an icon before restore to the default
442-
marker.setIcon(new LeafletIcon());
426+
marker.setIcon(getLeafletIcon());
443427
marker.closePopup();
444428
marker.unbindPopup();
445429
if (data.message !== undefined && data.message !== null && typeof data.message === 'string' && data.message !== "") {
@@ -461,7 +445,7 @@ angular.module("leaflet-directive").directive('markers', function ($log, $rootSc
461445
marker.setIcon(data.icon);
462446
} else {
463447
// This icon is a icon set in the model trough options
464-
marker.setIcon(new LeafletIcon(data.icon));
448+
marker.setIcon(getLeafletIcon(data.icon));
465449
}
466450
if (dragA) {
467451
marker.dragging.enable();
@@ -537,7 +521,7 @@ angular.module("leaflet-directive").directive('markers', function ($log, $rootSc
537521
if (marker.dragging) {
538522
dragG = marker.dragging.enabled();
539523
}
540-
marker.setIcon(new LeafletIcon(data.icon));
524+
marker.setIcon(getLeafletIcon(data.icon));
541525
if (dragG) {
542526
marker.dragging.enable();
543527
}
@@ -641,7 +625,7 @@ angular.module("leaflet-directive").directive('markers', function ($log, $rootSc
641625
if (data.icon) {
642626
micon = data.icon;
643627
} else {
644-
micon = new LeafletIcon();
628+
micon = getLeafletIcon();
645629
}
646630
var moptions = {
647631
icon: micon,

src/services/leafletLayerHelpers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
angular.module("leaflet-directive").factory('leafletLayerHelpers', function ($rootScope, $q, $log, leafletHelpers) {
1+
angular.module("leaflet-directive").factory('leafletLayerHelpers', function ($rootScope, $log, leafletHelpers) {
22
var Helpers = leafletHelpers,
33
isString = leafletHelpers.isString,
44
isObject = leafletHelpers.isObject,

src/services/leafletMapDefaults.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,6 @@ angular.module("leaflet-directive").factory('leafletMapDefaults', function ($q,
2121
tileLayerOptions: {
2222
attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
2323
},
24-
icon: {
25-
url: 'http://cdn.leafletjs.com/leaflet-0.7/images/marker-icon.png',
26-
retinaUrl: 'http://cdn.leafletjs.com/leaflet-0.7/images/marker-icon-2x.png',
27-
size: [25, 41],
28-
anchor: [12, 40],
29-
labelAnchor: [10, -20],
30-
popup: [0, -40],
31-
shadow: {
32-
url: 'http://cdn.leafletjs.com/leaflet-0.7/images/marker-shadow.png',
33-
retinaUrl: 'http://cdn.leafletjs.com/leaflet-0.7/images/marker-shadow.png',
34-
size: [41, 41],
35-
anchor: [12, 40]
36-
}
37-
},
3824
path: {
3925
weight: 10,
4026
opacity: 1,
@@ -104,7 +90,7 @@ angular.module("leaflet-directive").factory('leafletMapDefaults', function ($q,
10490
newDefaults.zoomControlPosition = isDefined(userDefaults.zoomControlPosition) ? userDefaults.zoomControlPosition : newDefaults.zoomControlPosition;
10591
newDefaults.keyboard = isDefined(userDefaults.keyboard) ? userDefaults.keyboard : newDefaults.keyboard;
10692
newDefaults.dragging = isDefined(userDefaults.dragging) ? userDefaults.dragging : newDefaults.dragging;
107-
93+
10894
newDefaults.controlLayersPosition = isDefined(userDefaults.controlLayersPosition) ? userDefaults.controlLayersPosition : newDefaults.controlLayersPosition;
10995

11096
if (isDefined(userDefaults.crs) && isDefined(L.CRS[userDefaults.crs])) {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
angular.module("leaflet-directive").factory('leafletMarkerHelpers', function () {
2+
3+
var LeafletDefaultIcon = L.Icon.extend({
4+
options: {
5+
iconUrl: 'http://cdn.leafletjs.com/leaflet-0.7/images/marker-icon.png',
6+
iconRetinaUrl: 'http://cdn.leafletjs.com/leaflet-0.7/images/marker-icon-2x.png',
7+
iconSize: [25, 41],
8+
iconAnchor: [12, 40],
9+
labelAnchor: [10, -20],
10+
popupAnchor: [0, -40],
11+
shadow: {
12+
url: 'http://cdn.leafletjs.com/leaflet-0.7/images/marker-shadow.png',
13+
retinaUrl: 'http://cdn.leafletjs.com/leaflet-0.7/images/marker-shadow.png',
14+
size: [41, 41],
15+
anchor: [12, 40]
16+
}
17+
}
18+
});
19+
20+
return {
21+
getLeafletIcon: function(data) {
22+
return new LeafletDefaultIcon(data);
23+
}
24+
};
25+
26+
});

0 commit comments

Comments
 (0)