1771 lines
58 KiB
JavaScript
1771 lines
58 KiB
JavaScript
import {
|
|
ImageLayer_default
|
|
} from "./chunk-NNDEYVSB.js";
|
|
import {
|
|
fromResolutionLike
|
|
} from "./chunk-F3ARDFTC.js";
|
|
import {
|
|
TileLayer_default
|
|
} from "./chunk-KFWBGRAN.js";
|
|
import {
|
|
TileProperty_default
|
|
} from "./chunk-4V7XJAUG.js";
|
|
import {
|
|
RenderTarget_default,
|
|
VectorLayer_default as VectorLayer_default2,
|
|
WebGLWorkerMessageType,
|
|
colorDecodeId,
|
|
colorEncodeId,
|
|
create as create2,
|
|
getWorldParameters,
|
|
parseLiteralStyle
|
|
} from "./chunk-MY3Y56DQ.js";
|
|
import {
|
|
ARRAY_BUFFER,
|
|
AttributeType,
|
|
Buffer_default,
|
|
DYNAMIC_DRAW,
|
|
DefaultUniform,
|
|
ELEMENT_ARRAY_BUFFER,
|
|
Layer_default as Layer_default2
|
|
} from "./chunk-PZZAKLYX.js";
|
|
import {
|
|
ImageCanvas_default
|
|
} from "./chunk-D56KDQKC.js";
|
|
import {
|
|
BuilderGroup_default,
|
|
DECLUTTER,
|
|
ExecutorGroup_default,
|
|
HIT_DETECT_RESOLUTION,
|
|
VectorLayer_default,
|
|
createHitDetectionImageData,
|
|
getSquaredTolerance,
|
|
hitDetect,
|
|
renderFeature
|
|
} from "./chunk-2RRPH7ER.js";
|
|
import {
|
|
ZIndexContext_default
|
|
} from "./chunk-JOOKRY6I.js";
|
|
import {
|
|
VectorEventType_default
|
|
} from "./chunk-V7WRBSQ6.js";
|
|
import {
|
|
TileState_default
|
|
} from "./chunk-5D2XPBR2.js";
|
|
import {
|
|
BaseVector_default
|
|
} from "./chunk-OVJRLVXU.js";
|
|
import {
|
|
RBush
|
|
} from "./chunk-PZOVY5ZG.js";
|
|
import {
|
|
Layer_default,
|
|
ViewHint_default
|
|
} from "./chunk-S5OMZ56B.js";
|
|
import {
|
|
toSize
|
|
} from "./chunk-PPP4FLHO.js";
|
|
import {
|
|
ImageState_default
|
|
} from "./chunk-5TDNKDLD.js";
|
|
import {
|
|
apply,
|
|
compose,
|
|
create,
|
|
makeInverse,
|
|
multiply,
|
|
reset,
|
|
scale,
|
|
translate
|
|
} from "./chunk-JFONEOYG.js";
|
|
import {
|
|
fromUserCoordinate,
|
|
getUserProjection
|
|
} from "./chunk-XZU4LSFD.js";
|
|
import {
|
|
wrapX
|
|
} from "./chunk-3JZANJYE.js";
|
|
import {
|
|
boundingExtent,
|
|
buffer,
|
|
containsExtent,
|
|
createEmpty,
|
|
equals,
|
|
getHeight,
|
|
getIntersection,
|
|
getTopLeft,
|
|
getWidth,
|
|
intersects,
|
|
isEmpty,
|
|
scaleFromCenter
|
|
} from "./chunk-CKDBVGKM.js";
|
|
import {
|
|
assert
|
|
} from "./chunk-QFCIXVZ3.js";
|
|
import {
|
|
getUid
|
|
} from "./chunk-H47PV7W6.js";
|
|
import {
|
|
EventType_default,
|
|
listen,
|
|
unlistenByKey
|
|
} from "./chunk-KJXIHBKT.js";
|
|
import {
|
|
ascending
|
|
} from "./chunk-FQY6EMA7.js";
|
|
|
|
// node_modules/ol/renderer/canvas/VectorImageLayer.js
|
|
var CanvasVectorImageLayerRenderer = class extends ImageLayer_default {
|
|
/**
|
|
* @param {import("../../layer/VectorImage.js").default} layer Vector image layer.
|
|
*/
|
|
constructor(layer) {
|
|
super(layer);
|
|
this.vectorRenderer_ = new VectorLayer_default(layer);
|
|
this.layerImageRatio_ = layer.getImageRatio();
|
|
this.coordinateToVectorPixelTransform_ = create();
|
|
this.renderedPixelToCoordinateTransform_ = null;
|
|
}
|
|
/**
|
|
* Clean up.
|
|
* @override
|
|
*/
|
|
disposeInternal() {
|
|
this.vectorRenderer_.dispose();
|
|
super.disposeInternal();
|
|
}
|
|
/**
|
|
* Asynchronous layer level hit detection.
|
|
* @param {import("../../pixel.js").Pixel} pixel Pixel.
|
|
* @return {Promise<Array<import("../../Feature").default>>} Promise that resolves with an array of features.
|
|
* @override
|
|
*/
|
|
getFeatures(pixel) {
|
|
if (!this.vectorRenderer_) {
|
|
return Promise.resolve([]);
|
|
}
|
|
const vectorPixel = apply(
|
|
this.coordinateToVectorPixelTransform_,
|
|
apply(this.renderedPixelToCoordinateTransform_, pixel.slice())
|
|
);
|
|
return this.vectorRenderer_.getFeatures(vectorPixel);
|
|
}
|
|
/**
|
|
* Perform action necessary to get the layer rendered after new fonts have loaded
|
|
* @override
|
|
*/
|
|
handleFontsChanged() {
|
|
this.vectorRenderer_.handleFontsChanged();
|
|
}
|
|
/**
|
|
* Determine whether render should be called.
|
|
* @param {import("../../Map.js").FrameState} frameState Frame state.
|
|
* @return {boolean} Layer is ready to be rendered.
|
|
* @override
|
|
*/
|
|
prepareFrame(frameState) {
|
|
var _a;
|
|
const pixelRatio = frameState.pixelRatio;
|
|
const viewState = frameState.viewState;
|
|
const viewResolution = viewState.resolution;
|
|
const hints = frameState.viewHints;
|
|
const vectorRenderer = this.vectorRenderer_;
|
|
let renderedExtent = frameState.extent;
|
|
if (this.layerImageRatio_ !== 1) {
|
|
renderedExtent = renderedExtent.slice(0);
|
|
scaleFromCenter(renderedExtent, this.layerImageRatio_);
|
|
}
|
|
const width = getWidth(renderedExtent) / viewResolution;
|
|
const height = getHeight(renderedExtent) / viewResolution;
|
|
if (!hints[ViewHint_default.ANIMATING] && !hints[ViewHint_default.INTERACTING] && !isEmpty(renderedExtent)) {
|
|
vectorRenderer.useContainer(null, null);
|
|
const context = vectorRenderer.context;
|
|
const layerState = frameState.layerStatesArray[frameState.layerIndex];
|
|
const imageLayerState = Object.assign({}, layerState, { opacity: 1 });
|
|
const imageFrameState = (
|
|
/** @type {import("../../Map.js").FrameState} */
|
|
Object.assign({}, frameState, {
|
|
extent: renderedExtent,
|
|
size: [width, height],
|
|
viewState: (
|
|
/** @type {import("../../View.js").State} */
|
|
Object.assign({}, frameState.viewState, {
|
|
rotation: 0
|
|
})
|
|
),
|
|
layerStatesArray: [imageLayerState],
|
|
layerIndex: 0,
|
|
declutter: null
|
|
})
|
|
);
|
|
const declutter = this.getLayer().getDeclutter();
|
|
if (declutter) {
|
|
imageFrameState.declutter = {
|
|
[declutter]: new RBush(9)
|
|
};
|
|
}
|
|
const image = new ImageCanvas_default(
|
|
renderedExtent,
|
|
viewResolution,
|
|
pixelRatio,
|
|
context.canvas,
|
|
function(callback) {
|
|
if (vectorRenderer.prepareFrame(imageFrameState) && vectorRenderer.replayGroupChanged) {
|
|
vectorRenderer.clipping = false;
|
|
vectorRenderer.renderFrame(imageFrameState, null);
|
|
vectorRenderer.renderDeclutter(imageFrameState);
|
|
vectorRenderer.renderDeferred(imageFrameState);
|
|
callback();
|
|
}
|
|
}
|
|
);
|
|
image.addEventListener(EventType_default.CHANGE, () => {
|
|
if (image.getState() !== ImageState_default.LOADED) {
|
|
return;
|
|
}
|
|
this.image = image;
|
|
const imagePixelRatio = image.getPixelRatio();
|
|
const renderedResolution = fromResolutionLike(image.getResolution()) * pixelRatio / imagePixelRatio;
|
|
this.renderedResolution = renderedResolution;
|
|
this.coordinateToVectorPixelTransform_ = compose(
|
|
this.coordinateToVectorPixelTransform_,
|
|
width / 2,
|
|
height / 2,
|
|
1 / renderedResolution,
|
|
-1 / renderedResolution,
|
|
0,
|
|
-viewState.center[0],
|
|
-viewState.center[1]
|
|
);
|
|
});
|
|
image.load();
|
|
}
|
|
if (this.image) {
|
|
this.renderedPixelToCoordinateTransform_ = frameState.pixelToCoordinateTransform.slice();
|
|
}
|
|
return !((_a = this.getLayer().getSource()) == null ? void 0 : _a.loading) && !!this.image;
|
|
}
|
|
/**
|
|
* @override
|
|
*/
|
|
preRender() {
|
|
}
|
|
/**
|
|
* @override
|
|
*/
|
|
postRender() {
|
|
}
|
|
/**
|
|
*/
|
|
renderDeclutter() {
|
|
}
|
|
/**
|
|
* @param {import("../../coordinate.js").Coordinate} coordinate Coordinate.
|
|
* @param {import("../../Map.js").FrameState} frameState Frame state.
|
|
* @param {number} hitTolerance Hit tolerance in pixels.
|
|
* @param {import("../vector.js").FeatureCallback<T>} callback Feature callback.
|
|
* @param {Array<import("../Map.js").HitMatch<T>>} matches The hit detected matches with tolerance.
|
|
* @return {T|undefined} Callback result.
|
|
* @template T
|
|
* @override
|
|
*/
|
|
forEachFeatureAtCoordinate(coordinate, frameState, hitTolerance, callback, matches) {
|
|
if (this.vectorRenderer_) {
|
|
return this.vectorRenderer_.forEachFeatureAtCoordinate(
|
|
coordinate,
|
|
frameState,
|
|
hitTolerance,
|
|
callback,
|
|
matches
|
|
);
|
|
}
|
|
return super.forEachFeatureAtCoordinate(
|
|
coordinate,
|
|
frameState,
|
|
hitTolerance,
|
|
callback,
|
|
matches
|
|
);
|
|
}
|
|
};
|
|
var VectorImageLayer_default = CanvasVectorImageLayerRenderer;
|
|
|
|
// node_modules/ol/layer/VectorImage.js
|
|
var VectorImageLayer = class extends BaseVector_default {
|
|
/**
|
|
* @param {Options<VectorSourceType, FeatureType>} [options] Options.
|
|
*/
|
|
constructor(options) {
|
|
options = options ? options : {};
|
|
const baseOptions = Object.assign({}, options);
|
|
delete baseOptions.imageRatio;
|
|
super(baseOptions);
|
|
this.imageRatio_ = options.imageRatio !== void 0 ? options.imageRatio : 1;
|
|
}
|
|
/**
|
|
* @return {number} Ratio between rendered extent size and viewport extent size.
|
|
*/
|
|
getImageRatio() {
|
|
return this.imageRatio_;
|
|
}
|
|
/**
|
|
* @override
|
|
*/
|
|
createRenderer() {
|
|
return new VectorImageLayer_default(this);
|
|
}
|
|
};
|
|
var VectorImage_default = VectorImageLayer;
|
|
|
|
// node_modules/ol/renderer/canvas/VectorTileLayer.js
|
|
var IMAGE_REPLAYS = {
|
|
"image": ["Polygon", "Circle", "LineString", "Image", "Text"],
|
|
"hybrid": ["Polygon", "LineString"],
|
|
"vector": []
|
|
};
|
|
var VECTOR_REPLAYS = {
|
|
"hybrid": ["Image", "Text", "Default"],
|
|
"vector": ["Polygon", "Circle", "LineString", "Image", "Text", "Default"]
|
|
};
|
|
var CanvasVectorTileLayerRenderer = class extends TileLayer_default {
|
|
/**
|
|
* @param {import("../../layer/VectorTile.js").default} layer VectorTile layer.
|
|
* @param {import("./TileLayer.js").Options} options Options.
|
|
*/
|
|
constructor(layer, options) {
|
|
super(layer, options);
|
|
this.boundHandleStyleImageChange_ = this.handleStyleImageChange_.bind(this);
|
|
this.renderedLayerRevision_;
|
|
this.renderedPixelToCoordinateTransform_ = null;
|
|
this.renderedRotation_;
|
|
this.renderedOpacity_ = 1;
|
|
this.tmpTransform_ = create();
|
|
this.tileClipContexts_ = null;
|
|
}
|
|
/**
|
|
* @param {import("../../VectorRenderTile.js").default} tile Tile.
|
|
* @param {import("../../Map.js").FrameState} frameState Frame state.
|
|
* @param {number} x Left of the tile.
|
|
* @param {number} y Top of the tile.
|
|
* @param {number} w Width of the tile.
|
|
* @param {number} h Height of the tile.
|
|
* @param {number} gutter Tile gutter.
|
|
* @param {boolean} transition Apply an alpha transition.
|
|
* @override
|
|
*/
|
|
drawTile(tile, frameState, x, y, w, h, gutter, transition) {
|
|
this.updateExecutorGroup_(
|
|
tile,
|
|
frameState.pixelRatio,
|
|
frameState.viewState.projection
|
|
);
|
|
if (this.tileImageNeedsRender_(tile)) {
|
|
this.renderTileImage_(tile, frameState);
|
|
}
|
|
super.drawTile(tile, frameState, x, y, w, h, gutter, transition);
|
|
}
|
|
/**
|
|
* @param {number} z Tile coordinate z.
|
|
* @param {number} x Tile coordinate x.
|
|
* @param {number} y Tile coordinate y.
|
|
* @param {import("../../Map.js").FrameState} frameState Frame state.
|
|
* @return {import("../../Tile.js").default|null} Tile (or null if outside source extent).
|
|
* @override
|
|
*/
|
|
getTile(z, x, y, frameState) {
|
|
const tile = (
|
|
/** @type {import("../../VectorRenderTile.js").default} */
|
|
this.getOrCreateTile(z, x, y, frameState)
|
|
);
|
|
if (!tile) {
|
|
return null;
|
|
}
|
|
const viewState = frameState.viewState;
|
|
const resolution = viewState.resolution;
|
|
const viewHints = frameState.viewHints;
|
|
const hifi = !(viewHints[ViewHint_default.ANIMATING] || viewHints[ViewHint_default.INTERACTING]);
|
|
if (hifi || !tile.wantedResolution) {
|
|
tile.wantedResolution = resolution;
|
|
}
|
|
return tile;
|
|
}
|
|
/**
|
|
* Determine whether render should be called.
|
|
* @param {import("../../Map.js").FrameState} frameState Frame state.
|
|
* @return {boolean} Layer is ready to be rendered.
|
|
* @override
|
|
*/
|
|
prepareFrame(frameState) {
|
|
const layerRevision = this.getLayer().getRevision();
|
|
if (this.renderedLayerRevision_ !== layerRevision) {
|
|
this.renderedLayerRevision_ = layerRevision;
|
|
this.renderedTiles.length = 0;
|
|
}
|
|
return super.prepareFrame(frameState);
|
|
}
|
|
/**
|
|
* @param {import("../../VectorRenderTile.js").default} tile Tile.
|
|
* @param {number} pixelRatio Pixel ratio.
|
|
* @param {import("../../proj/Projection.js").default} projection Projection.
|
|
* @private
|
|
*/
|
|
updateExecutorGroup_(tile, pixelRatio, projection) {
|
|
const layer = (
|
|
/** @type {import("../../layer/VectorTile.js").default} */
|
|
this.getLayer()
|
|
);
|
|
const revision = layer.getRevision();
|
|
const renderOrder = layer.getRenderOrder() || null;
|
|
const resolution = tile.wantedResolution;
|
|
const builderState = tile.getReplayState(layer);
|
|
if (!builderState.dirty && builderState.renderedResolution === resolution && builderState.renderedRevision == revision && builderState.renderedRenderOrder == renderOrder) {
|
|
return;
|
|
}
|
|
const source = layer.getSource();
|
|
const declutter = !!layer.getDeclutter();
|
|
const sourceTileGrid = source.getTileGrid();
|
|
const tileGrid = source.getTileGridForProjection(projection);
|
|
const tileExtent = tileGrid.getTileCoordExtent(tile.wrappedTileCoord);
|
|
const sourceTiles = source.getSourceTiles(pixelRatio, projection, tile);
|
|
const layerUid = getUid(layer);
|
|
delete tile.hitDetectionImageData[layerUid];
|
|
tile.executorGroups[layerUid] = [];
|
|
builderState.dirty = false;
|
|
for (let t = 0, tt = sourceTiles.length; t < tt; ++t) {
|
|
const sourceTile = sourceTiles[t];
|
|
if (sourceTile.getState() != TileState_default.LOADED) {
|
|
continue;
|
|
}
|
|
const sourceTileCoord = sourceTile.tileCoord;
|
|
const sourceTileExtent = sourceTileGrid.getTileCoordExtent(sourceTileCoord);
|
|
const sharedExtent = getIntersection(tileExtent, sourceTileExtent);
|
|
const builderExtent = buffer(
|
|
sharedExtent,
|
|
layer.getRenderBuffer() * resolution,
|
|
this.tempExtent
|
|
);
|
|
const bufferedExtent = equals(sourceTileExtent, sharedExtent) ? null : builderExtent;
|
|
const builderGroup = new BuilderGroup_default(
|
|
0,
|
|
sharedExtent,
|
|
resolution,
|
|
pixelRatio
|
|
);
|
|
const squaredTolerance = getSquaredTolerance(
|
|
resolution,
|
|
pixelRatio
|
|
);
|
|
const render = function(feature, index) {
|
|
let styles;
|
|
const styleFunction = feature.getStyleFunction() || layer.getStyleFunction();
|
|
if (styleFunction) {
|
|
styles = styleFunction(feature, resolution);
|
|
}
|
|
if (styles) {
|
|
const dirty = this.renderFeature(
|
|
feature,
|
|
squaredTolerance,
|
|
styles,
|
|
builderGroup,
|
|
declutter,
|
|
index
|
|
);
|
|
builderState.dirty = builderState.dirty || dirty;
|
|
}
|
|
};
|
|
const features = sourceTile.getFeatures();
|
|
if (renderOrder && renderOrder !== builderState.renderedRenderOrder) {
|
|
features.sort(renderOrder);
|
|
}
|
|
for (let i = 0, ii = features.length; i < ii; ++i) {
|
|
const feature = features[i];
|
|
if (!bufferedExtent || intersects(bufferedExtent, feature.getGeometry().getExtent())) {
|
|
render.call(this, feature, i);
|
|
}
|
|
}
|
|
const executorGroupInstructions = builderGroup.finish();
|
|
const replayExtent = layer.getRenderMode() !== "vector" && declutter && sourceTiles.length === 1 ? null : sharedExtent;
|
|
const renderingReplayGroup = new ExecutorGroup_default(
|
|
replayExtent,
|
|
resolution,
|
|
pixelRatio,
|
|
source.getOverlaps(),
|
|
executorGroupInstructions,
|
|
layer.getRenderBuffer(),
|
|
true
|
|
);
|
|
tile.executorGroups[layerUid].push(renderingReplayGroup);
|
|
}
|
|
builderState.renderedRevision = revision;
|
|
builderState.renderedRenderOrder = renderOrder;
|
|
builderState.renderedResolution = resolution;
|
|
}
|
|
/**
|
|
* @param {import("../../coordinate.js").Coordinate} coordinate Coordinate.
|
|
* @param {import("../../Map.js").FrameState} frameState Frame state.
|
|
* @param {number} hitTolerance Hit tolerance in pixels.
|
|
* @param {import("../vector.js").FeatureCallback<T>} callback Feature callback.
|
|
* @param {Array<import("../Map.js").HitMatch<T>>} matches The hit detected matches with tolerance.
|
|
* @return {T|undefined} Callback result.
|
|
* @template T
|
|
* @override
|
|
*/
|
|
forEachFeatureAtCoordinate(coordinate, frameState, hitTolerance, callback, matches) {
|
|
var _a, _b;
|
|
const resolution = frameState.viewState.resolution;
|
|
const rotation = frameState.viewState.rotation;
|
|
hitTolerance = hitTolerance == void 0 ? 0 : hitTolerance;
|
|
const layer = this.getLayer();
|
|
const source = layer.getSource();
|
|
const tileGrid = source.getTileGridForProjection(
|
|
frameState.viewState.projection
|
|
);
|
|
const hitExtent = boundingExtent([coordinate]);
|
|
buffer(hitExtent, resolution * hitTolerance, hitExtent);
|
|
const features = {};
|
|
const featureCallback = function(feature, geometry, distanceSq) {
|
|
let key = feature.getId();
|
|
if (key === void 0) {
|
|
key = getUid(feature);
|
|
}
|
|
const match = features[key];
|
|
if (!match) {
|
|
if (distanceSq === 0) {
|
|
features[key] = true;
|
|
return callback(feature, layer, geometry);
|
|
}
|
|
matches.push(
|
|
features[key] = {
|
|
feature,
|
|
layer,
|
|
geometry,
|
|
distanceSq,
|
|
callback
|
|
}
|
|
);
|
|
} else if (match !== true && distanceSq < match.distanceSq) {
|
|
if (distanceSq === 0) {
|
|
features[key] = true;
|
|
matches.splice(matches.lastIndexOf(match), 1);
|
|
return callback(feature, layer, geometry);
|
|
}
|
|
match.geometry = geometry;
|
|
match.distanceSq = distanceSq;
|
|
}
|
|
return void 0;
|
|
};
|
|
const renderedTiles = (
|
|
/** @type {Array<import("../../VectorRenderTile.js").default>} */
|
|
this.renderedTiles
|
|
);
|
|
const layerUid = getUid(layer);
|
|
const declutter = layer.getDeclutter();
|
|
const declutteredFeatures = declutter ? (_b = (_a = frameState.declutter) == null ? void 0 : _a[declutter]) == null ? void 0 : _b.all().map((item) => item.value) : null;
|
|
let found;
|
|
foundFeature: for (let i = 0, ii = renderedTiles.length; i < ii; ++i) {
|
|
const tile = renderedTiles[i];
|
|
const tileExtent = tileGrid.getTileCoordExtent(tile.wrappedTileCoord);
|
|
if (!intersects(tileExtent, hitExtent)) {
|
|
continue;
|
|
}
|
|
const executorGroups = tile.executorGroups[layerUid];
|
|
for (let t = 0, tt = executorGroups.length; t < tt; ++t) {
|
|
found = executorGroups[t].forEachFeatureAtCoordinate(
|
|
coordinate,
|
|
resolution,
|
|
rotation,
|
|
hitTolerance,
|
|
featureCallback,
|
|
declutteredFeatures
|
|
);
|
|
if (found) {
|
|
break foundFeature;
|
|
}
|
|
}
|
|
}
|
|
return found;
|
|
}
|
|
/**
|
|
* Asynchronous layer level hit detection.
|
|
* @param {import("../../pixel.js").Pixel} pixel Pixel.
|
|
* @return {Promise<Array<import("../../Feature.js").FeatureLike>>} Promise that resolves with an array of features.
|
|
* @override
|
|
*/
|
|
getFeatures(pixel) {
|
|
if (this.renderedTiles.length === 0) {
|
|
return Promise.resolve([]);
|
|
}
|
|
return new Promise((resolve, reject) => {
|
|
const layer = this.getLayer();
|
|
const source = layer.getSource();
|
|
const projection = this.renderedProjection;
|
|
const projectionExtent = projection.getExtent();
|
|
const resolution = this.renderedResolution;
|
|
const tileGrid = source.getTileGridForProjection(projection);
|
|
const coordinate = apply(
|
|
this.renderedPixelToCoordinateTransform_,
|
|
pixel.slice()
|
|
);
|
|
const tileCoordString = tileGrid.getTileCoordForCoordAndResolution(coordinate, resolution).toString();
|
|
const tile = (
|
|
/** @type {Array<import("../../VectorRenderTile.js").default>} */
|
|
this.renderedTiles.find(
|
|
(tile2) => tile2.tileCoord.toString() === tileCoordString && tile2.getState() === TileState_default.LOADED
|
|
)
|
|
);
|
|
if (!tile || tile.loadingSourceTiles > 0) {
|
|
resolve([]);
|
|
return;
|
|
}
|
|
if (source.getWrapX() && projection.canWrapX() && !containsExtent(
|
|
projectionExtent,
|
|
tileGrid.getTileCoordExtent(tile.tileCoord)
|
|
)) {
|
|
wrapX(coordinate, projection);
|
|
}
|
|
const layerUid = getUid(layer);
|
|
const extent = tileGrid.getTileCoordExtent(tile.wrappedTileCoord);
|
|
const corner = getTopLeft(extent);
|
|
const tilePixel = [
|
|
(coordinate[0] - corner[0]) / resolution,
|
|
(corner[1] - coordinate[1]) / resolution
|
|
];
|
|
const features = tile.getSourceTiles().reduce(
|
|
(accumulator, sourceTile) => accumulator.concat(sourceTile.getFeatures()),
|
|
/** @type {Array<import("../../Feature.js").FeatureLike>} */
|
|
[]
|
|
);
|
|
let hitDetectionImageData = tile.hitDetectionImageData[layerUid];
|
|
if (!hitDetectionImageData) {
|
|
const tileSize = toSize(
|
|
tileGrid.getTileSize(
|
|
tileGrid.getZForResolution(resolution, source.zDirection)
|
|
)
|
|
);
|
|
const rotation = this.renderedRotation_;
|
|
const transforms = [
|
|
this.getRenderTransform(
|
|
tileGrid.getTileCoordCenter(tile.wrappedTileCoord),
|
|
resolution,
|
|
0,
|
|
HIT_DETECT_RESOLUTION,
|
|
tileSize[0] * HIT_DETECT_RESOLUTION,
|
|
tileSize[1] * HIT_DETECT_RESOLUTION,
|
|
0
|
|
)
|
|
];
|
|
hitDetectionImageData = createHitDetectionImageData(
|
|
tileSize,
|
|
transforms,
|
|
features,
|
|
layer.getStyleFunction(),
|
|
tileGrid.getTileCoordExtent(tile.wrappedTileCoord),
|
|
tile.getReplayState(layer).renderedResolution,
|
|
rotation
|
|
);
|
|
tile.hitDetectionImageData[layerUid] = hitDetectionImageData;
|
|
}
|
|
resolve(hitDetect(tilePixel, features, hitDetectionImageData));
|
|
});
|
|
}
|
|
/**
|
|
* @param {import("../../extent.js").Extent} extent Extent.
|
|
* @return {Array<import('../../Feature.js').FeatureLike>} Features.
|
|
*/
|
|
getFeaturesInExtent(extent) {
|
|
const features = [];
|
|
const tileCache = this.getTileCache();
|
|
if (tileCache.getCount() === 0) {
|
|
return features;
|
|
}
|
|
const source = this.getLayer().getSource();
|
|
const tileGrid = source.getTileGridForProjection(
|
|
this.frameState.viewState.projection
|
|
);
|
|
const z = tileGrid.getZForResolution(this.renderedResolution);
|
|
const visitedSourceTiles = {};
|
|
tileCache.forEach((tile) => {
|
|
if (tile.tileCoord[0] !== z || tile.getState() !== TileState_default.LOADED) {
|
|
return;
|
|
}
|
|
const sourceTiles = tile.getSourceTiles();
|
|
for (let i = 0, ii = sourceTiles.length; i < ii; ++i) {
|
|
const sourceTile = sourceTiles[i];
|
|
const key = sourceTile.getKey();
|
|
if (key in visitedSourceTiles) {
|
|
continue;
|
|
}
|
|
visitedSourceTiles[key] = true;
|
|
const tileCoord = sourceTile.tileCoord;
|
|
if (intersects(extent, tileGrid.getTileCoordExtent(tileCoord))) {
|
|
const tileFeatures = sourceTile.getFeatures();
|
|
if (tileFeatures) {
|
|
for (let j = 0, jj = tileFeatures.length; j < jj; ++j) {
|
|
const candidate = tileFeatures[j];
|
|
const geometry = candidate.getGeometry();
|
|
if (intersects(extent, geometry.getExtent())) {
|
|
features.push(candidate);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
return features;
|
|
}
|
|
/**
|
|
* Perform action necessary to get the layer rendered after new fonts have loaded
|
|
* @override
|
|
*/
|
|
handleFontsChanged() {
|
|
const layer = this.getLayer();
|
|
if (layer.getVisible() && this.renderedLayerRevision_ !== void 0) {
|
|
layer.changed();
|
|
}
|
|
}
|
|
/**
|
|
* Handle changes in image style state.
|
|
* @param {import("../../events/Event.js").default} event Image style change event.
|
|
* @private
|
|
*/
|
|
handleStyleImageChange_(event) {
|
|
this.renderIfReadyAndVisible();
|
|
}
|
|
/**
|
|
* Render declutter items for this layer
|
|
* @param {import("../../Map.js").FrameState} frameState Frame state.
|
|
* @param {import("../../layer/Layer.js").State} layerState Layer state.
|
|
*/
|
|
renderDeclutter(frameState, layerState) {
|
|
var _a;
|
|
const context = this.context;
|
|
const alpha = context.globalAlpha;
|
|
context.globalAlpha = layerState.opacity;
|
|
const viewHints = frameState.viewHints;
|
|
const hifi = !(viewHints[ViewHint_default.ANIMATING] || viewHints[ViewHint_default.INTERACTING]);
|
|
const scaledCanvasSize = [
|
|
this.context.canvas.width,
|
|
this.context.canvas.height
|
|
];
|
|
const declutter = this.getLayer().getDeclutter();
|
|
const declutterTree = declutter ? (_a = frameState.declutter) == null ? void 0 : _a[declutter] : void 0;
|
|
const layerUid = getUid(this.getLayer());
|
|
const tiles = (
|
|
/** @type {Array<import("../../VectorRenderTile.js").default>} */
|
|
this.renderedTiles
|
|
);
|
|
for (let i = 0, ii = tiles.length; i < ii; ++i) {
|
|
const tile = tiles[i];
|
|
const executorGroups = tile.executorGroups[layerUid];
|
|
if (executorGroups) {
|
|
for (let j = executorGroups.length - 1; j >= 0; --j) {
|
|
executorGroups[j].execute(
|
|
this.context,
|
|
scaledCanvasSize,
|
|
this.getTileRenderTransform(tile, frameState),
|
|
frameState.viewState.rotation,
|
|
hifi,
|
|
DECLUTTER,
|
|
declutterTree
|
|
);
|
|
}
|
|
}
|
|
}
|
|
context.globalAlpha = alpha;
|
|
}
|
|
/**
|
|
* @param {import("../../Map.js").FrameState} frameState Frame state.
|
|
* @override
|
|
*/
|
|
renderDeferredInternal(frameState) {
|
|
const tiles = (
|
|
/** @type {Array<import("../../VectorRenderTile.js").default>} */
|
|
this.renderedTiles
|
|
);
|
|
const layerUid = getUid(this.getLayer());
|
|
const executorGroups = tiles.reduce(
|
|
(acc, tile, index) => {
|
|
tile.executorGroups[layerUid].forEach(
|
|
(executorGroup) => acc.push({
|
|
executorGroup,
|
|
index
|
|
})
|
|
);
|
|
return acc;
|
|
},
|
|
/** @type {Array<{executorGroup: CanvasExecutorGroup, index: number}>} */
|
|
[]
|
|
);
|
|
const executorGroupZIndexContexts = executorGroups.map(
|
|
({ executorGroup }) => executorGroup.getDeferredZIndexContexts()
|
|
);
|
|
const usedZIndices = {};
|
|
for (let i = 0, ii = executorGroups.length; i < ii; ++i) {
|
|
const executorGroupZindexContext = executorGroups[i].executorGroup.getDeferredZIndexContexts();
|
|
for (const key in executorGroupZindexContext) {
|
|
usedZIndices[key] = true;
|
|
}
|
|
}
|
|
const zIndexKeys = Object.keys(usedZIndices).map(Number).sort(ascending);
|
|
zIndexKeys.forEach((zIndex) => {
|
|
executorGroupZIndexContexts.forEach((zIndexContexts, i) => {
|
|
if (!zIndexContexts[zIndex]) {
|
|
return;
|
|
}
|
|
zIndexContexts[zIndex].forEach((zIndexContext) => {
|
|
const { executorGroup, index } = executorGroups[i];
|
|
const context = executorGroup.getRenderedContext();
|
|
const alpha = context.globalAlpha;
|
|
context.globalAlpha = this.renderedOpacity_;
|
|
const tileClipContext = this.tileClipContexts_[index];
|
|
if (tileClipContext) {
|
|
tileClipContext.draw(context);
|
|
}
|
|
zIndexContext.draw(context);
|
|
if (tileClipContext) {
|
|
context.restore();
|
|
}
|
|
context.globalAlpha = alpha;
|
|
zIndexContext.clear();
|
|
});
|
|
zIndexContexts[zIndex].length = 0;
|
|
});
|
|
});
|
|
}
|
|
/**
|
|
* @param {import("../../VectorRenderTile.js").default} tile The tile
|
|
* @param {import('../../Map.js').FrameState} frameState Current frame state
|
|
* @return {import('../../transform.js').Transform} Transform to use to render this tile
|
|
*/
|
|
getTileRenderTransform(tile, frameState) {
|
|
const pixelRatio = frameState.pixelRatio;
|
|
const viewState = frameState.viewState;
|
|
const center = viewState.center;
|
|
const resolution = viewState.resolution;
|
|
const rotation = viewState.rotation;
|
|
const size = frameState.size;
|
|
const width = Math.round(size[0] * pixelRatio);
|
|
const height = Math.round(size[1] * pixelRatio);
|
|
const source = this.getLayer().getSource();
|
|
const tileGrid = source.getTileGridForProjection(
|
|
frameState.viewState.projection
|
|
);
|
|
const tileCoord = tile.tileCoord;
|
|
const tileExtent = tileGrid.getTileCoordExtent(tile.wrappedTileCoord);
|
|
const worldOffset = tileGrid.getTileCoordExtent(tileCoord, this.tempExtent)[0] - tileExtent[0];
|
|
const transform = multiply(
|
|
scale(this.inversePixelTransform.slice(), 1 / pixelRatio, 1 / pixelRatio),
|
|
this.getRenderTransform(
|
|
center,
|
|
resolution,
|
|
rotation,
|
|
pixelRatio,
|
|
width,
|
|
height,
|
|
worldOffset
|
|
)
|
|
);
|
|
return transform;
|
|
}
|
|
/**
|
|
* Render the vectors for this layer.
|
|
* @param {CanvasRenderingContext2D} context Target context.
|
|
* @param {import("../../Map.js").FrameState} frameState Frame state.
|
|
* @override
|
|
*/
|
|
postRender(context, frameState) {
|
|
var _a;
|
|
const viewHints = frameState.viewHints;
|
|
const hifi = !(viewHints[ViewHint_default.ANIMATING] || viewHints[ViewHint_default.INTERACTING]);
|
|
this.renderedPixelToCoordinateTransform_ = frameState.pixelToCoordinateTransform.slice();
|
|
this.renderedRotation_ = frameState.viewState.rotation;
|
|
this.renderedOpacity_ = frameState.layerStatesArray[frameState.layerIndex].opacity;
|
|
const layer = (
|
|
/** @type {import("../../layer/VectorTile.js").default} */
|
|
this.getLayer()
|
|
);
|
|
const renderMode = layer.getRenderMode();
|
|
const alpha = context.globalAlpha;
|
|
context.globalAlpha = this.renderedOpacity_;
|
|
const declutter = layer.getDeclutter();
|
|
const replayTypes = declutter ? VECTOR_REPLAYS[renderMode].filter((type) => !DECLUTTER.includes(type)) : VECTOR_REPLAYS[renderMode];
|
|
const viewState = frameState.viewState;
|
|
const rotation = viewState.rotation;
|
|
const tileSource = layer.getSource();
|
|
const tileGrid = tileSource.getTileGridForProjection(viewState.projection);
|
|
const z = tileGrid.getZForResolution(
|
|
viewState.resolution,
|
|
tileSource.zDirection
|
|
);
|
|
const tiles = (
|
|
/** @type {Array<import("../../VectorRenderTile.js").default>} */
|
|
this.renderedTiles
|
|
);
|
|
const clips = [];
|
|
const clipZs = [];
|
|
const tileClipContexts = [];
|
|
const layerUid = getUid(layer);
|
|
let ready = true;
|
|
for (let i = tiles.length - 1; i >= 0; --i) {
|
|
const tile = tiles[i];
|
|
ready = ready && !tile.getReplayState(layer).dirty;
|
|
const executorGroups = tile.executorGroups[layerUid].filter(
|
|
(group) => group.hasExecutors(replayTypes)
|
|
);
|
|
if (executorGroups.length === 0) {
|
|
continue;
|
|
}
|
|
const transform = this.getTileRenderTransform(tile, frameState);
|
|
const currentZ = tile.tileCoord[0];
|
|
let contextSaved = false;
|
|
const currentClip = executorGroups[0].getClipCoords(transform);
|
|
let clipContext = context;
|
|
let tileClipContext;
|
|
if (currentClip) {
|
|
tileClipContext = new ZIndexContext_default();
|
|
clipContext = tileClipContext.getContext();
|
|
for (let j = 0, jj = clips.length; j < jj; ++j) {
|
|
if (z !== currentZ && currentZ < clipZs[j]) {
|
|
const clip = clips[j];
|
|
if (intersects(
|
|
[
|
|
currentClip[0],
|
|
currentClip[3],
|
|
currentClip[4],
|
|
currentClip[7]
|
|
],
|
|
[clip[0], clip[3], clip[4], clip[7]]
|
|
)) {
|
|
if (!contextSaved) {
|
|
clipContext.save();
|
|
contextSaved = true;
|
|
}
|
|
clipContext.beginPath();
|
|
clipContext.moveTo(currentClip[0], currentClip[1]);
|
|
clipContext.lineTo(currentClip[2], currentClip[3]);
|
|
clipContext.lineTo(currentClip[4], currentClip[5]);
|
|
clipContext.lineTo(currentClip[6], currentClip[7]);
|
|
clipContext.moveTo(clip[6], clip[7]);
|
|
clipContext.lineTo(clip[4], clip[5]);
|
|
clipContext.lineTo(clip[2], clip[3]);
|
|
clipContext.lineTo(clip[0], clip[1]);
|
|
clipContext.clip();
|
|
}
|
|
}
|
|
}
|
|
clips.push(currentClip);
|
|
clipZs.push(currentZ);
|
|
}
|
|
for (let t = 0, tt = executorGroups.length; t < tt; ++t) {
|
|
const executorGroup = executorGroups[t];
|
|
executorGroup.execute(
|
|
context,
|
|
[context.canvas.width, context.canvas.height],
|
|
transform,
|
|
rotation,
|
|
hifi,
|
|
replayTypes,
|
|
(_a = frameState.declutter) == null ? void 0 : _a[declutter]
|
|
);
|
|
}
|
|
if (contextSaved) {
|
|
if (clipContext === context) {
|
|
clipContext.restore();
|
|
} else {
|
|
tileClipContexts[i] = tileClipContext;
|
|
}
|
|
}
|
|
}
|
|
context.globalAlpha = alpha;
|
|
this.ready = ready;
|
|
this.tileClipContexts_ = tileClipContexts;
|
|
if (!frameState.declutter) {
|
|
this.renderDeferredInternal(frameState);
|
|
}
|
|
super.postRender(context, frameState);
|
|
}
|
|
/**
|
|
* @param {import("../../Feature.js").FeatureLike} feature Feature.
|
|
* @param {number} squaredTolerance Squared tolerance.
|
|
* @param {import("../../style/Style.js").default|Array<import("../../style/Style.js").default>} styles The style or array of styles.
|
|
* @param {import("../../render/canvas/BuilderGroup.js").default} builderGroup Replay group.
|
|
* @param {boolean} [declutter] Enable decluttering.
|
|
* @param {number} [index] Render order index.
|
|
* @return {boolean} `true` if an image is loading.
|
|
*/
|
|
renderFeature(feature, squaredTolerance, styles, builderGroup, declutter, index) {
|
|
if (!styles) {
|
|
return false;
|
|
}
|
|
let loading = false;
|
|
if (Array.isArray(styles)) {
|
|
for (let i = 0, ii = styles.length; i < ii; ++i) {
|
|
loading = renderFeature(
|
|
builderGroup,
|
|
feature,
|
|
styles[i],
|
|
squaredTolerance,
|
|
this.boundHandleStyleImageChange_,
|
|
void 0,
|
|
declutter,
|
|
index
|
|
) || loading;
|
|
}
|
|
} else {
|
|
loading = renderFeature(
|
|
builderGroup,
|
|
feature,
|
|
styles,
|
|
squaredTolerance,
|
|
this.boundHandleStyleImageChange_,
|
|
void 0,
|
|
declutter,
|
|
index
|
|
);
|
|
}
|
|
return loading;
|
|
}
|
|
/**
|
|
* @param {import("../../VectorRenderTile.js").default} tile Tile.
|
|
* @return {boolean} A new tile image was rendered.
|
|
* @private
|
|
*/
|
|
tileImageNeedsRender_(tile) {
|
|
const layer = (
|
|
/** @type {import("../../layer/VectorTile.js").default} */
|
|
this.getLayer()
|
|
);
|
|
if (layer.getRenderMode() === "vector") {
|
|
return false;
|
|
}
|
|
const replayState = tile.getReplayState(layer);
|
|
const revision = layer.getRevision();
|
|
const resolution = tile.wantedResolution;
|
|
return replayState.renderedTileResolution !== resolution || replayState.renderedTileRevision !== revision;
|
|
}
|
|
/**
|
|
* @param {import("../../VectorRenderTile.js").default} tile Tile.
|
|
* @param {import("../../Map").FrameState} frameState Frame state.
|
|
* @private
|
|
*/
|
|
renderTileImage_(tile, frameState) {
|
|
const layer = (
|
|
/** @type {import("../../layer/VectorTile.js").default} */
|
|
this.getLayer()
|
|
);
|
|
const replayState = tile.getReplayState(layer);
|
|
const revision = layer.getRevision();
|
|
const executorGroups = tile.executorGroups[getUid(layer)];
|
|
replayState.renderedTileRevision = revision;
|
|
const tileCoord = tile.wrappedTileCoord;
|
|
const z = tileCoord[0];
|
|
const source = layer.getSource();
|
|
let pixelRatio = frameState.pixelRatio;
|
|
const viewState = frameState.viewState;
|
|
const projection = viewState.projection;
|
|
const tileGrid = source.getTileGridForProjection(projection);
|
|
const tileResolution = tileGrid.getResolution(tile.tileCoord[0]);
|
|
const renderPixelRatio = frameState.pixelRatio / tile.wantedResolution * tileResolution;
|
|
const resolution = tileGrid.getResolution(z);
|
|
const context = tile.getContext();
|
|
pixelRatio = Math.round(
|
|
Math.max(pixelRatio, renderPixelRatio / pixelRatio)
|
|
);
|
|
const size = source.getTilePixelSize(z, pixelRatio, projection);
|
|
context.canvas.width = size[0];
|
|
context.canvas.height = size[1];
|
|
const renderScale = pixelRatio / renderPixelRatio;
|
|
if (renderScale !== 1) {
|
|
const canvasTransform = reset(this.tmpTransform_);
|
|
scale(canvasTransform, renderScale, renderScale);
|
|
context.setTransform.apply(context, canvasTransform);
|
|
}
|
|
const tileExtent = tileGrid.getTileCoordExtent(tileCoord, this.tempExtent);
|
|
const pixelScale = renderPixelRatio / resolution;
|
|
const transform = reset(this.tmpTransform_);
|
|
scale(transform, pixelScale, -pixelScale);
|
|
translate(transform, -tileExtent[0], -tileExtent[3]);
|
|
for (let i = 0, ii = executorGroups.length; i < ii; ++i) {
|
|
const executorGroup = executorGroups[i];
|
|
executorGroup.execute(
|
|
context,
|
|
[
|
|
context.canvas.width * renderScale,
|
|
context.canvas.height * renderScale
|
|
],
|
|
transform,
|
|
0,
|
|
true,
|
|
IMAGE_REPLAYS[layer.getRenderMode()],
|
|
null
|
|
);
|
|
}
|
|
replayState.renderedTileResolution = tile.wantedResolution;
|
|
}
|
|
};
|
|
var VectorTileLayer_default = CanvasVectorTileLayerRenderer;
|
|
|
|
// node_modules/ol/layer/VectorTile.js
|
|
var VectorTileLayer = class extends BaseVector_default {
|
|
/**
|
|
* @param {Options<VectorTileSourceType, FeatureType>} [options] Options.
|
|
*/
|
|
constructor(options) {
|
|
options = options ? options : {};
|
|
const baseOptions = Object.assign({}, options);
|
|
delete baseOptions.preload;
|
|
const cacheSize = options.cacheSize === void 0 ? 0 : options.cacheSize;
|
|
delete options.cacheSize;
|
|
delete baseOptions.useInterimTilesOnError;
|
|
super(baseOptions);
|
|
this.on;
|
|
this.once;
|
|
this.un;
|
|
this.cacheSize_ = cacheSize;
|
|
const renderMode = options.renderMode || "hybrid";
|
|
assert(
|
|
renderMode == "hybrid" || renderMode == "vector",
|
|
"`renderMode` must be `'hybrid'` or `'vector'`"
|
|
);
|
|
this.renderMode_ = renderMode;
|
|
this.setPreload(options.preload ? options.preload : 0);
|
|
this.setUseInterimTilesOnError(
|
|
options.useInterimTilesOnError !== void 0 ? options.useInterimTilesOnError : true
|
|
);
|
|
this.getBackground;
|
|
this.setBackground;
|
|
}
|
|
/**
|
|
* @override
|
|
*/
|
|
createRenderer() {
|
|
return new VectorTileLayer_default(this, {
|
|
cacheSize: this.cacheSize_
|
|
});
|
|
}
|
|
/**
|
|
* Get the topmost feature that intersects the given pixel on the viewport. Returns a promise
|
|
* that resolves with an array of features. The array will either contain the topmost feature
|
|
* when a hit was detected, or it will be empty.
|
|
*
|
|
* The hit detection algorithm used for this method is optimized for performance, but is less
|
|
* accurate than the one used in [map.getFeaturesAtPixel()]{@link import("../Map.js").default#getFeaturesAtPixel}.
|
|
* Text is not considered, and icons are only represented by their bounding box instead of the exact
|
|
* image.
|
|
*
|
|
* @param {import("../pixel.js").Pixel} pixel Pixel.
|
|
* @return {Promise<Array<import("../Feature").FeatureLike>>} Promise that resolves with an array of features.
|
|
* @api
|
|
* @override
|
|
*/
|
|
getFeatures(pixel) {
|
|
return super.getFeatures(pixel);
|
|
}
|
|
/**
|
|
* Get features whose bounding box intersects the provided extent. Only features for cached
|
|
* tiles for the last rendered zoom level are available in the source. So this method is only
|
|
* suitable for requesting tiles for extents that are currently rendered.
|
|
*
|
|
* Features are returned in random tile order and as they are included in the tiles. This means
|
|
* they can be clipped, duplicated across tiles, and simplified to the render resolution.
|
|
*
|
|
* @param {import("../extent.js").Extent} extent Extent.
|
|
* @return {Array<FeatureType>} Features.
|
|
* @api
|
|
*/
|
|
getFeaturesInExtent(extent) {
|
|
return (
|
|
/** @type {Array<FeatureType>} */
|
|
/** @type {*} */
|
|
this.getRenderer().getFeaturesInExtent(extent)
|
|
);
|
|
}
|
|
/**
|
|
* @return {VectorTileRenderType} The render mode.
|
|
*/
|
|
getRenderMode() {
|
|
return this.renderMode_;
|
|
}
|
|
/**
|
|
* Return the level as number to which we will preload tiles up to.
|
|
* @return {number} The level to preload tiles up to.
|
|
* @observable
|
|
* @api
|
|
*/
|
|
getPreload() {
|
|
return (
|
|
/** @type {number} */
|
|
this.get(TileProperty_default.PRELOAD)
|
|
);
|
|
}
|
|
/**
|
|
* Deprecated. Whether we use interim tiles on error.
|
|
* @return {boolean} Use interim tiles on error.
|
|
* @observable
|
|
* @api
|
|
*/
|
|
getUseInterimTilesOnError() {
|
|
return (
|
|
/** @type {boolean} */
|
|
this.get(TileProperty_default.USE_INTERIM_TILES_ON_ERROR)
|
|
);
|
|
}
|
|
/**
|
|
* Set the level as number to which we will preload tiles up to.
|
|
* @param {number} preload The level to preload tiles up to.
|
|
* @observable
|
|
* @api
|
|
*/
|
|
setPreload(preload) {
|
|
this.set(TileProperty_default.PRELOAD, preload);
|
|
}
|
|
/**
|
|
* Deprecated. Set whether we use interim tiles on error.
|
|
* @param {boolean} useInterimTilesOnError Use interim tiles on error.
|
|
* @observable
|
|
* @api
|
|
*/
|
|
setUseInterimTilesOnError(useInterimTilesOnError) {
|
|
this.set(TileProperty_default.USE_INTERIM_TILES_ON_ERROR, useInterimTilesOnError);
|
|
}
|
|
};
|
|
var VectorTile_default = VectorTileLayer;
|
|
|
|
// node_modules/ol/renderer/webgl/PointsLayer.js
|
|
var WebGLPointsLayerRenderer = class extends Layer_default2 {
|
|
/**
|
|
* @param {import("../../layer/Layer.js").default} layer Layer.
|
|
* @param {Options} options Options.
|
|
*/
|
|
constructor(layer, options) {
|
|
const uniforms = options.uniforms || {};
|
|
const projectionMatrixTransform = create();
|
|
uniforms[DefaultUniform.PROJECTION_MATRIX] = projectionMatrixTransform;
|
|
super(layer, {
|
|
uniforms,
|
|
postProcesses: options.postProcesses
|
|
});
|
|
this.sourceRevision_ = -1;
|
|
this.verticesBuffer_ = new Buffer_default(ARRAY_BUFFER, DYNAMIC_DRAW);
|
|
this.indicesBuffer_ = new Buffer_default(
|
|
ELEMENT_ARRAY_BUFFER,
|
|
DYNAMIC_DRAW
|
|
);
|
|
this.vertexShader_ = options.vertexShader;
|
|
this.fragmentShader_ = options.fragmentShader;
|
|
this.program_;
|
|
this.hitDetectionEnabled_ = options.hitDetectionEnabled ?? true;
|
|
const customAttributes = options.attributes ? options.attributes.map(function(attribute) {
|
|
return {
|
|
name: "a_" + attribute.name,
|
|
size: 1,
|
|
type: AttributeType.FLOAT
|
|
};
|
|
}) : [];
|
|
this.attributes = [
|
|
{
|
|
name: "a_position",
|
|
size: 2,
|
|
type: AttributeType.FLOAT
|
|
},
|
|
{
|
|
name: "a_index",
|
|
size: 1,
|
|
type: AttributeType.FLOAT
|
|
}
|
|
];
|
|
if (this.hitDetectionEnabled_) {
|
|
this.attributes.push({
|
|
name: "a_hitColor",
|
|
size: 4,
|
|
type: AttributeType.FLOAT
|
|
});
|
|
this.attributes.push({
|
|
name: "a_featureUid",
|
|
size: 1,
|
|
type: AttributeType.FLOAT
|
|
});
|
|
}
|
|
this.attributes.push(...customAttributes);
|
|
this.customAttributes = options.attributes ? options.attributes : [];
|
|
this.previousExtent_ = createEmpty();
|
|
this.currentTransform_ = projectionMatrixTransform;
|
|
this.renderTransform_ = create();
|
|
this.invertRenderTransform_ = create();
|
|
this.renderInstructions_ = new Float32Array(0);
|
|
this.hitRenderTarget_;
|
|
this.lastSentId = 0;
|
|
this.worker_ = create2();
|
|
this.worker_.addEventListener(
|
|
"message",
|
|
/**
|
|
* @param {*} event Event.
|
|
*/
|
|
(event) => {
|
|
const received = event.data;
|
|
if (received.type === WebGLWorkerMessageType.GENERATE_POINT_BUFFERS) {
|
|
const projectionTransform = received.projectionTransform;
|
|
this.verticesBuffer_.fromArrayBuffer(received.vertexBuffer);
|
|
this.helper.flushBufferData(this.verticesBuffer_);
|
|
this.indicesBuffer_.fromArrayBuffer(received.indexBuffer);
|
|
this.helper.flushBufferData(this.indicesBuffer_);
|
|
this.renderTransform_ = projectionTransform;
|
|
makeInverse(
|
|
this.invertRenderTransform_,
|
|
this.renderTransform_
|
|
);
|
|
this.renderInstructions_ = new Float32Array(
|
|
event.data.renderInstructions
|
|
);
|
|
if (received.id === this.lastSentId) {
|
|
this.ready = true;
|
|
}
|
|
this.getLayer().changed();
|
|
}
|
|
}
|
|
);
|
|
this.featureCache_ = {};
|
|
this.featureCount_ = 0;
|
|
const source = (
|
|
/** @type {import("../../source/Vector.js").default} */
|
|
this.getLayer().getSource()
|
|
);
|
|
this.sourceListenKeys_ = [
|
|
listen(
|
|
source,
|
|
VectorEventType_default.ADDFEATURE,
|
|
this.handleSourceFeatureAdded_,
|
|
this
|
|
),
|
|
listen(
|
|
source,
|
|
VectorEventType_default.CHANGEFEATURE,
|
|
this.handleSourceFeatureChanged_,
|
|
this
|
|
),
|
|
listen(
|
|
source,
|
|
VectorEventType_default.REMOVEFEATURE,
|
|
this.handleSourceFeatureDelete_,
|
|
this
|
|
),
|
|
listen(
|
|
source,
|
|
VectorEventType_default.CLEAR,
|
|
this.handleSourceFeatureClear_,
|
|
this
|
|
)
|
|
];
|
|
source.forEachFeature((feature) => {
|
|
const geometry = feature.getGeometry();
|
|
if (geometry && geometry.getType() === "Point") {
|
|
this.featureCache_[getUid(feature)] = {
|
|
feature: (
|
|
/** @type {PointFeature} */
|
|
feature
|
|
),
|
|
properties: feature.getProperties(),
|
|
flatCoordinates: (
|
|
/** @type {Point} */
|
|
geometry.getFlatCoordinates()
|
|
)
|
|
};
|
|
this.featureCount_++;
|
|
}
|
|
});
|
|
}
|
|
/**
|
|
* @override
|
|
*/
|
|
afterHelperCreated() {
|
|
this.program_ = this.helper.getProgram(
|
|
this.fragmentShader_,
|
|
this.vertexShader_
|
|
);
|
|
if (this.hitDetectionEnabled_) {
|
|
this.hitRenderTarget_ = new RenderTarget_default(this.helper);
|
|
}
|
|
if (this.verticesBuffer_.getArray()) {
|
|
this.helper.flushBufferData(this.verticesBuffer_);
|
|
}
|
|
if (this.indicesBuffer_.getArray()) {
|
|
this.helper.flushBufferData(this.indicesBuffer_);
|
|
}
|
|
}
|
|
/**
|
|
* @param {import("../../source/Vector.js").VectorSourceEvent} event Event.
|
|
* @private
|
|
*/
|
|
handleSourceFeatureAdded_(event) {
|
|
const feature = event.feature;
|
|
const geometry = feature.getGeometry();
|
|
if (geometry && geometry.getType() === "Point") {
|
|
this.featureCache_[getUid(feature)] = {
|
|
feature: (
|
|
/** @type {PointFeature} */
|
|
feature
|
|
),
|
|
properties: feature.getProperties(),
|
|
flatCoordinates: (
|
|
/** @type {Point} */
|
|
geometry.getFlatCoordinates()
|
|
)
|
|
};
|
|
this.featureCount_++;
|
|
}
|
|
}
|
|
/**
|
|
* @param {import("../../source/Vector.js").VectorSourceEvent} event Event.
|
|
* @private
|
|
*/
|
|
handleSourceFeatureChanged_(event) {
|
|
const feature = event.feature;
|
|
const featureUid = getUid(feature);
|
|
const item = this.featureCache_[featureUid];
|
|
const geometry = feature.getGeometry();
|
|
if (item) {
|
|
if (geometry && geometry.getType() === "Point") {
|
|
item.properties = feature.getProperties();
|
|
item.flatCoordinates = /** @type {Point} */
|
|
geometry.getFlatCoordinates();
|
|
} else {
|
|
delete this.featureCache_[featureUid];
|
|
this.featureCount_--;
|
|
}
|
|
} else {
|
|
if (geometry && geometry.getType() === "Point") {
|
|
this.featureCache_[featureUid] = {
|
|
feature: (
|
|
/** @type {PointFeature} */
|
|
feature
|
|
),
|
|
properties: feature.getProperties(),
|
|
flatCoordinates: (
|
|
/** @type {Point} */
|
|
geometry.getFlatCoordinates()
|
|
)
|
|
};
|
|
this.featureCount_++;
|
|
}
|
|
}
|
|
}
|
|
/**
|
|
* @param {import("../../source/Vector.js").VectorSourceEvent} event Event.
|
|
* @private
|
|
*/
|
|
handleSourceFeatureDelete_(event) {
|
|
const feature = event.feature;
|
|
const featureUid = getUid(feature);
|
|
if (featureUid in this.featureCache_) {
|
|
delete this.featureCache_[featureUid];
|
|
this.featureCount_--;
|
|
}
|
|
}
|
|
/**
|
|
* @private
|
|
*/
|
|
handleSourceFeatureClear_() {
|
|
this.featureCache_ = {};
|
|
this.featureCount_ = 0;
|
|
}
|
|
/**
|
|
* Render the layer.
|
|
* @param {import("../../Map.js").FrameState} frameState Frame state.
|
|
* @return {HTMLElement} The rendered element.
|
|
* @override
|
|
*/
|
|
renderFrame(frameState) {
|
|
const gl = this.helper.getGL();
|
|
this.preRender(gl, frameState);
|
|
const [startWorld, endWorld, worldWidth] = getWorldParameters(
|
|
frameState,
|
|
this.getLayer()
|
|
);
|
|
this.renderWorlds(frameState, false, startWorld, endWorld, worldWidth);
|
|
this.helper.finalizeDraw(
|
|
frameState,
|
|
this.dispatchPreComposeEvent,
|
|
this.dispatchPostComposeEvent
|
|
);
|
|
if (this.hitDetectionEnabled_) {
|
|
this.renderWorlds(frameState, true, startWorld, endWorld, worldWidth);
|
|
this.hitRenderTarget_.clearCachedData();
|
|
}
|
|
this.postRender(gl, frameState);
|
|
const canvas = this.helper.getCanvas();
|
|
return canvas;
|
|
}
|
|
/**
|
|
* Determine whether renderFrame should be called.
|
|
* @param {import("../../Map.js").FrameState} frameState Frame state.
|
|
* @return {boolean} Layer is ready to be rendered.
|
|
* @override
|
|
*/
|
|
prepareFrameInternal(frameState) {
|
|
const layer = this.getLayer();
|
|
const vectorSource = layer.getSource();
|
|
const viewState = frameState.viewState;
|
|
const viewNotMoving = !frameState.viewHints[ViewHint_default.ANIMATING] && !frameState.viewHints[ViewHint_default.INTERACTING];
|
|
const extentChanged = !equals(this.previousExtent_, frameState.extent);
|
|
const sourceChanged = this.sourceRevision_ < vectorSource.getRevision();
|
|
if (sourceChanged) {
|
|
this.sourceRevision_ = vectorSource.getRevision();
|
|
}
|
|
if (viewNotMoving && (extentChanged || sourceChanged)) {
|
|
const projection = viewState.projection;
|
|
const resolution = viewState.resolution;
|
|
const renderBuffer = layer instanceof BaseVector_default ? layer.getRenderBuffer() : 0;
|
|
const extent = buffer(frameState.extent, renderBuffer * resolution);
|
|
vectorSource.loadFeatures(extent, resolution, projection);
|
|
this.rebuildBuffers_(frameState);
|
|
this.previousExtent_ = frameState.extent.slice();
|
|
}
|
|
this.helper.useProgram(this.program_, frameState);
|
|
this.helper.prepareDraw(frameState);
|
|
this.helper.bindBuffer(this.verticesBuffer_);
|
|
this.helper.bindBuffer(this.indicesBuffer_);
|
|
this.helper.enableAttributes(this.attributes);
|
|
return true;
|
|
}
|
|
/**
|
|
* Rebuild internal webgl buffers based on current view extent; costly, should not be called too much
|
|
* @param {import("../../Map").FrameState} frameState Frame state.
|
|
* @private
|
|
*/
|
|
rebuildBuffers_(frameState) {
|
|
const projectionTransform = create();
|
|
this.helper.makeProjectionTransform(frameState, projectionTransform);
|
|
const userProjection = getUserProjection();
|
|
const baseInstructionLength = this.hitDetectionEnabled_ ? 7 : 2;
|
|
const singleInstructionLength = baseInstructionLength + this.customAttributes.length;
|
|
const totalSize = singleInstructionLength * this.featureCount_;
|
|
const renderInstructions = this.renderInstructions_ && this.renderInstructions_.length === totalSize ? this.renderInstructions_ : new Float32Array(totalSize);
|
|
this.renderInstructions_ = null;
|
|
let tmpCoords = [];
|
|
const tmpColor = [];
|
|
let idx = -1;
|
|
const projection = frameState.viewState.projection;
|
|
for (const featureUid in this.featureCache_) {
|
|
const featureCache = this.featureCache_[featureUid];
|
|
if (userProjection) {
|
|
tmpCoords = fromUserCoordinate(
|
|
featureCache.flatCoordinates,
|
|
projection
|
|
);
|
|
} else {
|
|
tmpCoords[0] = featureCache.flatCoordinates[0];
|
|
tmpCoords[1] = featureCache.flatCoordinates[1];
|
|
}
|
|
apply(projectionTransform, tmpCoords);
|
|
renderInstructions[++idx] = tmpCoords[0];
|
|
renderInstructions[++idx] = tmpCoords[1];
|
|
if (this.hitDetectionEnabled_) {
|
|
const hitColor = colorEncodeId(idx + 5, tmpColor);
|
|
renderInstructions[++idx] = hitColor[0];
|
|
renderInstructions[++idx] = hitColor[1];
|
|
renderInstructions[++idx] = hitColor[2];
|
|
renderInstructions[++idx] = hitColor[3];
|
|
renderInstructions[++idx] = Number(featureUid);
|
|
}
|
|
for (let j = 0; j < this.customAttributes.length; j++) {
|
|
const value = this.customAttributes[j].callback(
|
|
featureCache.feature,
|
|
featureCache.properties
|
|
);
|
|
renderInstructions[++idx] = value;
|
|
}
|
|
}
|
|
const message = {
|
|
id: ++this.lastSentId,
|
|
type: WebGLWorkerMessageType.GENERATE_POINT_BUFFERS,
|
|
renderInstructions: renderInstructions.buffer,
|
|
customAttributesSize: singleInstructionLength - 2
|
|
};
|
|
message["projectionTransform"] = projectionTransform;
|
|
this.ready = false;
|
|
this.worker_.postMessage(message, [renderInstructions.buffer]);
|
|
}
|
|
/**
|
|
* @param {import("../../coordinate.js").Coordinate} coordinate Coordinate.
|
|
* @param {import("../../Map.js").FrameState} frameState Frame state.
|
|
* @param {number} hitTolerance Hit tolerance in pixels.
|
|
* @param {import("../vector.js").FeatureCallback<T>} callback Feature callback.
|
|
* @param {Array<import("../Map.js").HitMatch<T>>} matches The hit detected matches with tolerance.
|
|
* @return {T|undefined} Callback result.
|
|
* @template T
|
|
* @override
|
|
*/
|
|
forEachFeatureAtCoordinate(coordinate, frameState, hitTolerance, callback, matches) {
|
|
assert(
|
|
this.hitDetectionEnabled_,
|
|
"`forEachFeatureAtCoordinate` cannot be used on a WebGL layer if the hit detection logic has been disabled using the `disableHitDetection: true` option."
|
|
);
|
|
if (!this.renderInstructions_ || !this.hitDetectionEnabled_) {
|
|
return void 0;
|
|
}
|
|
const pixel = apply(
|
|
frameState.coordinateToPixelTransform,
|
|
coordinate.slice()
|
|
);
|
|
const data = this.hitRenderTarget_.readPixel(pixel[0] / 2, pixel[1] / 2);
|
|
const color = [data[0] / 255, data[1] / 255, data[2] / 255, data[3] / 255];
|
|
const index = colorDecodeId(color);
|
|
const opacity = this.renderInstructions_[index];
|
|
const uid = Math.floor(opacity).toString();
|
|
const source = this.getLayer().getSource();
|
|
const feature = source.getFeatureByUid(uid);
|
|
if (feature) {
|
|
return callback(feature, this.getLayer(), null);
|
|
}
|
|
return void 0;
|
|
}
|
|
/**
|
|
* Render the world, either to the main framebuffer or to the hit framebuffer
|
|
* @param {import("../../Map.js").FrameState} frameState current frame state
|
|
* @param {boolean} forHitDetection whether the rendering is for hit detection
|
|
* @param {number} startWorld the world to render in the first iteration
|
|
* @param {number} endWorld the last world to render
|
|
* @param {number} worldWidth the width of the worlds being rendered
|
|
*/
|
|
renderWorlds(frameState, forHitDetection, startWorld, endWorld, worldWidth) {
|
|
let world = startWorld;
|
|
this.helper.useProgram(this.program_, frameState);
|
|
if (forHitDetection) {
|
|
this.hitRenderTarget_.setSize([
|
|
Math.floor(frameState.size[0] / 2),
|
|
Math.floor(frameState.size[1] / 2)
|
|
]);
|
|
this.helper.prepareDrawToRenderTarget(
|
|
frameState,
|
|
this.hitRenderTarget_,
|
|
true
|
|
);
|
|
}
|
|
this.helper.bindBuffer(this.verticesBuffer_);
|
|
this.helper.bindBuffer(this.indicesBuffer_);
|
|
this.helper.enableAttributes(this.attributes);
|
|
do {
|
|
this.helper.makeProjectionTransform(frameState, this.currentTransform_);
|
|
translate(this.currentTransform_, world * worldWidth, 0);
|
|
multiply(this.currentTransform_, this.invertRenderTransform_);
|
|
this.helper.applyUniforms(frameState);
|
|
this.helper.applyHitDetectionUniform(forHitDetection);
|
|
const renderCount = this.indicesBuffer_.getSize();
|
|
this.helper.drawElements(0, renderCount);
|
|
} while (++world < endWorld);
|
|
}
|
|
/**
|
|
* Clean up.
|
|
* @override
|
|
*/
|
|
disposeInternal() {
|
|
this.worker_.terminate();
|
|
this.sourceListenKeys_.forEach(function(key) {
|
|
unlistenByKey(key);
|
|
});
|
|
this.sourceListenKeys_ = null;
|
|
super.disposeInternal();
|
|
}
|
|
renderDeclutter() {
|
|
}
|
|
};
|
|
var PointsLayer_default = WebGLPointsLayerRenderer;
|
|
|
|
// node_modules/ol/layer/WebGLPoints.js
|
|
var WebGLPointsLayer = class extends Layer_default {
|
|
/**
|
|
* @param {Options<VectorSourceType>} options Options.
|
|
*/
|
|
constructor(options) {
|
|
const baseOptions = Object.assign({}, options);
|
|
super(baseOptions);
|
|
this.styleVariables_ = options.variables || {};
|
|
this.parseResult_ = parseLiteralStyle(
|
|
options.style,
|
|
this.styleVariables_,
|
|
options.filter
|
|
);
|
|
this.hitDetectionDisabled_ = !!options.disableHitDetection;
|
|
}
|
|
/**
|
|
* @override
|
|
*/
|
|
createRenderer() {
|
|
const attributes = Object.keys(this.parseResult_.attributes).map(
|
|
(name) => ({
|
|
name,
|
|
...this.parseResult_.attributes[name]
|
|
})
|
|
);
|
|
return new PointsLayer_default(this, {
|
|
vertexShader: this.parseResult_.builder.getSymbolVertexShader(),
|
|
fragmentShader: this.parseResult_.builder.getSymbolFragmentShader(),
|
|
hitDetectionEnabled: !this.hitDetectionDisabled_,
|
|
uniforms: this.parseResult_.uniforms,
|
|
attributes: (
|
|
/** @type {Array<import('../renderer/webgl/PointsLayer.js').CustomAttribute>} */
|
|
attributes
|
|
)
|
|
});
|
|
}
|
|
/**
|
|
* Update any variables used by the layer style and trigger a re-render.
|
|
* @param {Object<string, number>} variables Variables to update.
|
|
*/
|
|
updateStyleVariables(variables) {
|
|
Object.assign(this.styleVariables_, variables);
|
|
this.changed();
|
|
}
|
|
};
|
|
var WebGLPoints_default = WebGLPointsLayer;
|
|
|
|
// node_modules/ol/layer/WebGLVector.js
|
|
var WebGLVectorLayer = class extends Layer_default {
|
|
/**
|
|
* @param {Options<VectorSourceType, FeatureType>} [options] Options.
|
|
*/
|
|
constructor(options) {
|
|
const baseOptions = Object.assign({}, options);
|
|
super(baseOptions);
|
|
this.styleVariables_ = options.variables || {};
|
|
this.style_ = options.style;
|
|
this.hitDetectionDisabled_ = !!options.disableHitDetection;
|
|
}
|
|
/**
|
|
* @override
|
|
*/
|
|
createRenderer() {
|
|
return new VectorLayer_default2(this, {
|
|
style: this.style_,
|
|
variables: this.styleVariables_,
|
|
disableHitDetection: this.hitDetectionDisabled_
|
|
});
|
|
}
|
|
/**
|
|
* Update any variables used by the layer style and trigger a re-render.
|
|
* @param {import('../style/flat.js').StyleVariables} variables Variables to update.
|
|
*/
|
|
updateStyleVariables(variables) {
|
|
Object.assign(this.styleVariables_, variables);
|
|
this.changed();
|
|
}
|
|
/**
|
|
* Set the layer style.
|
|
* @param {import('../style/flat.js').FlatStyleLike} style Layer style.
|
|
*/
|
|
setStyle(style) {
|
|
this.style_ = style;
|
|
this.clearRenderer();
|
|
this.changed();
|
|
}
|
|
};
|
|
var WebGLVector_default = WebGLVectorLayer;
|
|
|
|
export {
|
|
VectorImage_default,
|
|
VectorTile_default,
|
|
WebGLPoints_default,
|
|
WebGLVector_default
|
|
};
|
|
//# sourceMappingURL=chunk-UX4SNNYH.js.map
|