mohsen-angular-leaflet-directive
Version:
angular-leaflet-directive - An AngularJS directive to easily interact with Leaflet maps
71 lines (61 loc) • 2.28 kB
JavaScript
angular.module('leaflet-directive')
.factory('leafletMarkerEvents', function($rootScope, $q, leafletLogger, leafletHelpers, LeafletEventsHelpersFactory, leafletLabelEvents) {
var safeApply = leafletHelpers.safeApply;
var isDefined = leafletHelpers.isDefined;
var Helpers = leafletHelpers;
var lblHelp = leafletLabelEvents;
var EventsHelper = LeafletEventsHelpersFactory;
var MarkerEvents = function() {
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();
});