',
link: function link(scope, element, attrs, controller) {
var isDefined = leafletHelpers.isDefined,
leafletScope = controller.getLeafletScope(),
layers = leafletScope.layers;
scope.$watch('icons', function () {
var defaultIcons = {
uncheck: 'fa fa-square-o',
check: 'fa fa-check-square-o',
radio: 'fa fa-dot-circle-o',
unradio: 'fa fa-circle-o',
up: 'fa fa-angle-up',
down: 'fa fa-angle-down',
open: 'fa fa-angle-double-down',
close: 'fa fa-angle-double-up',
toggleLegend: 'fa fa-pencil-square-o'
};
if (isDefined(scope.icons)) {
angular.extend(defaultIcons, scope.icons);
angular.extend(scope.icons, defaultIcons);
} else {
scope.icons = defaultIcons;
}
});
// Setting layer stack order.
attrs.order = isDefined(attrs.order) && (attrs.order === 'normal' || attrs.order === 'reverse') ? attrs.order : 'normal';
scope.order = attrs.order === 'normal';
scope.orderNumber = attrs.order === 'normal' ? -1 : 1;
scope.layers = layers;
controller.getMap().then(function (map) {
leafletScope.$watch('layers.baselayers', function (newBaseLayers) {
var baselayersArray = {};
leafletData.getLayers().then(function (leafletLayers) {
var key;
for (key in newBaseLayers) {
var layer = newBaseLayers[key];
layer.icon = scope.icons[map.hasLayer(leafletLayers.baselayers[key]) ? 'radio' : 'unradio'];
baselayersArray[key] = layer;
}
scope.baselayersArray = baselayersArray;
});
});
leafletScope.$watch('layers.overlays', function (newOverlayLayers) {
var overlaysArray = [];
var groupVisibleCount = {};
leafletData.getLayers().then(function () {
var key;
for (key in newOverlayLayers) {
var layer = newOverlayLayers[key];
layer.icon = scope.icons[layer.visible ? 'check' : 'uncheck'];
overlaysArray.push(layer);
if (!isDefined(scope.layerProperties[layer.name])) {
if (isDefined(layer.layerOptions.opacity)) {
layer.layerOptions.opacity = 1;
}
scope.layerProperties[layer.name] = {
opacityControl: false,
showLegend: true,
layerOptions: layer.layerOptions
};
}
if (isDefined(layer.group)) {
if (!isDefined(scope.groupProperties[layer.group])) {
scope.groupProperties[layer.group] = {
visible: false
};
}
groupVisibleCount[layer.group] = isDefined(groupVisibleCount[layer.group]) ? groupVisibleCount[layer.group] : {
count: 0,
visibles: 0
};
groupVisibleCount[layer.group].count++;
if (layer.visible) {
groupVisibleCount[layer.group].visibles++;
}
}
/*
if(isDefined(layer.index) && leafletLayers.overlays[key].setZIndex) {
leafletLayers.overlays[key].setZIndex(newOverlayLayers[key].index);
}
*/
}
for (key in groupVisibleCount) {
scope.groupProperties[key].visible = groupVisibleCount[key].visibles === groupVisibleCount[key].count;
}
scope.overlaysArray = overlaysArray;
});
}, true);
});
}
};
});
'use strict';
angular.module('ui-leaflet').directive('layers', function (leafletLogger, $q, leafletData, leafletHelpers, leafletLayerHelpers, leafletControlHelpers) {
// var $log = leafletLogger;
return {
restrict: "A",
scope: false,
replace: false,
require: 'leaflet',
controller: function controller($scope) {
$scope._leafletLayers = $q.defer();
this.getLayers = function () {
return $scope._leafletLayers.promise;
};
},
link: function link(scope, element, attrs, controller) {
var isDefined = leafletHelpers.isDefined,
leafletLayers = {},
leafletScope = controller.getLeafletScope(),
layers = leafletScope.layers,
createLayer = leafletLayerHelpers.createLayer,
safeAddLayer = leafletLayerHelpers.safeAddLayer,
safeRemoveLayer = leafletLayerHelpers.safeRemoveLayer,
changeOpacityListener = leafletLayerHelpers.changeOpacityListener,
updateLayersControl = leafletControlHelpers.updateLayersControl,
isLayersControlVisible = false;
scope.$on('$destroy', function () {
leafletControlHelpers.destroyMapLayersControl(scope.mapId);
});
controller.getMap().then(function (map) {
// We have baselayers to add to the map
scope._leafletLayers.resolve(leafletLayers);
leafletData.setLayers(leafletLayers, attrs.id);
leafletLayers.baselayers = {};
leafletLayers.overlays = {};
var mapId = attrs.id;
// Setup all baselayers definitions
var oneVisibleLayer = false;
for (var layerName in layers.baselayers) {
var newBaseLayer = createLayer(layers.baselayers[layerName]);
if (!isDefined(newBaseLayer)) {
delete layers.baselayers[layerName];
continue;
}
leafletLayers.baselayers[layerName] = newBaseLayer;
// Only add the visible layer to the map, layer control manages the addition to the map
// of layers in its control
if (layers.baselayers[layerName].top === true) {
safeAddLayer(map, leafletLayers.baselayers[layerName]);
oneVisibleLayer = true;
}
}
// If there is no visible layer add first to the map
if (!oneVisibleLayer && Object.keys(leafletLayers.baselayers).length > 0) {
safeAddLayer(map, leafletLayers.baselayers[Object.keys(layers.baselayers)[0]]);
}
// Setup the Overlays
for (layerName in layers.overlays) {
if (layers.overlays[layerName].type === 'cartodb') {}
var newOverlayLayer = createLayer(layers.overlays[layerName]);
if (!isDefined(newOverlayLayer)) {
delete layers.overlays[layerName];
continue;
}
leafletLayers.overlays[layerName] = newOverlayLayer;
// Only add the visible overlays to the map
if (layers.overlays[layerName].visible === true) {
safeAddLayer(map, leafletLayers.overlays[layerName]);
}
}
// Watch for the base layers
leafletScope.$watch('layers.baselayers', function (newBaseLayers, oldBaseLayers) {
if (angular.equals(newBaseLayers, oldBaseLayers)) {
isLayersControlVisible = updateLayersControl(map, mapId, isLayersControlVisible, newBaseLayers, layers.overlays, leafletLayers);
return true;
}
// Delete layers from the array
for (var name in leafletLayers.baselayers) {
if (!isDefined(newBaseLayers[name]) || newBaseLayers[name].doRefresh) {
// Remove from the map if it's on it
if (map.hasLayer(leafletLayers.baselayers[name])) {
map.removeLayer(leafletLayers.baselayers[name]);
}
delete leafletLayers.baselayers[name];
if (newBaseLayers[name] && newBaseLayers[name].doRefresh) {
newBaseLayers[name].doRefresh = false;
}
}
}
// add new layers
for (var newName in newBaseLayers) {
if (!isDefined(leafletLayers.baselayers[newName])) {
var testBaseLayer = createLayer(newBaseLayers[newName]);
if (isDefined(testBaseLayer)) {
leafletLayers.baselayers[newName] = testBaseLayer;
// Only add the visible layer to the map
if (newBaseLayers[newName].top === true) {
safeAddLayer(map, leafletLayers.baselayers[newName]);
}
}
} else {
if (newBaseLayers[newName].top === true && !map.hasLayer(leafletLayers.baselayers[newName])) {
safeAddLayer(map, leafletLayers.baselayers[newName]);
} else if (newBaseLayers[newName].top === false && map.hasLayer(leafletLayers.baselayers[newName])) {
map.removeLayer(leafletLayers.baselayers[newName]);
}
}
}
//we have layers, so we need to make, at least, one active
var found = false;
// search for an active layer
for (var key in leafletLayers.baselayers) {
if (map.hasLayer(leafletLayers.baselayers[key])) {
found = true;
break;
}
}
// If there is no active layer make one active
if (!found && Object.keys(leafletLayers.baselayers).length > 0) {
safeAddLayer(map, leafletLayers.baselayers[Object.keys(leafletLayers.baselayers)[0]]);
}
// Only show the layers switch selector control if we have more than one baselayer + overlay
isLayersControlVisible = updateLayersControl(map, mapId, isLayersControlVisible, newBaseLayers, layers.overlays, leafletLayers);
}, true);
// Watch for the overlay layers
leafletScope.$watch('layers.overlays', function (newOverlayLayers, oldOverlayLayers) {
if (angular.equals(newOverlayLayers, oldOverlayLayers)) {
isLayersControlVisible = updateLayersControl(map, mapId, isLayersControlVisible, layers.baselayers, newOverlayLayers, leafletLayers);
return true;
}
// Delete layers from the array
for (var name in leafletLayers.overlays) {
if (!isDefined(newOverlayLayers[name]) || newOverlayLayers[name].doRefresh) {
// Remove from the map if it's on it
if (map.hasLayer(leafletLayers.overlays[name])) {
// Safe remove when ArcGIS layers is loading.
var options = isDefined(newOverlayLayers[name]) ? newOverlayLayers[name].layerOptions : null;
safeRemoveLayer(map, leafletLayers.overlays[name], options);
}
// TODO: Depending on the layer type we will have to delete what's included on it
delete leafletLayers.overlays[name];
if (newOverlayLayers[name] && newOverlayLayers[name].doRefresh) {
newOverlayLayers[name].doRefresh = false;
}
}
}
// add new overlays
for (var newName in newOverlayLayers) {
if (!isDefined(leafletLayers.overlays[newName])) {
var testOverlayLayer = createLayer(newOverlayLayers[newName]);
if (!isDefined(testOverlayLayer)) {
// If the layer creation fails, continue to the next overlay
continue;
}
leafletLayers.overlays[newName] = testOverlayLayer;
if (newOverlayLayers[newName].visible === true) {
safeAddLayer(map, leafletLayers.overlays[newName]);
}
if (isDefined(newOverlayLayers[newName].index) && leafletLayers.overlays[newName].setZIndex) {
leafletLayers.overlays[newName].setZIndex(newOverlayLayers[newName].index);
}
} else {
// check for the .visible property to hide/show overLayers
if (newOverlayLayers[newName].visible && !map.hasLayer(leafletLayers.overlays[newName])) {
safeAddLayer(map, leafletLayers.overlays[newName]);
} else if (newOverlayLayers[newName].visible === false && map.hasLayer(leafletLayers.overlays[newName])) {
// Safe remove when ArcGIS layers is loading.
safeRemoveLayer(map, leafletLayers.overlays[newName], newOverlayLayers[newName].layerOptions);
}
// check for the .layerOptions.opacity property has changed.
var ly = leafletLayers.overlays[newName];
if (map.hasLayer(leafletLayers.overlays[newName])) {
if (newOverlayLayers[newName].layerOptions.opacity !== oldOverlayLayers[newName].layerOptions.opacity) {
if (isDefined(ly.setOpacity)) {
ly.setOpacity(newOverlayLayers[newName].layerOptions.opacity);
}
if (isDefined(ly.getLayers) && isDefined(ly.eachLayer)) {
ly.eachLayer(changeOpacityListener(newOverlayLayers[newName].layerOptions.opacity));
}
}
if (isDefined(newOverlayLayers[newName].index) && ly.setZIndex && newOverlayLayers[newName].index !== oldOverlayLayers[newName].index) {
ly.setZIndex(newOverlayLayers[newName].index);
}
}
}
//refresh heatmap data if present
if (newOverlayLayers[newName].visible && map._loaded && newOverlayLayers[newName].data && newOverlayLayers[newName].type === "heatmap") {
leafletLayers.overlays[newName].setData(newOverlayLayers[newName].data);
leafletLayers.overlays[newName].update();
}
}
// Only add the layers switch selector control if we have more than one baselayer + overlay
isLayersControlVisible = updateLayersControl(map, mapId, isLayersControlVisible, layers.baselayers, newOverlayLayers, leafletLayers);
}, true);
});
}
};
});
'use strict';
angular.module("ui-leaflet").directive('legend', function (leafletLogger, $http, $timeout, leafletHelpers, leafletLegendHelpers) {
var $log = leafletLogger,
errorHeader = leafletHelpers.errorHeader + ' [Legend] ';
return {
restrict: "A",
scope: false,
replace: false,
require: 'leaflet',
transclude: false,
link: function link(scope, element, attrs, controller) {
var isArray = leafletHelpers.isArray,
isString = leafletHelpers.isString,
isDefined = leafletHelpers.isDefined,
isFunction = leafletHelpers.isFunction,
leafletScope = controller.getLeafletScope(),
legend = leafletScope.legend;
var legendClass;
var position;
var leafletLegend;
var type;
leafletScope.$watch('legend', function (newLegend) {
if (isDefined(newLegend)) {
legendClass = newLegend.legendClass ? newLegend.legendClass : "legend";
position = newLegend.position || 'bottomright';
// default to arcgis
type = newLegend.type || 'arcgis';
}
}, true);
var createLegend = function createLegend(map, legendData, newURL) {
if (legendData && legendData.layers && legendData.layers.length > 0) {
if (isDefined(leafletLegend)) {
leafletLegendHelpers.updateLegend(leafletLegend.getContainer(), legendData, type, newURL);
} else {
leafletLegend = L.control({
position: position
});
leafletLegend.onAdd = leafletLegendHelpers.getOnAddLegend(legendData, legendClass, type, newURL);
leafletLegend.addTo(map);
}
if (isDefined(legend.loadedData) && isFunction(legend.loadedData)) {
legend.loadedData();
}
}
};
controller.getMap().then(function (map) {
leafletScope.$watch('legend', function (newLegend) {
if (!isDefined(newLegend)) {
if (isDefined(leafletLegend)) {
leafletLegend.removeFrom(map);
leafletLegend = null;
}
return;
}
if (!isDefined(newLegend.url) && type === 'arcgis' && (!isArray(newLegend.colors) || !isArray(newLegend.labels) || newLegend.colors.length !== newLegend.labels.length)) {
$log.warn(errorHeader + " legend.colors and legend.labels must be set.");
return;
}
if (isDefined(newLegend.url)) {
$log.info(errorHeader + " loading legend service.");
return;
}
if (isDefined(leafletLegend)) {
leafletLegend.removeFrom(map);
leafletLegend = null;
}
leafletLegend = L.control({
position: position
});
if (type === 'arcgis') {
leafletLegend.onAdd = leafletLegendHelpers.getOnAddArrayLegend(newLegend, legendClass);
}
leafletLegend.addTo(map);
});
leafletScope.$watch('legend.url', function (newURL) {
if (!isDefined(newURL)) {
return;
}
if (!isArray(newURL) && !isString(newURL)) {
$log.warn(errorHeader + " legend.url must be an array or string.");
return;
}
var urls = isString(newURL) ? [newURL] : newURL;
var legendData;
var onResult = function onResult(idx, url) {
return function (ld) {
if (isDefined(ld.data.error)) {
$log.warn(errorHeader + 'Error loadin legend from: ' + url, ld.data.error.message);
} else {
if (legendData && legendData.layers && legendData.layers.length > 0) {
legendData.layers = legendData.layers.concat(ld.data.layers);
} else {
legendData = ld.data;
}
}
if (idx === urls.length - 1) {
createLegend(map, legendData, newURL);
}
};
};
var onError = function onError(err) {
$log.warn(errorHeader + ' legend.url not loaded.', err);
};
for (var i = 0; i < urls.length; i++) {
leafletLegendHelpers.addLegendURL(attrs.id, {
url: urls[i],
method: 'GET'
}).then(onResult(i)).catch(onError);
}
});
leafletScope.$watch('legend.legendData', function (legendData) {
$log.debug('legendData', legendData);
if (isDefined(leafletScope.legend.url) || !isDefined(legendData)) {
return;
}
createLegend(map, legendData);
}, true);
});
}
};
});
'use strict';
angular.module('ui-leaflet').directive('markers', function (leafletLogger, $rootScope, $q, leafletData, leafletHelpers, leafletMapDefaults, leafletMarkersHelpers, leafletMarkerEvents, leafletIterators, leafletWatchHelpers, leafletDirectiveControlsHelpers) {
//less terse vars to helpers
var isDefined = leafletHelpers.isDefined,
errorHeader = leafletHelpers.errorHeader,
Helpers = leafletHelpers,
isString = leafletHelpers.isString,
addMarkerWatcher = leafletMarkersHelpers.addMarkerWatcher,
updateMarker = leafletMarkersHelpers.updateMarker,
listenMarkerEvents = leafletMarkersHelpers.listenMarkerEvents,
addMarkerToGroup = leafletMarkersHelpers.addMarkerToGroup,
createMarker = leafletMarkersHelpers.createMarker,
deleteMarker = leafletMarkersHelpers.deleteMarker,
getModelFromModels = leafletMarkersHelpers.getModelFromModels,
getLayerModels = leafletMarkersHelpers.getLayerModels,
resetUnusedMarkerGroups = leafletMarkersHelpers.resetUnusedMarkerGroups,
$it = leafletIterators,
_defaultWatchOptions = leafletHelpers.watchOptions,
maybeWatch = leafletWatchHelpers.maybeWatch,
extendDirectiveControls = leafletDirectiveControlsHelpers.extend,
$log = leafletLogger,
watchTrap = { changeFromDirective: false };
var _getLMarker = function _getLMarker(leafletMarkers, name, maybeLayerName) {
if (!Object.keys(leafletMarkers).length) return;
if (maybeLayerName && isString(maybeLayerName)) {
if (!leafletMarkers[maybeLayerName] || !Object.keys(leafletMarkers[maybeLayerName]).length) return;
return leafletMarkers[maybeLayerName][name];
}
return leafletMarkers[name];
};
var _setLMarker = function _setLMarker(lObject, leafletMarkers, name, maybeLayerName) {
if (maybeLayerName && isString(maybeLayerName)) {
if (!isDefined(leafletMarkers[maybeLayerName])) leafletMarkers[maybeLayerName] = {};
leafletMarkers[maybeLayerName][name] = lObject;
} else leafletMarkers[name] = lObject;
return lObject;
};
var _maybeAddMarkerToLayer = function _maybeAddMarkerToLayer(layerName, layers, model, marker, watchType, map) {
if (!isString(layerName)) {
$log.error(errorHeader + ' A layername must be a string');
return false;
}
if (!isDefined(layers)) {
$log.error(errorHeader + ' You must add layers to the directive if the markers are going to use this functionality.');
return false;
}
if (!isDefined(layers.overlays) || !isDefined(layers.overlays[layerName])) {
$log.error(errorHeader + ' A marker can only be added to a layer of type "group"');
return false;
}
var layerGroup = layers.overlays[layerName];
if (!(layerGroup instanceof L.LayerGroup || layerGroup instanceof L.FeatureGroup)) {
$log.error(errorHeader + ' Adding a marker to an overlay needs a overlay of the type "group" or "featureGroup"');
return false;
}
// The marker goes to a correct layer group, so first of all we add it
layerGroup.addLayer(marker);
// The marker is automatically added to the map depending on the visibility
// of the layer, so we only have to open the popup if the marker is in the map
if (watchType === null && map.hasLayer(marker) && model.focus === true) {
marker.openPopup();
}
return true;
};
//TODO: move to leafletMarkersHelpers??? or make a new class/function file (leafletMarkersHelpers is large already)
var _addMarkers = function _addMarkers(mapId, markersToRender, oldModels, map, layers, leafletMarkers, leafletScope, watchOptions, maybeLayerName, skips) {
$it.each(markersToRender, function (model, newName) {
if (skips[newName]) return;
if (newName.search("-") !== -1) {
$log.error('The marker can\'t use a "-" on his key name: "' + newName + '".');
return;
}
var pathToMarker = Helpers.getObjectDotPath(maybeLayerName ? [maybeLayerName, newName] : [newName]);
var maybeLMarker = _getLMarker(leafletMarkers, newName, maybeLayerName);
Helpers.modelChangeInDirective(watchTrap, "changeFromDirective", function () {
if (!isDefined(maybeLMarker)) {
var marker = createMarker(model);
var layerName = (model ? model.layer : undefined) || maybeLayerName; //original way takes pref
if (!isDefined(marker)) {
$log.error(errorHeader + ' Received invalid data on the marker ' + newName + '.');
return;
}
_setLMarker(marker, leafletMarkers, newName, maybeLayerName);
// Bind message
if (isDefined(model.message)) {
marker.bindPopup(model.message, model.popupOptions);
}
// Add the marker to a cluster group if needed
if (isDefined(model.group)) {
var groupOptions = isDefined(model.groupOption) ? model.groupOption : null;
addMarkerToGroup(marker, model.group, groupOptions, map);
}
// Show label if defined
if (Helpers.LabelPlugin.isLoaded() && isDefined(model.label) && isDefined(model.label.message)) {
marker.bindLabel(model.label.message, model.label.options);
}
// Check if the marker should be added to a layer
if (isDefined(model) && (isDefined(model.layer) || isDefined(maybeLayerName))) {
var pass = _maybeAddMarkerToLayer(layerName, layers, model, marker, watchOptions.individual.type, map);
if (!pass) return; //something went wrong move on in the loop
} else if (!isDefined(model.group)) {
// We do not have a layer attr, so the marker goes to the map layer
map.addLayer(marker);
if (watchOptions.individual.type === null && model.focus === true) {
marker.openPopup();
}
}
if (watchOptions.individual.type !== null) {
addMarkerWatcher(marker, pathToMarker, leafletScope, layers, map, watchOptions.individual);
}
listenMarkerEvents(marker, model, leafletScope, watchOptions.individual.type, map);
leafletMarkerEvents.bindEvents(mapId, marker, pathToMarker, model, leafletScope, layerName);
} else {
var oldModel = getModelFromModels(oldModels, newName, maybeLayerName);
updateMarker(model, oldModel, maybeLMarker, pathToMarker, leafletScope, layers, map);
}
});
});
};
var _seeWhatWeAlreadyHave = function _seeWhatWeAlreadyHave(markerModels, oldMarkerModels, lMarkers, isEqual, cb) {
var hasLogged = false,
equals = false,
oldMarker,
newMarker;
var doCheckOldModel = isDefined(oldMarkerModels);
for (var name in lMarkers) {
if (!hasLogged) {
$log.debug(errorHeader + "[markers] destroy: ");
hasLogged = true;
}
if (doCheckOldModel) {
//might want to make the option (in watch options) to disable deep checking
//ie the options to only check !== (reference check) instead of angular.equals (slow)
newMarker = markerModels[name];
oldMarker = oldMarkerModels[name];
equals = isEqual && angular.equals(newMarker, oldMarker);
}
if (!isDefined(markerModels) || !Object.keys(markerModels).length || !isDefined(markerModels[name]) || !Object.keys(markerModels[name]).length || equals) {
if (cb && Helpers.isFunction(cb)) cb(newMarker, oldMarker, name);
}
}
};
var _destroy = function _destroy(markerModels, oldMarkerModels, lMarkers, map, layers) {
_seeWhatWeAlreadyHave(markerModels, oldMarkerModels, lMarkers, false, function (newMarker, oldMarker, lMarkerName) {
$log.debug(errorHeader + '[marker] is deleting marker: ' + lMarkerName);
deleteMarker(lMarkers[lMarkerName], map, layers);
delete lMarkers[lMarkerName];
});
};
var _getNewModelsToSkipp = function _getNewModelsToSkipp(newModels, oldModels, lMarkers) {
var skips = {};
_seeWhatWeAlreadyHave(newModels, oldModels, lMarkers, true, function (newMarker, oldMarker, lMarkerName) {
$log.debug(errorHeader + '[marker] is already rendered, marker: ' + lMarkerName);
skips[lMarkerName] = newMarker;
});
return skips;
};
return {
restrict: "A",
scope: false,
replace: false,
require: ['leaflet', '?layers'],
link: function link(scope, element, attrs, controller) {
var mapController = controller[0],
leafletScope = mapController.getLeafletScope();
mapController.getMap().then(function (map) {
var leafletMarkers = {},
getLayers;
// If the layers attribute is used, we must wait until the layers are created
if (isDefined(controller[1])) {
getLayers = controller[1].getLayers;
} else {
getLayers = function getLayers() {
var deferred = $q.defer();
deferred.resolve();
return deferred.promise;
};
}
var watchOptions;
if (leafletScope.watchOptions && leafletScope.watchOptions.markers) {
watchOptions = leafletScope.watchOptions.markers;
} else {
watchOptions = _defaultWatchOptions;
}
var isNested = isDefined(attrs.markersNested) && Helpers.isTruthy(attrs.markersNested);
getLayers().then(function (layers) {
var _clean = function _clean(models, oldModels) {
resetUnusedMarkerGroups();
if (isNested) {
$it.each(models, function (markerToMaybeDel, layerName) {
var oldLayerModels = getLayerModels(oldModels, layerName);
_destroy(markerToMaybeDel, oldLayerModels, leafletMarkers[layerName], map, layers);
});
return;
}
_destroy(models, oldModels, leafletMarkers, map, layers);
};
var _create = function _create(models, oldModels) {
_clean(models, oldModels);
var skips = null;
if (isNested) {
$it.each(models, function (markersToAdd, layerName) {
var oldLayerModels = getLayerModels(oldModels, layerName);
var newlayerModels = getLayerModels(models, layerName);
skips = _getNewModelsToSkipp(newlayerModels, oldLayerModels, leafletMarkers[layerName]);
_addMarkers(attrs.id, markersToAdd, oldModels, map, layers, leafletMarkers, leafletScope, watchOptions, layerName, skips);
});
return;
}
skips = _getNewModelsToSkipp(models, oldModels, leafletMarkers);
_addMarkers(attrs.id, models, oldModels, map, layers, leafletMarkers, leafletScope, watchOptions, undefined, skips);
};
extendDirectiveControls(attrs.id, 'markers', _create, _clean);
leafletData.setMarkers(leafletMarkers, attrs.id);
maybeWatch(leafletScope, 'markers', watchOptions, function (newMarkers, oldMarkers) {
if (watchTrap.changeFromDirective) return;
_create(newMarkers, oldMarkers);
});
scope.$on('$destroy', function () {
_destroy(leafletScope.markers, {}, leafletMarkers, map, layers);
});
});
});
}
};
});
'use strict';
angular.module('ui-leaflet').directive('maxbounds', function (leafletLogger, leafletMapDefaults, leafletBoundsHelpers, leafletHelpers) {
// var $log = leafletLogger;
return {
restrict: "A",
scope: false,
replace: false,
require: 'leaflet',
link: function link(scope, element, attrs, controller) {
var leafletScope = controller.getLeafletScope(),
isValidBounds = leafletBoundsHelpers.isValidBounds,
isNumber = leafletHelpers.isNumber;
controller.getMap().then(function (map) {
leafletScope.$watch("maxbounds", function (maxbounds) {
if (!isValidBounds(maxbounds)) {
// Unset any previous maxbounds
map.setMaxBounds();
return;
}
var leafletBounds = leafletBoundsHelpers.createLeafletBounds(maxbounds);
if (isNumber(maxbounds.pad)) {
leafletBounds = leafletBounds.pad(maxbounds.pad);
}
map.setMaxBounds(leafletBounds);
if (!attrs.center && !attrs.lfCenter) {
map.fitBounds(leafletBounds);
}
});
});
}
};
});
'use strict';
angular.module('ui-leaflet').directive('paths', function (leafletLogger, $q, leafletData, leafletMapDefaults, leafletHelpers, leafletPathsHelpers, leafletPathEvents, leafletWatchHelpers) {
var $log = leafletLogger;
return {
restrict: "A",
scope: false,
replace: false,
require: ['leaflet', '?layers'],
link: function link(scope, element, attrs, controller) {
var mapController = controller[0],
isDefined = leafletHelpers.isDefined,
isString = leafletHelpers.isString,
leafletScope = mapController.getLeafletScope(),
paths = leafletScope.paths,
createPath = leafletPathsHelpers.createPath,
bindPathEvents = leafletPathEvents.bindPathEvents,
setPathOptions = leafletPathsHelpers.setPathOptions,
maybeWatch = leafletWatchHelpers.maybeWatch;
mapController.getMap().then(function (map) {
var defaults = leafletMapDefaults.getDefaults(attrs.id),
getLayers;
// If the layers attribute is used, we must wait until the layers are created
if (isDefined(controller[1])) {
getLayers = controller[1].getLayers;
} else {
getLayers = function getLayers() {
var deferred = $q.defer();
deferred.resolve();
return deferred.promise;
};
}
if (!isDefined(paths)) {
return;
}
//legacy behaviour does a watch collection on the paths
var _legacyWatchOptions = {
type: 'watchCollection',
individual: {
type: 'watchDeep'
}
};
var watchOptions;
if (leafletScope.watchOptions && leafletScope.watchOptions.paths) {
watchOptions = leafletScope.watchOptions.paths;
} else {
watchOptions = _legacyWatchOptions;
}
getLayers().then(function (layers) {
var leafletPaths = {};
leafletData.setPaths(leafletPaths, attrs.id);
// Function for listening every single path once created
var watchPathFn = function watchPathFn(leafletPath, name, watchOptions) {
var pathWatchPath = "paths[\"" + name + "\"]";
maybeWatch(leafletScope, pathWatchPath, watchOptions, function (pathData, old, clearWatch) {
if (!isDefined(pathData)) {
if (isDefined(old.layer)) {
for (var i in layers.overlays) {
var overlay = layers.overlays[i];
overlay.removeLayer(leafletPath);
}
}
map.removeLayer(leafletPath);
clearWatch();
return;
}
setPathOptions(leafletPath, pathData.type, pathData);
});
};
var _clean = function _clean(newPaths) {
// Delete paths (by name) from the array
for (var name in leafletPaths) {
if (!isDefined(newPaths[name])) {
map.removeLayer(leafletPaths[name]);
delete leafletPaths[name];
}
}
};
var _create = function _create(newPaths) {
_clean(newPaths);
// Create the new paths
for (var newName in newPaths) {
if (newName.search('\\$') === 0) {
continue;
}
if (newName.search("-") !== -1) {
$log.error('[AngularJS - Leaflet] The path name "' + newName + '" is not valid. It must not include "-" and a number.');
continue;
}
if (!isDefined(leafletPaths[newName])) {
var pathData = newPaths[newName];
var newPath = createPath(newName, newPaths[newName], defaults);
// bind popup if defined
if (isDefined(newPath) && isDefined(pathData.message)) {
newPath.bindPopup(pathData.message, pathData.popupOptions);
}
// Show label if defined
if (leafletHelpers.LabelPlugin.isLoaded() && isDefined(pathData.label) && isDefined(pathData.label.message)) {
newPath.bindLabel(pathData.label.message, pathData.label.options);
}
// Check if the marker should be added to a layer
if (isDefined(pathData) && isDefined(pathData.layer)) {
if (!isString(pathData.layer)) {
$log.error('[AngularJS - Leaflet] A layername must be a string');
continue;
}
if (!isDefined(layers)) {
$log.error('[AngularJS - Leaflet] You must add layers to the directive if the markers are going to use this functionality.');
continue;
}
if (!isDefined(layers.overlays) || !isDefined(layers.overlays[pathData.layer])) {
$log.error('[AngularJS - Leaflet] A path can only be added to a layer of type "group"');
continue;
}
var layerGroup = layers.overlays[pathData.layer];
if (!(layerGroup instanceof L.LayerGroup || layerGroup instanceof L.FeatureGroup)) {
$log.error('[AngularJS - Leaflet] Adding a path to an overlay needs a overlay of the type "group" or "featureGroup"');
continue;
}
// Listen for changes on the new path
leafletPaths[newName] = newPath;
// The path goes to a correct layer group, so first of all we add it
layerGroup.addLayer(newPath);
if (watchOptions.individual.type !== null) {
watchPathFn(newPath, newName, watchOptions.individual);
} else {
setPathOptions(newPath, pathData.type, pathData);
}
} else if (isDefined(newPath)) {
// Listen for changes on the new path
leafletPaths[newName] = newPath;
map.addLayer(newPath);
if (watchOptions.individual.type !== null) {
watchPathFn(newPath, newName, watchOptions.individual);
} else {
setPathOptions(newPath, pathData.type, pathData);
}
}
bindPathEvents(attrs.id, newPath, newName, pathData, leafletScope);
}
}
};
maybeWatch(leafletScope, 'paths', watchOptions, function (newPaths) {
_create(newPaths);
});
});
});
}
};
});
'use strict';
angular.module('ui-leaflet').directive('tiles', function (leafletLogger, leafletData, leafletMapDefaults, leafletHelpers) {
var $log = leafletLogger;
return {
restrict: "A",
scope: false,
replace: false,
require: 'leaflet',
link: function link(scope, element, attrs, controller) {
var isDefined = leafletHelpers.isDefined,
leafletScope = controller.getLeafletScope(),
tiles = leafletScope.tiles;
if (!isDefined(tiles) || !isDefined(tiles.url)) {
$log.warn("[AngularJS - Leaflet] The 'tiles' definition doesn't have the 'url' property.");
return;
}
controller.getMap().then(function (map) {
var defaults = leafletMapDefaults.getDefaults(attrs.id);
var tileLayerObj;
leafletScope.$watch("tiles", function (tiles) {
var tileLayerOptions = defaults.tileLayerOptions;
var tileLayerUrl = defaults.tileLayer;
// If no valid tiles are in the scope, remove the last layer
if (!isDefined(tiles.url) && isDefined(tileLayerObj)) {
map.removeLayer(tileLayerObj);
return;
}
// No leafletTiles object defined yet
if (!isDefined(tileLayerObj)) {
if (isDefined(tiles.options)) {
angular.copy(tiles.options, tileLayerOptions);
}
if (isDefined(tiles.url)) {
tileLayerUrl = tiles.url;
}
tileLayerObj = L.tileLayer(tileLayerUrl, tileLayerOptions);
tileLayerObj.addTo(map);
leafletData.setTiles(tileLayerObj, attrs.id);
return;
}
// If the options of the tilelayer is changed, we need to redraw the layer
if (isDefined(tiles.url) && isDefined(tiles.options) && !angular.equals(tiles.options, tileLayerOptions)) {
map.removeLayer(tileLayerObj);
tileLayerOptions = defaults.tileLayerOptions;
angular.copy(tiles.options, tileLayerOptions);
tileLayerUrl = tiles.url;
tileLayerObj = L.tileLayer(tileLayerUrl, tileLayerOptions);
tileLayerObj.addTo(map);
leafletData.setTiles(tileLayerObj, attrs.id);
return;
}
// Only the URL of the layer is changed, update the tiles object
if (isDefined(tiles.url)) {
tileLayerObj.setUrl(tiles.url);
}
}, true);
});
}
};
});
'use strict';
angular.module('ui-leaflet').directive('watchOptions', ['$log', '$rootScope', '$q', 'leafletData', 'leafletHelpers', function (leafletLogger, $rootScope, $q, leafletData, leafletHelpers) {
var isDefined = leafletHelpers.isDefined,
errorHeader = leafletHelpers.errorHeader,
isObject = leafletHelpers.isObject,
$log = leafletLogger;
return {
restrict: "A",
scope: false,
replace: false,
require: ['leaflet'],
link: function link(scope, element, attrs, controller) {
var mapController = controller[0],
leafletScope = mapController.getLeafletScope();
var _isValidWatchType = function _isValidWatchType(type) {
return type === 'watch' || type === 'watchCollection' || type === 'watchDeep' || type === null;
};
if (isDefined(leafletScope.watchOptions) && isObject(leafletScope.watchOptions)) {
angular.forEach(['markers', 'geojson', 'paths'], function (name) {
if (isDefined(leafletScope.watchOptions[name])) {
if (!_isValidWatchType(leafletScope.watchOptions[name].type)) {
$log.error(errorHeader + ' watchOptions.' + name + '.type is not a valid type.');
}
if (isDefined(leafletScope.watchOptions[name].individual)) {
if (!_isValidWatchType(leafletScope.watchOptions[name].individual.type)) {
$log.error(errorHeader + ' watchOptions.' + name + '.individual.type is not a valid type.');
}
} else {
$log.error(errorHeader + ' watchOptions.' + name + '.type.individual must be defined.');
}
}
});
}
}
};
}]);
'use strict';
angular.module('ui-leaflet').factory('leafletEventsHelpersFactory', function ($rootScope, $q, leafletLogger, leafletHelpers) {
var safeApply = leafletHelpers.safeApply,
isDefined = leafletHelpers.isDefined,
isObject = leafletHelpers.isObject,
isArray = leafletHelpers.isArray,
errorHeader = leafletHelpers.errorHeader,
$log = leafletLogger;
var EventsHelper = function EventsHelper(rootBroadcastName, lObjectType) {
this.rootBroadcastName = rootBroadcastName;
$log.debug("leafletEventsHelpersFactory: lObjectType: " + lObjectType + "rootBroadcastName: " + rootBroadcastName);
//used to path/key out certain properties based on the type , "markers", "geojson"
this.lObjectType = lObjectType;
};
EventsHelper.prototype.getAvailableEvents = function () {
return [];
};
/*
argument: name: Note this can be a single string or dot notation
Example:
markerModel : {
m1: { lat:_, lon: _}
}
//would yield name of
name = "m1"
If nested:
markerModel : {
cars: {
m1: { lat:_, lon: _}
}
}
//would yield name of
name = "cars.m1"
*/
EventsHelper.prototype.genDispatchEvent = function (maybeMapId, eventName, logic, leafletScope, lObject, name, model, layerName, extra) {
var _this = this;
maybeMapId = maybeMapId || '';
if (maybeMapId) maybeMapId = '.' + maybeMapId;
return function (e) {
var broadcastName = _this.rootBroadcastName + maybeMapId + '.' + eventName;
$log.debug(broadcastName);
_this.fire(leafletScope, broadcastName, logic, e, e.target || lObject, model, name, layerName, extra);
};
};
EventsHelper.prototype.fire = function (scope, broadcastName, logic, event, lObject, model, modelName, layerName, extra) {
// Safely broadcast the event
safeApply(scope, function () {
var toSend = {
leafletEvent: event,
leafletObject: lObject,
modelName: modelName,
model: model
};
if (isDefined(layerName)) angular.extend(toSend, { layerName: layerName });
if (logic === "emit") {
scope.$emit(broadcastName, toSend);
} else {
$rootScope.$broadcast(broadcastName, toSend);
}
});
};
EventsHelper.prototype.bindEvents = function (maybeMapId, lObject, name, model, leafletScope, layerName, extra) {
var events = [];
var logic = 'emit';
var _this = this;
if (!isDefined(leafletScope.eventBroadcast)) {
// Backward compatibility, if no event-broadcast attribute, all events are broadcasted
events = this.getAvailableEvents();
} else if (!isObject(leafletScope.eventBroadcast)) {
// Not a valid object
$log.error(errorHeader + "event-broadcast must be an object check your model.");
} else {
// We have a possible valid object
if (!isDefined(leafletScope.eventBroadcast[_this.lObjectType])) {
// We do not have events enable/disable do we do nothing (all enabled by default)
events = this.getAvailableEvents();
} else if (!isObject(leafletScope.eventBroadcast[_this.lObjectType])) {
// Not a valid object
$log.warn(errorHeader + 'event-broadcast.' + [_this.lObjectType] + ' must be an object check your model.');
} else {
// We have a possible valid map object
// Event propadation logic
if (isDefined(leafletScope.eventBroadcast[this.lObjectType].logic)) {
// We take care of possible propagation logic
if (leafletScope.eventBroadcast[_this.lObjectType].logic !== "emit" && leafletScope.eventBroadcast[_this.lObjectType].logic !== "broadcast") $log.warn(errorHeader + "Available event propagation logic are: 'emit' or 'broadcast'.");
}
// Enable / Disable
var eventsEnable = false,
eventsDisable = false;
if (isDefined(leafletScope.eventBroadcast[_this.lObjectType].enable) && isArray(leafletScope.eventBroadcast[_this.lObjectType].enable)) eventsEnable = true;
if (isDefined(leafletScope.eventBroadcast[_this.lObjectType].disable) && isArray(leafletScope.eventBroadcast[_this.lObjectType].disable)) eventsDisable = true;
if (eventsEnable && eventsDisable) {
// Both are active, this is an error
$log.warn(errorHeader + "can not enable and disable events at the same time");
} else if (!eventsEnable && !eventsDisable) {
// Both are inactive, this is an error
$log.warn(errorHeader + "must enable or disable events");
} else {
// At this point the object is OK, lets enable or disable events
if (eventsEnable) {
// Enable events
leafletScope.eventBroadcast[this.lObjectType].enable.forEach(function (eventName) {
// Do we have already the event enabled?
if (events.indexOf(eventName) !== -1) {
// Repeated event, this is an error
$log.warn(errorHeader + "This event " + eventName + " is already enabled");
} else {
// Does the event exists?
if (_this.getAvailableEvents().indexOf(eventName) === -1) {
// The event does not exists, this is an error
$log.warn(errorHeader + "This event " + eventName + " does not exist");
} else {
// All ok enable the event
events.push(eventName);
}
}
});
} else {
// Disable events
events = this.getAvailableEvents();
leafletScope.eventBroadcast[_this.lObjectType].disable.forEach(function (eventName) {
var index = events.indexOf(eventName);
if (index === -1) {
// The event does not exist
$log.warn(errorHeader + "This event " + eventName + " does not exist or has been already disabled");
} else {
events.splice(index, 1);
}
});
}
}
}
}
events.forEach(function (eventName) {
lObject.on(eventName, _this.genDispatchEvent(maybeMapId, eventName, logic, leafletScope, lObject, name, model, layerName, extra));
});
return logic;
};
return EventsHelper;
}).service('leafletEventsHelpers', function (leafletEventsHelpersFactory) {
return new leafletEventsHelpersFactory();
});
'use strict';
angular.module('ui-leaflet').factory('leafletGeoJsonEvents', function ($rootScope, $q, leafletLogger, leafletHelpers, leafletEventsHelpersFactory, leafletData) {
var safeApply = leafletHelpers.safeApply,
EventsHelper = leafletEventsHelpersFactory;
// $log = leafletLogger;
var GeoJsonEvents = function GeoJsonEvents() {
EventsHelper.call(this, 'leafletDirectiveGeoJson', 'geojson');
};
GeoJsonEvents.prototype = new EventsHelper();
GeoJsonEvents.prototype.genDispatchEvent = function (maybeMapId, eventName, logic, leafletScope, lObject, name, model, layerName, extra) {
var base = EventsHelper.prototype.genDispatchEvent.call(this, maybeMapId, eventName, logic, leafletScope, lObject, name, model, layerName),
_this = this;
return function (e) {
if (eventName === 'mouseout') {
if (extra.resetStyleOnMouseout) {
leafletData.getGeoJSON(extra.mapId).then(function (leafletGeoJSON) {
//this is broken on nested needs to traverse or user layerName (nested)
var lobj = layerName ? leafletGeoJSON[layerName] : leafletGeoJSON;
lobj.resetStyle(e.target);
});
}
safeApply(leafletScope, function () {
$rootScope.$broadcast(_this.rootBroadcastName + '.mouseout', e);
});
}
base(e); //common
};
};
GeoJsonEvents.prototype.getAvailableEvents = function () {
return ['click', 'dblclick', 'mouseover', 'mouseout'];
};
return new GeoJsonEvents();
});
'use strict';
angular.module('ui-leaflet').factory('leafletLabelEvents', function ($rootScope, $q, leafletLogger, leafletHelpers, leafletEventsHelpersFactory) {
var Helpers = leafletHelpers,
EventsHelper = leafletEventsHelpersFactory;
//$log = leafletLogger;
var LabelEvents = function LabelEvents() {
EventsHelper.call(this, 'leafletDirectiveLabel', 'markers');
};
LabelEvents.prototype = new EventsHelper();
LabelEvents.prototype.genDispatchEvent = function (maybeMapId, eventName, logic, leafletScope, lObject, name, model, layerName) {
var markerName = name.replace('markers.', '');
return EventsHelper.prototype.genDispatchEvent.call(this, maybeMapId, eventName, logic, leafletScope, lObject, markerName, model, layerName);
};
LabelEvents.prototype.getAvailableEvents = function () {
return ['click', 'dblclick', 'mousedown', 'mouseover', 'mouseout', 'contextmenu'];
};
LabelEvents.prototype.genEvents = function (maybeMapId, eventName, logic, leafletScope, lObject, name, model, layerName) {
var _this = this;
var labelEvents = this.getAvailableEvents();
var scopeWatchName = Helpers.getObjectArrayPath("markers." + name);
labelEvents.forEach(function (eventName) {
lObject.label.on(eventName, _this.genDispatchEvent(maybeMapId, eventName, logic, leafletScope, lObject.label, scopeWatchName, model, layerName));
});
};
LabelEvents.prototype.bindEvents = function (maybeMapId, lObject, name, model, leafletScope, layerName) {};
return new LabelEvents();
});
'use strict';
angular.module('ui-leaflet').factory('leafletMapEvents', function ($rootScope, $q, leafletLogger, leafletHelpers, leafletEventsHelpers, leafletIterators) {
var isDefined = leafletHelpers.isDefined,
fire = leafletEventsHelpers.fire;
var _getAvailableMapEvents = function _getAvailableMapEvents() {
return ['click', 'dblclick', 'mousedown', 'mouseup', 'mouseover', 'mouseout', 'mousemove', 'contextmenu', 'focus', 'blur', 'preclick', 'load', 'unload', 'viewreset', 'movestart', 'move', 'moveend', 'dragstart', 'drag', 'dragend', 'zoomstart', 'zoomanim', 'zoomend', 'zoomlevelschange', 'resize', 'autopanstart', 'layeradd', 'layerremove', 'baselayerchange', 'overlayadd', 'overlayremove', 'locationfound', 'locationerror', 'popupopen', 'popupclose', 'draw:created', 'draw:edited', 'draw:deleted', 'draw:drawstart', 'draw:drawstop', 'draw:editstart', 'draw:editstop', 'draw:deletestart', 'draw:deletestop'];
};
var _genDispatchMapEvent = function _genDispatchMapEvent(scope, eventName, logic, maybeMapId) {
if (maybeMapId) {
maybeMapId = maybeMapId + '.';
}
return function (e) {
// Put together broadcast name
var broadcastName = 'leafletDirectiveMap.' + maybeMapId + eventName;
leafletLogger.debug(broadcastName);
// Safely broadcast the event
fire(scope, broadcastName, logic, e, e.target, scope);
};
};
var _notifyCenterChangedToBounds = function _notifyCenterChangedToBounds(scope) {
scope.$broadcast("boundsChanged");
};
var _notifyCenterUrlHashChanged = function _notifyCenterUrlHashChanged(scope, map, attrs, search) {
if (!isDefined(attrs.urlHashCenter)) {
return;
}
var center = map.getCenter();
var centerUrlHash = center.lat.toFixed(4) + ":" + center.lng.toFixed(4) + ":" + map.getZoom();
if (!isDefined(search.c) || search.c !== centerUrlHash) {
//$log.debug("notified new center...");
scope.$emit("centerUrlHash", centerUrlHash);
}
};
var _addEvents = function _addEvents(map, mapId, mapEvents, contextName, scope, logic) {
leafletIterators.each(mapEvents, function (eventName) {
var context = {};
context[contextName] = eventName;
if (!mapId) {
mapId = map._container.id || '';
}
map.on(eventName, _genDispatchMapEvent(scope, eventName, logic, mapId), context);
});
};
return {
getAvailableMapEvents: _getAvailableMapEvents,
genDispatchMapEvent: _genDispatchMapEvent,
notifyCenterChangedToBounds: _notifyCenterChangedToBounds,
notifyCenterUrlHashChanged: _notifyCenterUrlHashChanged,
addEvents: _addEvents
};
});
'use strict';
angular.module('ui-leaflet').factory('leafletMarkerEvents', function ($rootScope, $q, leafletLogger, leafletHelpers, leafletEventsHelpersFactory, leafletLabelEvents) {
var safeApply = leafletHelpers.safeApply,
isDefined = leafletHelpers.isDefined,
Helpers = leafletHelpers,
lblHelp = leafletLabelEvents,
EventsHelper = leafletEventsHelpersFactory,
$log = leafletLogger;
var MarkerEvents = function MarkerEvents() {
EventsHelper.call(this, 'leafletDirectiveMarker', 'markers');
};
MarkerEvents.prototype = new EventsHelper();
MarkerEvents.prototype.genDispatchEvent = function (maybeMapId, eventName, logic, leafletScope, lObject, name, model, layerName) {
var handle = EventsHelper.prototype.genDispatchEvent.call(this, maybeMapId, eventName, logic, leafletScope, lObject, name, model, layerName);
return function (e) {
// Broadcast old marker click name for backwards compatibility
if (eventName === "click") {
safeApply(leafletScope, function () {
$rootScope.$broadcast('leafletDirectiveMarkersClick', name);
});
} else if (eventName === 'dragend') {
safeApply(leafletScope, function () {
model.lat = lObject.getLatLng().lat;
model.lng = lObject.getLatLng().lng;
});
if (model.message && model.focus === true) {
lObject.openPopup();
}
}
handle(e); //common
};
};
MarkerEvents.prototype.getAvailableEvents = function () {
return ['click', 'dblclick', 'mousedown', 'mouseover', 'mouseout', 'contextmenu', 'dragstart', 'drag', 'dragend', 'move', 'remove', 'popupopen', 'popupclose', 'touchend', 'touchstart', 'touchmove', 'touchcancel', 'touchleave'];
};
MarkerEvents.prototype.bindEvents = function (maybeMapId, lObject, name, model, leafletScope, layerName) {
var logic = EventsHelper.prototype.bindEvents.call(this, maybeMapId, lObject, name, model, leafletScope, layerName);
if (Helpers.LabelPlugin.isLoaded() && isDefined(lObject.label)) {
lblHelp.genEvents(maybeMapId, name, logic, leafletScope, lObject, model, layerName);
}
};
return new MarkerEvents();
});
'use strict';
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
angular.module('ui-leaflet').factory('leafletPathEvents', function ($rootScope, $q, leafletLogger, leafletHelpers, leafletLabelEvents, leafletEventsHelpers) {
var isDefined = leafletHelpers.isDefined,
isObject = leafletHelpers.isObject,
Helpers = leafletHelpers,
errorHeader = leafletHelpers.errorHeader,
lblHelp = leafletLabelEvents,
fire = leafletEventsHelpers.fire,
$log = leafletLogger;
/*
TODO (nmccready) This EventsHelper needs to be derrived from leafletEventsHelpers to elminate copy and paste code.
*/
var _genDispatchPathEvent = function _genDispatchPathEvent(maybeMapId, eventName, logic, leafletScope, lObject, name, model, layerName) {
maybeMapId = maybeMapId || '';
if (maybeMapId) maybeMapId = '.' + maybeMapId;
return function (e) {
var broadcastName = 'leafletDirectivePath' + maybeMapId + '.' + eventName;
$log.debug(broadcastName);
fire(leafletScope, broadcastName, logic, e, e.target || lObject, model, name, layerName);
};
};
var _bindPathEvents = function _bindPathEvents(maybeMapId, lObject, name, model, leafletScope) {
var pathEvents = [],
i,
eventName,
logic = "broadcast";
if (!isDefined(leafletScope.eventBroadcast)) {
// Backward compatibility, if no event-broadcast attribute, all events are broadcasted
pathEvents = _getAvailablePathEvents();
} else if (!isObject(leafletScope.eventBroadcast)) {
// Not a valid object
$log.error(errorHeader + "event-broadcast must be an object check your model.");
} else {
// We have a possible valid object
if (!isDefined(leafletScope.eventBroadcast.path)) {
// We do not have events enable/disable do we do nothing (all enabled by default)
pathEvents = _getAvailablePathEvents();
} else if (isObject(leafletScope.eventBroadcast.paths)) {
// Not a valid object
$log.warn(errorHeader + "event-broadcast.path must be an object check your model.");
} else {
// We have a possible valid map object
// Event propadation logic
if (leafletScope.eventBroadcast.path.logic !== undefined && leafletScope.eventBroadcast.path.logic !== null) {
// We take care of possible propagation logic
if (leafletScope.eventBroadcast.path.logic !== "emit" && leafletScope.eventBroadcast.path.logic !== "broadcast") {
// This is an error
$log.warn(errorHeader + "Available event propagation logic are: 'emit' or 'broadcast'.");
} else if (leafletScope.eventBroadcast.path.logic === "emit") {
logic = "emit";
}
}
// Enable / Disable
var pathEventsEnable = false,
pathEventsDisable = false;
if (leafletScope.eventBroadcast.path.enable !== undefined && leafletScope.eventBroadcast.path.enable !== null) {
if (_typeof(leafletScope.eventBroadcast.path.enable) === 'object') {
pathEventsEnable = true;
}
}
if (leafletScope.eventBroadcast.path.disable !== undefined && leafletScope.eventBroadcast.path.disable !== null) {
if (_typeof(leafletScope.eventBroadcast.path.disable) === 'object') {
pathEventsDisable = true;
}
}
if (pathEventsEnable && pathEventsDisable) {
// Both are active, this is an error
$log.warn(errorHeader + "can not enable and disable events at the same time");
} else if (!pathEventsEnable && !pathEventsDisable) {
// Both are inactive, this is an error
$log.warn(errorHeader + "must enable or disable events");
} else {
// At this point the path object is OK, lets enable or disable events
if (pathEventsEnable) {
// Enable events
for (i = 0; i < leafletScope.eventBroadcast.path.enable.length; i++) {
eventName = leafletScope.eventBroadcast.path.enable[i];
// Do we have already the event enabled?
if (pathEvents.indexOf(eventName) !== -1) {
// Repeated event, this is an error
$log.warn(errorHeader + "This event " + eventName + " is already enabled");
} else {
// Does the event exists?
if (_getAvailablePathEvents().indexOf(eventName) === -1) {
// The event does not exists, this is an error
$log.warn(errorHeader + "This event " + eventName + " does not exist");
} else {
// All ok enable the event
pathEvents.push(eventName);
}
}
}
} else {
// Disable events
pathEvents = _getAvailablePathEvents();
for (i = 0; i < leafletScope.eventBroadcast.path.disable.length; i++) {
eventName = leafletScope.eventBroadcast.path.disable[i];
var index = pathEvents.indexOf(eventName);
if (index === -1) {
// The event does not exist
$log.warn(errorHeader + "This event " + eventName + " does not exist or has been already disabled");
} else {
pathEvents.splice(index, 1);
}
}
}
}
}
}
for (i = 0; i < pathEvents.length; i++) {
eventName = pathEvents[i];
lObject.on(eventName, _genDispatchPathEvent(maybeMapId, eventName, logic, leafletScope, pathEvents, name));
}
if (Helpers.LabelPlugin.isLoaded() && isDefined(lObject.label)) {
lblHelp.genEvents(maybeMapId, name, logic, leafletScope, lObject, model);
}
};
var _getAvailablePathEvents = function _getAvailablePathEvents() {
return ['click', 'dblclick', 'mousedown', 'mouseover', 'mouseout', 'contextmenu', 'add', 'remove', 'popupopen', 'popupclose'];
};
return {
getAvailablePathEvents: _getAvailablePathEvents,
bindPathEvents: _bindPathEvents
};
});
}(angular));
//# sourceMappingURL=ui-leaflet_dev_mapped.js.map