UNPKG

mohsen-angular-leaflet-directive

Version:

angular-leaflet-directive - An AngularJS directive to easily interact with Leaflet maps

48 lines (38 loc) 1.57 kB
angular.module('leaflet-directive') .factory('leafletGeoJsonEvents', function($rootScope, $q, leafletLogger, leafletHelpers, LeafletEventsHelpersFactory, leafletData) { var safeApply = leafletHelpers.safeApply; var EventsHelper = LeafletEventsHelpersFactory; var GeoJsonEvents = function() { 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); var _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(); });