revert: do not lint public directory
Signed-off-by: Vinayak Kulkarni <19776877+vinayakkulkarni@users.noreply.github.com>
This commit is contained in:
parent
85b1b69c93
commit
63fa46e356
8 changed files with 403 additions and 97293 deletions
|
|
@ -1,249 +1,243 @@
|
|||
// @class TileLayer
|
||||
|
||||
L.TileLayer.mergeOptions({
|
||||
// @option keepBuffer
|
||||
// The amount of tiles outside the visible map area to be kept in the stitched
|
||||
// `TileLayer`.
|
||||
// @option keepBuffer
|
||||
// The amount of tiles outside the visible map area to be kept in the stitched
|
||||
// `TileLayer`.
|
||||
|
||||
// @option dumpToCanvas: Boolean = true
|
||||
// Whether to dump loaded tiles to a `<canvas>` to prevent some rendering
|
||||
// artifacts. (Disabled by default in IE)
|
||||
dumpToCanvas: L.Browser.canvas && !L.Browser.ie,
|
||||
// @option dumpToCanvas: Boolean = true
|
||||
// Whether to dump loaded tiles to a `<canvas>` to prevent some rendering
|
||||
// artifacts. (Disabled by default in IE)
|
||||
dumpToCanvas: L.Browser.canvas && !L.Browser.ie,
|
||||
});
|
||||
|
||||
L.TileLayer.include({
|
||||
_onUpdateLevel: function (z, zoom) {
|
||||
if (this.options.dumpToCanvas) {
|
||||
this._levels[z].canvas.style.zIndex =
|
||||
this.options.maxZoom - Math.abs(zoom - z);
|
||||
}
|
||||
},
|
||||
_onUpdateLevel: function(z, zoom) {
|
||||
if (this.options.dumpToCanvas) {
|
||||
this._levels[z].canvas.style.zIndex =
|
||||
this.options.maxZoom - Math.abs(zoom - z);
|
||||
}
|
||||
},
|
||||
|
||||
_onRemoveLevel: function (z) {
|
||||
if (this.options.dumpToCanvas) {
|
||||
L.DomUtil.remove(this._levels[z].canvas);
|
||||
}
|
||||
},
|
||||
_onRemoveLevel: function(z) {
|
||||
if (this.options.dumpToCanvas) {
|
||||
L.DomUtil.remove(this._levels[z].canvas);
|
||||
}
|
||||
},
|
||||
|
||||
_onCreateLevel: function (level) {
|
||||
if (this.options.dumpToCanvas) {
|
||||
level.canvas = L.DomUtil.create(
|
||||
'canvas',
|
||||
'leaflet-tile-container leaflet-zoom-animated',
|
||||
this._container,
|
||||
);
|
||||
level.ctx = level.canvas.getContext('2d');
|
||||
this._resetCanvasSize(level);
|
||||
}
|
||||
},
|
||||
_onCreateLevel: function(level) {
|
||||
if (this.options.dumpToCanvas) {
|
||||
level.canvas = L.DomUtil.create(
|
||||
"canvas",
|
||||
"leaflet-tile-container leaflet-zoom-animated",
|
||||
this._container
|
||||
);
|
||||
level.ctx = level.canvas.getContext("2d");
|
||||
this._resetCanvasSize(level);
|
||||
}
|
||||
},
|
||||
|
||||
_removeTile: function (key) {
|
||||
if (this.options.dumpToCanvas) {
|
||||
var tile = this._tiles[key];
|
||||
var level = this._levels[tile.coords.z];
|
||||
var tileSize = this.getTileSize();
|
||||
_removeTile: function(key) {
|
||||
if (this.options.dumpToCanvas) {
|
||||
var tile = this._tiles[key];
|
||||
var level = this._levels[tile.coords.z];
|
||||
var tileSize = this.getTileSize();
|
||||
|
||||
if (level) {
|
||||
// Where in the canvas should this tile go?
|
||||
var offset = L.point(tile.coords.x, tile.coords.y)
|
||||
.subtract(level.canvasRange.min)
|
||||
.scaleBy(this.getTileSize());
|
||||
if (level) {
|
||||
// Where in the canvas should this tile go?
|
||||
var offset = L.point(tile.coords.x, tile.coords.y)
|
||||
.subtract(level.canvasRange.min)
|
||||
.scaleBy(this.getTileSize());
|
||||
|
||||
level.ctx.clearRect(offset.x, offset.y, tileSize.x, tileSize.y);
|
||||
}
|
||||
}
|
||||
level.ctx.clearRect(offset.x, offset.y, tileSize.x, tileSize.y);
|
||||
}
|
||||
}
|
||||
|
||||
L.GridLayer.prototype._removeTile.call(this, key);
|
||||
},
|
||||
L.GridLayer.prototype._removeTile.call(this, key);
|
||||
},
|
||||
|
||||
_resetCanvasSize: function (level) {
|
||||
var buff = this.options.keepBuffer,
|
||||
pixelBounds = this._getTiledPixelBounds(this._map.getCenter()),
|
||||
tileRange = this._pxBoundsToTileRange(pixelBounds),
|
||||
tileSize = this.getTileSize();
|
||||
_resetCanvasSize: function(level) {
|
||||
var buff = this.options.keepBuffer,
|
||||
pixelBounds = this._getTiledPixelBounds(this._map.getCenter()),
|
||||
tileRange = this._pxBoundsToTileRange(pixelBounds),
|
||||
tileSize = this.getTileSize();
|
||||
|
||||
tileRange.min = tileRange.min.subtract([buff, buff]); // This adds the no-prune buffer
|
||||
tileRange.max = tileRange.max.add([buff + 1, buff + 1]);
|
||||
tileRange.min = tileRange.min.subtract([buff, buff]); // This adds the no-prune buffer
|
||||
tileRange.max = tileRange.max.add([buff + 1, buff + 1]);
|
||||
|
||||
var pixelRange = L.bounds(
|
||||
tileRange.min.scaleBy(tileSize),
|
||||
tileRange.max.add([1, 1]).scaleBy(tileSize), // This prevents an off-by-one when checking if tiles are inside
|
||||
),
|
||||
mustRepositionCanvas = false,
|
||||
neededSize = pixelRange.max.subtract(pixelRange.min);
|
||||
var pixelRange = L.bounds(
|
||||
tileRange.min.scaleBy(tileSize),
|
||||
tileRange.max.add([1, 1]).scaleBy(tileSize) // This prevents an off-by-one when checking if tiles are inside
|
||||
),
|
||||
mustRepositionCanvas = false,
|
||||
neededSize = pixelRange.max.subtract(pixelRange.min);
|
||||
|
||||
// Resize the canvas, if needed, and only to make it bigger.
|
||||
if (
|
||||
neededSize.x > level.canvas.width ||
|
||||
neededSize.y > level.canvas.height
|
||||
) {
|
||||
// Resizing canvases erases the currently drawn content, I'm afraid.
|
||||
// To keep it, dump the pixels to another canvas, then display it on
|
||||
// top. This could be done with getImageData/putImageData, but that
|
||||
// would break for tainted canvases (in non-CORS tilesets)
|
||||
var oldSize = { x: level.canvas.width, y: level.canvas.height };
|
||||
// console.info('Resizing canvas from ', oldSize, 'to ', neededSize);
|
||||
// Resize the canvas, if needed, and only to make it bigger.
|
||||
if (
|
||||
neededSize.x > level.canvas.width ||
|
||||
neededSize.y > level.canvas.height
|
||||
) {
|
||||
// Resizing canvases erases the currently drawn content, I'm afraid.
|
||||
// To keep it, dump the pixels to another canvas, then display it on
|
||||
// top. This could be done with getImageData/putImageData, but that
|
||||
// would break for tainted canvases (in non-CORS tilesets)
|
||||
var oldSize = { x: level.canvas.width, y: level.canvas.height };
|
||||
// console.info('Resizing canvas from ', oldSize, 'to ', neededSize);
|
||||
|
||||
var tmpCanvas = L.DomUtil.create('canvas');
|
||||
tmpCanvas.style.width = (tmpCanvas.width = oldSize.x) + 'px';
|
||||
tmpCanvas.style.height = (tmpCanvas.height = oldSize.y) + 'px';
|
||||
tmpCanvas.getContext('2d').drawImage(level.canvas, 0, 0);
|
||||
// var data = level.ctx.getImageData(0, 0, oldSize.x, oldSize.y);
|
||||
var tmpCanvas = L.DomUtil.create("canvas");
|
||||
tmpCanvas.style.width = (tmpCanvas.width = oldSize.x) + "px";
|
||||
tmpCanvas.style.height = (tmpCanvas.height = oldSize.y) + "px";
|
||||
tmpCanvas.getContext("2d").drawImage(level.canvas, 0, 0);
|
||||
// var data = level.ctx.getImageData(0, 0, oldSize.x, oldSize.y);
|
||||
|
||||
level.canvas.style.width = (level.canvas.width = neededSize.x) + 'px';
|
||||
level.canvas.style.height = (level.canvas.height = neededSize.y) + 'px';
|
||||
level.ctx.drawImage(tmpCanvas, 0, 0);
|
||||
// level.ctx.putImageData(data, 0, 0, 0, 0, oldSize.x, oldSize.y);
|
||||
}
|
||||
level.canvas.style.width = (level.canvas.width = neededSize.x) + "px";
|
||||
level.canvas.style.height = (level.canvas.height = neededSize.y) + "px";
|
||||
level.ctx.drawImage(tmpCanvas, 0, 0);
|
||||
// level.ctx.putImageData(data, 0, 0, 0, 0, oldSize.x, oldSize.y);
|
||||
}
|
||||
|
||||
// Translate the canvas contents if it's moved around
|
||||
if (level.canvasRange) {
|
||||
var offset = level.canvasRange.min
|
||||
.subtract(tileRange.min)
|
||||
.scaleBy(this.getTileSize());
|
||||
// Translate the canvas contents if it's moved around
|
||||
if (level.canvasRange) {
|
||||
var offset = level.canvasRange.min
|
||||
.subtract(tileRange.min)
|
||||
.scaleBy(this.getTileSize());
|
||||
|
||||
// console.info('Offsetting by ', offset);
|
||||
// console.info('Offsetting by ', offset);
|
||||
|
||||
if (!L.Browser.safari) {
|
||||
// By default, canvases copy things "on top of" existing pixels, but we want
|
||||
// this to *replace* the existing pixels when doing a drawImage() call.
|
||||
// This will also clear the sides, so no clearRect() calls are needed to make room
|
||||
// for the new tiles.
|
||||
level.ctx.globalCompositeOperation = 'copy';
|
||||
level.ctx.drawImage(level.canvas, offset.x, offset.y);
|
||||
level.ctx.globalCompositeOperation = 'source-over';
|
||||
} else {
|
||||
// Safari clears the canvas when copying from itself :-(
|
||||
if (!this._tmpCanvas) {
|
||||
var t = (this._tmpCanvas = L.DomUtil.create('canvas'));
|
||||
t.width = level.canvas.width;
|
||||
t.height = level.canvas.height;
|
||||
this._tmpContext = t.getContext('2d');
|
||||
}
|
||||
this._tmpContext.clearRect(
|
||||
0,
|
||||
0,
|
||||
level.canvas.width,
|
||||
level.canvas.height,
|
||||
);
|
||||
this._tmpContext.drawImage(level.canvas, 0, 0);
|
||||
level.ctx.clearRect(0, 0, level.canvas.width, level.canvas.height);
|
||||
level.ctx.drawImage(this._tmpCanvas, offset.x, offset.y);
|
||||
}
|
||||
if (!L.Browser.safari) {
|
||||
// By default, canvases copy things "on top of" existing pixels, but we want
|
||||
// this to *replace* the existing pixels when doing a drawImage() call.
|
||||
// This will also clear the sides, so no clearRect() calls are needed to make room
|
||||
// for the new tiles.
|
||||
level.ctx.globalCompositeOperation = "copy";
|
||||
level.ctx.drawImage(level.canvas, offset.x, offset.y);
|
||||
level.ctx.globalCompositeOperation = "source-over";
|
||||
} else {
|
||||
// Safari clears the canvas when copying from itself :-(
|
||||
if (!this._tmpCanvas) {
|
||||
var t = (this._tmpCanvas = L.DomUtil.create("canvas"));
|
||||
t.width = level.canvas.width;
|
||||
t.height = level.canvas.height;
|
||||
this._tmpContext = t.getContext("2d");
|
||||
}
|
||||
this._tmpContext.clearRect(
|
||||
0,
|
||||
0,
|
||||
level.canvas.width,
|
||||
level.canvas.height
|
||||
);
|
||||
this._tmpContext.drawImage(level.canvas, 0, 0);
|
||||
level.ctx.clearRect(0, 0, level.canvas.width, level.canvas.height);
|
||||
level.ctx.drawImage(this._tmpCanvas, offset.x, offset.y);
|
||||
}
|
||||
|
||||
mustRepositionCanvas = true; // Wait until new props are set
|
||||
}
|
||||
mustRepositionCanvas = true; // Wait until new props are set
|
||||
}
|
||||
|
||||
level.canvasRange = tileRange;
|
||||
level.canvasPxRange = pixelRange;
|
||||
level.canvasOrigin = pixelRange.min;
|
||||
level.canvasRange = tileRange;
|
||||
level.canvasPxRange = pixelRange;
|
||||
level.canvasOrigin = pixelRange.min;
|
||||
|
||||
// console.log('Canvas tile range: ', level, tileRange.min, tileRange.max );
|
||||
// console.log('Canvas pixel range: ', pixelRange.min, pixelRange.max );
|
||||
// console.log('Level origin: ', level.origin );
|
||||
// console.log('Canvas tile range: ', level, tileRange.min, tileRange.max );
|
||||
// console.log('Canvas pixel range: ', pixelRange.min, pixelRange.max );
|
||||
// console.log('Level origin: ', level.origin );
|
||||
|
||||
if (mustRepositionCanvas) {
|
||||
this._setCanvasZoomTransform(
|
||||
level,
|
||||
this._map.getCenter(),
|
||||
this._map.getZoom(),
|
||||
);
|
||||
}
|
||||
},
|
||||
if (mustRepositionCanvas) {
|
||||
this._setCanvasZoomTransform(
|
||||
level,
|
||||
this._map.getCenter(),
|
||||
this._map.getZoom()
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
/// set transform/position of canvas, in addition to the transform/position of the individual tile container
|
||||
_setZoomTransform: function (level, center, zoom) {
|
||||
L.GridLayer.prototype._setZoomTransform.call(this, level, center, zoom);
|
||||
if (this.options.dumpToCanvas) {
|
||||
this._setCanvasZoomTransform(level, center, zoom);
|
||||
}
|
||||
},
|
||||
/// set transform/position of canvas, in addition to the transform/position of the individual tile container
|
||||
_setZoomTransform: function(level, center, zoom) {
|
||||
L.GridLayer.prototype._setZoomTransform.call(this, level, center, zoom);
|
||||
if (this.options.dumpToCanvas) {
|
||||
this._setCanvasZoomTransform(level, center, zoom);
|
||||
}
|
||||
},
|
||||
|
||||
// This will get called twice:
|
||||
// * From _setZoomTransform
|
||||
// * When the canvas has shifted due to a new tile being loaded
|
||||
_setCanvasZoomTransform: function (level, center, zoom) {
|
||||
// console.log('_setCanvasZoomTransform', level, center, zoom);
|
||||
if (!level.canvasOrigin) {
|
||||
return;
|
||||
}
|
||||
var scale = this._map.getZoomScale(zoom, level.zoom),
|
||||
translate = level.canvasOrigin
|
||||
.multiplyBy(scale)
|
||||
.subtract(this._map._getNewPixelOrigin(center, zoom))
|
||||
.round();
|
||||
// This will get called twice:
|
||||
// * From _setZoomTransform
|
||||
// * When the canvas has shifted due to a new tile being loaded
|
||||
_setCanvasZoomTransform: function(level, center, zoom) {
|
||||
// console.log('_setCanvasZoomTransform', level, center, zoom);
|
||||
if (!level.canvasOrigin) {
|
||||
return;
|
||||
}
|
||||
var scale = this._map.getZoomScale(zoom, level.zoom),
|
||||
translate = level.canvasOrigin
|
||||
.multiplyBy(scale)
|
||||
.subtract(this._map._getNewPixelOrigin(center, zoom))
|
||||
.round();
|
||||
|
||||
if (L.Browser.any3d) {
|
||||
L.DomUtil.setTransform(level.canvas, translate, scale);
|
||||
} else {
|
||||
L.DomUtil.setPosition(level.canvas, translate);
|
||||
}
|
||||
},
|
||||
if (L.Browser.any3d) {
|
||||
L.DomUtil.setTransform(level.canvas, translate, scale);
|
||||
} else {
|
||||
L.DomUtil.setPosition(level.canvas, translate);
|
||||
}
|
||||
},
|
||||
|
||||
_onOpaqueTile: function (tile) {
|
||||
if (!this.options.dumpToCanvas) {
|
||||
return;
|
||||
}
|
||||
_onOpaqueTile: function(tile) {
|
||||
if (!this.options.dumpToCanvas) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Guard against an NS_ERROR_NOT_AVAILABLE (or similar) exception
|
||||
// when a non-image-tile has been loaded (e.g. a WMS error).
|
||||
// Checking for tile.el.complete is not enough, as it has been
|
||||
// already marked as loaded and ready somehow.
|
||||
try {
|
||||
this.dumpPixels(tile.coords, tile.el);
|
||||
} catch (ex) {
|
||||
return this.fire('tileerror', {
|
||||
error: 'Could not copy tile pixels: ' + ex,
|
||||
tile: tile,
|
||||
coods: tile.coords,
|
||||
});
|
||||
}
|
||||
// Guard against an NS_ERROR_NOT_AVAILABLE (or similar) exception
|
||||
// when a non-image-tile has been loaded (e.g. a WMS error).
|
||||
// Checking for tile.el.complete is not enough, as it has been
|
||||
// already marked as loaded and ready somehow.
|
||||
try {
|
||||
this.dumpPixels(tile.coords, tile.el);
|
||||
} catch (ex) {
|
||||
return this.fire("tileerror", {
|
||||
error: "Could not copy tile pixels: " + ex,
|
||||
tile: tile,
|
||||
coods: tile.coords,
|
||||
});
|
||||
}
|
||||
|
||||
// If dumping the pixels was successful, then hide the tile.
|
||||
// Do not remove the tile itself, as it is needed to check if the whole
|
||||
// level (and its canvas) should be removed (via level.el.children.length)
|
||||
tile.el.style.display = 'none';
|
||||
},
|
||||
// If dumping the pixels was successful, then hide the tile.
|
||||
// Do not remove the tile itself, as it is needed to check if the whole
|
||||
// level (and its canvas) should be removed (via level.el.children.length)
|
||||
tile.el.style.display = "none";
|
||||
},
|
||||
|
||||
// @section Extension methods
|
||||
// @uninheritable
|
||||
// @section Extension methods
|
||||
// @uninheritable
|
||||
|
||||
// @method dumpPixels(coords: Object, imageSource: CanvasImageSource): this
|
||||
// Dumps pixels from the given `CanvasImageSource` into the layer, into
|
||||
// the space for the tile represented by the `coords` tile coordinates (an object
|
||||
// like `{x: Number, y: Number, z: Number}`; the image source must have the
|
||||
// same size as the `tileSize` option for the layer. Has no effect if `dumpToCanvas`
|
||||
// is `false`.
|
||||
dumpPixels: function (coords, imageSource) {
|
||||
var level = this._levels[coords.z],
|
||||
tileSize = this.getTileSize();
|
||||
// @method dumpPixels(coords: Object, imageSource: CanvasImageSource): this
|
||||
// Dumps pixels from the given `CanvasImageSource` into the layer, into
|
||||
// the space for the tile represented by the `coords` tile coordinates (an object
|
||||
// like `{x: Number, y: Number, z: Number}`; the image source must have the
|
||||
// same size as the `tileSize` option for the layer. Has no effect if `dumpToCanvas`
|
||||
// is `false`.
|
||||
dumpPixels: function(coords, imageSource) {
|
||||
var level = this._levels[coords.z],
|
||||
tileSize = this.getTileSize();
|
||||
|
||||
if (!level.canvasRange || !this.options.dumpToCanvas) {
|
||||
return;
|
||||
}
|
||||
if (!level.canvasRange || !this.options.dumpToCanvas) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if the tile is inside the currently visible map bounds
|
||||
// There is a possible race condition when tiles are loaded after they
|
||||
// have been panned outside of the map.
|
||||
if (!level.canvasRange.contains(coords)) {
|
||||
this._resetCanvasSize(level);
|
||||
}
|
||||
// Check if the tile is inside the currently visible map bounds
|
||||
// There is a possible race condition when tiles are loaded after they
|
||||
// have been panned outside of the map.
|
||||
if (!level.canvasRange.contains(coords)) {
|
||||
this._resetCanvasSize(level);
|
||||
}
|
||||
|
||||
// Where in the canvas should this tile go?
|
||||
var offset = L.point(coords.x, coords.y)
|
||||
.subtract(level.canvasRange.min)
|
||||
.scaleBy(this.getTileSize());
|
||||
// Where in the canvas should this tile go?
|
||||
var offset = L.point(coords.x, coords.y)
|
||||
.subtract(level.canvasRange.min)
|
||||
.scaleBy(this.getTileSize());
|
||||
|
||||
level.ctx.drawImage(
|
||||
imageSource,
|
||||
offset.x,
|
||||
offset.y,
|
||||
tileSize.x,
|
||||
tileSize.y,
|
||||
);
|
||||
level.ctx.drawImage(imageSource, offset.x, offset.y, tileSize.x, tileSize.y);
|
||||
|
||||
// TODO: Clear the pixels of other levels' canvases where they overlap
|
||||
// this newly dumped tile.
|
||||
return this;
|
||||
},
|
||||
// TODO: Clear the pixels of other levels' canvases where they overlap
|
||||
// this newly dumped tile.
|
||||
return this;
|
||||
},
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,162 +1,162 @@
|
|||
(function (window) {
|
||||
var HAS_HASHCHANGE = (function () {
|
||||
var doc_mode = window.documentMode;
|
||||
return 'onhashchange' in window && (doc_mode === undefined || doc_mode > 7);
|
||||
})();
|
||||
(function(window) {
|
||||
var HAS_HASHCHANGE = (function() {
|
||||
var doc_mode = window.documentMode;
|
||||
return ('onhashchange' in window) &&
|
||||
(doc_mode === undefined || doc_mode > 7);
|
||||
})();
|
||||
|
||||
L.Hash = function (map) {
|
||||
this.onHashChange = L.Util.bind(this.onHashChange, this);
|
||||
L.Hash = function(map) {
|
||||
this.onHashChange = L.Util.bind(this.onHashChange, this);
|
||||
|
||||
if (map) {
|
||||
this.init(map);
|
||||
}
|
||||
};
|
||||
if (map) {
|
||||
this.init(map);
|
||||
}
|
||||
};
|
||||
|
||||
L.Hash.parseHash = function (hash) {
|
||||
if (hash.indexOf('#') === 0) {
|
||||
hash = hash.substr(1);
|
||||
}
|
||||
var args = hash.split('/');
|
||||
if (args.length == 3) {
|
||||
var zoom = parseInt(args[0], 10),
|
||||
lat = parseFloat(args[1]),
|
||||
lon = parseFloat(args[2]);
|
||||
if (isNaN(zoom) || isNaN(lat) || isNaN(lon)) {
|
||||
return false;
|
||||
} else {
|
||||
return {
|
||||
center: new L.LatLng(lat, lon),
|
||||
zoom: zoom,
|
||||
};
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
L.Hash.parseHash = function(hash) {
|
||||
if(hash.indexOf('#') === 0) {
|
||||
hash = hash.substr(1);
|
||||
}
|
||||
var args = hash.split("/");
|
||||
if (args.length == 3) {
|
||||
var zoom = parseInt(args[0], 10),
|
||||
lat = parseFloat(args[1]),
|
||||
lon = parseFloat(args[2]);
|
||||
if (isNaN(zoom) || isNaN(lat) || isNaN(lon)) {
|
||||
return false;
|
||||
} else {
|
||||
return {
|
||||
center: new L.LatLng(lat, lon),
|
||||
zoom: zoom
|
||||
};
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
(L.Hash.formatHash = function (map) {
|
||||
var center = map.getCenter(),
|
||||
zoom = map.getZoom(),
|
||||
precision = Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2));
|
||||
L.Hash.formatHash = function(map) {
|
||||
var center = map.getCenter(),
|
||||
zoom = map.getZoom(),
|
||||
precision = Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2));
|
||||
|
||||
return (
|
||||
'#' +
|
||||
[zoom, center.lat.toFixed(precision), center.lng.toFixed(precision)].join(
|
||||
'/',
|
||||
)
|
||||
);
|
||||
}),
|
||||
(L.Hash.prototype = {
|
||||
map: null,
|
||||
lastHash: null,
|
||||
return "#" + [zoom,
|
||||
center.lat.toFixed(precision),
|
||||
center.lng.toFixed(precision)
|
||||
].join("/");
|
||||
},
|
||||
|
||||
parseHash: L.Hash.parseHash,
|
||||
formatHash: L.Hash.formatHash,
|
||||
L.Hash.prototype = {
|
||||
map: null,
|
||||
lastHash: null,
|
||||
|
||||
init: function (map) {
|
||||
this.map = map;
|
||||
parseHash: L.Hash.parseHash,
|
||||
formatHash: L.Hash.formatHash,
|
||||
|
||||
// reset the hash
|
||||
this.lastHash = null;
|
||||
this.onHashChange();
|
||||
init: function(map) {
|
||||
this.map = map;
|
||||
|
||||
if (!this.isListening) {
|
||||
this.startListening();
|
||||
}
|
||||
},
|
||||
// reset the hash
|
||||
this.lastHash = null;
|
||||
this.onHashChange();
|
||||
|
||||
removeFrom: function (map) {
|
||||
if (this.changeTimeout) {
|
||||
clearTimeout(this.changeTimeout);
|
||||
}
|
||||
if (!this.isListening) {
|
||||
this.startListening();
|
||||
}
|
||||
},
|
||||
|
||||
if (this.isListening) {
|
||||
this.stopListening();
|
||||
}
|
||||
removeFrom: function(map) {
|
||||
if (this.changeTimeout) {
|
||||
clearTimeout(this.changeTimeout);
|
||||
}
|
||||
|
||||
this.map = null;
|
||||
},
|
||||
if (this.isListening) {
|
||||
this.stopListening();
|
||||
}
|
||||
|
||||
onMapMove: function () {
|
||||
// bail if we're moving the map (updating from a hash),
|
||||
// or if the map is not yet loaded
|
||||
this.map = null;
|
||||
},
|
||||
|
||||
if (this.movingMap || !this.map._loaded) {
|
||||
return false;
|
||||
}
|
||||
onMapMove: function() {
|
||||
// bail if we're moving the map (updating from a hash),
|
||||
// or if the map is not yet loaded
|
||||
|
||||
var hash = this.formatHash(this.map);
|
||||
if (this.lastHash != hash) {
|
||||
location.replace(hash);
|
||||
this.lastHash = hash;
|
||||
}
|
||||
},
|
||||
if (this.movingMap || !this.map._loaded) {
|
||||
return false;
|
||||
}
|
||||
|
||||
movingMap: false,
|
||||
update: function () {
|
||||
var hash = location.hash;
|
||||
if (hash === this.lastHash) {
|
||||
return;
|
||||
}
|
||||
var parsed = this.parseHash(hash);
|
||||
if (parsed) {
|
||||
this.movingMap = true;
|
||||
var hash = this.formatHash(this.map);
|
||||
if (this.lastHash != hash) {
|
||||
location.replace(hash);
|
||||
this.lastHash = hash;
|
||||
}
|
||||
},
|
||||
|
||||
this.map.setView(parsed.center, parsed.zoom);
|
||||
movingMap: false,
|
||||
update: function() {
|
||||
var hash = location.hash;
|
||||
if (hash === this.lastHash) {
|
||||
return;
|
||||
}
|
||||
var parsed = this.parseHash(hash);
|
||||
if (parsed) {
|
||||
this.movingMap = true;
|
||||
|
||||
this.movingMap = false;
|
||||
} else {
|
||||
this.onMapMove(this.map);
|
||||
}
|
||||
},
|
||||
this.map.setView(parsed.center, parsed.zoom);
|
||||
|
||||
// defer hash change updates every 100ms
|
||||
changeDefer: 100,
|
||||
changeTimeout: null,
|
||||
onHashChange: function () {
|
||||
// throttle calls to update() so that they only happen every
|
||||
// `changeDefer` ms
|
||||
if (!this.changeTimeout) {
|
||||
var that = this;
|
||||
this.changeTimeout = setTimeout(function () {
|
||||
that.update();
|
||||
that.changeTimeout = null;
|
||||
}, this.changeDefer);
|
||||
}
|
||||
},
|
||||
this.movingMap = false;
|
||||
} else {
|
||||
this.onMapMove(this.map);
|
||||
}
|
||||
},
|
||||
|
||||
isListening: false,
|
||||
hashChangeInterval: null,
|
||||
startListening: function () {
|
||||
this.map.on('moveend', this.onMapMove, this);
|
||||
// defer hash change updates every 100ms
|
||||
changeDefer: 100,
|
||||
changeTimeout: null,
|
||||
onHashChange: function() {
|
||||
// throttle calls to update() so that they only happen every
|
||||
// `changeDefer` ms
|
||||
if (!this.changeTimeout) {
|
||||
var that = this;
|
||||
this.changeTimeout = setTimeout(function() {
|
||||
that.update();
|
||||
that.changeTimeout = null;
|
||||
}, this.changeDefer);
|
||||
}
|
||||
},
|
||||
|
||||
if (HAS_HASHCHANGE) {
|
||||
L.DomEvent.addListener(window, 'hashchange', this.onHashChange);
|
||||
} else {
|
||||
clearInterval(this.hashChangeInterval);
|
||||
this.hashChangeInterval = setInterval(this.onHashChange, 50);
|
||||
}
|
||||
this.isListening = true;
|
||||
},
|
||||
isListening: false,
|
||||
hashChangeInterval: null,
|
||||
startListening: function() {
|
||||
this.map.on("moveend", this.onMapMove, this);
|
||||
|
||||
stopListening: function () {
|
||||
this.map.off('moveend', this.onMapMove, this);
|
||||
if (HAS_HASHCHANGE) {
|
||||
L.DomEvent.addListener(window, "hashchange", this.onHashChange);
|
||||
} else {
|
||||
clearInterval(this.hashChangeInterval);
|
||||
this.hashChangeInterval = setInterval(this.onHashChange, 50);
|
||||
}
|
||||
this.isListening = true;
|
||||
},
|
||||
|
||||
if (HAS_HASHCHANGE) {
|
||||
L.DomEvent.removeListener(window, 'hashchange', this.onHashChange);
|
||||
} else {
|
||||
clearInterval(this.hashChangeInterval);
|
||||
}
|
||||
this.isListening = false;
|
||||
},
|
||||
});
|
||||
L.hash = function (map) {
|
||||
return new L.Hash(map);
|
||||
};
|
||||
L.Map.prototype.addHash = function () {
|
||||
this._hash = L.hash(this);
|
||||
};
|
||||
L.Map.prototype.removeHash = function () {
|
||||
this._hash.removeFrom();
|
||||
};
|
||||
stopListening: function() {
|
||||
this.map.off("moveend", this.onMapMove, this);
|
||||
|
||||
if (HAS_HASHCHANGE) {
|
||||
L.DomEvent.removeListener(window, "hashchange", this.onHashChange);
|
||||
} else {
|
||||
clearInterval(this.hashChangeInterval);
|
||||
}
|
||||
this.isListening = false;
|
||||
}
|
||||
};
|
||||
L.hash = function(map) {
|
||||
return new L.Hash(map);
|
||||
};
|
||||
L.Map.prototype.addHash = function() {
|
||||
this._hash = L.hash(this);
|
||||
};
|
||||
L.Map.prototype.removeHash = function() {
|
||||
this._hash.removeFrom();
|
||||
};
|
||||
})(window);
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
1656
public/resources/maplibre-gl-inspect-compat.min.js
vendored
1656
public/resources/maplibre-gl-inspect-compat.min.js
vendored
File diff suppressed because one or more lines are too long
1599
public/resources/maplibre-gl-inspect.min.js
vendored
1599
public/resources/maplibre-gl-inspect.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue