all files / src/ index.js

89.78% Statements 123/137
70.69% Branches 41/58
96.43% Functions 27/28
90.29% Lines 93/103
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
/******/ (function(modules) { // webpackBootstrap
/******/ 	// The module cache
/******/ 	var installedModules = {};
 
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
 
/******/ 		// Check if module is in cache
/******/ 		Iif(installedModules[moduleId])
/******/ 			return installedModules[moduleId].exports;
 
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = installedModules[moduleId] = {
/******/ 			exports: {},
/******/ 			id: moduleId,
/******/ 			loaded: false
/******/ 		};
 
/******/ 		// Execute the module function
/******/ 		modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
 
/******/ 		// Flag the module as loaded
/******/ 		module.loaded = true;
 
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
 
 
/******/ 	// expose the modules object (__webpack_modules__)
/******/ 	__webpack_require__.m = modules;
 
/******/ 	// expose the module cache
/******/ 	__webpack_require__.c = installedModules;
 
/******/ 	// __webpack_public_path__
/******/ 	__webpack_require__.p = "/_karma_webpack_//";
 
/******/ 	// Load entry module and return exports
/******/ 	return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
 
	'use strict';
 
	Object.defineProperty(exports, "__esModule", {
	    value: true
	});
 
	var _leaflet = __webpack_require__(1);
 
	var _leaflet2 = _interopRequireDefault(_leaflet);
 
	var _leaflet3 = __webpack_require__(3);
 
	var _leaflet4 = _interopRequireDefault(_leaflet3);
 
	function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
 
	/* angular module angular-leaflet */
	exports.default = angular.module('angular-leaflet', [])
 
	/**
	 * This component provide a default leaflet map initialized with id='map'
	 * if no id has been provided.
	 * @usage
	    <leaflet on-map-initialized="$ctrl.onMapInitialized(map)"></leaflet>
	*/
	.component('leaflet', {
	    template: '<div></div>',
	    controller: _leaflet4.default,
	    bindings: {
	        onMapInitialized: '&'
	    }
	}).provider('leafletService', _leaflet2.default);
 
/***/ },
/* 1 */
/***/ function(module, exports, __webpack_require__) {
 
	'use strict';
 
	Object.defineProperty(exports, "__esModule", {
	    value: true
	});
 
	var _leaflet = __webpack_require__(2);
 
	var _leaflet2 = _interopRequireDefault(_leaflet);
 
	function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
 
	/**
	 * LeafletServiceProvider
	 * @constructor
	 */
	function LeafletServiceProvider() {
	    var defaultSettings = {
	        tiles: {
	            url: 'http://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png',
	            options: {
	                attribution: '&copy; Openstreetmap France | &copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
	                maxZoom: 19
	            }
	        },
	        center: {
	            lat: 47.21117290969667,
	            lng: -1.5569686889648438,
	            zoom: 12
	        }
	    };
	    this.settings = {};
	    this.$get = function factory($compile) {
	        'ngInject';
 
	        var service = new _leaflet2.default($compile);
	        service.settings = defaultSettings;
	        for (var pp in this.settings) {
	            service.settings[pp] = this.settings[pp];
	        }
	        return service;
	    };
	    this.$get.$inject = ['$compile'];
	}
 
	exports.default = LeafletServiceProvider;
 
/***/ },
/* 2 */
/***/ function(module, exports) {
 
	'use strict';
 
	Object.defineProperty(exports, "__esModule", {
	    value: true
	});
 
	var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; Eif ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { Eif (protoProps) defineProperties(Constructor.prototype, protoProps); Iif (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
 
	function _classCallCheck(instance, Constructor) { Iif (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
 
	/**
	 * Class LeafletService which provide API 
	 * to let leaflet work well with AngularJS
	 * You can pass settings throw the provider
	 */
 
	var LeafletService = function () {
	    /**
	     * LeafletService constructor
	     * @constructor
	     * @param  {Object} $compile angular $compile
	     */
 
	    function LeafletService($complie) {
	        _classCallCheck(this, LeafletService);
 
	        this.settings = {};
	        this.data = {};
	    }
 
	    /**
	     * handle events
	     * @description integrate Leaflet map.on function with angular
	     * most of the work consist to call scope.$apply only if needed
	     * @param {String} event the name of the event to listen like 'click'
	     * You will find all supported event on the http://leafletjs.com/reference.html#
	     * @param {function} callback the function to call when this event happens
	     * @param {Object} leafletObject the object that has '.on' function
	     * @param {Ojbect} scope the scope of your current controller/directive/component
	    */
 
 
	    _createClass(LeafletService, [{
	        key: 'on',
	        value: function on(event, callback, lobj, scope) {
	            lobj.on(event, function (e) {
	                callback(e);
	                if (scope.$root.$$phase != '$apply' && scope.$root.$$phase != '$digest') {
	                    scope.$apply();
	                }
	            });
	            scope.$on('$destroy', function () {
	                lobj.off(event, callback);
	            });
	        }
 
	        /**
	         * @description integrate Leaflet map.on function with angular
	         * most of the work consist to call scope.$apply only if needed.
	         * @example
	         var settings = {
	            center: {
	                lat: 47.184112659842015,
	                lng: -1.619110107421875,
	                zoom: 17
	            },
	            minZoom: 12,
	            maxBounds: [[47.143496,-1.652756],[47.296462,-1.461868]]
	            tiles: {
	                url: 'http://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png',
	                options: {
	                    attribution: '&copy; Openstreetmap France | &copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
	                    maxZoom: 19
	                }
	            },
	            layers: {
	                baselayers: {
	                    layerid: {}
	                },
	                overlays: {
	                    overlayid: {}
	                }
	            }
	         };
	         * @param {Object} map the leaflet map object update
	         * @param {Object} settings
	        */
 
	    }, {
	        key: 'updateMapFromSettings',
	        value: function updateMapFromSettings(map, settings) {
	            var s = settings || this.settings;
	            Eif (s.center) {
	                map.setView([s.center.lat, s.center.lng], s.center.zoom);
	            }
	            if (s.minZoom) {
	                map.options.minZoom = s.minZoom;
	            }
	            if (s.maxZoom) {
	                map.options.maxZoom = s.maxZoom;
	            }
	            if (s.maxBounds) {
	                map.setMaxBounds(s.maxBounds);
	            }
	            Eif (s.tiles) {
	                L.tileLayer(s.tiles.url, s.tiles.options).addTo(map);
	            }
	            if (s.layers) {
	                var baselayers = {};
	                var overlays = {};
	                Iif (s.layers.baselayers) {
	                    for (var layerid in s.layers.baselayers) {
	                        var layer = s.layers.baselayers[layerid];
	                        baselayers[layer.name] = L.tileLayer(layer.url, layer.options);
	                    }
	                }
	                Iif (s.layers.overlays) {
	                    for (var _layerid in s.layers.overlays) {
	                        var _layer = s.layers.overlays[_layerid];
	                        overlays[_layer.name] = L.tileLayer(_layer.url, _layer.options);
	                    }
	                }
	                L.control.layers(baselayers, overlays).addTo(map);
	            }
	        }
	    }]);
 
	    return LeafletService;
	}();
 
	LeafletService.$inject = ['$compile'];
	exports.default = LeafletService;
 
/***/ },
/* 3 */
/***/ function(module, exports) {
 
	'use strict';
 
	Object.defineProperty(exports, "__esModule", {
	    value: true
	});
 
	var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; Eif ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { Eif (protoProps) defineProperties(Constructor.prototype, protoProps); Iif (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
 
	function _classCallCheck(instance, Constructor) { Iif (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
 
	/**
	 * Class LeafletCtrl
	 * This is the controller of the leaflet directive
	 */
 
	var LeafletCtrl = function () {
	    /**
	     * LeafletCtrl constructor
	     * @constructor
	     * @param {Object} $element angular $element
	     * @param {Object} leafletService local service
	     */
 
	    function LeafletCtrl($element, leafletService) {
	        _classCallCheck(this, LeafletCtrl);
 
	        this.$element = $element;
	        this.leafletService = leafletService;
	    }
 
	    _createClass(LeafletCtrl, [{
	        key: '$onInit',
	        value: function $onInit() {
	            this.mapid = this.$element.attr('id') || 'map';
	            this.$element.removeAttr('id');
	            var div = this.$element.find('div');
	            div.attr('id', this.mapid);
	            div.attr('id', this.mapid);
	            div.attr('style', this.$element.attr('style'));
	            div.attr('class', this.$element.attr('class'));
	            this.container = div[0];
	        }
	    }, {
	        key: '$postLink',
	        value: function $postLink() {
	            Iif (!L.Icon.Default.imagePath && this.leafletService.settings.imagePath) {
	                L.Icon.Default.imagePath = this.leafletService.settings.imagePath;
	            }
	            var map = L.map(this.container);
	            this.leafletService.data[this.mapid] = map;
	            this.leafletService.updateMapFromSettings(map);
	            this.onMapInitialized({ map: map });
	        }
	    }]);
 
	    return LeafletCtrl;
	}();
 
	LeafletCtrl.$inject = ['$element', 'leafletService'];
	exports.default = LeafletCtrl;
 
/***/ }
/******/ ]);