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

Commit

Permalink
feat(build): Added a new service leafletMarkerHelpers with the method…
Browse files Browse the repository at this point in the history
…s needed to manage the marker attribute
  • Loading branch information
tombatossals committed Dec 14, 2013
1 parent afa17e5 commit f0dadaf
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 80 deletions.
1 change: 1 addition & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ module.exports = function(grunt) {
'src/services/leafletMapDefaults.js',
'src/services/leafletEvents.js',
'src/services/leafletLayerHelpers.js',
'src/services/leafletMarkerHelpers.js',
'src/services/leafletHelpers.js'
],
dest: 'dist/angular-leaflet-directive.js',
Expand Down
75 changes: 36 additions & 39 deletions dist/angular-leaflet-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ angular.module("leaflet-directive").directive('bounds', function ($log, leafletH
};
});

angular.module("leaflet-directive").directive('markers', function ($log, $rootScope, $q, leafletData, leafletHelpers, leafletMapDefaults, leafletEvents) {
angular.module("leaflet-directive").directive('markers', function ($log, $rootScope, $q, leafletData, leafletHelpers, leafletMapDefaults, leafletMarkerHelpers, leafletEvents) {
return {
restrict: "A",
scope: false,
Expand All @@ -611,11 +611,11 @@ angular.module("leaflet-directive").directive('markers', function ($log, $rootSc
safeApply = leafletHelpers.safeApply,
leafletScope = mapController.getLeafletScope(),
markers = leafletScope.markers,
getLeafletIcon = leafletMarkerHelpers.getLeafletIcon,
availableMarkerEvents = leafletEvents.getAvailableMarkerEvents();

mapController.getMap().then(function(map) {
var defaults = leafletMapDefaults.getDefaults(attrs.id),
leafletMarkers = {},
var leafletMarkers = {},
groups = {},
getLayers;

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

// Default leaflet icon object used in all markers as a default
var LeafletIcon = L.Icon.extend({
options: {
iconUrl: defaults.icon.url,
iconRetinaUrl: defaults.icon.retinaUrl,
iconSize: defaults.icon.size,
iconAnchor: defaults.icon.anchor,
labelAnchor: defaults.icon.labelAnchor,
popupAnchor: defaults.icon.popup,
shadowUrl: defaults.icon.shadow.url,
shadowRetinaUrl: defaults.icon.shadow.retinaUrl,
shadowSize: defaults.icon.shadow.size,
shadowAnchor: defaults.icon.shadow.anchor
}
});

if (!isDefined(markers)) {
return;
}
Expand Down Expand Up @@ -1034,7 +1018,7 @@ angular.module("leaflet-directive").directive('markers', function ($log, $rootSc
// If there is no icon property or it's not an object
if (old_data.icon !== undefined && old_data.icon !== null && typeof old_data.icon === 'object') {
// If there was an icon before restore to the default
marker.setIcon(new LeafletIcon());
marker.setIcon(getLeafletIcon());
marker.closePopup();
marker.unbindPopup();
if (data.message !== undefined && data.message !== null && typeof data.message === 'string' && data.message !== "") {
Expand All @@ -1056,7 +1040,7 @@ angular.module("leaflet-directive").directive('markers', function ($log, $rootSc
marker.setIcon(data.icon);
} else {
// This icon is a icon set in the model trough options
marker.setIcon(new LeafletIcon(data.icon));
marker.setIcon(getLeafletIcon(data.icon));
}
if (dragA) {
marker.dragging.enable();
Expand Down Expand Up @@ -1132,7 +1116,7 @@ angular.module("leaflet-directive").directive('markers', function ($log, $rootSc
if (marker.dragging) {
dragG = marker.dragging.enabled();
}
marker.setIcon(new LeafletIcon(data.icon));
marker.setIcon(getLeafletIcon(data.icon));
if (dragG) {
marker.dragging.enable();
}
Expand Down Expand Up @@ -1236,7 +1220,7 @@ angular.module("leaflet-directive").directive('markers', function ($log, $rootSc
if (data.icon) {
micon = data.icon;
} else {
micon = new LeafletIcon();
micon = getLeafletIcon();
}
var moptions = {
icon: micon,
Expand Down Expand Up @@ -1692,20 +1676,6 @@ angular.module("leaflet-directive").factory('leafletMapDefaults', function ($q,
tileLayerOptions: {
attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
},
icon: {
url: 'http://cdn.leafletjs.com/leaflet-0.7/images/marker-icon.png',
retinaUrl: 'http://cdn.leafletjs.com/leaflet-0.7/images/marker-icon-2x.png',
size: [25, 41],
anchor: [12, 40],
labelAnchor: [10, -20],
popup: [0, -40],
shadow: {
url: 'http://cdn.leafletjs.com/leaflet-0.7/images/marker-shadow.png',
retinaUrl: 'http://cdn.leafletjs.com/leaflet-0.7/images/marker-shadow.png',
size: [41, 41],
anchor: [12, 40]
}
},
path: {
weight: 10,
opacity: 1,
Expand Down Expand Up @@ -1775,7 +1745,7 @@ angular.module("leaflet-directive").factory('leafletMapDefaults', function ($q,
newDefaults.zoomControlPosition = isDefined(userDefaults.zoomControlPosition) ? userDefaults.zoomControlPosition : newDefaults.zoomControlPosition;
newDefaults.keyboard = isDefined(userDefaults.keyboard) ? userDefaults.keyboard : newDefaults.keyboard;
newDefaults.dragging = isDefined(userDefaults.dragging) ? userDefaults.dragging : newDefaults.dragging;

newDefaults.controlLayersPosition = isDefined(userDefaults.controlLayersPosition) ? userDefaults.controlLayersPosition : newDefaults.controlLayersPosition;

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


angular.module("leaflet-directive").factory('leafletLayerHelpers', function ($rootScope, $q, $log, leafletHelpers) {
angular.module("leaflet-directive").factory('leafletLayerHelpers', function ($rootScope, $log, leafletHelpers) {
var Helpers = leafletHelpers,
isString = leafletHelpers.isString,
isObject = leafletHelpers.isObject,
Expand Down Expand Up @@ -2096,6 +2066,33 @@ angular.module("leaflet-directive").factory('leafletLayerHelpers', function ($ro
};
});

angular.module("leaflet-directive").factory('leafletMarkerHelpers', function () {

var LeafletDefaultIcon = L.Icon.extend({
options: {
iconUrl: 'http://cdn.leafletjs.com/leaflet-0.7/images/marker-icon.png',
iconRetinaUrl: 'http://cdn.leafletjs.com/leaflet-0.7/images/marker-icon-2x.png',
iconSize: [25, 41],
iconAnchor: [12, 40],
labelAnchor: [10, -20],
popupAnchor: [0, -40],
shadow: {
url: 'http://cdn.leafletjs.com/leaflet-0.7/images/marker-shadow.png',
retinaUrl: 'http://cdn.leafletjs.com/leaflet-0.7/images/marker-shadow.png',
size: [41, 41],
anchor: [12, 40]
}
}
});

return {
getLeafletIcon: function(data) {
return new LeafletDefaultIcon(data);
}
};

});

angular.module("leaflet-directive").factory('leafletHelpers', function ($q, $log) {

function _obtainEffectiveMapId(d, mapId) {
Expand Down
4 changes: 2 additions & 2 deletions dist/angular-leaflet-directive.min.js

Large diffs are not rendered by default.

30 changes: 7 additions & 23 deletions src/directives/markers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
angular.module("leaflet-directive").directive('markers', function ($log, $rootScope, $q, leafletData, leafletHelpers, leafletMapDefaults, leafletEvents) {
angular.module("leaflet-directive").directive('markers', function ($log, $rootScope, $q, leafletData, leafletHelpers, leafletMapDefaults, leafletMarkerHelpers, leafletEvents) {
return {
restrict: "A",
scope: false,
Expand All @@ -16,11 +16,11 @@ angular.module("leaflet-directive").directive('markers', function ($log, $rootSc
safeApply = leafletHelpers.safeApply,
leafletScope = mapController.getLeafletScope(),
markers = leafletScope.markers,
getLeafletIcon = leafletMarkerHelpers.getLeafletIcon,
availableMarkerEvents = leafletEvents.getAvailableMarkerEvents();

mapController.getMap().then(function(map) {
var defaults = leafletMapDefaults.getDefaults(attrs.id),
leafletMarkers = {},
var leafletMarkers = {},
groups = {},
getLayers;

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

// Default leaflet icon object used in all markers as a default
var LeafletIcon = L.Icon.extend({
options: {
iconUrl: defaults.icon.url,
iconRetinaUrl: defaults.icon.retinaUrl,
iconSize: defaults.icon.size,
iconAnchor: defaults.icon.anchor,
labelAnchor: defaults.icon.labelAnchor,
popupAnchor: defaults.icon.popup,
shadowUrl: defaults.icon.shadow.url,
shadowRetinaUrl: defaults.icon.shadow.retinaUrl,
shadowSize: defaults.icon.shadow.size,
shadowAnchor: defaults.icon.shadow.anchor
}
});

if (!isDefined(markers)) {
return;
}
Expand Down Expand Up @@ -439,7 +423,7 @@ angular.module("leaflet-directive").directive('markers', function ($log, $rootSc
// If there is no icon property or it's not an object
if (old_data.icon !== undefined && old_data.icon !== null && typeof old_data.icon === 'object') {
// If there was an icon before restore to the default
marker.setIcon(new LeafletIcon());
marker.setIcon(getLeafletIcon());
marker.closePopup();
marker.unbindPopup();
if (data.message !== undefined && data.message !== null && typeof data.message === 'string' && data.message !== "") {
Expand All @@ -461,7 +445,7 @@ angular.module("leaflet-directive").directive('markers', function ($log, $rootSc
marker.setIcon(data.icon);
} else {
// This icon is a icon set in the model trough options
marker.setIcon(new LeafletIcon(data.icon));
marker.setIcon(getLeafletIcon(data.icon));
}
if (dragA) {
marker.dragging.enable();
Expand Down Expand Up @@ -537,7 +521,7 @@ angular.module("leaflet-directive").directive('markers', function ($log, $rootSc
if (marker.dragging) {
dragG = marker.dragging.enabled();
}
marker.setIcon(new LeafletIcon(data.icon));
marker.setIcon(getLeafletIcon(data.icon));
if (dragG) {
marker.dragging.enable();
}
Expand Down Expand Up @@ -641,7 +625,7 @@ angular.module("leaflet-directive").directive('markers', function ($log, $rootSc
if (data.icon) {
micon = data.icon;
} else {
micon = new LeafletIcon();
micon = getLeafletIcon();
}
var moptions = {
icon: micon,
Expand Down
2 changes: 1 addition & 1 deletion src/services/leafletLayerHelpers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
angular.module("leaflet-directive").factory('leafletLayerHelpers', function ($rootScope, $q, $log, leafletHelpers) {
angular.module("leaflet-directive").factory('leafletLayerHelpers', function ($rootScope, $log, leafletHelpers) {
var Helpers = leafletHelpers,
isString = leafletHelpers.isString,
isObject = leafletHelpers.isObject,
Expand Down
16 changes: 1 addition & 15 deletions src/services/leafletMapDefaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,6 @@ angular.module("leaflet-directive").factory('leafletMapDefaults', function ($q,
tileLayerOptions: {
attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
},
icon: {
url: 'http://cdn.leafletjs.com/leaflet-0.7/images/marker-icon.png',
retinaUrl: 'http://cdn.leafletjs.com/leaflet-0.7/images/marker-icon-2x.png',
size: [25, 41],
anchor: [12, 40],
labelAnchor: [10, -20],
popup: [0, -40],
shadow: {
url: 'http://cdn.leafletjs.com/leaflet-0.7/images/marker-shadow.png',
retinaUrl: 'http://cdn.leafletjs.com/leaflet-0.7/images/marker-shadow.png',
size: [41, 41],
anchor: [12, 40]
}
},
path: {
weight: 10,
opacity: 1,
Expand Down Expand Up @@ -104,7 +90,7 @@ angular.module("leaflet-directive").factory('leafletMapDefaults', function ($q,
newDefaults.zoomControlPosition = isDefined(userDefaults.zoomControlPosition) ? userDefaults.zoomControlPosition : newDefaults.zoomControlPosition;
newDefaults.keyboard = isDefined(userDefaults.keyboard) ? userDefaults.keyboard : newDefaults.keyboard;
newDefaults.dragging = isDefined(userDefaults.dragging) ? userDefaults.dragging : newDefaults.dragging;

newDefaults.controlLayersPosition = isDefined(userDefaults.controlLayersPosition) ? userDefaults.controlLayersPosition : newDefaults.controlLayersPosition;

if (isDefined(userDefaults.crs) && isDefined(L.CRS[userDefaults.crs])) {
Expand Down
26 changes: 26 additions & 0 deletions src/services/leafletMarkerHelpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
angular.module("leaflet-directive").factory('leafletMarkerHelpers', function () {

var LeafletDefaultIcon = L.Icon.extend({
options: {
iconUrl: 'http://cdn.leafletjs.com/leaflet-0.7/images/marker-icon.png',
iconRetinaUrl: 'http://cdn.leafletjs.com/leaflet-0.7/images/marker-icon-2x.png',
iconSize: [25, 41],
iconAnchor: [12, 40],
labelAnchor: [10, -20],
popupAnchor: [0, -40],
shadow: {
url: 'http://cdn.leafletjs.com/leaflet-0.7/images/marker-shadow.png',
retinaUrl: 'http://cdn.leafletjs.com/leaflet-0.7/images/marker-shadow.png',
size: [41, 41],
anchor: [12, 40]
}
}
});

return {
getLeafletIcon: function(data) {
return new LeafletDefaultIcon(data);
}
};

});

0 comments on commit f0dadaf

Please sign in to comment.