` element
+// and optionally an object literal with `Map options`.
+//
+// @alternative
+// @factory L.map(el: HTMLElement, options?: Map options)
+// Instantiates a map object given an instance of a `
` HTML element
+// and optionally an object literal with `Map options`.
+function createMap(id, options) {
+ return new Map(id, options);
+}
+
+/*
+ * @class Control
+ * @aka L.Control
+ * @inherits Class
+ *
+ * L.Control is a base class for implementing map controls. Handles positioning.
+ * All other controls extend from this class.
+ */
+
+var Control = Class.extend({
+ // @section
+ // @aka Control options
+ options: {
+ // @option position: String = 'topright'
+ // The position of the control (one of the map corners). Possible values are `'topleft'`,
+ // `'topright'`, `'bottomleft'` or `'bottomright'`
+ position: 'topright'
+ },
+
+ initialize: function (options) {
+ setOptions(this, options);
+ },
+
+ /* @section
+ * Classes extending L.Control will inherit the following methods:
+ *
+ * @method getPosition: string
+ * Returns the position of the control.
+ */
+ getPosition: function () {
+ return this.options.position;
+ },
+
+ // @method setPosition(position: string): this
+ // Sets the position of the control.
+ setPosition: function (position) {
+ var map = this._map;
+
+ if (map) {
+ map.removeControl(this);
+ }
+
+ this.options.position = position;
+
+ if (map) {
+ map.addControl(this);
+ }
+
+ return this;
+ },
+
+ // @method getContainer: HTMLElement
+ // Returns the HTMLElement that contains the control.
+ getContainer: function () {
+ return this._container;
+ },
+
+ // @method addTo(map: Map): this
+ // Adds the control to the given map.
+ addTo: function (map) {
+ this.remove();
+ this._map = map;
+
+ var container = this._container = this.onAdd(map),
+ pos = this.getPosition(),
+ corner = map._controlCorners[pos];
+
+ addClass(container, 'leaflet-control');
+
+ if (pos.indexOf('bottom') !== -1) {
+ corner.insertBefore(container, corner.firstChild);
+ } else {
+ corner.appendChild(container);
+ }
+
+ return this;
+ },
+
+ // @method remove: this
+ // Removes the control from the map it is currently active on.
+ remove: function () {
+ if (!this._map) {
+ return this;
+ }
+
+ remove(this._container);
+
+ if (this.onRemove) {
+ this.onRemove(this._map);
+ }
+
+ this._map = null;
+
+ return this;
+ },
+
+ _refocusOnMap: function (e) {
+ // if map exists and event is not a keyboard event
+ if (this._map && e && e.screenX > 0 && e.screenY > 0) {
+ this._map.getContainer().focus();
+ }
+ }
+});
+
+var control = function (options) {
+ return new Control(options);
+};
+
+/* @section Extension methods
+ * @uninheritable
+ *
+ * Every control should extend from `L.Control` and (re-)implement the following methods.
+ *
+ * @method onAdd(map: Map): HTMLElement
+ * Should return the container DOM element for the control and add listeners on relevant map events. Called on [`control.addTo(map)`](#control-addTo).
+ *
+ * @method onRemove(map: Map)
+ * Optional method. Should contain all clean up code that removes the listeners previously added in [`onAdd`](#control-onadd). Called on [`control.remove()`](#control-remove).
+ */
+
+/* @namespace Map
+ * @section Methods for Layers and Controls
+ */
+Map.include({
+ // @method addControl(control: Control): this
+ // Adds the given control to the map
+ addControl: function (control) {
+ control.addTo(this);
+ return this;
+ },
+
+ // @method removeControl(control: Control): this
+ // Removes the given control from the map
+ removeControl: function (control) {
+ control.remove();
+ return this;
+ },
+
+ _initControlPos: function () {
+ var corners = this._controlCorners = {},
+ l = 'leaflet-',
+ container = this._controlContainer =
+ create$1('div', l + 'control-container', this._container);
+
+ function createCorner(vSide, hSide) {
+ var className = l + vSide + ' ' + l + hSide;
+
+ corners[vSide + hSide] = create$1('div', className, container);
+ }
+
+ createCorner('top', 'left');
+ createCorner('top', 'right');
+ createCorner('bottom', 'left');
+ createCorner('bottom', 'right');
+ },
+
+ _clearControlPos: function () {
+ for (var i in this._controlCorners) {
+ remove(this._controlCorners[i]);
+ }
+ remove(this._controlContainer);
+ delete this._controlCorners;
+ delete this._controlContainer;
+ }
+});
+
+/*
+ * @class Control.Layers
+ * @aka L.Control.Layers
+ * @inherits Control
+ *
+ * The layers control gives users the ability to switch between different base layers and switch overlays on/off (check out the [detailed example](http://leafletjs.com/examples/layers-control/)). Extends `Control`.
+ *
+ * @example
+ *
+ * ```js
+ * var baseLayers = {
+ * "Mapbox": mapbox,
+ * "OpenStreetMap": osm
+ * };
+ *
+ * var overlays = {
+ * "Marker": marker,
+ * "Roads": roadsLayer
+ * };
+ *
+ * L.control.layers(baseLayers, overlays).addTo(map);
+ * ```
+ *
+ * The `baseLayers` and `overlays` parameters are object literals with layer names as keys and `Layer` objects as values:
+ *
+ * ```js
+ * {
+ * "
": layer1,
+ * "": layer2
+ * }
+ * ```
+ *
+ * The layer names can contain HTML, which allows you to add additional styling to the items:
+ *
+ * ```js
+ * {" My Layer": myLayer}
+ * ```
+ */
+
+var Layers = Control.extend({
+ // @section
+ // @aka Control.Layers options
+ options: {
+ // @option collapsed: Boolean = true
+ // If `true`, the control will be collapsed into an icon and expanded on mouse hover or touch.
+ collapsed: true,
+ position: 'topright',
+
+ // @option autoZIndex: Boolean = true
+ // If `true`, the control will assign zIndexes in increasing order to all of its layers so that the order is preserved when switching them on/off.
+ autoZIndex: true,
+
+ // @option hideSingleBase: Boolean = false
+ // If `true`, the base layers in the control will be hidden when there is only one.
+ hideSingleBase: false,
+
+ // @option sortLayers: Boolean = false
+ // Whether to sort the layers. When `false`, layers will keep the order
+ // in which they were added to the control.
+ sortLayers: false,
+
+ // @option sortFunction: Function = *
+ // A [compare function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)
+ // that will be used for sorting the layers, when `sortLayers` is `true`.
+ // The function receives both the `L.Layer` instances and their names, as in
+ // `sortFunction(layerA, layerB, nameA, nameB)`.
+ // By default, it sorts layers alphabetically by their name.
+ sortFunction: function (layerA, layerB, nameA, nameB) {
+ return nameA < nameB ? -1 : (nameB < nameA ? 1 : 0);
+ }
+ },
+
+ initialize: function (baseLayers, overlays, options) {
+ setOptions(this, options);
+
+ this._layerControlInputs = [];
+ this._layers = [];
+ this._lastZIndex = 0;
+ this._handlingClick = false;
+
+ for (var i in baseLayers) {
+ this._addLayer(baseLayers[i], i);
+ }
+
+ for (i in overlays) {
+ this._addLayer(overlays[i], i, true);
+ }
+ },
+
+ onAdd: function (map) {
+ this._initLayout();
+ this._update();
+
+ this._map = map;
+ map.on('zoomend', this._checkDisabledLayers, this);
+
+ for (var i = 0; i < this._layers.length; i++) {
+ this._layers[i].layer.on('add remove', this._onLayerChange, this);
+ }
+
+ return this._container;
+ },
+
+ addTo: function (map) {
+ Control.prototype.addTo.call(this, map);
+ // Trigger expand after Layers Control has been inserted into DOM so that is now has an actual height.
+ return this._expandIfNotCollapsed();
+ },
+
+ onRemove: function () {
+ this._map.off('zoomend', this._checkDisabledLayers, this);
+
+ for (var i = 0; i < this._layers.length; i++) {
+ this._layers[i].layer.off('add remove', this._onLayerChange, this);
+ }
+ },
+
+ // @method addBaseLayer(layer: Layer, name: String): this
+ // Adds a base layer (radio button entry) with the given name to the control.
+ addBaseLayer: function (layer, name) {
+ this._addLayer(layer, name);
+ return (this._map) ? this._update() : this;
+ },
+
+ // @method addOverlay(layer: Layer, name: String): this
+ // Adds an overlay (checkbox entry) with the given name to the control.
+ addOverlay: function (layer, name) {
+ this._addLayer(layer, name, true);
+ return (this._map) ? this._update() : this;
+ },
+
+ // @method removeLayer(layer: Layer): this
+ // Remove the given layer from the control.
+ removeLayer: function (layer) {
+ layer.off('add remove', this._onLayerChange, this);
+
+ var obj = this._getLayer(stamp(layer));
+ if (obj) {
+ this._layers.splice(this._layers.indexOf(obj), 1);
+ }
+ return (this._map) ? this._update() : this;
+ },
+
+ // @method expand(): this
+ // Expand the control container if collapsed.
+ expand: function () {
+ addClass(this._container, 'leaflet-control-layers-expanded');
+ this._form.style.height = null;
+ var acceptableHeight = this._map.getSize().y - (this._container.offsetTop + 50);
+ if (acceptableHeight < this._form.clientHeight) {
+ addClass(this._form, 'leaflet-control-layers-scrollbar');
+ this._form.style.height = acceptableHeight + 'px';
+ } else {
+ removeClass(this._form, 'leaflet-control-layers-scrollbar');
+ }
+ this._checkDisabledLayers();
+ return this;
+ },
+
+ // @method collapse(): this
+ // Collapse the control container if expanded.
+ collapse: function () {
+ removeClass(this._container, 'leaflet-control-layers-expanded');
+ return this;
+ },
+
+ _initLayout: function () {
+ var className = 'leaflet-control-layers',
+ container = this._container = create$1('div', className),
+ collapsed = this.options.collapsed;
+
+ // makes this work on IE touch devices by stopping it from firing a mouseout event when the touch is released
+ container.setAttribute('aria-haspopup', true);
+
+ disableClickPropagation(container);
+ disableScrollPropagation(container);
+
+ var form = this._form = create$1('form', className + '-list');
+
+ if (collapsed) {
+ this._map.on('click', this.collapse, this);
+
+ if (!android) {
+ on(container, {
+ mouseenter: this.expand,
+ mouseleave: this.collapse
+ }, this);
+ }
+ }
+
+ var link = this._layersLink = create$1('a', className + '-toggle', container);
+ link.href = '#';
+ link.title = 'Layers';
+
+ if (touch) {
+ on(link, 'click', stop);
+ on(link, 'click', this.expand, this);
+ } else {
+ on(link, 'focus', this.expand, this);
+ }
+
+ if (!collapsed) {
+ this.expand();
+ }
+
+ this._baseLayersList = create$1('div', className + '-base', form);
+ this._separator = create$1('div', className + '-separator', form);
+ this._overlaysList = create$1('div', className + '-overlays', form);
+
+ container.appendChild(form);
+ },
+
+ _getLayer: function (id) {
+ for (var i = 0; i < this._layers.length; i++) {
+
+ if (this._layers[i] && stamp(this._layers[i].layer) === id) {
+ return this._layers[i];
+ }
+ }
+ },
+
+ _addLayer: function (layer, name, overlay) {
+ if (this._map) {
+ layer.on('add remove', this._onLayerChange, this);
+ }
+
+ this._layers.push({
+ layer: layer,
+ name: name,
+ overlay: overlay
+ });
+
+ if (this.options.sortLayers) {
+ this._layers.sort(bind(function (a, b) {
+ return this.options.sortFunction(a.layer, b.layer, a.name, b.name);
+ }, this));
+ }
+
+ if (this.options.autoZIndex && layer.setZIndex) {
+ this._lastZIndex++;
+ layer.setZIndex(this._lastZIndex);
+ }
+
+ this._expandIfNotCollapsed();
+ },
+
+ _update: function () {
+ if (!this._container) { return this; }
+
+ empty(this._baseLayersList);
+ empty(this._overlaysList);
+
+ this._layerControlInputs = [];
+ var baseLayersPresent, overlaysPresent, i, obj, baseLayersCount = 0;
+
+ for (i = 0; i < this._layers.length; i++) {
+ obj = this._layers[i];
+ this._addItem(obj);
+ overlaysPresent = overlaysPresent || obj.overlay;
+ baseLayersPresent = baseLayersPresent || !obj.overlay;
+ baseLayersCount += !obj.overlay ? 1 : 0;
+ }
+
+ // Hide base layers section if there's only one layer.
+ if (this.options.hideSingleBase) {
+ baseLayersPresent = baseLayersPresent && baseLayersCount > 1;
+ this._baseLayersList.style.display = baseLayersPresent ? '' : 'none';
+ }
+
+ this._separator.style.display = overlaysPresent && baseLayersPresent ? '' : 'none';
+
+ return this;
+ },
+
+ _onLayerChange: function (e) {
+ if (!this._handlingClick) {
+ this._update();
+ }
+
+ var obj = this._getLayer(stamp(e.target));
+
+ // @namespace Map
+ // @section Layer events
+ // @event baselayerchange: LayersControlEvent
+ // Fired when the base layer is changed through the [layer control](#control-layers).
+ // @event overlayadd: LayersControlEvent
+ // Fired when an overlay is selected through the [layer control](#control-layers).
+ // @event overlayremove: LayersControlEvent
+ // Fired when an overlay is deselected through the [layer control](#control-layers).
+ // @namespace Control.Layers
+ var type = obj.overlay ?
+ (e.type === 'add' ? 'overlayadd' : 'overlayremove') :
+ (e.type === 'add' ? 'baselayerchange' : null);
+
+ if (type) {
+ this._map.fire(type, obj);
+ }
+ },
+
+ // IE7 bugs out if you create a radio dynamically, so you have to do it this hacky way (see http://bit.ly/PqYLBe)
+ _createRadioElement: function (name, checked) {
+
+ var radioHtml = '';
+
+ var radioFragment = document.createElement('div');
+ radioFragment.innerHTML = radioHtml;
+
+ return radioFragment.firstChild;
+ },
+
+ _addItem: function (obj) {
+ var label = document.createElement('label'),
+ checked = this._map.hasLayer(obj.layer),
+ input;
+
+ if (obj.overlay) {
+ input = document.createElement('input');
+ input.type = 'checkbox';
+ input.className = 'leaflet-control-layers-selector';
+ input.defaultChecked = checked;
+ } else {
+ input = this._createRadioElement('leaflet-base-layers', checked);
+ }
+
+ this._layerControlInputs.push(input);
+ input.layerId = stamp(obj.layer);
+
+ on(input, 'click', this._onInputClick, this);
+
+ var name = document.createElement('span');
+ name.innerHTML = ' ' + obj.name;
+
+ // Helps from preventing layer control flicker when checkboxes are disabled
+ // https://github.com/Leaflet/Leaflet/issues/2771
+ var holder = document.createElement('div');
+
+ label.appendChild(holder);
+ holder.appendChild(input);
+ holder.appendChild(name);
+
+ var container = obj.overlay ? this._overlaysList : this._baseLayersList;
+ container.appendChild(label);
+
+ this._checkDisabledLayers();
+ return label;
+ },
+
+ _onInputClick: function () {
+ var inputs = this._layerControlInputs,
+ input, layer;
+ var addedLayers = [],
+ removedLayers = [];
+
+ this._handlingClick = true;
+
+ for (var i = inputs.length - 1; i >= 0; i--) {
+ input = inputs[i];
+ layer = this._getLayer(input.layerId).layer;
+
+ if (input.checked) {
+ addedLayers.push(layer);
+ } else if (!input.checked) {
+ removedLayers.push(layer);
+ }
+ }
+
+ // Bugfix issue 2318: Should remove all old layers before readding new ones
+ for (i = 0; i < removedLayers.length; i++) {
+ if (this._map.hasLayer(removedLayers[i])) {
+ this._map.removeLayer(removedLayers[i]);
+ }
+ }
+ for (i = 0; i < addedLayers.length; i++) {
+ if (!this._map.hasLayer(addedLayers[i])) {
+ this._map.addLayer(addedLayers[i]);
+ }
+ }
+
+ this._handlingClick = false;
+
+ this._refocusOnMap();
+ },
+
+ _checkDisabledLayers: function () {
+ var inputs = this._layerControlInputs,
+ input,
+ layer,
+ zoom = this._map.getZoom();
+
+ for (var i = inputs.length - 1; i >= 0; i--) {
+ input = inputs[i];
+ layer = this._getLayer(input.layerId).layer;
+ input.disabled = (layer.options.minZoom !== undefined && zoom < layer.options.minZoom) ||
+ (layer.options.maxZoom !== undefined && zoom > layer.options.maxZoom);
+
+ }
+ },
+
+ _expandIfNotCollapsed: function () {
+ if (this._map && !this.options.collapsed) {
+ this.expand();
+ }
+ return this;
+ },
+
+ _expand: function () {
+ // Backward compatibility, remove me in 1.1.
+ return this.expand();
+ },
+
+ _collapse: function () {
+ // Backward compatibility, remove me in 1.1.
+ return this.collapse();
+ }
+
+});
+
+
+// @factory L.control.layers(baselayers?: Object, overlays?: Object, options?: Control.Layers options)
+// Creates an attribution control with the given layers. Base layers will be switched with radio buttons, while overlays will be switched with checkboxes. Note that all base layers should be passed in the base layers object, but only one should be added to the map during map instantiation.
+var layers = function (baseLayers, overlays, options) {
+ return new Layers(baseLayers, overlays, options);
+};
+
+/*
+ * @class Control.Zoom
+ * @aka L.Control.Zoom
+ * @inherits Control
+ *
+ * A basic zoom control with two buttons (zoom in and zoom out). It is put on the map by default unless you set its [`zoomControl` option](#map-zoomcontrol) to `false`. Extends `Control`.
+ */
+
+var Zoom = Control.extend({
+ // @section
+ // @aka Control.Zoom options
+ options: {
+ position: 'topleft',
+
+ // @option zoomInText: String = '+'
+ // The text set on the 'zoom in' button.
+ zoomInText: '+',
+
+ // @option zoomInTitle: String = 'Zoom in'
+ // The title set on the 'zoom in' button.
+ zoomInTitle: 'Zoom in',
+
+ // @option zoomOutText: String = '−'
+ // The text set on the 'zoom out' button.
+ zoomOutText: '−',
+
+ // @option zoomOutTitle: String = 'Zoom out'
+ // The title set on the 'zoom out' button.
+ zoomOutTitle: 'Zoom out'
+ },
+
+ onAdd: function (map) {
+ var zoomName = 'leaflet-control-zoom',
+ container = create$1('div', zoomName + ' leaflet-bar'),
+ options = this.options;
+
+ this._zoomInButton = this._createButton(options.zoomInText, options.zoomInTitle,
+ zoomName + '-in', container, this._zoomIn);
+ this._zoomOutButton = this._createButton(options.zoomOutText, options.zoomOutTitle,
+ zoomName + '-out', container, this._zoomOut);
+
+ this._updateDisabled();
+ map.on('zoomend zoomlevelschange', this._updateDisabled, this);
+
+ return container;
+ },
+
+ onRemove: function (map) {
+ map.off('zoomend zoomlevelschange', this._updateDisabled, this);
+ },
+
+ disable: function () {
+ this._disabled = true;
+ this._updateDisabled();
+ return this;
+ },
+
+ enable: function () {
+ this._disabled = false;
+ this._updateDisabled();
+ return this;
+ },
+
+ _zoomIn: function (e) {
+ if (!this._disabled && this._map._zoom < this._map.getMaxZoom()) {
+ this._map.zoomIn(this._map.options.zoomDelta * (e.shiftKey ? 3 : 1));
+ }
+ },
+
+ _zoomOut: function (e) {
+ if (!this._disabled && this._map._zoom > this._map.getMinZoom()) {
+ this._map.zoomOut(this._map.options.zoomDelta * (e.shiftKey ? 3 : 1));
+ }
+ },
+
+ _createButton: function (html, title, className, container, fn) {
+ var link = create$1('a', className, container);
+ link.innerHTML = html;
+ link.href = '#';
+ link.title = title;
+
+ /*
+ * Will force screen readers like VoiceOver to read this as "Zoom in - button"
+ */
+ link.setAttribute('role', 'button');
+ link.setAttribute('aria-label', title);
+
+ disableClickPropagation(link);
+ on(link, 'click', stop);
+ on(link, 'click', fn, this);
+ on(link, 'click', this._refocusOnMap, this);
+
+ return link;
+ },
+
+ _updateDisabled: function () {
+ var map = this._map,
+ className = 'leaflet-disabled';
+
+ removeClass(this._zoomInButton, className);
+ removeClass(this._zoomOutButton, className);
+
+ if (this._disabled || map._zoom === map.getMinZoom()) {
+ addClass(this._zoomOutButton, className);
+ }
+ if (this._disabled || map._zoom === map.getMaxZoom()) {
+ addClass(this._zoomInButton, className);
+ }
+ }
+});
+
+// @namespace Map
+// @section Control options
+// @option zoomControl: Boolean = true
+// Whether a [zoom control](#control-zoom) is added to the map by default.
+Map.mergeOptions({
+ zoomControl: true
+});
+
+Map.addInitHook(function () {
+ if (this.options.zoomControl) {
+ this.zoomControl = new Zoom();
+ this.addControl(this.zoomControl);
+ }
+});
+
+// @namespace Control.Zoom
+// @factory L.control.zoom(options: Control.Zoom options)
+// Creates a zoom control
+var zoom = function (options) {
+ return new Zoom(options);
+};
+
+/*
+ * @class Control.Scale
+ * @aka L.Control.Scale
+ * @inherits Control
+ *
+ * A simple scale control that shows the scale of the current center of screen in metric (m/km) and imperial (mi/ft) systems. Extends `Control`.
+ *
+ * @example
+ *
+ * ```js
+ * L.control.scale().addTo(map);
+ * ```
+ */
+
+var Scale = Control.extend({
+ // @section
+ // @aka Control.Scale options
+ options: {
+ position: 'bottomleft',
+
+ // @option maxWidth: Number = 100
+ // Maximum width of the control in pixels. The width is set dynamically to show round values (e.g. 100, 200, 500).
+ maxWidth: 100,
+
+ // @option metric: Boolean = True
+ // Whether to show the metric scale line (m/km).
+ metric: true,
+
+ // @option imperial: Boolean = True
+ // Whether to show the imperial scale line (mi/ft).
+ imperial: true
+
+ // @option updateWhenIdle: Boolean = false
+ // If `true`, the control is updated on [`moveend`](#map-moveend), otherwise it's always up-to-date (updated on [`move`](#map-move)).
+ },
+
+ onAdd: function (map) {
+ var className = 'leaflet-control-scale',
+ container = create$1('div', className),
+ options = this.options;
+
+ this._addScales(options, className + '-line', container);
+
+ map.on(options.updateWhenIdle ? 'moveend' : 'move', this._update, this);
+ map.whenReady(this._update, this);
+
+ return container;
+ },
+
+ onRemove: function (map) {
+ map.off(this.options.updateWhenIdle ? 'moveend' : 'move', this._update, this);
+ },
+
+ _addScales: function (options, className, container) {
+ if (options.metric) {
+ this._mScale = create$1('div', className, container);
+ }
+ if (options.imperial) {
+ this._iScale = create$1('div', className, container);
+ }
+ },
+
+ _update: function () {
+ var map = this._map,
+ y = map.getSize().y / 2;
+
+ var maxMeters = map.distance(
+ map.containerPointToLatLng([0, y]),
+ map.containerPointToLatLng([this.options.maxWidth, y]));
+
+ this._updateScales(maxMeters);
+ },
+
+ _updateScales: function (maxMeters) {
+ if (this.options.metric && maxMeters) {
+ this._updateMetric(maxMeters);
+ }
+ if (this.options.imperial && maxMeters) {
+ this._updateImperial(maxMeters);
+ }
+ },
+
+ _updateMetric: function (maxMeters) {
+ var meters = this._getRoundNum(maxMeters),
+ label = meters < 1000 ? meters + ' m' : (meters / 1000) + ' km';
+
+ this._updateScale(this._mScale, label, meters / maxMeters);
+ },
+
+ _updateImperial: function (maxMeters) {
+ var maxFeet = maxMeters * 3.2808399,
+ maxMiles, miles, feet;
+
+ if (maxFeet > 5280) {
+ maxMiles = maxFeet / 5280;
+ miles = this._getRoundNum(maxMiles);
+ this._updateScale(this._iScale, miles + ' mi', miles / maxMiles);
+
+ } else {
+ feet = this._getRoundNum(maxFeet);
+ this._updateScale(this._iScale, feet + ' ft', feet / maxFeet);
+ }
+ },
+
+ _updateScale: function (scale, text, ratio) {
+ scale.style.width = Math.round(this.options.maxWidth * ratio) + 'px';
+ scale.innerHTML = text;
+ },
+
+ _getRoundNum: function (num) {
+ var pow10 = Math.pow(10, (Math.floor(num) + '').length - 1),
+ d = num / pow10;
+
+ d = d >= 10 ? 10 :
+ d >= 5 ? 5 :
+ d >= 3 ? 3 :
+ d >= 2 ? 2 : 1;
+
+ return pow10 * d;
+ }
+});
+
+
+// @factory L.control.scale(options?: Control.Scale options)
+// Creates an scale control with the given options.
+var scale = function (options) {
+ return new Scale(options);
+};
+
+/*
+ * @class Control.Attribution
+ * @aka L.Control.Attribution
+ * @inherits Control
+ *
+ * The attribution control allows you to display attribution data in a small text box on a map. It is put on the map by default unless you set its [`attributionControl` option](#map-attributioncontrol) to `false`, and it fetches attribution texts from layers with the [`getAttribution` method](#layer-getattribution) automatically. Extends Control.
+ */
+
+var Attribution = Control.extend({
+ // @section
+ // @aka Control.Attribution options
+ options: {
+ position: 'bottomright',
+
+ // @option prefix: String = 'Leaflet'
+ // The HTML text shown before the attributions. Pass `false` to disable.
+ prefix: 'Leaflet'
+ },
+
+ initialize: function (options) {
+ setOptions(this, options);
+
+ this._attributions = {};
+ },
+
+ onAdd: function (map) {
+ map.attributionControl = this;
+ this._container = create$1('div', 'leaflet-control-attribution');
+ disableClickPropagation(this._container);
+
+ // TODO ugly, refactor
+ for (var i in map._layers) {
+ if (map._layers[i].getAttribution) {
+ this.addAttribution(map._layers[i].getAttribution());
+ }
+ }
+
+ this._update();
+
+ return this._container;
+ },
+
+ // @method setPrefix(prefix: String): this
+ // Sets the text before the attributions.
+ setPrefix: function (prefix) {
+ this.options.prefix = prefix;
+ this._update();
+ return this;
+ },
+
+ // @method addAttribution(text: String): this
+ // Adds an attribution text (e.g. `'Vector data © Mapbox'`).
+ addAttribution: function (text) {
+ if (!text) { return this; }
+
+ if (!this._attributions[text]) {
+ this._attributions[text] = 0;
+ }
+ this._attributions[text]++;
+
+ this._update();
+
+ return this;
+ },
+
+ // @method removeAttribution(text: String): this
+ // Removes an attribution text.
+ removeAttribution: function (text) {
+ if (!text) { return this; }
+
+ if (this._attributions[text]) {
+ this._attributions[text]--;
+ this._update();
+ }
+
+ return this;
+ },
+
+ _update: function () {
+ if (!this._map) { return; }
+
+ var attribs = [];
+
+ for (var i in this._attributions) {
+ if (this._attributions[i]) {
+ attribs.push(i);
+ }
+ }
+
+ var prefixAndAttribs = [];
+
+ if (this.options.prefix) {
+ prefixAndAttribs.push(this.options.prefix);
+ }
+ if (attribs.length) {
+ prefixAndAttribs.push(attribs.join(', '));
+ }
+
+ this._container.innerHTML = prefixAndAttribs.join(' | ');
+ }
+});
+
+// @namespace Map
+// @section Control options
+// @option attributionControl: Boolean = true
+// Whether a [attribution control](#control-attribution) is added to the map by default.
+Map.mergeOptions({
+ attributionControl: true
+});
+
+Map.addInitHook(function () {
+ if (this.options.attributionControl) {
+ new Attribution().addTo(this);
+ }
+});
+
+// @namespace Control.Attribution
+// @factory L.control.attribution(options: Control.Attribution options)
+// Creates an attribution control.
+var attribution = function (options) {
+ return new Attribution(options);
+};
+
+Control.Layers = Layers;
+Control.Zoom = Zoom;
+Control.Scale = Scale;
+Control.Attribution = Attribution;
+
+control.layers = layers;
+control.zoom = zoom;
+control.scale = scale;
+control.attribution = attribution;
+
+/*
+ L.Handler is a base class for handler classes that are used internally to inject
+ interaction features like dragging to classes like Map and Marker.
+*/
+
+// @class Handler
+// @aka L.Handler
+// Abstract class for map interaction handlers
+
+var Handler = Class.extend({
+ initialize: function (map) {
+ this._map = map;
+ },
+
+ // @method enable(): this
+ // Enables the handler
+ enable: function () {
+ if (this._enabled) { return this; }
+
+ this._enabled = true;
+ this.addHooks();
+ return this;
+ },
+
+ // @method disable(): this
+ // Disables the handler
+ disable: function () {
+ if (!this._enabled) { return this; }
+
+ this._enabled = false;
+ this.removeHooks();
+ return this;
+ },
+
+ // @method enabled(): Boolean
+ // Returns `true` if the handler is enabled
+ enabled: function () {
+ return !!this._enabled;
+ }
+
+ // @section Extension methods
+ // Classes inheriting from `Handler` must implement the two following methods:
+ // @method addHooks()
+ // Called when the handler is enabled, should add event hooks.
+ // @method removeHooks()
+ // Called when the handler is disabled, should remove the event hooks added previously.
+});
+
+// @section There is static function which can be called without instantiating L.Handler:
+// @function addTo(map: Map, name: String): this
+// Adds a new Handler to the given map with the given name.
+Handler.addTo = function (map, name) {
+ map.addHandler(name, this);
+ return this;
+};
+
+var Mixin = {Events: Events};
+
+/*
+ * @class Draggable
+ * @aka L.Draggable
+ * @inherits Evented
+ *
+ * A class for making DOM elements draggable (including touch support).
+ * Used internally for map and marker dragging. Only works for elements
+ * that were positioned with [`L.DomUtil.setPosition`](#domutil-setposition).
+ *
+ * @example
+ * ```js
+ * var draggable = new L.Draggable(elementToDrag);
+ * draggable.enable();
+ * ```
+ */
+
+var START = touch ? 'touchstart mousedown' : 'mousedown';
+var END = {
+ mousedown: 'mouseup',
+ touchstart: 'touchend',
+ pointerdown: 'touchend',
+ MSPointerDown: 'touchend'
+};
+var MOVE = {
+ mousedown: 'mousemove',
+ touchstart: 'touchmove',
+ pointerdown: 'touchmove',
+ MSPointerDown: 'touchmove'
+};
+
+
+var Draggable = Evented.extend({
+
+ options: {
+ // @section
+ // @aka Draggable options
+ // @option clickTolerance: Number = 3
+ // The max number of pixels a user can shift the mouse pointer during a click
+ // for it to be considered a valid click (as opposed to a mouse drag).
+ clickTolerance: 3
+ },
+
+ // @constructor L.Draggable(el: HTMLElement, dragHandle?: HTMLElement, preventOutline?: Boolean, options?: Draggable options)
+ // Creates a `Draggable` object for moving `el` when you start dragging the `dragHandle` element (equals `el` itself by default).
+ initialize: function (element, dragStartTarget, preventOutline$$1, options) {
+ setOptions(this, options);
+
+ this._element = element;
+ this._dragStartTarget = dragStartTarget || element;
+ this._preventOutline = preventOutline$$1;
+ },
+
+ // @method enable()
+ // Enables the dragging ability
+ enable: function () {
+ if (this._enabled) { return; }
+
+ on(this._dragStartTarget, START, this._onDown, this);
+
+ this._enabled = true;
+ },
+
+ // @method disable()
+ // Disables the dragging ability
+ disable: function () {
+ if (!this._enabled) { return; }
+
+ // If we're currently dragging this draggable,
+ // disabling it counts as first ending the drag.
+ if (Draggable._dragging === this) {
+ this.finishDrag();
+ }
+
+ off(this._dragStartTarget, START, this._onDown, this);
+
+ this._enabled = false;
+ this._moved = false;
+ },
+
+ _onDown: function (e) {
+ // Ignore simulated events, since we handle both touch and
+ // mouse explicitly; otherwise we risk getting duplicates of
+ // touch events, see #4315.
+ // Also ignore the event if disabled; this happens in IE11
+ // under some circumstances, see #3666.
+ if (e._simulated || !this._enabled) { return; }
+
+ this._moved = false;
+
+ if (hasClass(this._element, 'leaflet-zoom-anim')) { return; }
+
+ if (Draggable._dragging || e.shiftKey || ((e.which !== 1) && (e.button !== 1) && !e.touches)) { return; }
+ Draggable._dragging = this; // Prevent dragging multiple objects at once.
+
+ if (this._preventOutline) {
+ preventOutline(this._element);
+ }
+
+ disableImageDrag();
+ disableTextSelection();
+
+ if (this._moving) { return; }
+
+ // @event down: Event
+ // Fired when a drag is about to start.
+ this.fire('down');
+
+ var first = e.touches ? e.touches[0] : e;
+
+ this._startPoint = new Point(first.clientX, first.clientY);
+
+ on(document, MOVE[e.type], this._onMove, this);
+ on(document, END[e.type], this._onUp, this);
+ },
+
+ _onMove: function (e) {
+ // Ignore simulated events, since we handle both touch and
+ // mouse explicitly; otherwise we risk getting duplicates of
+ // touch events, see #4315.
+ // Also ignore the event if disabled; this happens in IE11
+ // under some circumstances, see #3666.
+ if (e._simulated || !this._enabled) { return; }
+
+ if (e.touches && e.touches.length > 1) {
+ this._moved = true;
+ return;
+ }
+
+ var first = (e.touches && e.touches.length === 1 ? e.touches[0] : e),
+ newPoint = new Point(first.clientX, first.clientY),
+ offset = newPoint.subtract(this._startPoint);
+
+ if (!offset.x && !offset.y) { return; }
+ if (Math.abs(offset.x) + Math.abs(offset.y) < this.options.clickTolerance) { return; }
+
+ preventDefault(e);
+
+ if (!this._moved) {
+ // @event dragstart: Event
+ // Fired when a drag starts
+ this.fire('dragstart');
+
+ this._moved = true;
+ this._startPos = getPosition(this._element).subtract(offset);
+
+ addClass(document.body, 'leaflet-dragging');
+
+ this._lastTarget = e.target || e.srcElement;
+ // IE and Edge do not give the