/* @preserve
- * Leaflet 1.3.2, a JS library for interactive maps. http://leafletjs.com
+ * Leaflet 1.4.0, a JS library for interactive maps. http://leafletjs.com
* (c) 2010-2018 Vladimir Agafonkin, (c) 2010-2011 CloudMade
*/
(factory((global.L = {})));
}(this, (function (exports) { 'use strict';
-var version = "1.3.2";
+var version = "1.4.0";
/*
* @namespace Util
// @property TRANSFORM: String
// Vendor-prefixed transform style name (e.g. `'webkitTransform'` for WebKit).
var TRANSFORM = testProp(
- ['transform', 'WebkitTransform', 'OTransform', 'MozTransform', 'msTransform']);
+ ['transform', 'webkitTransform', 'OTransform', 'MozTransform', 'msTransform']);
// webkitTransition comes first because some browser versions that drop vendor prefix don't do
// the same for the transitionend event, in particular the Android 4.1 stock browser
// Makes `el` the last child of its parent, so it renders in front of the other children.
function toFront(el) {
var parent = el.parentNode;
- if (parent.lastChild !== el) {
+ if (parent && parent.lastChild !== el) {
parent.appendChild(el);
}
}
// Makes `el` the first child of its parent, so it renders behind the other children.
function toBack(el) {
var parent = el.parentNode;
- if (parent.firstChild !== el) {
+ if (parent && parent.firstChild !== el) {
parent.insertBefore(el, parent.firstChild);
}
}
// @function getClass(el: HTMLElement): String
// Returns the element's class.
function getClass(el) {
+ // Check if the element is an SVGElementInstance and use the correspondingElement instead
+ // (Required for linked SVG elements in IE11.)
+ if (el.correspondingElement) {
+ el = el.correspondingElement;
+ }
return el.className.baseVal === undefined ? el.className : el.className.baseVal;
}
initialize: function (id, options) { // (HTMLElement or String, Object)
options = setOptions(this, options);
+ // Make sure to assign internal flags at the beginning,
+ // to avoid inconsistent state in some edge cases.
+ this._handlers = [];
+ this._layers = {};
+ this._zoomBoundLayers = {};
+ this._sizeChanged = true;
+
this._initContainer(id);
this._initLayout();
this.setView(toLatLng(options.center), options.zoom, {reset: true});
}
- this._handlers = [];
- this._layers = {};
- this._zoomBoundLayers = {};
- this._sizeChanged = true;
-
this.callInitHooks();
// don't animate on browsers without hardware-accelerated transitions or old Android/Opera
return this;
},
+ // @method panInside(latlng: LatLng, options?: options): this
+ // Pans the map the minimum amount to make the `latlng` visible. Use
+ // `padding`, `paddingTopLeft` and `paddingTopRight` options to fit
+ // the display to more restricted bounds, like [`fitBounds`](#map-fitbounds).
+ // If `latlng` is already within the (optionally padded) display bounds,
+ // the map will not be panned.
+ panInside: function (latlng, options) {
+ options = options || {};
+
+ var paddingTL = toPoint(options.paddingTopLeft || options.padding || [0, 0]),
+ paddingBR = toPoint(options.paddingBottomRight || options.padding || [0, 0]),
+ center = this.getCenter(),
+ pixelCenter = this.project(center),
+ pixelPoint = this.project(latlng),
+ pixelBounds = this.getPixelBounds(),
+ halfPixelBounds = pixelBounds.getSize().divideBy(2),
+ paddedBounds = toBounds([pixelBounds.min.add(paddingTL), pixelBounds.max.subtract(paddingBR)]);
+
+ if (!paddedBounds.contains(pixelPoint)) {
+ this._enforcingBounds = true;
+ var diff = pixelCenter.subtract(pixelPoint),
+ newCenter = toPoint(pixelPoint.x + diff.x, pixelPoint.y + diff.y);
+
+ if (pixelPoint.x < paddedBounds.min.x || pixelPoint.x > paddedBounds.max.x) {
+ newCenter.x = pixelCenter.x - diff.x;
+ if (diff.x > 0) {
+ newCenter.x += halfPixelBounds.x - paddingTL.x;
+ } else {
+ newCenter.x -= halfPixelBounds.x - paddingBR.x;
+ }
+ }
+ if (pixelPoint.y < paddedBounds.min.y || pixelPoint.y > paddedBounds.max.y) {
+ newCenter.y = pixelCenter.y - diff.y;
+ if (diff.y > 0) {
+ newCenter.y += halfPixelBounds.y - paddingTL.y;
+ } else {
+ newCenter.y -= halfPixelBounds.y - paddingBR.y;
+ }
+ }
+ this.panTo(this.unproject(newCenter), options);
+ this._enforcingBounds = false;
+ }
+ return this;
+ },
+
// @method invalidateSize(options: Zoom/pan options): this
// Checks if the map container size changed and updates the map if so —
// call it after you've changed the map size dynamically, also animating
}
// @event zoomanim: ZoomAnimEvent
- // Fired on every frame of a zoom animation
+ // Fired at least once per zoom animation. For continous zoom, like pinch zooming, fired once per frame during zoom.
this.fire('zoomanim', {
center: center,
zoom: zoom,
// Expand the control container if collapsed.
expand: function () {
addClass(this._container, 'leaflet-control-layers-expanded');
- this._form.style.height = null;
+ this._section.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';
+ if (acceptableHeight < this._section.clientHeight) {
+ addClass(this._section, 'leaflet-control-layers-scrollbar');
+ this._section.style.height = acceptableHeight + 'px';
} else {
- removeClass(this._form, 'leaflet-control-layers-scrollbar');
+ removeClass(this._section, 'leaflet-control-layers-scrollbar');
}
this._checkDisabledLayers();
return this;
disableClickPropagation(container);
disableScrollPropagation(container);
- var form = this._form = create$1('form', className + '-list');
+ var section = this._section = create$1('section', className + '-list');
if (collapsed) {
this._map.on('click', this.collapse, this);
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);
+ this._baseLayersList = create$1('div', className + '-base', section);
+ this._separator = create$1('div', className + '-separator', section);
+ this._overlaysList = create$1('div', className + '-overlays', section);
- container.appendChild(form);
+ container.appendChild(section);
},
_getLayer: function (id) {
Map.addInitHook(function () {
if (this.options.zoomControl) {
+ // @section Controls
+ // @property zoomControl: Control.Zoom
+ // The default zoom control (only available if the
+ // [`zoomControl` option](#map-zoomcontrol) was `true` when creating the map).
this.zoomControl = new Zoom();
this.addControl(this.zoomControl);
}
pane: 'overlayPane',
// @option attribution: String = null
- // String to be shown in the attribution control, describes the layer data, e.g. "© Mapbox".
+ // String to be shown in the attribution control, e.g. "© OpenStreetMap contributors". It describes the layer data and is often a legal obligation towards copyright holders and tile providers.
attribution: null,
bubblingMouseEvents: true
options: {
popupAnchor: [0, 0],
- tooltipAnchor: [0, 0],
+ tooltipAnchor: [0, 0]
},
initialize: function (options) {
// Option inherited from "Interactive layer" abstract class
interactive: true,
- // @option draggable: Boolean = false
- // Whether the marker is draggable with mouse/touch or not.
- draggable: false,
-
- // @option autoPan: Boolean = false
- // Set it to `true` if you want the map to do panning animation when marker hits the edges.
- autoPan: false,
-
- // @option autoPanPadding: Point = Point(50, 50)
- // Equivalent of setting both top left and bottom right autopan padding to the same value.
- autoPanPadding: [50, 50],
-
- // @option autoPanSpeed: Number = 10
- // Number of pixels the map should move by.
- autoPanSpeed: 10,
-
// @option keyboard: Boolean = true
// Whether the marker can be tabbed to with a keyboard and clicked by pressing enter.
keyboard: true,
// @option bubblingMouseEvents: Boolean = false
// When `true`, a mouse event on this marker will trigger the same event on the map
// (unless [`L.DomEvent.stopPropagation`](#domevent-stoppropagation) is used).
- bubblingMouseEvents: false
+ bubblingMouseEvents: false,
+
+ // @section Draggable marker options
+ // @option draggable: Boolean = false
+ // Whether the marker is draggable with mouse/touch or not.
+ draggable: false,
+
+ // @option autoPan: Boolean = false
+ // Whether to pan the map when dragging this marker near its edge or not.
+ autoPan: false,
+
+ // @option autoPanPadding: Point = Point(50, 50)
+ // Distance (in pixels to the left/right and to the top/bottom) of the
+ // map edge to start panning the map.
+ autoPanPadding: [50, 50],
+
+ // @option autoPanSpeed: Number = 10
+ // Number of pixels the map should pan by.
+ autoPanSpeed: 10
},
/* @section
errorOverlayUrl: '',
// @option zIndex: Number = 1
- // The explicit [zIndex](https://developer.mozilla.org/docs/Web/CSS/CSS_Positioning/Understanding_z_index) of the tile layer.
+ // The explicit [zIndex](https://developer.mozilla.org/docs/Web/CSS/CSS_Positioning/Understanding_z_index) of the overlay layer.
zIndex: 1,
// @option className: String = ''
// A custom class name to assign to the image. Empty by default.
- className: '',
+ className: ''
},
initialize: function (url, bounds, options) { // (String, LatLngBounds, Object)
return events;
},
- // @method: setZIndex(value: Number) : this
+ // @method setZIndex(value: Number): this
// Changes the [zIndex](#imageoverlay-zindex) of the image overlay.
setZIndex: function (value) {
this.options.zIndex = value;
_overlayOnError: function () {
// @event error: Event
- // Fired when the ImageOverlay layer has loaded its image
+ // Fired when the ImageOverlay layer fails to load its image
this.fire('error');
var errorUrl = this.options.errorOverlayUrl;
},
_adjustPan: function () {
- if (!this.options.autoPan || (this._map._panAnim && this._map._panAnim._inProgress)) { return; }
+ if (!this.options.autoPan) { return; }
+ if (this._map._panAnim) { this._map._panAnim.stop(); }
var map = this._map,
marginBottom = parseInt(getStyle(this._container, 'marginBottom'), 10) || 0,
var tile = this._tiles[key];
if (!tile) { return; }
- // Cancels any pending http requests associated with the tile
- // unless we're on Android's stock browser,
- // see https://github.com/Leaflet/Leaflet/issues/137
- if (!androidStock) {
- tile.el.setAttribute('src', emptyImageUrl);
- }
remove(tile.el);
delete this._tiles[key];
},
_tileReady: function (coords, err, tile) {
- if (!this._map || tile.getAttribute('src') === emptyImageUrl) { return; }
-
if (err) {
// @event tileerror: TileErrorEvent
// Fired when there is an error loading a tile.
* @class TileLayer
* @inherits GridLayer
* @aka L.TileLayer
- * Used to load and display tile layers on the map. Extends `GridLayer`.
+ * Used to load and display tile layers on the map. Note that most tile servers require attribution, which you can set under `Layer`. Extends `GridLayer`.
*
* @example
*
* ```js
- * L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png?{foo}', {foo: 'bar'}).addTo(map);
+ * L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png?{foo}', {foo: 'bar', attribution: 'Map data © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>'}).addTo(map);
* ```
*
* @section URL template
// @method setUrl(url: String, noRedraw?: Boolean): this
// Updates the layer's URL template and redraws it (unless `noRedraw` is set to `true`).
+ // If the URL does not change, the layer will not be redrawn unless
+ // the noRedraw parameter is set to false.
setUrl: function (url, noRedraw) {
+ if (this._url === url && noRedraw === undefined) {
+ noRedraw = true;
+ }
+
this._url = url;
if (!noRedraw) {
}
}
}
+ },
+
+ _removeTile: function (key) {
+ var tile = this._tiles[key];
+ if (!tile) { return; }
+
+ // Cancels any pending http requests associated with the tile
+ // unless we're on Android's stock browser,
+ // see https://github.com/Leaflet/Leaflet/issues/137
+ if (!androidStock) {
+ tile.el.setAttribute('src', emptyImageUrl);
+ }
+
+ return GridLayer.prototype._removeTile.call(this, key);
+ },
+
+ _tileReady: function (coords, err, tile) {
+ if (!this._map || (tile && tile.getAttribute('src') === emptyImageUrl)) {
+ return;
+ }
+
+ return GridLayer.prototype._tileReady.call(this, coords, err, tile);
}
});
_update: function () {
if (this._map._animatingZoom && this._bounds) { return; }
- this._drawnLayers = {};
-
Renderer.prototype._update.call(this);
var b = this._bounds,
this._drawFirst = next;
}
- delete this._drawnLayers[layer._leaflet_id];
-
delete layer._order;
delete this._layers[stamp(layer)];
_updateDashArray: function (layer) {
if (typeof layer.options.dashArray === 'string') {
- var parts = layer.options.dashArray.split(','),
+ var parts = layer.options.dashArray.split(/[, ]+/),
dashArray = [],
+ dashValue,
i;
for (i = 0; i < parts.length; i++) {
- dashArray.push(Number(parts[i]));
+ dashValue = Number(parts[i]);
+ // Ignore dash array containing invalid lengths
+ if (isNaN(dashValue)) { return; }
+ dashArray.push(dashValue);
}
layer.options._dashArray = dashArray;
} else {
if (!len) { return; }
- this._drawnLayers[layer._leaflet_id] = layer;
-
ctx.beginPath();
for (i = 0; i < len; i++) {
r = Math.max(Math.round(layer._radius), 1),
s = (Math.max(Math.round(layer._radiusY), 1) || r) / r;
- this._drawnLayers[layer._leaflet_id] = layer;
-
if (s !== 1) {
ctx.save();
ctx.scale(1, s);
_bringToFront: function (layer) {
var order = layer._order;
+
+ if (!order) { return; }
+
var next = order.next;
var prev = order.prev;
_bringToBack: function (layer) {
var order = layer._order;
+
+ if (!order) { return; }
+
var next = order.next;
var prev = order.prev;
/*
* @class SVG
*
- * Although SVG is not available on IE7 and IE8, these browsers support [VML](https://en.wikipedia.org/wiki/Vector_Markup_Language), and the SVG renderer will fall back to VML in this case.
*
* VML was deprecated in 2012, which means VML functionality exists only for backwards compatibility
* with old versions of Internet Explorer.