From: Tom Hughes Date: Wed, 9 Aug 2017 21:48:56 +0000 (+0100) Subject: Update to leaflet 1.2.0 X-Git-Tag: live~3846 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/ff7244d08550b3e151c24a87f78002b0c016d78a Update to leaflet 1.2.0 --- diff --git a/Vendorfile b/Vendorfile index 8c9898dd9..d66dd80d8 100644 --- a/Vendorfile +++ b/Vendorfile @@ -11,13 +11,13 @@ folder 'vendor/assets' do end folder 'leaflet' do - file 'leaflet.js', 'https://unpkg.com/leaflet@1.1.0/dist/leaflet-src.js' - file 'leaflet.css', 'https://unpkg.com/leaflet@1.1.0/dist/leaflet.css' + file 'leaflet.js', 'https://unpkg.com/leaflet@1.2.0/dist/leaflet-src.js' + file 'leaflet.css', 'https://unpkg.com/leaflet@1.2.0/dist/leaflet.css' [ 'layers.png', 'layers-2x.png', 'marker-icon.png', 'marker-icon-2x.png', 'marker-shadow.png' ].each do |image| - file "images/#{image}", "https://unpkg.com/leaflet@1.1.0/dist/images/#{image}" + file "images/#{image}", "https://unpkg.com/leaflet@1.2.0/dist/images/#{image}" end from 'git://github.com/aratcliffe/Leaflet.contextmenu.git', :tag => 'v1.2.1' do diff --git a/vendor/assets/leaflet/leaflet.css b/vendor/assets/leaflet/leaflet.css index 41126abde..fa5abca60 100644 --- a/vendor/assets/leaflet/leaflet.css +++ b/vendor/assets/leaflet/leaflet.css @@ -366,6 +366,7 @@ } .leaflet-control-layers-scrollbar { overflow-y: scroll; + overflow-x: hidden; padding-right: 5px; } .leaflet-control-layers-selector { diff --git a/vendor/assets/leaflet/leaflet.js b/vendor/assets/leaflet/leaflet.js index 5e6ab2b54..0f239b11e 100644 --- a/vendor/assets/leaflet/leaflet.js +++ b/vendor/assets/leaflet/leaflet.js @@ -1,14 +1,14 @@ -/* - * Leaflet 1.1.0, a JS library for interactive maps. http://leafletjs.com +/* @preserve + * Leaflet 1.2.0, a JS library for interactive maps. http://leafletjs.com * (c) 2010-2017 Vladimir Agafonkin, (c) 2010-2011 CloudMade */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : - (factory((global.L = global.L || {}))); + (factory((global.L = {}))); }(this, (function (exports) { 'use strict'; -var version = "1.1.0"; +var version = "1.2.0"; /* * @namespace Util @@ -16,6 +16,9 @@ var version = "1.1.0"; * Various utility functions, used by Leaflet internally. */ +var freeze = Object.freeze; +Object.freeze = function (obj) { return obj; }; + // @function extend(dest: Object, src?: Object): Object // Merges the properties of the `src` object (or multiple objects) into `dest` object and returns the latter. Has an `L.extend` shortcut. function extend(dest) { @@ -251,6 +254,7 @@ function cancelAnimFrame(id) { var Util = (Object.freeze || Object)({ + freeze: freeze, extend: extend, create: create, bind: bind, @@ -2214,6 +2218,8 @@ function off(obj, types, fn, context) { } delete obj[eventsKey]; } + + return this; } function addOne(obj, type, fn, context) { @@ -2323,7 +2329,8 @@ function stopPropagation(e) { // @function disableScrollPropagation(el: HTMLElement): this // Adds `stopPropagation` to the element's `'mousewheel'` events (plus browser variants). function disableScrollPropagation(el) { - return addOne(el, 'mousewheel', stopPropagation); + addOne(el, 'mousewheel', stopPropagation); + return this; } // @function disableClickPropagation(el: HTMLElement): this @@ -4912,13 +4919,6 @@ var Layers = Control.extend({ on(link, 'focus', this.expand, this); } - // work around for Firefox Android issue https://github.com/Leaflet/Leaflet/issues/2033 - on(form, 'click', function () { - setTimeout(bind(this._onInputClick, this), 0); - }, this); - - // TODO keyboard accessibility - if (!collapsed) { this.expand(); } @@ -4951,7 +4951,7 @@ var Layers = Control.extend({ }); if (this.options.sortLayers) { - this._layers.sort(L.bind(function (a, b) { + this._layers.sort(bind(function (a, b) { return this.options.sortFunction(a.layer, b.layer, a.name, b.name); }, this)); } @@ -5068,7 +5068,7 @@ var Layers = Control.extend({ _onInputClick: function () { var inputs = this._layerControlInputs, - input, layer, hasLayer; + input, layer; var addedLayers = [], removedLayers = []; @@ -5077,22 +5077,24 @@ var Layers = Control.extend({ for (var i = inputs.length - 1; i >= 0; i--) { input = inputs[i]; layer = this._getLayer(input.layerId).layer; - hasLayer = this._map.hasLayer(layer); - if (input.checked && !hasLayer) { + if (input.checked) { addedLayers.push(layer); - - } else if (!input.checked && hasLayer) { + } 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++) { - this._map.removeLayer(removedLayers[i]); + if (this._map.hasLayer(removedLayers[i])) { + this._map.removeLayer(removedLayers[i]); + } } for (i = 0; i < addedLayers.length; i++) { - this._map.addLayer(addedLayers[i]); + if (!this._map.hasLayer(addedLayers[i])) { + this._map.addLayer(addedLayers[i]); + } } this._handlingClick = false; @@ -5602,7 +5604,6 @@ var Mixin = {Events: Events}; * ``` */ -var _dragging = false; var START = touch ? 'touchstart mousedown' : 'mousedown'; var END = { mousedown: 'mouseup', @@ -5656,7 +5657,7 @@ var Draggable = Evented.extend({ // If we're currently dragging this draggable, // disabling it counts as first ending the drag. - if (L.Draggable._dragging === this) { + if (Draggable._dragging === this) { this.finishDrag(); } @@ -5678,8 +5679,8 @@ var Draggable = Evented.extend({ if (hasClass(this._element, 'leaflet-zoom-anim')) { return; } - if (_dragging || e.shiftKey || ((e.which !== 1) && (e.button !== 1) && !e.touches)) { return; } - _dragging = this; // Prevent dragging multiple objects at once. + 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); @@ -5803,7 +5804,7 @@ var Draggable = Evented.extend({ } this._moving = false; - _dragging = false; + Draggable._dragging = false; } }); @@ -6036,11 +6037,17 @@ function _sqClosestPointOnSegment(p, p1, p2, sqDist) { } -function _flat(latlngs) { - // true if it's a flat array of latlngs; false if nested +// @function isFlat(latlngs: LatLng[]): Boolean +// Returns true if `latlngs` is a flat array, false is nested. +function isFlat(latlngs) { return !isArray(latlngs[0]) || (typeof latlngs[0][0] !== 'object' && typeof latlngs[0][0] !== 'undefined'); } +function _flat(latlngs) { + console.warn('Deprecated use of _flat, please use L.LineUtil.isFlat instead.'); + return isFlat(latlngs); +} + var LineUtil = (Object.freeze || Object)({ simplify: simplify, @@ -6050,6 +6057,7 @@ var LineUtil = (Object.freeze || Object)({ _getEdgeIntersection: _getEdgeIntersection, _getBitCode: _getBitCode, _sqClosestPointOnSegment: _sqClosestPointOnSegment, + isFlat: isFlat, _flat: _flat }); @@ -6328,8 +6336,8 @@ var Layer = Evented.extend({ /* @section * Classes extending `L.Layer` will inherit the following methods: * - * @method addTo(map: Map): this - * Adds the layer to the given map + * @method addTo(map: Map|LayerGroup): this + * Adds the layer to the given map or layer group. */ addTo: function (map) { map.addLayer(this); @@ -6438,6 +6446,10 @@ Map.include({ // @method addLayer(layer: Layer): this // Adds the given layer to the map addLayer: function (layer) { + if (!layer._layerAdd) { + throw new Error('The provided object is not a Layer.'); + } + var id = stamp(layer); if (this._layers[id]) { return this; } this._layers[id] = layer; @@ -6714,7 +6726,7 @@ var LayerGroup = Layer.extend({ }); -// @factory L.layerGroup(layers: Layer[]) +// @factory L.layerGroup(layers?: Layer[]) // Create a layer group, optionally given an initial set of layers. var layerGroup = function (layers) { return new LayerGroup(layers); @@ -7984,13 +7996,13 @@ var Polyline = Path.extend({ }, _defaultShape: function () { - return _flat(this._latlngs) ? this._latlngs : this._latlngs[0]; + return isFlat(this._latlngs) ? this._latlngs : this._latlngs[0]; }, // recursively convert latlngs input into actual LatLng instances; calculate bounds along the way _convertLatLngs: function (latlngs) { var result = [], - flat = _flat(latlngs); + flat = isFlat(latlngs); for (var i = 0, len = latlngs.length; i < len; i++) { if (flat) { @@ -8130,6 +8142,9 @@ function polyline(latlngs, options) { return new Polyline(latlngs, options); } +// Retrocompat. Allow plugins to support Leaflet versions before and after 1.1. +Polyline._flat = _flat; + /* * @class Polygon * @aka L.Polygon @@ -8234,13 +8249,13 @@ var Polygon = Polyline.extend({ _setLatLngs: function (latlngs) { Polyline.prototype._setLatLngs.call(this, latlngs); - if (_flat(this._latlngs)) { + if (isFlat(this._latlngs)) { this._latlngs = [this._latlngs]; } }, _defaultShape: function () { - return _flat(this._latlngs[0]) ? this._latlngs[0] : this._latlngs[0][0]; + return isFlat(this._latlngs[0]) ? this._latlngs[0] : this._latlngs[0][0]; }, _clipPoints: function () { @@ -8612,7 +8627,7 @@ CircleMarker.include(PointToGeoJSON); // Returns a [`GeoJSON`](http://en.wikipedia.org/wiki/GeoJSON) representation of the polyline (as a GeoJSON `LineString` or `MultiLineString` Feature). Polyline.include({ toGeoJSON: function (precision) { - var multi = !_flat(this._latlngs); + var multi = !isFlat(this._latlngs); var coords = latLngsToCoords(this._latlngs, multi ? 1 : 0, false, precision); @@ -8628,8 +8643,8 @@ Polyline.include({ // Returns a [`GeoJSON`](http://en.wikipedia.org/wiki/GeoJSON) representation of the polygon (as a GeoJSON `Polygon` or `MultiPolygon` Feature). Polygon.include({ toGeoJSON: function (precision) { - var holes = !_flat(this._latlngs), - multi = holes && !_flat(this._latlngs[0]); + var holes = !isFlat(this._latlngs), + multi = holes && !isFlat(this._latlngs[0]); var coords = latLngsToCoords(this._latlngs, multi ? 2 : holes ? 1 : 0, true, precision); @@ -8848,7 +8863,7 @@ var ImageOverlay = Layer.extend({ // @method setBounds(bounds: LatLngBounds): this // Update the bounds that this ImageOverlay covers setBounds: function (bounds) { - this._bounds = bounds; + this._bounds = toLatLngBounds(bounds); if (this._map) { this._reset(); @@ -8979,8 +8994,8 @@ var imageOverlay = function (url, bounds, options) { * * ```js * var videoUrl = 'https://www.mapbox.com/bites/00188/patricia_nasa.webm', - * imageBounds = [[ 32, -130], [ 13, -100]]; - * L.imageOverlay(imageUrl, imageBounds).addTo(map); + * videoBounds = [[ 32, -130], [ 13, -100]]; + * L.VideoOverlay(videoUrl, videoBounds ).addTo(map); * ``` */ @@ -8999,8 +9014,11 @@ var VideoOverlay = ImageOverlay.extend({ }, _initImage: function () { - var vid = this._image = create$1('video', - 'leaflet-image-layer ' + (this._zoomAnimated ? 'leaflet-zoom-animated' : '')); + var wasElementSupplied = this._url.tagName === 'VIDEO'; + var vid = this._image = wasElementSupplied ? this._url : create$1('video'); + + vid.class = vid.class || ''; + vid.class += 'leaflet-image-layer ' + (this._zoomAnimated ? 'leaflet-zoom-animated' : ''); vid.onselectstart = falseFn; vid.onmousemove = falseFn; @@ -9009,6 +9027,8 @@ var VideoOverlay = ImageOverlay.extend({ // Fired when the video has finished loading the first frame vid.onloadeddata = bind(this.fire, this, 'load'); + if (wasElementSupplied) { return; } + if (!isArray(this._url)) { this._url = [this._url]; } vid.autoplay = !!this.options.autoplay; @@ -9026,11 +9046,12 @@ var VideoOverlay = ImageOverlay.extend({ }); -// @factory L.videoOverlay(videoUrl: String|Array, bounds: LatLngBounds, options?: VideoOverlay options) -// Instantiates an image overlay object given the URL of the video (or array of URLs) and the +// @factory L.videoOverlay(video: String|Array|HTMLVideoElement, bounds: LatLngBounds, options?: VideoOverlay options) +// Instantiates an image overlay object given the URL of the video (or array of URLs, or even a video element) and the // geographical bounds it is tied to. -function videoOverlay(url, bounds, options) { - return new VideoOverlay(url, bounds, options); + +function videoOverlay(video, bounds, options) { + return new VideoOverlay(video, bounds, options); } /* @@ -9588,7 +9609,7 @@ Layer.include({ // @method bindPopup(content: String|HTMLElement|Function|Popup, options?: Popup options): this // Binds a popup to the layer with the passed `content` and sets up the - // neccessary event listeners. If a `Function` is passed it will receive + // necessary event listeners. If a `Function` is passed it will receive // the layer as the first argument and should return a `String` or `HTMLElement`. bindPopup: function (content, options) { @@ -9991,7 +10012,7 @@ Layer.include({ // @method bindTooltip(content: String|HTMLElement|Function|Tooltip, options?: Tooltip options): this // Binds a tooltip to the layer with the passed `content` and sets up the - // neccessary event listeners. If a `Function` is passed it will receive + // necessary event listeners. If a `Function` is passed it will receive // the layer as the first argument and should return a `String` or `HTMLElement`. bindTooltip: function (content, options) { @@ -10304,8 +10325,11 @@ var GridLayer = Layer.extend({ // Opacity of the tiles. Can be used in the `createTile()` function. opacity: 1, - // @option updateWhenIdle: Boolean = depends - // If `false`, new tiles are loaded during panning, otherwise only after it (for better performance). `true` by default on mobile browsers, otherwise `false`. + // @option updateWhenIdle: Boolean = (depends) + // Load new tiles only when panning ends. + // `true` by default on mobile browsers, in order to avoid too many requests and keep smooth navigation. + // `false` otherwise in order to display new tiles _during_ panning, since it is easy to pan outside the + // [`keepBuffer`](#gridlayer-keepbuffer) option in desktop browsers. updateWhenIdle: mobile, // @option updateWhenZooming: Boolean = true @@ -11157,7 +11181,7 @@ function gridLayer(options) { * 'http://{s}.somedomain.com/blabla/{z}/{x}/{y}{r}.png' * ``` * - * `{s}` means one of the available subdomains (used sequentially to help with browser parallel requests per domain limitation; subdomain values are specified in options; `a`, `b` or `c` by default, can be omitted), `{z}` — zoom level, `{x}` and `{y}` — tile coordinates. `{r}` can be used to add @2x to the URL to load retina tiles. + * `{s}` means one of the available subdomains (used sequentially to help with browser parallel requests per domain limitation; subdomain values are specified in options; `a`, `b` or `c` by default, can be omitted), `{z}` — zoom level, `{x}` and `{y}` — tile coordinates. `{r}` can be used to add "@2x" to the URL to load retina tiles. * * You can use custom keys in the template, which will be [evaluated](#util-template) from TileLayer options, like this: * @@ -13501,6 +13525,8 @@ function noConflict() { // Always export us to window global (see #2364) window.L = exports; +Object.freeze = freeze; + exports.version = version; exports.noConflict = noConflict; exports.Control = Control;