1409 lines
45 KiB
JavaScript
1409 lines
45 KiB
JavaScript
import {
|
|
Source_default
|
|
} from "./chunk-6Y7C6NBJ.js";
|
|
import {
|
|
ImageTile_default,
|
|
TileRange_default,
|
|
Tile_default2 as Tile_default,
|
|
createOrUpdate as createOrUpdate2,
|
|
createOrUpdate2 as createOrUpdate3,
|
|
getCacheKey,
|
|
hash,
|
|
hashZXY,
|
|
withinExtentAndZ
|
|
} from "./chunk-7XMWB3J4.js";
|
|
import {
|
|
TileState_default
|
|
} from "./chunk-5D2XPBR2.js";
|
|
import {
|
|
scale,
|
|
toSize
|
|
} from "./chunk-SHUBVYN4.js";
|
|
import {
|
|
DEFAULT_MAX_ZOOM,
|
|
DEFAULT_TILE_SIZE
|
|
} from "./chunk-FM44FOIC.js";
|
|
import {
|
|
intersectsLinearRing
|
|
} from "./chunk-X52LGBOS.js";
|
|
import {
|
|
assert
|
|
} from "./chunk-QFCIXVZ3.js";
|
|
import {
|
|
METERS_PER_UNIT,
|
|
equivalent,
|
|
get
|
|
} from "./chunk-A3RXLHYB.js";
|
|
import {
|
|
ceil,
|
|
clamp,
|
|
floor,
|
|
modulo
|
|
} from "./chunk-54BTDBAD.js";
|
|
import {
|
|
WORKER_OFFSCREEN_CANVAS
|
|
} from "./chunk-5XHD7RSF.js";
|
|
import {
|
|
abstract,
|
|
getUid
|
|
} from "./chunk-Q5ZULJHM.js";
|
|
import {
|
|
Event_default
|
|
} from "./chunk-NGFXCWUF.js";
|
|
import {
|
|
EventType_default,
|
|
isSorted,
|
|
linearFindNearest
|
|
} from "./chunk-K25ZO44T.js";
|
|
import {
|
|
containsCoordinate,
|
|
createOrUpdate,
|
|
getCorner,
|
|
getHeight,
|
|
getTopLeft,
|
|
getWidth
|
|
} from "./chunk-SRXHWJOY.js";
|
|
|
|
// node_modules/ol/tilegrid/TileGrid.js
|
|
var tmpTileCoord = [0, 0, 0];
|
|
var DECIMALS = 5;
|
|
var TileGrid = class {
|
|
/**
|
|
* @param {Options} options Tile grid options.
|
|
*/
|
|
constructor(options) {
|
|
this.minZoom = options.minZoom !== void 0 ? options.minZoom : 0;
|
|
this.resolutions_ = options.resolutions;
|
|
assert(
|
|
isSorted(
|
|
this.resolutions_,
|
|
/**
|
|
* @param {number} a First resolution
|
|
* @param {number} b Second resolution
|
|
* @return {number} Comparison result
|
|
*/
|
|
(a, b) => b - a,
|
|
true
|
|
),
|
|
"`resolutions` must be sorted in descending order"
|
|
);
|
|
let zoomFactor;
|
|
if (!options.origins) {
|
|
for (let i = 0, ii = this.resolutions_.length - 1; i < ii; ++i) {
|
|
if (!zoomFactor) {
|
|
zoomFactor = this.resolutions_[i] / this.resolutions_[i + 1];
|
|
} else {
|
|
if (this.resolutions_[i] / this.resolutions_[i + 1] !== zoomFactor) {
|
|
zoomFactor = void 0;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
this.zoomFactor_ = zoomFactor;
|
|
this.maxZoom = this.resolutions_.length - 1;
|
|
this.origin_ = options.origin !== void 0 ? options.origin : null;
|
|
this.origins_ = null;
|
|
if (options.origins !== void 0) {
|
|
this.origins_ = options.origins;
|
|
assert(
|
|
this.origins_.length == this.resolutions_.length,
|
|
"Number of `origins` and `resolutions` must be equal"
|
|
);
|
|
}
|
|
const extent = options.extent;
|
|
if (extent !== void 0 && !this.origin_ && !this.origins_) {
|
|
this.origin_ = getTopLeft(extent);
|
|
}
|
|
assert(
|
|
!this.origin_ && this.origins_ || this.origin_ && !this.origins_,
|
|
"Either `origin` or `origins` must be configured, never both"
|
|
);
|
|
this.tileSizes_ = null;
|
|
if (options.tileSizes !== void 0) {
|
|
this.tileSizes_ = options.tileSizes;
|
|
assert(
|
|
this.tileSizes_.length == this.resolutions_.length,
|
|
"Number of `tileSizes` and `resolutions` must be equal"
|
|
);
|
|
}
|
|
this.tileSize_ = options.tileSize !== void 0 ? options.tileSize : !this.tileSizes_ ? DEFAULT_TILE_SIZE : null;
|
|
assert(
|
|
!this.tileSize_ && this.tileSizes_ || this.tileSize_ && !this.tileSizes_,
|
|
"Either `tileSize` or `tileSizes` must be configured, never both"
|
|
);
|
|
this.extent_ = extent !== void 0 ? extent : null;
|
|
this.fullTileRanges_ = null;
|
|
this.tmpSize_ = [0, 0];
|
|
this.tmpExtent_ = [0, 0, 0, 0];
|
|
if (options.sizes !== void 0) {
|
|
this.fullTileRanges_ = options.sizes.map((size, z) => {
|
|
const tileRange = new TileRange_default(
|
|
Math.min(0, size[0]),
|
|
Math.max(size[0] - 1, -1),
|
|
Math.min(0, size[1]),
|
|
Math.max(size[1] - 1, -1)
|
|
);
|
|
if (extent) {
|
|
const restrictedTileRange = this.getTileRangeForExtentAndZ(extent, z);
|
|
tileRange.minX = Math.max(restrictedTileRange.minX, tileRange.minX);
|
|
tileRange.maxX = Math.min(restrictedTileRange.maxX, tileRange.maxX);
|
|
tileRange.minY = Math.max(restrictedTileRange.minY, tileRange.minY);
|
|
tileRange.maxY = Math.min(restrictedTileRange.maxY, tileRange.maxY);
|
|
}
|
|
return tileRange;
|
|
});
|
|
} else if (extent) {
|
|
this.calculateTileRanges_(extent);
|
|
}
|
|
}
|
|
/**
|
|
* Call a function with each tile coordinate for a given extent and zoom level.
|
|
*
|
|
* @param {import("../extent.js").Extent} extent Extent.
|
|
* @param {number} zoom Integer zoom level.
|
|
* @param {function(import("../tilecoord.js").TileCoord): void} callback Function called with each tile coordinate.
|
|
* @api
|
|
*/
|
|
forEachTileCoord(extent, zoom, callback) {
|
|
const tileRange = this.getTileRangeForExtentAndZ(extent, zoom);
|
|
for (let i = tileRange.minX, ii = tileRange.maxX; i <= ii; ++i) {
|
|
for (let j = tileRange.minY, jj = tileRange.maxY; j <= jj; ++j) {
|
|
callback([zoom, i, j]);
|
|
}
|
|
}
|
|
}
|
|
/**
|
|
* @param {import("../tilecoord.js").TileCoord} tileCoord Tile coordinate.
|
|
* @param {function(number, import("../TileRange.js").default): boolean} callback Callback.
|
|
* @param {import("../TileRange.js").default} [tempTileRange] Temporary import("../TileRange.js").default object.
|
|
* @param {import("../extent.js").Extent} [tempExtent] Temporary import("../extent.js").Extent object.
|
|
* @return {boolean} Callback succeeded.
|
|
*/
|
|
forEachTileCoordParentTileRange(tileCoord, callback, tempTileRange, tempExtent) {
|
|
let tileRange, x, y;
|
|
let tileCoordExtent = null;
|
|
let z = tileCoord[0] - 1;
|
|
if (this.zoomFactor_ === 2) {
|
|
x = tileCoord[1];
|
|
y = tileCoord[2];
|
|
} else {
|
|
tileCoordExtent = this.getTileCoordExtent(tileCoord, tempExtent);
|
|
}
|
|
while (z >= this.minZoom) {
|
|
if (x !== void 0 && y !== void 0) {
|
|
x = Math.floor(x / 2);
|
|
y = Math.floor(y / 2);
|
|
tileRange = createOrUpdate2(x, x, y, y, tempTileRange);
|
|
} else {
|
|
tileRange = this.getTileRangeForExtentAndZ(
|
|
tileCoordExtent,
|
|
z,
|
|
tempTileRange
|
|
);
|
|
}
|
|
if (callback(z, tileRange)) {
|
|
return true;
|
|
}
|
|
--z;
|
|
}
|
|
return false;
|
|
}
|
|
/**
|
|
* Get the extent for this tile grid, if it was configured.
|
|
* @return {import("../extent.js").Extent} Extent.
|
|
* @api
|
|
*/
|
|
getExtent() {
|
|
return this.extent_;
|
|
}
|
|
/**
|
|
* Get the maximum zoom level for the grid.
|
|
* @return {number} Max zoom.
|
|
* @api
|
|
*/
|
|
getMaxZoom() {
|
|
return this.maxZoom;
|
|
}
|
|
/**
|
|
* Get the minimum zoom level for the grid.
|
|
* @return {number} Min zoom.
|
|
* @api
|
|
*/
|
|
getMinZoom() {
|
|
return this.minZoom;
|
|
}
|
|
/**
|
|
* Get the origin for the grid at the given zoom level.
|
|
* @param {number} z Integer zoom level.
|
|
* @return {import("../coordinate.js").Coordinate} Origin.
|
|
* @api
|
|
*/
|
|
getOrigin(z) {
|
|
if (this.origin_) {
|
|
return this.origin_;
|
|
}
|
|
return this.origins_[z];
|
|
}
|
|
/**
|
|
* Get the resolution for the given zoom level.
|
|
* @param {number} z Integer zoom level.
|
|
* @return {number} Resolution.
|
|
* @api
|
|
*/
|
|
getResolution(z) {
|
|
return this.resolutions_[z];
|
|
}
|
|
/**
|
|
* Get the list of resolutions for the tile grid.
|
|
* @return {Array<number>} Resolutions.
|
|
* @api
|
|
*/
|
|
getResolutions() {
|
|
return this.resolutions_;
|
|
}
|
|
/**
|
|
* @param {import("../tilecoord.js").TileCoord} tileCoord Tile coordinate.
|
|
* @param {import("../TileRange.js").default} [tempTileRange] Temporary import("../TileRange.js").default object.
|
|
* @param {import("../extent.js").Extent} [tempExtent] Temporary import("../extent.js").Extent object.
|
|
* @return {import("../TileRange.js").default|null} Tile range.
|
|
*/
|
|
getTileCoordChildTileRange(tileCoord, tempTileRange, tempExtent) {
|
|
if (tileCoord[0] < this.maxZoom) {
|
|
if (this.zoomFactor_ === 2) {
|
|
const minX = tileCoord[1] * 2;
|
|
const minY = tileCoord[2] * 2;
|
|
return createOrUpdate2(
|
|
minX,
|
|
minX + 1,
|
|
minY,
|
|
minY + 1,
|
|
tempTileRange
|
|
);
|
|
}
|
|
const tileCoordExtent = this.getTileCoordExtent(
|
|
tileCoord,
|
|
tempExtent || this.tmpExtent_
|
|
);
|
|
return this.getTileRangeForExtentAndZ(
|
|
tileCoordExtent,
|
|
tileCoord[0] + 1,
|
|
tempTileRange
|
|
);
|
|
}
|
|
return null;
|
|
}
|
|
/**
|
|
* @param {import("../tilecoord.js").TileCoord} tileCoord Tile coordinate.
|
|
* @param {number} z Integer zoom level.
|
|
* @param {import("../TileRange.js").default} [tempTileRange] Temporary import("../TileRange.js").default object.
|
|
* @return {import("../TileRange.js").default|null} Tile range.
|
|
*/
|
|
getTileRangeForTileCoordAndZ(tileCoord, z, tempTileRange) {
|
|
if (z > this.maxZoom || z < this.minZoom) {
|
|
return null;
|
|
}
|
|
const tileCoordZ = tileCoord[0];
|
|
const tileCoordX = tileCoord[1];
|
|
const tileCoordY = tileCoord[2];
|
|
if (z === tileCoordZ) {
|
|
return createOrUpdate2(
|
|
tileCoordX,
|
|
tileCoordY,
|
|
tileCoordX,
|
|
tileCoordY,
|
|
tempTileRange
|
|
);
|
|
}
|
|
if (this.zoomFactor_) {
|
|
const factor = Math.pow(this.zoomFactor_, z - tileCoordZ);
|
|
const minX = Math.floor(tileCoordX * factor);
|
|
const minY = Math.floor(tileCoordY * factor);
|
|
if (z < tileCoordZ) {
|
|
return createOrUpdate2(minX, minX, minY, minY, tempTileRange);
|
|
}
|
|
const maxX = Math.floor(factor * (tileCoordX + 1)) - 1;
|
|
const maxY = Math.floor(factor * (tileCoordY + 1)) - 1;
|
|
return createOrUpdate2(minX, maxX, minY, maxY, tempTileRange);
|
|
}
|
|
const tileCoordExtent = this.getTileCoordExtent(tileCoord, this.tmpExtent_);
|
|
return this.getTileRangeForExtentAndZ(tileCoordExtent, z, tempTileRange);
|
|
}
|
|
/**
|
|
* Get a tile range for the given extent and integer zoom level.
|
|
* @param {import("../extent.js").Extent} extent Extent.
|
|
* @param {number} z Integer zoom level.
|
|
* @param {import("../TileRange.js").default} [tempTileRange] Temporary tile range object.
|
|
* @return {import("../TileRange.js").default} Tile range.
|
|
*/
|
|
getTileRangeForExtentAndZ(extent, z, tempTileRange) {
|
|
this.getTileCoordForXYAndZ_(extent[0], extent[3], z, false, tmpTileCoord);
|
|
const minX = tmpTileCoord[1];
|
|
const minY = tmpTileCoord[2];
|
|
this.getTileCoordForXYAndZ_(extent[2], extent[1], z, true, tmpTileCoord);
|
|
const maxX = tmpTileCoord[1];
|
|
const maxY = tmpTileCoord[2];
|
|
return createOrUpdate2(minX, maxX, minY, maxY, tempTileRange);
|
|
}
|
|
/**
|
|
* @param {import("../tilecoord.js").TileCoord} tileCoord Tile coordinate.
|
|
* @return {import("../coordinate.js").Coordinate} Tile center.
|
|
*/
|
|
getTileCoordCenter(tileCoord) {
|
|
const origin = this.getOrigin(tileCoord[0]);
|
|
const resolution = this.getResolution(tileCoord[0]);
|
|
const tileSize = toSize(this.getTileSize(tileCoord[0]), this.tmpSize_);
|
|
return [
|
|
origin[0] + (tileCoord[1] + 0.5) * tileSize[0] * resolution,
|
|
origin[1] - (tileCoord[2] + 0.5) * tileSize[1] * resolution
|
|
];
|
|
}
|
|
/**
|
|
* Get the extent of a tile coordinate.
|
|
*
|
|
* @param {import("../tilecoord.js").TileCoord} tileCoord Tile coordinate.
|
|
* @param {import("../extent.js").Extent} [tempExtent] Temporary extent object.
|
|
* @return {import("../extent.js").Extent} Extent.
|
|
* @api
|
|
*/
|
|
getTileCoordExtent(tileCoord, tempExtent) {
|
|
const origin = this.getOrigin(tileCoord[0]);
|
|
const resolution = this.getResolution(tileCoord[0]);
|
|
const tileSize = toSize(this.getTileSize(tileCoord[0]), this.tmpSize_);
|
|
const minX = origin[0] + tileCoord[1] * tileSize[0] * resolution;
|
|
const minY = origin[1] - (tileCoord[2] + 1) * tileSize[1] * resolution;
|
|
const maxX = minX + tileSize[0] * resolution;
|
|
const maxY = minY + tileSize[1] * resolution;
|
|
return createOrUpdate(minX, minY, maxX, maxY, tempExtent);
|
|
}
|
|
/**
|
|
* Get the tile coordinate for the given map coordinate and resolution. This
|
|
* method considers that coordinates that intersect tile boundaries should be
|
|
* assigned the higher tile coordinate.
|
|
*
|
|
* @param {import("../coordinate.js").Coordinate} coordinate Coordinate.
|
|
* @param {number} resolution Resolution.
|
|
* @param {import("../tilecoord.js").TileCoord} [opt_tileCoord] Destination import("../tilecoord.js").TileCoord object.
|
|
* @return {import("../tilecoord.js").TileCoord} Tile coordinate.
|
|
* @api
|
|
*/
|
|
getTileCoordForCoordAndResolution(coordinate, resolution, opt_tileCoord) {
|
|
return this.getTileCoordForXYAndResolution_(
|
|
coordinate[0],
|
|
coordinate[1],
|
|
resolution,
|
|
false,
|
|
opt_tileCoord
|
|
);
|
|
}
|
|
/**
|
|
* Note that this method should not be called for resolutions that correspond
|
|
* to an integer zoom level. Instead call the `getTileCoordForXYAndZ_` method.
|
|
* @param {number} x X.
|
|
* @param {number} y Y.
|
|
* @param {number} resolution Resolution (for a non-integer zoom level).
|
|
* @param {boolean} reverseIntersectionPolicy Instead of letting edge
|
|
* intersections go to the higher tile coordinate, let edge intersections
|
|
* go to the lower tile coordinate.
|
|
* @param {import("../tilecoord.js").TileCoord} [opt_tileCoord] Temporary import("../tilecoord.js").TileCoord object.
|
|
* @return {import("../tilecoord.js").TileCoord} Tile coordinate.
|
|
* @private
|
|
*/
|
|
getTileCoordForXYAndResolution_(x, y, resolution, reverseIntersectionPolicy, opt_tileCoord) {
|
|
const z = this.getZForResolution(resolution);
|
|
const scale2 = resolution / this.getResolution(z);
|
|
const origin = this.getOrigin(z);
|
|
const tileSize = toSize(this.getTileSize(z), this.tmpSize_);
|
|
let tileCoordX = scale2 * (x - origin[0]) / resolution / tileSize[0];
|
|
let tileCoordY = scale2 * (origin[1] - y) / resolution / tileSize[1];
|
|
if (reverseIntersectionPolicy) {
|
|
tileCoordX = ceil(tileCoordX, DECIMALS) - 1;
|
|
tileCoordY = ceil(tileCoordY, DECIMALS) - 1;
|
|
} else {
|
|
tileCoordX = floor(tileCoordX, DECIMALS);
|
|
tileCoordY = floor(tileCoordY, DECIMALS);
|
|
}
|
|
return createOrUpdate3(z, tileCoordX, tileCoordY, opt_tileCoord);
|
|
}
|
|
/**
|
|
* Although there is repetition between this method and `getTileCoordForXYAndResolution_`,
|
|
* they should have separate implementations. This method is for integer zoom
|
|
* levels. The other method should only be called for resolutions corresponding
|
|
* to non-integer zoom levels.
|
|
* @param {number} x Map x coordinate.
|
|
* @param {number} y Map y coordinate.
|
|
* @param {number} z Integer zoom level.
|
|
* @param {boolean} reverseIntersectionPolicy Instead of letting edge
|
|
* intersections go to the higher tile coordinate, let edge intersections
|
|
* go to the lower tile coordinate.
|
|
* @param {import("../tilecoord.js").TileCoord} [opt_tileCoord] Temporary import("../tilecoord.js").TileCoord object.
|
|
* @return {import("../tilecoord.js").TileCoord} Tile coordinate.
|
|
* @private
|
|
*/
|
|
getTileCoordForXYAndZ_(x, y, z, reverseIntersectionPolicy, opt_tileCoord) {
|
|
const origin = this.getOrigin(z);
|
|
const resolution = this.getResolution(z);
|
|
const tileSize = toSize(this.getTileSize(z), this.tmpSize_);
|
|
let tileCoordX = (x - origin[0]) / resolution / tileSize[0];
|
|
let tileCoordY = (origin[1] - y) / resolution / tileSize[1];
|
|
if (reverseIntersectionPolicy) {
|
|
tileCoordX = ceil(tileCoordX, DECIMALS) - 1;
|
|
tileCoordY = ceil(tileCoordY, DECIMALS) - 1;
|
|
} else {
|
|
tileCoordX = floor(tileCoordX, DECIMALS);
|
|
tileCoordY = floor(tileCoordY, DECIMALS);
|
|
}
|
|
return createOrUpdate3(z, tileCoordX, tileCoordY, opt_tileCoord);
|
|
}
|
|
/**
|
|
* Get a tile coordinate given a map coordinate and zoom level.
|
|
* @param {import("../coordinate.js").Coordinate} coordinate Coordinate.
|
|
* @param {number} z Integer zoom level, e.g. the result of a `getZForResolution()` method call
|
|
* @param {import("../tilecoord.js").TileCoord} [opt_tileCoord] Destination import("../tilecoord.js").TileCoord object.
|
|
* @return {import("../tilecoord.js").TileCoord} Tile coordinate.
|
|
* @api
|
|
*/
|
|
getTileCoordForCoordAndZ(coordinate, z, opt_tileCoord) {
|
|
return this.getTileCoordForXYAndZ_(
|
|
coordinate[0],
|
|
coordinate[1],
|
|
z,
|
|
false,
|
|
opt_tileCoord
|
|
);
|
|
}
|
|
/**
|
|
* @param {import("../tilecoord.js").TileCoord} tileCoord Tile coordinate.
|
|
* @return {number} Tile resolution.
|
|
*/
|
|
getTileCoordResolution(tileCoord) {
|
|
return this.resolutions_[tileCoord[0]];
|
|
}
|
|
/**
|
|
* Get the tile size for a zoom level. The type of the return value matches the
|
|
* `tileSize` or `tileSizes` that the tile grid was configured with. To always
|
|
* get an {@link import("../size.js").Size}, run the result through {@link module:ol/size.toSize}.
|
|
* @param {number} z Z.
|
|
* @return {number|import("../size.js").Size} Tile size.
|
|
* @api
|
|
*/
|
|
getTileSize(z) {
|
|
if (this.tileSize_) {
|
|
return this.tileSize_;
|
|
}
|
|
return this.tileSizes_[z];
|
|
}
|
|
/**
|
|
* @param {number} z Zoom level.
|
|
* @return {import("../TileRange.js").default|null} Extent tile range for the specified zoom level.
|
|
*/
|
|
getFullTileRange(z) {
|
|
if (!this.fullTileRanges_) {
|
|
return this.extent_ ? this.getTileRangeForExtentAndZ(this.extent_, z) : null;
|
|
}
|
|
return this.fullTileRanges_[z];
|
|
}
|
|
/**
|
|
* @param {number} resolution Resolution.
|
|
* @param {number|import("../array.js").NearestDirectionFunction} [opt_direction]
|
|
* If 0, the nearest resolution will be used.
|
|
* If 1, the nearest higher resolution (lower Z) will be used. If -1, the
|
|
* nearest lower resolution (higher Z) will be used. Default is 0.
|
|
* Use a {@link module:ol/array~NearestDirectionFunction} for more precise control.
|
|
*
|
|
* For example to change tile Z at the midpoint of zoom levels
|
|
* ```js
|
|
* function(value, high, low) {
|
|
* return value - low * Math.sqrt(high / low);
|
|
* }
|
|
* ```
|
|
* @return {number} Z.
|
|
* @api
|
|
*/
|
|
getZForResolution(resolution, opt_direction) {
|
|
const z = linearFindNearest(
|
|
this.resolutions_,
|
|
resolution,
|
|
opt_direction || 0
|
|
);
|
|
return clamp(z, this.minZoom, this.maxZoom);
|
|
}
|
|
/**
|
|
* The tile with the provided tile coordinate intersects the given viewport.
|
|
* @param {import('../tilecoord.js').TileCoord} tileCoord Tile coordinate.
|
|
* @param {Array<number>} viewport Viewport as returned from {@link module:ol/extent.getRotatedViewport}.
|
|
* @return {boolean} The tile with the provided tile coordinate intersects the given viewport.
|
|
*/
|
|
tileCoordIntersectsViewport(tileCoord, viewport) {
|
|
return intersectsLinearRing(
|
|
viewport,
|
|
0,
|
|
viewport.length,
|
|
2,
|
|
this.getTileCoordExtent(tileCoord)
|
|
);
|
|
}
|
|
/**
|
|
* @param {!import("../extent.js").Extent} extent Extent for this tile grid.
|
|
* @private
|
|
*/
|
|
calculateTileRanges_(extent) {
|
|
const length = this.resolutions_.length;
|
|
const fullTileRanges = new Array(length);
|
|
for (let z = this.minZoom; z < length; ++z) {
|
|
fullTileRanges[z] = this.getTileRangeForExtentAndZ(extent, z);
|
|
}
|
|
this.fullTileRanges_ = fullTileRanges;
|
|
}
|
|
};
|
|
var TileGrid_default = TileGrid;
|
|
|
|
// node_modules/ol/tilegrid.js
|
|
function getForProjection(projection) {
|
|
let tileGrid = projection.getDefaultTileGrid();
|
|
if (!tileGrid) {
|
|
tileGrid = createForProjection(projection);
|
|
projection.setDefaultTileGrid(tileGrid);
|
|
}
|
|
return tileGrid;
|
|
}
|
|
function wrapX(tileGrid, tileCoord, projection) {
|
|
const z = tileCoord[0];
|
|
const center = tileGrid.getTileCoordCenter(tileCoord);
|
|
const projectionExtent = extentFromProjection(projection);
|
|
if (!containsCoordinate(projectionExtent, center)) {
|
|
const worldWidth = getWidth(projectionExtent);
|
|
const worldsAway = Math.ceil(
|
|
(projectionExtent[0] - center[0]) / worldWidth
|
|
);
|
|
center[0] += worldWidth * worldsAway;
|
|
return tileGrid.getTileCoordForCoordAndZ(center, z);
|
|
}
|
|
return tileCoord;
|
|
}
|
|
function createForExtent(extent, maxZoom, tileSize, corner) {
|
|
corner = corner !== void 0 ? corner : "top-left";
|
|
const resolutions = resolutionsFromExtent(extent, maxZoom, tileSize);
|
|
return new TileGrid_default({
|
|
extent,
|
|
origin: getCorner(extent, corner),
|
|
resolutions,
|
|
tileSize
|
|
});
|
|
}
|
|
function createXYZ(options) {
|
|
const xyzOptions = options || {};
|
|
const extent = xyzOptions.extent || get("EPSG:3857").getExtent();
|
|
const gridOptions = {
|
|
extent,
|
|
minZoom: xyzOptions.minZoom,
|
|
tileSize: xyzOptions.tileSize,
|
|
resolutions: resolutionsFromExtent(
|
|
extent,
|
|
xyzOptions.maxZoom,
|
|
xyzOptions.tileSize,
|
|
xyzOptions.maxResolution
|
|
)
|
|
};
|
|
return new TileGrid_default(gridOptions);
|
|
}
|
|
function resolutionsFromExtent(extent, maxZoom, tileSize, maxResolution) {
|
|
maxZoom = maxZoom !== void 0 ? maxZoom : DEFAULT_MAX_ZOOM;
|
|
tileSize = toSize(tileSize !== void 0 ? tileSize : DEFAULT_TILE_SIZE);
|
|
const height = getHeight(extent);
|
|
const width = getWidth(extent);
|
|
maxResolution = maxResolution > 0 ? maxResolution : Math.max(width / tileSize[0], height / tileSize[1]);
|
|
const length = maxZoom + 1;
|
|
const resolutions = new Array(length);
|
|
for (let z = 0; z < length; ++z) {
|
|
resolutions[z] = maxResolution / Math.pow(2, z);
|
|
}
|
|
return resolutions;
|
|
}
|
|
function createForProjection(projection, maxZoom, tileSize, corner) {
|
|
const extent = extentFromProjection(projection);
|
|
return createForExtent(extent, maxZoom, tileSize, corner);
|
|
}
|
|
function extentFromProjection(projection) {
|
|
projection = get(projection);
|
|
let extent = projection.getExtent();
|
|
if (!extent) {
|
|
const half = 180 * METERS_PER_UNIT.degrees / projection.getMetersPerUnit();
|
|
extent = createOrUpdate(-half, -half, half, half);
|
|
}
|
|
return extent;
|
|
}
|
|
|
|
// node_modules/ol/uri.js
|
|
function appendParams(uri, params) {
|
|
const keyParams = [];
|
|
Object.keys(params).forEach(function(k) {
|
|
if (params[k] !== null && params[k] !== void 0) {
|
|
keyParams.push(k + "=" + encodeURIComponent(params[k]));
|
|
}
|
|
});
|
|
const qs = keyParams.join("&");
|
|
uri = uri.replace(/[?&]$/, "");
|
|
uri += uri.includes("?") ? "&" : "?";
|
|
return uri + qs;
|
|
}
|
|
var zRegEx = /\{z\}/g;
|
|
var xRegEx = /\{x\}/g;
|
|
var yRegEx = /\{y\}/g;
|
|
var dashYRegEx = /\{-y\}/g;
|
|
function renderXYZTemplate(template, z, x, y, maxY) {
|
|
return template.replace(zRegEx, z.toString()).replace(xRegEx, x.toString()).replace(yRegEx, y.toString()).replace(dashYRegEx, function() {
|
|
if (maxY === void 0) {
|
|
throw new Error(
|
|
"If the URL template has a {-y} placeholder, the grid extent must be known"
|
|
);
|
|
}
|
|
return (maxY - y).toString();
|
|
});
|
|
}
|
|
function pickUrl(urls, z, x, y) {
|
|
const hash2 = hashZXY(z, x, y);
|
|
const index = modulo(hash2, urls.length);
|
|
return urls[index];
|
|
}
|
|
function expandUrl(url) {
|
|
const urls = [];
|
|
let match = /\{([a-z])-([a-z])\}/.exec(url);
|
|
if (match) {
|
|
const startCharCode = match[1].charCodeAt(0);
|
|
const stopCharCode = match[2].charCodeAt(0);
|
|
let charCode;
|
|
for (charCode = startCharCode; charCode <= stopCharCode; ++charCode) {
|
|
urls.push(url.replace(match[0], String.fromCharCode(charCode)));
|
|
}
|
|
return urls;
|
|
}
|
|
match = /\{(\d+)-(\d+)\}/.exec(url);
|
|
if (match) {
|
|
const stop = parseInt(match[2], 10);
|
|
for (let i = parseInt(match[1], 10); i <= stop; i++) {
|
|
urls.push(url.replace(match[0], i.toString()));
|
|
}
|
|
return urls;
|
|
}
|
|
urls.push(url);
|
|
return urls;
|
|
}
|
|
|
|
// node_modules/ol/tileurlfunction.js
|
|
function createFromTemplate(template, tileGrid) {
|
|
return (
|
|
/**
|
|
* @param {import("./tilecoord.js").TileCoord} tileCoord Tile Coordinate.
|
|
* @param {number} pixelRatio Pixel ratio.
|
|
* @param {import("./proj/Projection.js").default} projection Projection.
|
|
* @return {string|undefined} Tile URL.
|
|
*/
|
|
(function(tileCoord, pixelRatio, projection) {
|
|
if (!tileCoord) {
|
|
return void 0;
|
|
}
|
|
let maxY;
|
|
const z = tileCoord[0];
|
|
if (tileGrid) {
|
|
const range = tileGrid.getFullTileRange(z);
|
|
if (range) {
|
|
maxY = range.getHeight() - 1;
|
|
}
|
|
}
|
|
return renderXYZTemplate(template, z, tileCoord[1], tileCoord[2], maxY);
|
|
})
|
|
);
|
|
}
|
|
function createFromTemplates(templates, tileGrid) {
|
|
const len = templates.length;
|
|
const tileUrlFunctions = new Array(len);
|
|
for (let i = 0; i < len; ++i) {
|
|
tileUrlFunctions[i] = createFromTemplate(templates[i], tileGrid);
|
|
}
|
|
return createFromTileUrlFunctions(tileUrlFunctions);
|
|
}
|
|
function createFromTileUrlFunctions(tileUrlFunctions) {
|
|
if (tileUrlFunctions.length === 1) {
|
|
return tileUrlFunctions[0];
|
|
}
|
|
return (
|
|
/**
|
|
* @param {import("./tilecoord.js").TileCoord} tileCoord Tile Coordinate.
|
|
* @param {number} pixelRatio Pixel ratio.
|
|
* @param {import("./proj/Projection.js").default} projection Projection.
|
|
* @return {string|undefined} Tile URL.
|
|
*/
|
|
(function(tileCoord, pixelRatio, projection) {
|
|
if (!tileCoord) {
|
|
return void 0;
|
|
}
|
|
const h = hash(tileCoord);
|
|
const index = modulo(h, tileUrlFunctions.length);
|
|
return tileUrlFunctions[index](tileCoord, pixelRatio, projection);
|
|
})
|
|
);
|
|
}
|
|
function nullTileUrlFunction(tileCoord, pixelRatio, projection) {
|
|
return void 0;
|
|
}
|
|
|
|
// node_modules/ol/source/Tile.js
|
|
var TileSource = class extends Source_default {
|
|
/**
|
|
* @param {Options} options SourceTile source options.
|
|
*/
|
|
constructor(options) {
|
|
super({
|
|
attributions: options.attributions,
|
|
attributionsCollapsible: options.attributionsCollapsible,
|
|
projection: options.projection,
|
|
state: options.state,
|
|
wrapX: options.wrapX,
|
|
interpolate: options.interpolate
|
|
});
|
|
this.on;
|
|
this.once;
|
|
this.un;
|
|
this.tilePixelRatio_ = options.tilePixelRatio !== void 0 ? options.tilePixelRatio : 1;
|
|
this.tileGrid = options.tileGrid !== void 0 ? options.tileGrid : null;
|
|
const tileSize = [256, 256];
|
|
if (this.tileGrid) {
|
|
toSize(this.tileGrid.getTileSize(this.tileGrid.getMinZoom()), tileSize);
|
|
}
|
|
this.tmpSize = [0, 0];
|
|
this.key_ = options.key || getUid(this);
|
|
this.tileOptions = {
|
|
transition: options.transition,
|
|
interpolate: options.interpolate
|
|
};
|
|
this.zDirection = options.zDirection ? options.zDirection : 0;
|
|
}
|
|
/**
|
|
* @param {import("../proj/Projection.js").default} projection Projection.
|
|
* @return {number} Gutter.
|
|
*/
|
|
getGutterForProjection(projection) {
|
|
return 0;
|
|
}
|
|
/**
|
|
* Return the key to be used for all tiles in the source.
|
|
* @return {string} The key for all tiles.
|
|
*/
|
|
getKey() {
|
|
return this.key_;
|
|
}
|
|
/**
|
|
* Set the value to be used as the key for all tiles in the source.
|
|
* @param {string} key The key for tiles.
|
|
* @protected
|
|
*/
|
|
setKey(key) {
|
|
if (this.key_ !== key) {
|
|
this.key_ = key;
|
|
this.changed();
|
|
}
|
|
}
|
|
/**
|
|
* @param {import("../proj/Projection").default} [projection] Projection.
|
|
* @return {Array<number>|null} Resolutions.
|
|
* @override
|
|
*/
|
|
getResolutions(projection) {
|
|
const tileGrid = projection ? this.getTileGridForProjection(projection) : this.tileGrid;
|
|
if (!tileGrid) {
|
|
return null;
|
|
}
|
|
return tileGrid.getResolutions();
|
|
}
|
|
/**
|
|
* @abstract
|
|
* @param {number} z Tile coordinate z.
|
|
* @param {number} x Tile coordinate x.
|
|
* @param {number} y Tile coordinate y.
|
|
* @param {number} pixelRatio Pixel ratio.
|
|
* @param {import("../proj/Projection.js").default} projection Projection.
|
|
* @param {import("../structs/LRUCache.js").default<import("../Tile.js").default>} [tileCache] Tile cache.
|
|
* @return {TileType|null} Tile.
|
|
*/
|
|
getTile(z, x, y, pixelRatio, projection, tileCache) {
|
|
return abstract();
|
|
}
|
|
/**
|
|
* Return the tile grid of the tile source.
|
|
* @return {import("../tilegrid/TileGrid.js").default|null} Tile grid.
|
|
* @api
|
|
*/
|
|
getTileGrid() {
|
|
return this.tileGrid;
|
|
}
|
|
/**
|
|
* @param {import("../proj/Projection.js").default} projection Projection.
|
|
* @return {!import("../tilegrid/TileGrid.js").default} Tile grid.
|
|
*/
|
|
getTileGridForProjection(projection) {
|
|
if (!this.tileGrid) {
|
|
return getForProjection(projection);
|
|
}
|
|
return this.tileGrid;
|
|
}
|
|
/**
|
|
* Get the tile pixel ratio for this source. Subclasses may override this
|
|
* method, which is meant to return a supported pixel ratio that matches the
|
|
* provided `pixelRatio` as close as possible.
|
|
* @param {number} pixelRatio Pixel ratio.
|
|
* @return {number} Tile pixel ratio.
|
|
*/
|
|
getTilePixelRatio(pixelRatio) {
|
|
return this.tilePixelRatio_;
|
|
}
|
|
/**
|
|
* @param {number} z Z.
|
|
* @param {number} pixelRatio Pixel ratio.
|
|
* @param {import("../proj/Projection.js").default} projection Projection.
|
|
* @return {import("../size.js").Size} Tile size.
|
|
*/
|
|
getTilePixelSize(z, pixelRatio, projection) {
|
|
const tileGrid = this.getTileGridForProjection(projection);
|
|
const tilePixelRatio = this.getTilePixelRatio(pixelRatio);
|
|
const tileSize = toSize(tileGrid.getTileSize(z), this.tmpSize);
|
|
if (tilePixelRatio == 1) {
|
|
return tileSize;
|
|
}
|
|
return scale(tileSize, tilePixelRatio, this.tmpSize);
|
|
}
|
|
/**
|
|
* Returns a tile coordinate wrapped around the x-axis. When the tile coordinate
|
|
* is outside the resolution and extent range of the tile grid, `null` will be
|
|
* returned.
|
|
* @param {import("../tilecoord.js").TileCoord} tileCoord Tile coordinate.
|
|
* @param {import("../proj/Projection.js").default} [projection] Projection.
|
|
* @return {import("../tilecoord.js").TileCoord} Tile coordinate to be passed to the tileUrlFunction or
|
|
* null if no tile URL should be created for the passed `tileCoord`.
|
|
*/
|
|
getTileCoordForTileUrlFunction(tileCoord, projection) {
|
|
const gridProjection = projection !== void 0 ? projection : this.getProjection();
|
|
const tileGrid = projection !== void 0 ? this.getTileGridForProjection(gridProjection) : this.tileGrid || this.getTileGridForProjection(gridProjection);
|
|
if (this.getWrapX() && gridProjection.isGlobal()) {
|
|
tileCoord = wrapX(tileGrid, tileCoord, gridProjection);
|
|
}
|
|
return withinExtentAndZ(tileCoord, tileGrid) ? tileCoord : null;
|
|
}
|
|
/**
|
|
* Remove all cached reprojected tiles from the source. The next render cycle will create new tiles.
|
|
* @api
|
|
*/
|
|
clear() {
|
|
}
|
|
/**
|
|
* @override
|
|
*/
|
|
refresh() {
|
|
this.clear();
|
|
super.refresh();
|
|
}
|
|
};
|
|
var TileSourceEvent = class extends Event_default {
|
|
/**
|
|
* @param {string} type Type.
|
|
* @param {import("../Tile.js").default} tile The tile.
|
|
*/
|
|
constructor(type, tile) {
|
|
super(type);
|
|
this.tile = tile;
|
|
}
|
|
};
|
|
var Tile_default2 = TileSource;
|
|
|
|
// node_modules/ol/source/TileEventType.js
|
|
var TileEventType_default = {
|
|
/**
|
|
* Triggered when a tile starts loading.
|
|
* @event module:ol/source/Tile.TileSourceEvent#tileloadstart
|
|
* @api
|
|
*/
|
|
TILELOADSTART: "tileloadstart",
|
|
/**
|
|
* Triggered when a tile finishes loading, either when its data is loaded,
|
|
* or when loading was aborted because the tile is no longer needed.
|
|
* @event module:ol/source/Tile.TileSourceEvent#tileloadend
|
|
* @api
|
|
*/
|
|
TILELOADEND: "tileloadend",
|
|
/**
|
|
* Triggered if tile loading results in an error. Note that this is not the
|
|
* right place to re-fetch tiles. See {@link module:ol/ImageTile~ImageTile#load}
|
|
* for details.
|
|
* @event module:ol/source/Tile.TileSourceEvent#tileloaderror
|
|
* @api
|
|
*/
|
|
TILELOADERROR: "tileloaderror"
|
|
};
|
|
|
|
// node_modules/ol/source/UrlTile.js
|
|
var UrlTile = class _UrlTile extends Tile_default2 {
|
|
/**
|
|
* @param {Options} options Image tile options.
|
|
*/
|
|
constructor(options) {
|
|
super({
|
|
attributions: options.attributions,
|
|
cacheSize: options.cacheSize,
|
|
projection: options.projection,
|
|
state: options.state,
|
|
tileGrid: options.tileGrid,
|
|
tilePixelRatio: options.tilePixelRatio,
|
|
wrapX: options.wrapX,
|
|
transition: options.transition,
|
|
interpolate: options.interpolate,
|
|
key: options.key,
|
|
attributionsCollapsible: options.attributionsCollapsible,
|
|
zDirection: options.zDirection
|
|
});
|
|
this.generateTileUrlFunction_ = this.tileUrlFunction === _UrlTile.prototype.tileUrlFunction;
|
|
this.tileLoadFunction = options.tileLoadFunction;
|
|
if (options.tileUrlFunction) {
|
|
this.tileUrlFunction = options.tileUrlFunction;
|
|
}
|
|
this.urls = null;
|
|
if (options.urls) {
|
|
this.setUrls(options.urls);
|
|
} else if (options.url) {
|
|
this.setUrl(options.url);
|
|
}
|
|
this.tileLoadingKeys_ = {};
|
|
}
|
|
/**
|
|
* Deprecated. Use an ImageTile source instead.
|
|
* Return the tile load function of the source.
|
|
* @return {import("../Tile.js").LoadFunction} TileLoadFunction
|
|
* @api
|
|
*/
|
|
getTileLoadFunction() {
|
|
return this.tileLoadFunction;
|
|
}
|
|
/**
|
|
* Deprecated. Use an ImageTile source instead.
|
|
* Return the tile URL function of the source.
|
|
* @return {import("../Tile.js").UrlFunction} TileUrlFunction
|
|
* @api
|
|
*/
|
|
getTileUrlFunction() {
|
|
return Object.getPrototypeOf(this).tileUrlFunction === this.tileUrlFunction ? this.tileUrlFunction.bind(this) : this.tileUrlFunction;
|
|
}
|
|
/**
|
|
* Deprecated. Use an ImageTile source instead.
|
|
* Return the URLs used for this source.
|
|
* When a tileUrlFunction is used instead of url or urls,
|
|
* null will be returned.
|
|
* @return {!Array<string>|null} URLs.
|
|
* @api
|
|
*/
|
|
getUrls() {
|
|
return this.urls;
|
|
}
|
|
/**
|
|
* Handle tile change events.
|
|
* @param {import("../events/Event.js").default} event Event.
|
|
* @protected
|
|
*/
|
|
handleTileChange(event) {
|
|
const tile = (
|
|
/** @type {import("../Tile.js").default} */
|
|
event.target
|
|
);
|
|
const uid = getUid(tile);
|
|
const tileState = tile.getState();
|
|
let type;
|
|
if (tileState == TileState_default.LOADING) {
|
|
this.tileLoadingKeys_[uid] = true;
|
|
type = TileEventType_default.TILELOADSTART;
|
|
} else if (uid in this.tileLoadingKeys_) {
|
|
delete this.tileLoadingKeys_[uid];
|
|
type = tileState == TileState_default.ERROR ? TileEventType_default.TILELOADERROR : tileState == TileState_default.LOADED ? TileEventType_default.TILELOADEND : void 0;
|
|
}
|
|
if (type != void 0) {
|
|
this.dispatchEvent(new TileSourceEvent(type, tile));
|
|
}
|
|
}
|
|
/**
|
|
* Deprecated. Use an ImageTile source instead.
|
|
* Set the tile load function of the source.
|
|
* @param {import("../Tile.js").LoadFunction} tileLoadFunction Tile load function.
|
|
* @api
|
|
*/
|
|
setTileLoadFunction(tileLoadFunction) {
|
|
this.tileLoadFunction = tileLoadFunction;
|
|
this.changed();
|
|
}
|
|
/**
|
|
* Deprecated. Use an ImageTile source instead.
|
|
* Set the tile URL function of the source.
|
|
* @param {import("../Tile.js").UrlFunction} tileUrlFunction Tile URL function.
|
|
* @param {string} [key] Optional new tile key for the source.
|
|
* @api
|
|
*/
|
|
setTileUrlFunction(tileUrlFunction, key) {
|
|
this.tileUrlFunction = tileUrlFunction;
|
|
if (typeof key !== "undefined") {
|
|
this.setKey(key);
|
|
} else {
|
|
this.changed();
|
|
}
|
|
}
|
|
/**
|
|
* Set the URL to use for requests.
|
|
* @param {string} url URL.
|
|
* @api
|
|
*/
|
|
setUrl(url) {
|
|
const urls = expandUrl(url);
|
|
this.urls = urls;
|
|
this.setUrls(urls);
|
|
}
|
|
/**
|
|
* Deprecated. Use an ImageTile source instead.
|
|
* Set the URLs to use for requests.
|
|
* @param {Array<string>} urls URLs.
|
|
* @api
|
|
*/
|
|
setUrls(urls) {
|
|
this.urls = urls;
|
|
const key = urls.join("\n");
|
|
if (this.generateTileUrlFunction_) {
|
|
this.setTileUrlFunction(createFromTemplates(urls, this.tileGrid), key);
|
|
} else {
|
|
this.setKey(key);
|
|
}
|
|
}
|
|
/**
|
|
* @param {import("../tilecoord.js").TileCoord} tileCoord Tile coordinate.
|
|
* @param {number} pixelRatio Pixel ratio.
|
|
* @param {import("../proj/Projection.js").default} projection Projection.
|
|
* @return {string|undefined} Tile URL.
|
|
*/
|
|
tileUrlFunction(tileCoord, pixelRatio, projection) {
|
|
return void 0;
|
|
}
|
|
};
|
|
var UrlTile_default = UrlTile;
|
|
|
|
// node_modules/ol/source/TileImage.js
|
|
var TileImage = class extends UrlTile_default {
|
|
/**
|
|
* @param {!Options} options Image tile options.
|
|
*/
|
|
constructor(options) {
|
|
super({
|
|
attributions: options.attributions,
|
|
cacheSize: options.cacheSize,
|
|
projection: options.projection,
|
|
state: options.state,
|
|
tileGrid: options.tileGrid,
|
|
tileLoadFunction: options.tileLoadFunction ? options.tileLoadFunction : defaultTileLoadFunction,
|
|
tilePixelRatio: options.tilePixelRatio,
|
|
tileUrlFunction: options.tileUrlFunction,
|
|
url: options.url,
|
|
urls: options.urls,
|
|
wrapX: options.wrapX,
|
|
transition: options.transition,
|
|
interpolate: options.interpolate !== void 0 ? options.interpolate : true,
|
|
key: options.key,
|
|
attributionsCollapsible: options.attributionsCollapsible,
|
|
zDirection: options.zDirection
|
|
});
|
|
this.crossOrigin = options.crossOrigin !== void 0 ? options.crossOrigin : null;
|
|
this.tileClass = options.tileClass !== void 0 ? options.tileClass : ImageTile_default;
|
|
this.tileGridForProjection = {};
|
|
this.reprojectionErrorThreshold_ = options.reprojectionErrorThreshold;
|
|
this.renderReprojectionEdges_ = false;
|
|
}
|
|
/**
|
|
* @param {import("../proj/Projection.js").default} projection Projection.
|
|
* @return {number} Gutter.
|
|
* @override
|
|
*/
|
|
getGutterForProjection(projection) {
|
|
if (this.getProjection() && projection && !equivalent(this.getProjection(), projection)) {
|
|
return 0;
|
|
}
|
|
return this.getGutter();
|
|
}
|
|
/**
|
|
* @return {number} Gutter.
|
|
*/
|
|
getGutter() {
|
|
return 0;
|
|
}
|
|
/**
|
|
* Return the key to be used for all tiles in the source.
|
|
* @return {string} The key for all tiles.
|
|
* @override
|
|
*/
|
|
getKey() {
|
|
let key = super.getKey();
|
|
if (!this.getInterpolate()) {
|
|
key += ":disable-interpolation";
|
|
}
|
|
return key;
|
|
}
|
|
/**
|
|
* @param {import("../proj/Projection.js").default} projection Projection.
|
|
* @return {!import("../tilegrid/TileGrid.js").default} Tile grid.
|
|
* @override
|
|
*/
|
|
getTileGridForProjection(projection) {
|
|
const thisProj = this.getProjection();
|
|
if (this.tileGrid && (!thisProj || equivalent(thisProj, projection))) {
|
|
return this.tileGrid;
|
|
}
|
|
const projKey = getUid(projection);
|
|
if (!(projKey in this.tileGridForProjection)) {
|
|
this.tileGridForProjection[projKey] = getForProjection(projection);
|
|
}
|
|
return this.tileGridForProjection[projKey];
|
|
}
|
|
/**
|
|
* @param {number} z Tile coordinate z.
|
|
* @param {number} x Tile coordinate x.
|
|
* @param {number} y Tile coordinate y.
|
|
* @param {number} pixelRatio Pixel ratio.
|
|
* @param {import("../proj/Projection.js").default} projection Projection.
|
|
* @param {string} key The key set on the tile.
|
|
* @return {!ImageTile} Tile.
|
|
* @private
|
|
*/
|
|
createTile_(z, x, y, pixelRatio, projection, key) {
|
|
const tileCoord = [z, x, y];
|
|
const urlTileCoord = this.getTileCoordForTileUrlFunction(
|
|
tileCoord,
|
|
projection
|
|
);
|
|
const tileUrl = urlTileCoord ? this.tileUrlFunction(urlTileCoord, pixelRatio, projection) : void 0;
|
|
const tile = new this.tileClass(
|
|
tileCoord,
|
|
tileUrl !== void 0 ? TileState_default.IDLE : TileState_default.EMPTY,
|
|
tileUrl !== void 0 ? tileUrl : "",
|
|
this.crossOrigin,
|
|
this.tileLoadFunction,
|
|
this.tileOptions
|
|
);
|
|
tile.key = key;
|
|
tile.addEventListener(EventType_default.CHANGE, this.handleTileChange.bind(this));
|
|
return tile;
|
|
}
|
|
/**
|
|
* @param {number} z Tile coordinate z.
|
|
* @param {number} x Tile coordinate x.
|
|
* @param {number} y Tile coordinate y.
|
|
* @param {number} pixelRatio Pixel ratio.
|
|
* @param {import("../proj/Projection.js").default} projection Projection.
|
|
* @param {import("../structs/LRUCache.js").default<import("../Tile.js").default>} [tileCache] Tile cache.
|
|
* @return {!(ImageTile|ReprojTile)} Tile.
|
|
* @override
|
|
*/
|
|
getTile(z, x, y, pixelRatio, projection, tileCache) {
|
|
const sourceProjection = this.getProjection();
|
|
if (!sourceProjection || !projection || equivalent(sourceProjection, projection)) {
|
|
return this.getTileInternal(
|
|
z,
|
|
x,
|
|
y,
|
|
pixelRatio,
|
|
sourceProjection || projection
|
|
);
|
|
}
|
|
const tileCoord = [z, x, y];
|
|
const key = this.getKey();
|
|
const sourceTileGrid = this.getTileGridForProjection(sourceProjection);
|
|
const targetTileGrid = this.getTileGridForProjection(projection);
|
|
const wrappedTileCoord = this.getTileCoordForTileUrlFunction(
|
|
tileCoord,
|
|
projection
|
|
);
|
|
const tile = new Tile_default(
|
|
sourceProjection,
|
|
sourceTileGrid,
|
|
projection,
|
|
targetTileGrid,
|
|
tileCoord,
|
|
wrappedTileCoord,
|
|
this.getTilePixelRatio(pixelRatio),
|
|
this.getGutter(),
|
|
(z2, x2, y2, pixelRatio2) => this.getTileInternal(z2, x2, y2, pixelRatio2, sourceProjection, tileCache),
|
|
this.reprojectionErrorThreshold_,
|
|
this.renderReprojectionEdges_,
|
|
this.tileOptions
|
|
);
|
|
tile.key = key;
|
|
return tile;
|
|
}
|
|
/**
|
|
* @param {number} z Tile coordinate z.
|
|
* @param {number} x Tile coordinate x.
|
|
* @param {number} y Tile coordinate y.
|
|
* @param {number} pixelRatio Pixel ratio.
|
|
* @param {!import("../proj/Projection.js").default} projection Projection.
|
|
* @param {import("../structs/LRUCache.js").default<import("../Tile.js").default>} [tileCache] Tile cache.
|
|
* @return {!ImageTile} Tile.
|
|
* @protected
|
|
*/
|
|
getTileInternal(z, x, y, pixelRatio, projection, tileCache) {
|
|
const key = this.getKey();
|
|
const cacheKey = getCacheKey(this, key, z, x, y);
|
|
if (tileCache && tileCache.containsKey(cacheKey)) {
|
|
const tile2 = (
|
|
/** @type {!ImageTile} */
|
|
tileCache.get(cacheKey)
|
|
);
|
|
return tile2;
|
|
}
|
|
const tile = this.createTile_(z, x, y, pixelRatio, projection, key);
|
|
tileCache == null ? void 0 : tileCache.set(cacheKey, tile);
|
|
return tile;
|
|
}
|
|
/**
|
|
* Sets whether to render reprojection edges or not (usually for debugging).
|
|
* @param {boolean} render Render the edges.
|
|
* @api
|
|
*/
|
|
setRenderReprojectionEdges(render) {
|
|
if (this.renderReprojectionEdges_ == render) {
|
|
return;
|
|
}
|
|
this.renderReprojectionEdges_ = render;
|
|
this.changed();
|
|
}
|
|
/**
|
|
* Sets the tile grid to use when reprojecting the tiles to the given
|
|
* projection instead of the default tile grid for the projection.
|
|
*
|
|
* This can be useful when the default tile grid cannot be created
|
|
* (e.g. projection has no extent defined) or
|
|
* for optimization reasons (custom tile size, resolutions, ...).
|
|
*
|
|
* @param {import("../proj.js").ProjectionLike} projection Projection.
|
|
* @param {import("../tilegrid/TileGrid.js").default} tilegrid Tile grid to use for the projection.
|
|
* @api
|
|
*/
|
|
setTileGridForProjection(projection, tilegrid) {
|
|
const proj = get(projection);
|
|
if (proj) {
|
|
const projKey = getUid(proj);
|
|
if (!(projKey in this.tileGridForProjection)) {
|
|
this.tileGridForProjection[projKey] = tilegrid;
|
|
}
|
|
}
|
|
}
|
|
};
|
|
function defaultTileLoadFunction(imageTile, src) {
|
|
if (WORKER_OFFSCREEN_CANVAS) {
|
|
const crossOrigin = imageTile.getCrossOrigin();
|
|
let mode = "same-origin";
|
|
let credentials = "same-origin";
|
|
if (crossOrigin === "anonymous" || crossOrigin === "") {
|
|
mode = "cors";
|
|
credentials = "omit";
|
|
} else if (crossOrigin === "use-credentials") {
|
|
mode = "cors";
|
|
credentials = "include";
|
|
}
|
|
fetch(src, {
|
|
mode,
|
|
credentials
|
|
}).then((response) => {
|
|
if (!response.ok) {
|
|
throw new Error(`HTTP ${response.status}`);
|
|
}
|
|
return response.blob();
|
|
}).then((blob) => {
|
|
return createImageBitmap(blob);
|
|
}).then((imageBitmap) => {
|
|
var _a;
|
|
const canvas = imageTile.getImage();
|
|
canvas.width = imageBitmap.width;
|
|
canvas.height = imageBitmap.height;
|
|
const ctx = (
|
|
/** @type {OffscreenCanvas} */
|
|
canvas.getContext("2d")
|
|
);
|
|
ctx.drawImage(imageBitmap, 0, 0);
|
|
(_a = imageBitmap.close) == null ? void 0 : _a.call(imageBitmap);
|
|
canvas.dispatchEvent(new Event("load"));
|
|
}).catch(() => {
|
|
const canvas = imageTile.getImage();
|
|
canvas.dispatchEvent(new Event("error"));
|
|
});
|
|
return;
|
|
}
|
|
imageTile.getImage().src = src;
|
|
}
|
|
var TileImage_default = TileImage;
|
|
|
|
// node_modules/ol/source/XYZ.js
|
|
var XYZ = class extends TileImage_default {
|
|
/**
|
|
* @param {Options} [options] XYZ options.
|
|
*/
|
|
constructor(options) {
|
|
options = options || {};
|
|
const projection = options.projection !== void 0 ? options.projection : "EPSG:3857";
|
|
const tileGrid = options.tileGrid !== void 0 ? options.tileGrid : createXYZ({
|
|
extent: extentFromProjection(projection),
|
|
maxResolution: options.maxResolution,
|
|
maxZoom: options.maxZoom,
|
|
minZoom: options.minZoom,
|
|
tileSize: options.tileSize
|
|
});
|
|
super({
|
|
attributions: options.attributions,
|
|
cacheSize: options.cacheSize,
|
|
crossOrigin: options.crossOrigin,
|
|
interpolate: options.interpolate,
|
|
projection,
|
|
reprojectionErrorThreshold: options.reprojectionErrorThreshold,
|
|
tileGrid,
|
|
tileLoadFunction: options.tileLoadFunction,
|
|
tilePixelRatio: options.tilePixelRatio,
|
|
tileUrlFunction: options.tileUrlFunction,
|
|
url: options.url,
|
|
urls: options.urls,
|
|
wrapX: options.wrapX !== void 0 ? options.wrapX : true,
|
|
transition: options.transition,
|
|
attributionsCollapsible: options.attributionsCollapsible,
|
|
zDirection: options.zDirection
|
|
});
|
|
this.gutter_ = options.gutter !== void 0 ? options.gutter : 0;
|
|
}
|
|
/**
|
|
* @return {number} Gutter.
|
|
* @override
|
|
*/
|
|
getGutter() {
|
|
return this.gutter_;
|
|
}
|
|
};
|
|
var XYZ_default = XYZ;
|
|
|
|
export {
|
|
TileGrid_default,
|
|
getForProjection,
|
|
createXYZ,
|
|
extentFromProjection,
|
|
appendParams,
|
|
renderXYZTemplate,
|
|
pickUrl,
|
|
expandUrl,
|
|
createFromTemplates,
|
|
createFromTileUrlFunctions,
|
|
nullTileUrlFunction,
|
|
TileSourceEvent,
|
|
Tile_default2 as Tile_default,
|
|
TileEventType_default,
|
|
UrlTile_default,
|
|
defaultTileLoadFunction,
|
|
TileImage_default,
|
|
XYZ_default
|
|
};
|
|
//# sourceMappingURL=chunk-3ZDRPUXW.js.map
|