SourceTermAnalysisSystem_vue/node_modules/.vite/deps/chunk-QL7JR4NF.js
2026-05-15 10:22:44 +08:00

291 lines
9.1 KiB
JavaScript

import {
ERROR_THRESHOLD,
Triangulation_default,
calculateSourceExtentResolution,
canvasPool,
render
} from "./chunk-4YO3ZZ7L.js";
import {
Tile_default
} from "./chunk-MESSQWK4.js";
import {
TileState_default
} from "./chunk-5D2XPBR2.js";
import {
releaseCanvas
} from "./chunk-YWIWRQT2.js";
import {
clamp
} from "./chunk-54BTDBAD.js";
import {
getArea,
getIntersection,
getWidth,
wrapAndSliceX
} from "./chunk-CKDBVGKM.js";
import {
EventType_default,
listen,
unlistenByKey
} from "./chunk-KJXIHBKT.js";
// node_modules/ol/reproj/Tile.js
var ReprojTile = class extends Tile_default {
/**
* @param {import("../proj/Projection.js").default} sourceProj Source projection.
* @param {import("../tilegrid/TileGrid.js").default} sourceTileGrid Source tile grid.
* @param {import("../proj/Projection.js").default} targetProj Target projection.
* @param {import("../tilegrid/TileGrid.js").default} targetTileGrid Target tile grid.
* @param {import("../tilecoord.js").TileCoord} tileCoord Coordinate of the tile.
* @param {import("../tilecoord.js").TileCoord} wrappedTileCoord Coordinate of the tile wrapped in X.
* @param {number} pixelRatio Pixel ratio.
* @param {number} gutter Gutter of the source tiles.
* @param {FunctionType} getTileFunction
* Function returning source tiles (z, x, y, pixelRatio).
* @param {number} [errorThreshold] Acceptable reprojection error (in px).
* @param {boolean} [renderEdges] Render reprojection edges.
* @param {import("../Tile.js").Options} [options] Tile options.
*/
constructor(sourceProj, sourceTileGrid, targetProj, targetTileGrid, tileCoord, wrappedTileCoord, pixelRatio, gutter, getTileFunction, errorThreshold, renderEdges, options) {
super(tileCoord, TileState_default.IDLE, options);
this.renderEdges_ = renderEdges !== void 0 ? renderEdges : false;
this.pixelRatio_ = pixelRatio;
this.gutter_ = gutter;
this.canvas_ = null;
this.sourceTileGrid_ = sourceTileGrid;
this.targetTileGrid_ = targetTileGrid;
this.wrappedTileCoord_ = wrappedTileCoord ? wrappedTileCoord : tileCoord;
this.sourceTiles_ = [];
this.sourcesListenerKeys_ = null;
this.sourceZ_ = 0;
this.clipExtent_ = sourceProj.canWrapX() ? sourceProj.getExtent() : void 0;
const targetExtent = targetTileGrid.getTileCoordExtent(
this.wrappedTileCoord_
);
const maxTargetExtent = this.targetTileGrid_.getExtent();
let maxSourceExtent = this.sourceTileGrid_.getExtent();
const limitedTargetExtent = maxTargetExtent ? getIntersection(targetExtent, maxTargetExtent) : targetExtent;
if (getArea(limitedTargetExtent) === 0) {
this.state = TileState_default.EMPTY;
return;
}
const sourceProjExtent = sourceProj.getExtent();
if (sourceProjExtent) {
if (!maxSourceExtent) {
maxSourceExtent = sourceProjExtent;
} else {
maxSourceExtent = getIntersection(maxSourceExtent, sourceProjExtent);
}
}
const targetResolution = targetTileGrid.getResolution(
this.wrappedTileCoord_[0]
);
const sourceResolution = calculateSourceExtentResolution(
sourceProj,
targetProj,
limitedTargetExtent,
targetResolution
);
if (!isFinite(sourceResolution) || sourceResolution <= 0) {
this.state = TileState_default.EMPTY;
return;
}
const errorThresholdInPixels = errorThreshold !== void 0 ? errorThreshold : ERROR_THRESHOLD;
this.triangulation_ = new Triangulation_default(
sourceProj,
targetProj,
limitedTargetExtent,
maxSourceExtent,
sourceResolution * errorThresholdInPixels,
targetResolution
);
if (this.triangulation_.getTriangles().length === 0) {
this.state = TileState_default.EMPTY;
return;
}
this.sourceZ_ = sourceTileGrid.getZForResolution(sourceResolution);
let sourceExtent = this.triangulation_.calculateSourceExtent();
if (maxSourceExtent) {
if (sourceProj.canWrapX()) {
sourceExtent[1] = clamp(
sourceExtent[1],
maxSourceExtent[1],
maxSourceExtent[3]
);
sourceExtent[3] = clamp(
sourceExtent[3],
maxSourceExtent[1],
maxSourceExtent[3]
);
} else {
sourceExtent = getIntersection(sourceExtent, maxSourceExtent);
}
}
if (!getArea(sourceExtent)) {
this.state = TileState_default.EMPTY;
} else {
let worldWidth = 0;
let worldsAway = 0;
if (sourceProj.canWrapX()) {
worldWidth = getWidth(sourceProjExtent);
worldsAway = Math.floor(
(sourceExtent[0] - sourceProjExtent[0]) / worldWidth
);
}
const sourceExtents = wrapAndSliceX(
sourceExtent.slice(),
sourceProj,
true
);
sourceExtents.forEach((extent) => {
const sourceRange = sourceTileGrid.getTileRangeForExtentAndZ(
extent,
this.sourceZ_
);
for (let srcX = sourceRange.minX; srcX <= sourceRange.maxX; srcX++) {
for (let srcY = sourceRange.minY; srcY <= sourceRange.maxY; srcY++) {
const tile = getTileFunction(this.sourceZ_, srcX, srcY, pixelRatio);
if (tile) {
const offset = worldsAway * worldWidth;
this.sourceTiles_.push({ tile, offset });
}
}
}
++worldsAway;
});
if (this.sourceTiles_.length === 0) {
this.state = TileState_default.EMPTY;
}
}
}
/**
* Get the HTML Canvas element for this tile.
* @return {HTMLCanvasElement} Canvas.
*/
getImage() {
return this.canvas_;
}
/**
* @private
*/
reproject_() {
const sources = [];
this.sourceTiles_.forEach((source) => {
var _a;
const tile = source.tile;
if (tile && tile.getState() == TileState_default.LOADED) {
const extent = this.sourceTileGrid_.getTileCoordExtent(tile.tileCoord);
extent[0] += source.offset;
extent[2] += source.offset;
const clipExtent = (_a = this.clipExtent_) == null ? void 0 : _a.slice();
if (clipExtent) {
clipExtent[0] += source.offset;
clipExtent[2] += source.offset;
}
sources.push({
extent,
clipExtent,
image: tile.getImage()
});
}
});
this.sourceTiles_.length = 0;
if (sources.length === 0) {
this.state = TileState_default.ERROR;
} else {
const z = this.wrappedTileCoord_[0];
const size = this.targetTileGrid_.getTileSize(z);
const width = typeof size === "number" ? size : size[0];
const height = typeof size === "number" ? size : size[1];
const targetResolution = this.targetTileGrid_.getResolution(z);
const sourceResolution = this.sourceTileGrid_.getResolution(
this.sourceZ_
);
const targetExtent = this.targetTileGrid_.getTileCoordExtent(
this.wrappedTileCoord_
);
this.canvas_ = render(
width,
height,
this.pixelRatio_,
sourceResolution,
this.sourceTileGrid_.getExtent(),
targetResolution,
targetExtent,
this.triangulation_,
sources,
this.gutter_,
this.renderEdges_,
this.interpolate
);
this.state = TileState_default.LOADED;
}
this.changed();
}
/**
* Load not yet loaded URI.
* @override
*/
load() {
if (this.state == TileState_default.IDLE) {
this.state = TileState_default.LOADING;
this.changed();
let leftToLoad = 0;
this.sourcesListenerKeys_ = [];
this.sourceTiles_.forEach(({ tile }) => {
const state = tile.getState();
if (state == TileState_default.IDLE || state == TileState_default.LOADING) {
leftToLoad++;
const sourceListenKey = listen(tile, EventType_default.CHANGE, (e) => {
const state2 = tile.getState();
if (state2 == TileState_default.LOADED || state2 == TileState_default.ERROR || state2 == TileState_default.EMPTY) {
unlistenByKey(sourceListenKey);
leftToLoad--;
if (leftToLoad === 0) {
this.unlistenSources_();
this.reproject_();
}
}
});
this.sourcesListenerKeys_.push(sourceListenKey);
}
});
if (leftToLoad === 0) {
setTimeout(this.reproject_.bind(this), 0);
} else {
this.sourceTiles_.forEach(function({ tile }, i, arr) {
const state = tile.getState();
if (state == TileState_default.IDLE) {
tile.load();
}
});
}
}
}
/**
* @private
*/
unlistenSources_() {
this.sourcesListenerKeys_.forEach(unlistenByKey);
this.sourcesListenerKeys_ = null;
}
/**
* Remove from the cache due to expiry
* @override
*/
release() {
if (this.canvas_) {
releaseCanvas(this.canvas_.getContext("2d"));
canvasPool.push(this.canvas_);
this.canvas_ = null;
}
super.release();
}
};
var Tile_default2 = ReprojTile;
export {
Tile_default2 as Tile_default
};
//# sourceMappingURL=chunk-QL7JR4NF.js.map