planning
All checks were successful
Publish To Prod / deploy_and_publish (push) Successful in 35s

This commit is contained in:
2024-10-14 09:15:30 +02:00
parent bcba00a730
commit 6e64e138e2
21059 changed files with 2317811 additions and 1 deletions

398
node_modules/ol/src/layer/Base.js generated vendored Normal file
View File

@@ -0,0 +1,398 @@
/**
* @module ol/layer/Base
*/
import BaseObject from '../Object.js';
import LayerProperty from './Property.js';
import {abstract} from '../util.js';
import {assert} from '../asserts.js';
import {assign} from '../obj.js';
import {clamp} from '../math.js';
/**
* A css color, or a function called with a view resolution returning a css color.
*
* @typedef {string|function(number):string} BackgroundColor
* @api
*/
/**
* @typedef {import("../ObjectEventType").Types|'change:extent'|'change:maxResolution'|'change:maxZoom'|
* 'change:minResolution'|'change:minZoom'|'change:opacity'|'change:visible'|'change:zIndex'} BaseLayerObjectEventTypes
*/
/***
* @template Return
* @typedef {import("../Observable").OnSignature<import("../Observable").EventTypes, import("../events/Event.js").default, Return> &
* import("../Observable").OnSignature<BaseLayerObjectEventTypes, import("../Object").ObjectEvent, Return> &
* import("../Observable").CombinedOnSignature<import("../Observable").EventTypes|BaseLayerObjectEventTypes, Return>} BaseLayerOnSignature
*/
/**
* @typedef {Object} Options
* @property {string} [className='ol-layer'] A CSS class name to set to the layer element.
* @property {number} [opacity=1] Opacity (0, 1).
* @property {boolean} [visible=true] Visibility.
* @property {import("../extent.js").Extent} [extent] The bounding extent for layer rendering. The layer will not be
* rendered outside of this extent.
* @property {number} [zIndex] The z-index for layer rendering. At rendering time, the layers
* will be ordered, first by Z-index and then by position. When `undefined`, a `zIndex` of 0 is assumed
* for layers that are added to the map's `layers` collection, or `Infinity` when the layer's `setMap()`
* method was used.
* @property {number} [minResolution] The minimum resolution (inclusive) at which this layer will be
* visible.
* @property {number} [maxResolution] The maximum resolution (exclusive) below which this layer will
* be visible.
* @property {number} [minZoom] The minimum view zoom level (exclusive) above which this layer will be
* visible.
* @property {number} [maxZoom] The maximum view zoom level (inclusive) at which this layer will
* be visible.
* @property {BackgroundColor} [background] Background color for the layer. If not specified, no background
* will be rendered.
* @property {Object<string, *>} [properties] Arbitrary observable properties. Can be accessed with `#get()` and `#set()`.
*/
/**
* @classdesc
* Abstract base class; normally only used for creating subclasses and not
* instantiated in apps.
* Note that with {@link module:ol/layer/Base~BaseLayer} and all its subclasses, any property set in
* the options is set as a {@link module:ol/Object~BaseObject} property on the layer object, so
* is observable, and has get/set accessors.
*
* @api
*/
class BaseLayer extends BaseObject {
/**
* @param {Options} options Layer options.
*/
constructor(options) {
super();
/***
* @type {BaseLayerOnSignature<import("../events").EventsKey>}
*/
this.on;
/***
* @type {BaseLayerOnSignature<import("../events").EventsKey>}
*/
this.once;
/***
* @type {BaseLayerOnSignature<void>}
*/
this.un;
/**
* @type {BackgroundColor|false}
* @private
*/
this.background_ = options.background;
/**
* @type {Object<string, *>}
*/
const properties = assign({}, options);
if (typeof options.properties === 'object') {
delete properties.properties;
assign(properties, options.properties);
}
properties[LayerProperty.OPACITY] =
options.opacity !== undefined ? options.opacity : 1;
assert(typeof properties[LayerProperty.OPACITY] === 'number', 64); // Layer opacity must be a number
properties[LayerProperty.VISIBLE] =
options.visible !== undefined ? options.visible : true;
properties[LayerProperty.Z_INDEX] = options.zIndex;
properties[LayerProperty.MAX_RESOLUTION] =
options.maxResolution !== undefined ? options.maxResolution : Infinity;
properties[LayerProperty.MIN_RESOLUTION] =
options.minResolution !== undefined ? options.minResolution : 0;
properties[LayerProperty.MIN_ZOOM] =
options.minZoom !== undefined ? options.minZoom : -Infinity;
properties[LayerProperty.MAX_ZOOM] =
options.maxZoom !== undefined ? options.maxZoom : Infinity;
/**
* @type {string}
* @private
*/
this.className_ =
properties.className !== undefined ? properties.className : 'ol-layer';
delete properties.className;
this.setProperties(properties);
/**
* @type {import("./Layer.js").State}
* @private
*/
this.state_ = null;
}
/**
* Get the background for this layer.
* @return {BackgroundColor|false} Layer background.
*/
getBackground() {
return this.background_;
}
/**
* @return {string} CSS class name.
*/
getClassName() {
return this.className_;
}
/**
* This method is not meant to be called by layers or layer renderers because the state
* is incorrect if the layer is included in a layer group.
*
* @param {boolean} [opt_managed] Layer is managed.
* @return {import("./Layer.js").State} Layer state.
*/
getLayerState(opt_managed) {
/** @type {import("./Layer.js").State} */
const state =
this.state_ ||
/** @type {?} */ ({
layer: this,
managed: opt_managed === undefined ? true : opt_managed,
});
const zIndex = this.getZIndex();
state.opacity = clamp(Math.round(this.getOpacity() * 100) / 100, 0, 1);
state.visible = this.getVisible();
state.extent = this.getExtent();
state.zIndex = zIndex === undefined && !state.managed ? Infinity : zIndex;
state.maxResolution = this.getMaxResolution();
state.minResolution = Math.max(this.getMinResolution(), 0);
state.minZoom = this.getMinZoom();
state.maxZoom = this.getMaxZoom();
this.state_ = state;
return state;
}
/**
* @abstract
* @param {Array<import("./Layer.js").default>} [opt_array] Array of layers (to be
* modified in place).
* @return {Array<import("./Layer.js").default>} Array of layers.
*/
getLayersArray(opt_array) {
return abstract();
}
/**
* @abstract
* @param {Array<import("./Layer.js").State>} [opt_states] Optional list of layer
* states (to be modified in place).
* @return {Array<import("./Layer.js").State>} List of layer states.
*/
getLayerStatesArray(opt_states) {
return abstract();
}
/**
* Return the {@link module:ol/extent~Extent extent} of the layer or `undefined` if it
* will be visible regardless of extent.
* @return {import("../extent.js").Extent|undefined} The layer extent.
* @observable
* @api
*/
getExtent() {
return /** @type {import("../extent.js").Extent|undefined} */ (
this.get(LayerProperty.EXTENT)
);
}
/**
* Return the maximum resolution of the layer.
* @return {number} The maximum resolution of the layer.
* @observable
* @api
*/
getMaxResolution() {
return /** @type {number} */ (this.get(LayerProperty.MAX_RESOLUTION));
}
/**
* Return the minimum resolution of the layer.
* @return {number} The minimum resolution of the layer.
* @observable
* @api
*/
getMinResolution() {
return /** @type {number} */ (this.get(LayerProperty.MIN_RESOLUTION));
}
/**
* Return the minimum zoom level of the layer.
* @return {number} The minimum zoom level of the layer.
* @observable
* @api
*/
getMinZoom() {
return /** @type {number} */ (this.get(LayerProperty.MIN_ZOOM));
}
/**
* Return the maximum zoom level of the layer.
* @return {number} The maximum zoom level of the layer.
* @observable
* @api
*/
getMaxZoom() {
return /** @type {number} */ (this.get(LayerProperty.MAX_ZOOM));
}
/**
* Return the opacity of the layer (between 0 and 1).
* @return {number} The opacity of the layer.
* @observable
* @api
*/
getOpacity() {
return /** @type {number} */ (this.get(LayerProperty.OPACITY));
}
/**
* @abstract
* @return {import("../source/Source.js").State} Source state.
*/
getSourceState() {
return abstract();
}
/**
* Return the visibility of the layer (`true` or `false`).
* @return {boolean} The visibility of the layer.
* @observable
* @api
*/
getVisible() {
return /** @type {boolean} */ (this.get(LayerProperty.VISIBLE));
}
/**
* Return the Z-index of the layer, which is used to order layers before
* rendering. The default Z-index is 0.
* @return {number} The Z-index of the layer.
* @observable
* @api
*/
getZIndex() {
return /** @type {number} */ (this.get(LayerProperty.Z_INDEX));
}
/**
* Sets the background color.
* @param {BackgroundColor} [opt_background] Background color.
*/
setBackground(opt_background) {
this.background_ = opt_background;
this.changed();
}
/**
* Set the extent at which the layer is visible. If `undefined`, the layer
* will be visible at all extents.
* @param {import("../extent.js").Extent|undefined} extent The extent of the layer.
* @observable
* @api
*/
setExtent(extent) {
this.set(LayerProperty.EXTENT, extent);
}
/**
* Set the maximum resolution at which the layer is visible.
* @param {number} maxResolution The maximum resolution of the layer.
* @observable
* @api
*/
setMaxResolution(maxResolution) {
this.set(LayerProperty.MAX_RESOLUTION, maxResolution);
}
/**
* Set the minimum resolution at which the layer is visible.
* @param {number} minResolution The minimum resolution of the layer.
* @observable
* @api
*/
setMinResolution(minResolution) {
this.set(LayerProperty.MIN_RESOLUTION, minResolution);
}
/**
* Set the maximum zoom (exclusive) at which the layer is visible.
* Note that the zoom levels for layer visibility are based on the
* view zoom level, which may be different from a tile source zoom level.
* @param {number} maxZoom The maximum zoom of the layer.
* @observable
* @api
*/
setMaxZoom(maxZoom) {
this.set(LayerProperty.MAX_ZOOM, maxZoom);
}
/**
* Set the minimum zoom (inclusive) at which the layer is visible.
* Note that the zoom levels for layer visibility are based on the
* view zoom level, which may be different from a tile source zoom level.
* @param {number} minZoom The minimum zoom of the layer.
* @observable
* @api
*/
setMinZoom(minZoom) {
this.set(LayerProperty.MIN_ZOOM, minZoom);
}
/**
* Set the opacity of the layer, allowed values range from 0 to 1.
* @param {number} opacity The opacity of the layer.
* @observable
* @api
*/
setOpacity(opacity) {
assert(typeof opacity === 'number', 64); // Layer opacity must be a number
this.set(LayerProperty.OPACITY, opacity);
}
/**
* Set the visibility of the layer (`true` or `false`).
* @param {boolean} visible The visibility of the layer.
* @observable
* @api
*/
setVisible(visible) {
this.set(LayerProperty.VISIBLE, visible);
}
/**
* Set Z-index of the layer, which is used to order layers before rendering.
* The default Z-index is 0.
* @param {number} zindex The z-index of the layer.
* @observable
* @api
*/
setZIndex(zindex) {
this.set(LayerProperty.Z_INDEX, zindex);
}
/**
* Clean up.
*/
disposeInternal() {
if (this.state_) {
this.state_.layer = null;
this.state_ = null;
}
super.disposeInternal();
}
}
export default BaseLayer;

57
node_modules/ol/src/layer/BaseImage.js generated vendored Normal file
View File

@@ -0,0 +1,57 @@
/**
* @module ol/layer/BaseImage
*/
import Layer from './Layer.js';
/**
* @template {import("../source/Image.js").default} ImageSourceType
* @typedef {Object} Options
* @property {string} [className='ol-layer'] A CSS class name to set to the layer element.
* @property {number} [opacity=1] Opacity (0, 1).
* @property {boolean} [visible=true] Visibility.
* @property {import("../extent.js").Extent} [extent] The bounding extent for layer rendering. The layer will not be
* rendered outside of this extent.
* @property {number} [zIndex] The z-index for layer rendering. At rendering time, the layers
* will be ordered, first by Z-index and then by position. When `undefined`, a `zIndex` of 0 is assumed
* for layers that are added to the map's `layers` collection, or `Infinity` when the layer's `setMap()`
* method was used.
* @property {number} [minResolution] The minimum resolution (inclusive) at which this layer will be
* visible.
* @property {number} [maxResolution] The maximum resolution (exclusive) below which this layer will
* be visible.
* @property {number} [minZoom] The minimum view zoom level (exclusive) above which this layer will be
* visible.
* @property {number} [maxZoom] The maximum view zoom level (inclusive) at which this layer will
* be visible.
* @property {import("../PluggableMap.js").default} [map] Sets the layer as overlay on a map. The map will not manage
* this layer in its layers collection, and the layer will be rendered on top. This is useful for
* temporary layers. The standard way to add a layer to a map and have it managed by the map is to
* use {@link import("../PluggableMap.js").default#addLayer map.addLayer()}.
* @property {ImageSourceType} [source] Source for this layer.
* @property {Object<string, *>} [properties] Arbitrary observable properties. Can be accessed with `#get()` and `#set()`.
*/
/**
* @classdesc
* Server-rendered images that are available for arbitrary extents and
* resolutions.
* Note that any property set in the options is set as a {@link module:ol/Object~BaseObject}
* property on the layer object; for example, setting `title: 'My Title'` in the
* options means that `title` is observable, and has get/set accessors.
*
* @template {import("../source/Image.js").default} ImageSourceType
* @template {import("../renderer/Layer.js").default} RendererType
* @extends {Layer<ImageSourceType, RendererType>}
* @api
*/
class BaseImageLayer extends Layer {
/**
* @param {Options<ImageSourceType>} [opt_options] Layer options.
*/
constructor(opt_options) {
const options = opt_options ? opt_options : {};
super(options);
}
}
export default BaseImageLayer;

161
node_modules/ol/src/layer/BaseTile.js generated vendored Normal file
View File

@@ -0,0 +1,161 @@
/**
* @module ol/layer/BaseTile
*/
import Layer from './Layer.js';
import TileProperty from './TileProperty.js';
import {assign} from '../obj.js';
/***
* @template Return
* @typedef {import("../Observable").OnSignature<import("../Observable").EventTypes, import("../events/Event.js").default, Return> &
* import("../Observable").OnSignature<import("./Base").BaseLayerObjectEventTypes|
* 'change:source'|'change:preload'|'change:useInterimTilesOnError', import("../Object").ObjectEvent, Return> &
* import("../Observable").OnSignature<import("../render/EventType").LayerRenderEventTypes, import("../render/Event").default, Return> &
* import("../Observable").CombinedOnSignature<import("../Observable").EventTypes|import("./Base").BaseLayerObjectEventTypes|
* 'change:source'|'change:preload'|'change:useInterimTilesOnError'|import("../render/EventType").LayerRenderEventTypes, Return>} BaseTileLayerOnSignature
*/
/**
* @template {import("../source/Tile.js").default} TileSourceType
* @typedef {Object} Options
* @property {string} [className='ol-layer'] A CSS class name to set to the layer element.
* @property {number} [opacity=1] Opacity (0, 1).
* @property {boolean} [visible=true] Visibility.
* @property {import("../extent.js").Extent} [extent] The bounding extent for layer rendering. The layer will not be
* rendered outside of this extent.
* @property {number} [zIndex] The z-index for layer rendering. At rendering time, the layers
* will be ordered, first by Z-index and then by position. When `undefined`, a `zIndex` of 0 is assumed
* for layers that are added to the map's `layers` collection, or `Infinity` when the layer's `setMap()`
* method was used.
* @property {number} [minResolution] The minimum resolution (inclusive) at which this layer will be
* visible.
* @property {number} [maxResolution] The maximum resolution (exclusive) below which this layer will
* be visible.
* @property {number} [minZoom] The minimum view zoom level (exclusive) above which this layer will be
* visible.
* @property {number} [maxZoom] The maximum view zoom level (inclusive) at which this layer will
* be visible.
* @property {number} [preload=0] Preload. Load low-resolution tiles up to `preload` levels. `0`
* means no preloading.
* @property {TileSourceType} [source] Source for this layer.
* @property {import("../PluggableMap.js").default} [map] Sets the layer as overlay on a map. The map will not manage
* this layer in its layers collection, and the layer will be rendered on top. This is useful for
* temporary layers. The standard way to add a layer to a map and have it managed by the map is to
* use {@link import("../PluggableMap.js").default#addLayer map.addLayer()}.
* @property {boolean} [useInterimTilesOnError=true] Use interim tiles on error.
* @property {Object<string, *>} [properties] Arbitrary observable properties. Can be accessed with `#get()` and `#set()`.
*/
/**
* @classdesc
* For layer sources that provide pre-rendered, tiled images in grids that are
* organized by zoom levels for specific resolutions.
* Note that any property set in the options is set as a {@link module:ol/Object~BaseObject}
* property on the layer object; for example, setting `title: 'My Title'` in the
* options means that `title` is observable, and has get/set accessors.
*
* @template {import("../source/Tile.js").default} TileSourceType
* @template {import("../renderer/Layer.js").default} RendererType
* @extends {Layer<TileSourceType, RendererType>}
* @api
*/
class BaseTileLayer extends Layer {
/**
* @param {Options<TileSourceType>} [opt_options] Tile layer options.
*/
constructor(opt_options) {
const options = opt_options ? opt_options : {};
const baseOptions = assign({}, options);
delete baseOptions.preload;
delete baseOptions.useInterimTilesOnError;
super(baseOptions);
/***
* @type {BaseTileLayerOnSignature<import("../events").EventsKey>}
*/
this.on;
/***
* @type {BaseTileLayerOnSignature<import("../events").EventsKey>}
*/
this.once;
/***
* @type {BaseTileLayerOnSignature<void>}
*/
this.un;
this.setPreload(options.preload !== undefined ? options.preload : 0);
this.setUseInterimTilesOnError(
options.useInterimTilesOnError !== undefined
? options.useInterimTilesOnError
: true
);
}
/**
* 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.PRELOAD));
}
/**
* 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.PRELOAD, preload);
}
/**
* Whether we use interim tiles on error.
* @return {boolean} Use interim tiles on error.
* @observable
* @api
*/
getUseInterimTilesOnError() {
return /** @type {boolean} */ (
this.get(TileProperty.USE_INTERIM_TILES_ON_ERROR)
);
}
/**
* Set whether we use interim tiles on error.
* @param {boolean} useInterimTilesOnError Use interim tiles on error.
* @observable
* @api
*/
setUseInterimTilesOnError(useInterimTilesOnError) {
this.set(TileProperty.USE_INTERIM_TILES_ON_ERROR, useInterimTilesOnError);
}
/**
* Get data for a pixel location. The return type depends on the source data. For image tiles,
* a four element RGBA array will be returned. For data tiles, the array length will match the
* number of bands in the dataset. For requests outside the layer extent, `null` will be returned.
* Data for a image tiles can only be retrieved if the source's `crossOrigin` property is set.
*
* ```js
* // display layer data on every pointer move
* map.on('pointermove', (event) => {
* console.log(layer.getData(event.pixel));
* });
* ```
* @param {import("../pixel").Pixel} pixel Pixel.
* @return {Uint8ClampedArray|Uint8Array|Float32Array|DataView|null} Pixel data.
* @api
*/
getData(pixel) {
return super.getData(pixel);
}
}
export default BaseTileLayer;

265
node_modules/ol/src/layer/BaseVector.js generated vendored Normal file
View File

@@ -0,0 +1,265 @@
/**
* @module ol/layer/BaseVector
*/
import Layer from './Layer.js';
import RBush from 'rbush';
import {assign} from '../obj.js';
import {
createDefaultStyle,
toFunction as toStyleFunction,
} from '../style/Style.js';
/**
* @template {import("../source/Vector.js").default|import("../source/VectorTile.js").default} VectorSourceType
* @typedef {Object} Options
* @property {string} [className='ol-layer'] A CSS class name to set to the layer element.
* @property {number} [opacity=1] Opacity (0, 1).
* @property {boolean} [visible=true] Visibility.
* @property {import("../extent.js").Extent} [extent] The bounding extent for layer rendering. The layer will not be
* rendered outside of this extent.
* @property {number} [zIndex] The z-index for layer rendering. At rendering time, the layers
* will be ordered, first by Z-index and then by position. When `undefined`, a `zIndex` of 0 is assumed
* for layers that are added to the map's `layers` collection, or `Infinity` when the layer's `setMap()`
* method was used.
* @property {number} [minResolution] The minimum resolution (inclusive) at which this layer will be
* visible.
* @property {number} [maxResolution] The maximum resolution (exclusive) below which this layer will
* be visible.
* @property {number} [minZoom] The minimum view zoom level (exclusive) above which this layer will be
* visible.
* @property {number} [maxZoom] The maximum view zoom level (inclusive) at which this layer will
* be visible.
* @property {import("../render.js").OrderFunction} [renderOrder] Render order. Function to be used when sorting
* features before rendering. By default features are drawn in the order that they are created. Use
* `null` to avoid the sort, but get an undefined draw order.
* @property {number} [renderBuffer=100] The buffer in pixels around the viewport extent used by the
* renderer when getting features from the vector source for the rendering or hit-detection.
* Recommended value: the size of the largest symbol, line width or label.
* @property {VectorSourceType} [source] Source.
* @property {import("../PluggableMap.js").default} [map] Sets the layer as overlay on a map. The map will not manage
* this layer in its layers collection, and the layer will be rendered on top. This is useful for
* temporary layers. The standard way to add a layer to a map and have it managed by the map is to
* use {@link import("../PluggableMap.js").default#addLayer map.addLayer()}.
* @property {boolean} [declutter=false] Declutter images and text. Decluttering is applied to all
* image and text styles of all Vector and VectorTile layers that have set this to `true`. The priority
* is defined by the z-index of the layer, the `zIndex` of the style and the render order of features.
* Higher z-index means higher priority. Within the same z-index, a feature rendered before another has
* higher priority.
*
* As an optimization decluttered features from layers with the same `className` are rendered above
* the fill and stroke styles of all of those layers regardless of z-index. To opt out of this
* behavior and place declutterd features with their own layer configure the layer with a `className`
* other than `ol-layer`.
* @property {import("../style/Style.js").StyleLike|null} [style] Layer style. When set to `null`, only
* features that have their own style will be rendered. See {@link module:ol/style/Style~Style} for the default style
* which will be used if this is not set.
* @property {import("./Base.js").BackgroundColor} [background] Background color for the layer. If not specified, no background
* will be rendered.
* @property {boolean} [updateWhileAnimating=false] When set to `true`, feature batches will
* be recreated during animations. This means that no vectors will be shown clipped, but the
* setting will have a performance impact for large amounts of vector data. When set to `false`,
* batches will be recreated when no animation is active.
* @property {boolean} [updateWhileInteracting=false] When set to `true`, feature batches will
* be recreated during interactions. See also `updateWhileAnimating`.
* @property {Object<string, *>} [properties] Arbitrary observable properties. Can be accessed with `#get()` and `#set()`.
*/
/**
* @enum {string}
* @private
*/
const Property = {
RENDER_ORDER: 'renderOrder',
};
/**
* @classdesc
* Vector data that is rendered client-side.
* Note that any property set in the options is set as a {@link module:ol/Object~BaseObject}
* property on the layer object; for example, setting `title: 'My Title'` in the
* options means that `title` is observable, and has get/set accessors.
*
* @template {import("../source/Vector.js").default|import("../source/VectorTile.js").default} VectorSourceType
* @template {import("../renderer/canvas/VectorLayer.js").default|import("../renderer/canvas/VectorTileLayer.js").default|import("../renderer/canvas/VectorImageLayer.js").default|import("../renderer/webgl/PointsLayer.js").default} RendererType
* @extends {Layer<VectorSourceType, RendererType>}
* @api
*/
class BaseVectorLayer extends Layer {
/**
* @param {Options<VectorSourceType>} [opt_options] Options.
*/
constructor(opt_options) {
const options = opt_options ? opt_options : {};
const baseOptions = assign({}, options);
delete baseOptions.style;
delete baseOptions.renderBuffer;
delete baseOptions.updateWhileAnimating;
delete baseOptions.updateWhileInteracting;
super(baseOptions);
/**
* @private
* @type {boolean}
*/
this.declutter_ =
options.declutter !== undefined ? options.declutter : false;
/**
* @type {number}
* @private
*/
this.renderBuffer_ =
options.renderBuffer !== undefined ? options.renderBuffer : 100;
/**
* User provided style.
* @type {import("../style/Style.js").StyleLike}
* @private
*/
this.style_ = null;
/**
* Style function for use within the library.
* @type {import("../style/Style.js").StyleFunction|undefined}
* @private
*/
this.styleFunction_ = undefined;
this.setStyle(options.style);
/**
* @type {boolean}
* @private
*/
this.updateWhileAnimating_ =
options.updateWhileAnimating !== undefined
? options.updateWhileAnimating
: false;
/**
* @type {boolean}
* @private
*/
this.updateWhileInteracting_ =
options.updateWhileInteracting !== undefined
? options.updateWhileInteracting
: false;
}
/**
* @return {boolean} Declutter.
*/
getDeclutter() {
return this.declutter_;
}
/**
* 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 {@link import("../PluggableMap.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").default>>} Promise that resolves with an array of features.
* @api
*/
getFeatures(pixel) {
return super.getFeatures(pixel);
}
/**
* @return {number|undefined} Render buffer.
*/
getRenderBuffer() {
return this.renderBuffer_;
}
/**
* @return {function(import("../Feature.js").default, import("../Feature.js").default): number|null|undefined} Render
* order.
*/
getRenderOrder() {
return /** @type {import("../render.js").OrderFunction|null|undefined} */ (
this.get(Property.RENDER_ORDER)
);
}
/**
* Get the style for features. This returns whatever was passed to the `style`
* option at construction or to the `setStyle` method.
* @return {import("../style/Style.js").StyleLike|null|undefined} Layer style.
* @api
*/
getStyle() {
return this.style_;
}
/**
* Get the style function.
* @return {import("../style/Style.js").StyleFunction|undefined} Layer style function.
* @api
*/
getStyleFunction() {
return this.styleFunction_;
}
/**
* @return {boolean} Whether the rendered layer should be updated while
* animating.
*/
getUpdateWhileAnimating() {
return this.updateWhileAnimating_;
}
/**
* @return {boolean} Whether the rendered layer should be updated while
* interacting.
*/
getUpdateWhileInteracting() {
return this.updateWhileInteracting_;
}
/**
* Render declutter items for this layer
* @param {import("../PluggableMap.js").FrameState} frameState Frame state.
*/
renderDeclutter(frameState) {
if (!frameState.declutterTree) {
frameState.declutterTree = new RBush(9);
}
/** @type {*} */ (this.getRenderer()).renderDeclutter(frameState);
}
/**
* @param {import("../render.js").OrderFunction|null|undefined} renderOrder
* Render order.
*/
setRenderOrder(renderOrder) {
this.set(Property.RENDER_ORDER, renderOrder);
}
/**
* Set the style for features. This can be a single style object, an array
* of styles, or a function that takes a feature and resolution and returns
* an array of styles. If set to `null`, the layer has no style (a `null` style),
* so only features that have their own styles will be rendered in the layer. Call
* `setStyle()` without arguments to reset to the default style. See
* {@link module:ol/style/Style~Style} for information on the default style.
* @param {import("../style/Style.js").StyleLike|null} [opt_style] Layer style.
* @api
*/
setStyle(opt_style) {
this.style_ = opt_style !== undefined ? opt_style : createDefaultStyle;
this.styleFunction_ =
opt_style === null ? undefined : toStyleFunction(this.style_);
this.changed();
}
}
export default BaseVectorLayer;

1245
node_modules/ol/src/layer/Graticule.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

352
node_modules/ol/src/layer/Group.js generated vendored Normal file
View File

@@ -0,0 +1,352 @@
/**
* @module ol/layer/Group
*/
import BaseLayer from './Base.js';
import Collection from '../Collection.js';
import CollectionEventType from '../CollectionEventType.js';
import Event from '../events/Event.js';
import EventType from '../events/EventType.js';
import ObjectEventType from '../ObjectEventType.js';
import {assert} from '../asserts.js';
import {assign, clear} from '../obj.js';
import {getIntersection} from '../extent.js';
import {getUid} from '../util.js';
import {listen, unlistenByKey} from '../events.js';
/**
* @typedef {'addlayer'|'removelayer'} EventType
*/
/**
* @classdesc
* A layer group triggers 'addlayer' and 'removelayer' events when layers are added to or removed from
* the group or one of its child groups. When a layer group is added to or removed from another layer group,
* a single event will be triggered (instead of one per layer in the group added or removed).
*/
export class GroupEvent extends Event {
/**
* @param {EventType} type The event type.
* @param {BaseLayer} layer The layer.
*/
constructor(type, layer) {
super(type);
/**
* The added or removed layer.
* @type {BaseLayer}
* @api
*/
this.layer = layer;
}
}
/***
* @template Return
* @typedef {import("../Observable").OnSignature<import("../Observable").EventTypes, import("../events/Event.js").default, Return> &
* import("../Observable").OnSignature<import("./Base").BaseLayerObjectEventTypes|
* 'change:layers', import("../Object").ObjectEvent, Return> &
* import("../Observable").CombinedOnSignature<import("../Observable").EventTypes|import("./Base").BaseLayerObjectEventTypes|'change:layers', Return>} GroupOnSignature
*/
/**
* @typedef {Object} Options
* @property {number} [opacity=1] Opacity (0, 1).
* @property {boolean} [visible=true] Visibility.
* @property {import("../extent.js").Extent} [extent] The bounding extent for layer rendering. The layer will not be
* rendered outside of this extent.
* @property {number} [zIndex] The z-index for layer rendering. At rendering time, the layers
* will be ordered, first by Z-index and then by position. When `undefined`, a `zIndex` of 0 is assumed
* for layers that are added to the map's `layers` collection, or `Infinity` when the layer's `setMap()`
* method was used.
* @property {number} [minResolution] The minimum resolution (inclusive) at which this layer will be
* visible.
* @property {number} [maxResolution] The maximum resolution (exclusive) below which this layer will
* be visible.
* @property {number} [minZoom] The minimum view zoom level (exclusive) above which this layer will be
* visible.
* @property {number} [maxZoom] The maximum view zoom level (inclusive) at which this layer will
* be visible.
* @property {Array<import("./Base.js").default>|import("../Collection.js").default<import("./Base.js").default>} [layers] Child layers.
* @property {Object<string, *>} [properties] Arbitrary observable properties. Can be accessed with `#get()` and `#set()`.
*/
/**
* @enum {string}
* @private
*/
const Property = {
LAYERS: 'layers',
};
/**
* @classdesc
* A {@link module:ol/Collection~Collection} of layers that are handled together.
*
* A generic `change` event is triggered when the group/Collection changes.
*
* @api
*/
class LayerGroup extends BaseLayer {
/**
* @param {Options} [opt_options] Layer options.
*/
constructor(opt_options) {
const options = opt_options || {};
const baseOptions = /** @type {Options} */ (assign({}, options));
delete baseOptions.layers;
let layers = options.layers;
super(baseOptions);
/***
* @type {GroupOnSignature<import("../events").EventsKey>}
*/
this.on;
/***
* @type {GroupOnSignature<import("../events").EventsKey>}
*/
this.once;
/***
* @type {GroupOnSignature<void>}
*/
this.un;
/**
* @private
* @type {Array<import("../events.js").EventsKey>}
*/
this.layersListenerKeys_ = [];
/**
* @private
* @type {Object<string, Array<import("../events.js").EventsKey>>}
*/
this.listenerKeys_ = {};
this.addChangeListener(Property.LAYERS, this.handleLayersChanged_);
if (layers) {
if (Array.isArray(layers)) {
layers = new Collection(layers.slice(), {unique: true});
} else {
assert(typeof (/** @type {?} */ (layers).getArray) === 'function', 43); // Expected `layers` to be an array or a `Collection`
}
} else {
layers = new Collection(undefined, {unique: true});
}
this.setLayers(layers);
}
/**
* @private
*/
handleLayerChange_() {
this.changed();
}
/**
* @private
*/
handleLayersChanged_() {
this.layersListenerKeys_.forEach(unlistenByKey);
this.layersListenerKeys_.length = 0;
const layers = this.getLayers();
this.layersListenerKeys_.push(
listen(layers, CollectionEventType.ADD, this.handleLayersAdd_, this),
listen(layers, CollectionEventType.REMOVE, this.handleLayersRemove_, this)
);
for (const id in this.listenerKeys_) {
this.listenerKeys_[id].forEach(unlistenByKey);
}
clear(this.listenerKeys_);
const layersArray = layers.getArray();
for (let i = 0, ii = layersArray.length; i < ii; i++) {
const layer = layersArray[i];
this.registerLayerListeners_(layer);
this.dispatchEvent(new GroupEvent('addlayer', layer));
}
this.changed();
}
/**
* @param {BaseLayer} layer The layer.
*/
registerLayerListeners_(layer) {
const listenerKeys = [
listen(
layer,
ObjectEventType.PROPERTYCHANGE,
this.handleLayerChange_,
this
),
listen(layer, EventType.CHANGE, this.handleLayerChange_, this),
];
if (layer instanceof LayerGroup) {
listenerKeys.push(
listen(layer, 'addlayer', this.handleLayerGroupAdd_, this),
listen(layer, 'removelayer', this.handleLayerGroupRemove_, this)
);
}
this.listenerKeys_[getUid(layer)] = listenerKeys;
}
/**
* @param {GroupEvent} event The layer group event.
*/
handleLayerGroupAdd_(event) {
this.dispatchEvent(new GroupEvent('addlayer', event.layer));
}
/**
* @param {GroupEvent} event The layer group event.
*/
handleLayerGroupRemove_(event) {
this.dispatchEvent(new GroupEvent('removelayer', event.layer));
}
/**
* @param {import("../Collection.js").CollectionEvent} collectionEvent CollectionEvent.
* @private
*/
handleLayersAdd_(collectionEvent) {
const layer = /** @type {import("./Base.js").default} */ (
collectionEvent.element
);
this.registerLayerListeners_(layer);
this.dispatchEvent(new GroupEvent('addlayer', layer));
this.changed();
}
/**
* @param {import("../Collection.js").CollectionEvent} collectionEvent CollectionEvent.
* @private
*/
handleLayersRemove_(collectionEvent) {
const layer = /** @type {import("./Base.js").default} */ (
collectionEvent.element
);
const key = getUid(layer);
this.listenerKeys_[key].forEach(unlistenByKey);
delete this.listenerKeys_[key];
this.dispatchEvent(new GroupEvent('removelayer', layer));
this.changed();
}
/**
* Returns the {@link module:ol/Collection~Collection collection} of {@link module:ol/layer/Layer~Layer layers}
* in this group.
* @return {!import("../Collection.js").default<import("./Base.js").default>} Collection of
* {@link module:ol/layer/Base~BaseLayer layers} that are part of this group.
* @observable
* @api
*/
getLayers() {
return /** @type {!import("../Collection.js").default<import("./Base.js").default>} */ (
this.get(Property.LAYERS)
);
}
/**
* Set the {@link module:ol/Collection~Collection collection} of {@link module:ol/layer/Layer~Layer layers}
* in this group.
* @param {!import("../Collection.js").default<import("./Base.js").default>} layers Collection of
* {@link module:ol/layer/Base~BaseLayer layers} that are part of this group.
* @observable
* @api
*/
setLayers(layers) {
const collection = this.getLayers();
if (collection) {
const currentLayers = collection.getArray();
for (let i = 0, ii = currentLayers.length; i < ii; ++i) {
this.dispatchEvent(new GroupEvent('removelayer', currentLayers[i]));
}
}
this.set(Property.LAYERS, layers);
}
/**
* @param {Array<import("./Layer.js").default>} [opt_array] Array of layers (to be modified in place).
* @return {Array<import("./Layer.js").default>} Array of layers.
*/
getLayersArray(opt_array) {
const array = opt_array !== undefined ? opt_array : [];
this.getLayers().forEach(function (layer) {
layer.getLayersArray(array);
});
return array;
}
/**
* Get the layer states list and use this groups z-index as the default
* for all layers in this and nested groups, if it is unset at this point.
* If opt_states is not provided and this group's z-index is undefined
* 0 is used a the default z-index.
* @param {Array<import("./Layer.js").State>} [opt_states] Optional list
* of layer states (to be modified in place).
* @return {Array<import("./Layer.js").State>} List of layer states.
*/
getLayerStatesArray(opt_states) {
const states = opt_states !== undefined ? opt_states : [];
const pos = states.length;
this.getLayers().forEach(function (layer) {
layer.getLayerStatesArray(states);
});
const ownLayerState = this.getLayerState();
let defaultZIndex = ownLayerState.zIndex;
if (!opt_states && ownLayerState.zIndex === undefined) {
defaultZIndex = 0;
}
for (let i = pos, ii = states.length; i < ii; i++) {
const layerState = states[i];
layerState.opacity *= ownLayerState.opacity;
layerState.visible = layerState.visible && ownLayerState.visible;
layerState.maxResolution = Math.min(
layerState.maxResolution,
ownLayerState.maxResolution
);
layerState.minResolution = Math.max(
layerState.minResolution,
ownLayerState.minResolution
);
layerState.minZoom = Math.max(layerState.minZoom, ownLayerState.minZoom);
layerState.maxZoom = Math.min(layerState.maxZoom, ownLayerState.maxZoom);
if (ownLayerState.extent !== undefined) {
if (layerState.extent !== undefined) {
layerState.extent = getIntersection(
layerState.extent,
ownLayerState.extent
);
} else {
layerState.extent = ownLayerState.extent;
}
}
if (layerState.zIndex === undefined) {
layerState.zIndex = defaultZIndex;
}
}
return states;
}
/**
* @return {import("../source/Source.js").State} Source state.
*/
getSourceState() {
return 'ready';
}
}
export default LayerGroup;

335
node_modules/ol/src/layer/Heatmap.js generated vendored Normal file
View File

@@ -0,0 +1,335 @@
/**
* @module ol/layer/Heatmap
*/
import BaseVector from './BaseVector.js';
import WebGLPointsLayerRenderer from '../renderer/webgl/PointsLayer.js';
import {assign} from '../obj.js';
import {clamp} from '../math.js';
import {createCanvasContext2D} from '../dom.js';
/**
* @typedef {Object} Options
* @property {string} [className='ol-layer'] A CSS class name to set to the layer element.
* @property {number} [opacity=1] Opacity (0, 1).
* @property {boolean} [visible=true] Visibility.
* @property {import("../extent.js").Extent} [extent] The bounding extent for layer rendering. The layer will not be
* rendered outside of this extent.
* @property {number} [zIndex] The z-index for layer rendering. At rendering time, the layers
* will be ordered, first by Z-index and then by position. When `undefined`, a `zIndex` of 0 is assumed
* for layers that are added to the map's `layers` collection, or `Infinity` when the layer's `setMap()`
* method was used.
* @property {number} [minResolution] The minimum resolution (inclusive) at which this layer will be
* visible.
* @property {number} [maxResolution] The maximum resolution (exclusive) below which this layer will
* be visible.
* @property {number} [minZoom] The minimum view zoom level (exclusive) above which this layer will be
* visible.
* @property {number} [maxZoom] The maximum view zoom level (inclusive) at which this layer will
* be visible.
* @property {Array<string>} [gradient=['#00f', '#0ff', '#0f0', '#ff0', '#f00']] The color gradient
* of the heatmap, specified as an array of CSS color strings.
* @property {number} [radius=8] Radius size in pixels.
* @property {number} [blur=15] Blur size in pixels.
* @property {string|function(import("../Feature.js").default):number} [weight='weight'] The feature
* attribute to use for the weight or a function that returns a weight from a feature. Weight values
* should range from 0 to 1 (and values outside will be clamped to that range).
* @property {import("../source/Vector.js").default<import("../geom/Point.js").default>} [source] Point source.
* @property {Object<string, *>} [properties] Arbitrary observable properties. Can be accessed with `#get()` and `#set()`.
*/
/**
* @enum {string}
* @private
*/
const Property = {
BLUR: 'blur',
GRADIENT: 'gradient',
RADIUS: 'radius',
};
/**
* @const
* @type {Array<string>}
*/
const DEFAULT_GRADIENT = ['#00f', '#0ff', '#0f0', '#ff0', '#f00'];
/**
* @classdesc
* Layer for rendering vector data as a heatmap.
* Note that any property set in the options is set as a {@link module:ol/Object~BaseObject}
* property on the layer object; for example, setting `title: 'My Title'` in the
* options means that `title` is observable, and has get/set accessors.
*
* @fires import("../render/Event.js").RenderEvent
* @extends {BaseVector<import("../source/Vector.js").default, WebGLPointsLayerRenderer>}
* @api
*/
class Heatmap extends BaseVector {
/**
* @param {Options} [opt_options] Options.
*/
constructor(opt_options) {
const options = opt_options ? opt_options : {};
const baseOptions = assign({}, options);
delete baseOptions.gradient;
delete baseOptions.radius;
delete baseOptions.blur;
delete baseOptions.weight;
super(baseOptions);
/**
* @private
* @type {HTMLCanvasElement}
*/
this.gradient_ = null;
this.addChangeListener(Property.GRADIENT, this.handleGradientChanged_);
this.setGradient(options.gradient ? options.gradient : DEFAULT_GRADIENT);
this.setBlur(options.blur !== undefined ? options.blur : 15);
this.setRadius(options.radius !== undefined ? options.radius : 8);
const weight = options.weight ? options.weight : 'weight';
if (typeof weight === 'string') {
this.weightFunction_ = function (feature) {
return feature.get(weight);
};
} else {
this.weightFunction_ = weight;
}
// For performance reasons, don't sort the features before rendering.
// The render order is not relevant for a heatmap representation.
this.setRenderOrder(null);
}
/**
* Return the blur size in pixels.
* @return {number} Blur size in pixels.
* @api
* @observable
*/
getBlur() {
return /** @type {number} */ (this.get(Property.BLUR));
}
/**
* Return the gradient colors as array of strings.
* @return {Array<string>} Colors.
* @api
* @observable
*/
getGradient() {
return /** @type {Array<string>} */ (this.get(Property.GRADIENT));
}
/**
* Return the size of the radius in pixels.
* @return {number} Radius size in pixel.
* @api
* @observable
*/
getRadius() {
return /** @type {number} */ (this.get(Property.RADIUS));
}
/**
* @private
*/
handleGradientChanged_() {
this.gradient_ = createGradient(this.getGradient());
}
/**
* Set the blur size in pixels.
* @param {number} blur Blur size in pixels.
* @api
* @observable
*/
setBlur(blur) {
this.set(Property.BLUR, blur);
}
/**
* Set the gradient colors as array of strings.
* @param {Array<string>} colors Gradient.
* @api
* @observable
*/
setGradient(colors) {
this.set(Property.GRADIENT, colors);
}
/**
* Set the size of the radius in pixels.
* @param {number} radius Radius size in pixel.
* @api
* @observable
*/
setRadius(radius) {
this.set(Property.RADIUS, radius);
}
createRenderer() {
return new WebGLPointsLayerRenderer(this, {
className: this.getClassName(),
attributes: [
{
name: 'weight',
callback: function (feature) {
const weight = this.weightFunction_(feature);
return weight !== undefined ? clamp(weight, 0, 1) : 1;
}.bind(this),
},
],
vertexShader: `
precision mediump float;
uniform mat4 u_projectionMatrix;
uniform mat4 u_offsetScaleMatrix;
uniform float u_size;
attribute vec2 a_position;
attribute float a_index;
attribute float a_weight;
varying vec2 v_texCoord;
varying float v_weight;
void main(void) {
mat4 offsetMatrix = u_offsetScaleMatrix;
float offsetX = a_index == 0.0 || a_index == 3.0 ? -u_size / 2.0 : u_size / 2.0;
float offsetY = a_index == 0.0 || a_index == 1.0 ? -u_size / 2.0 : u_size / 2.0;
vec4 offsets = offsetMatrix * vec4(offsetX, offsetY, 0.0, 0.0);
gl_Position = u_projectionMatrix * vec4(a_position, 0.0, 1.0) + offsets;
float u = a_index == 0.0 || a_index == 3.0 ? 0.0 : 1.0;
float v = a_index == 0.0 || a_index == 1.0 ? 0.0 : 1.0;
v_texCoord = vec2(u, v);
v_weight = a_weight;
}`,
fragmentShader: `
precision mediump float;
uniform float u_blurSlope;
varying vec2 v_texCoord;
varying float v_weight;
void main(void) {
vec2 texCoord = v_texCoord * 2.0 - vec2(1.0, 1.0);
float sqRadius = texCoord.x * texCoord.x + texCoord.y * texCoord.y;
float value = (1.0 - sqrt(sqRadius)) * u_blurSlope;
float alpha = smoothstep(0.0, 1.0, value) * v_weight;
gl_FragColor = vec4(alpha, alpha, alpha, alpha);
}`,
hitVertexShader: `
precision mediump float;
uniform mat4 u_projectionMatrix;
uniform mat4 u_offsetScaleMatrix;
uniform float u_size;
attribute vec2 a_position;
attribute float a_index;
attribute float a_weight;
attribute vec4 a_hitColor;
varying vec2 v_texCoord;
varying float v_weight;
varying vec4 v_hitColor;
void main(void) {
mat4 offsetMatrix = u_offsetScaleMatrix;
float offsetX = a_index == 0.0 || a_index == 3.0 ? -u_size / 2.0 : u_size / 2.0;
float offsetY = a_index == 0.0 || a_index == 1.0 ? -u_size / 2.0 : u_size / 2.0;
vec4 offsets = offsetMatrix * vec4(offsetX, offsetY, 0.0, 0.0);
gl_Position = u_projectionMatrix * vec4(a_position, 0.0, 1.0) + offsets;
float u = a_index == 0.0 || a_index == 3.0 ? 0.0 : 1.0;
float v = a_index == 0.0 || a_index == 1.0 ? 0.0 : 1.0;
v_texCoord = vec2(u, v);
v_hitColor = a_hitColor;
v_weight = a_weight;
}`,
hitFragmentShader: `
precision mediump float;
uniform float u_blurSlope;
varying vec2 v_texCoord;
varying float v_weight;
varying vec4 v_hitColor;
void main(void) {
vec2 texCoord = v_texCoord * 2.0 - vec2(1.0, 1.0);
float sqRadius = texCoord.x * texCoord.x + texCoord.y * texCoord.y;
float value = (1.0 - sqrt(sqRadius)) * u_blurSlope;
float alpha = smoothstep(0.0, 1.0, value) * v_weight;
if (alpha < 0.05) {
discard;
}
gl_FragColor = v_hitColor;
}`,
uniforms: {
u_size: function () {
return (this.get(Property.RADIUS) + this.get(Property.BLUR)) * 2;
}.bind(this),
u_blurSlope: function () {
return (
this.get(Property.RADIUS) / Math.max(1, this.get(Property.BLUR))
);
}.bind(this),
},
postProcesses: [
{
fragmentShader: `
precision mediump float;
uniform sampler2D u_image;
uniform sampler2D u_gradientTexture;
uniform float u_opacity;
varying vec2 v_texCoord;
void main() {
vec4 color = texture2D(u_image, v_texCoord);
gl_FragColor.a = color.a * u_opacity;
gl_FragColor.rgb = texture2D(u_gradientTexture, vec2(0.5, color.a)).rgb;
gl_FragColor.rgb *= gl_FragColor.a;
}`,
uniforms: {
u_gradientTexture: function () {
return this.gradient_;
}.bind(this),
u_opacity: function () {
return this.getOpacity();
}.bind(this),
},
},
],
});
}
renderDeclutter() {}
}
/**
* @param {Array<string>} colors A list of colored.
* @return {HTMLCanvasElement} canvas with gradient texture.
*/
function createGradient(colors) {
const width = 1;
const height = 256;
const context = createCanvasContext2D(width, height);
const gradient = context.createLinearGradient(0, 0, width, height);
const step = 1 / (colors.length - 1);
for (let i = 0, ii = colors.length; i < ii; ++i) {
gradient.addColorStop(i * step, colors[i]);
}
context.fillStyle = gradient;
context.fillRect(0, 0, width, height);
return context.canvas;
}
export default Heatmap;

51
node_modules/ol/src/layer/Image.js generated vendored Normal file
View File

@@ -0,0 +1,51 @@
/**
* @module ol/layer/Image
*/
import BaseImageLayer from './BaseImage.js';
import CanvasImageLayerRenderer from '../renderer/canvas/ImageLayer.js';
/**
* @classdesc
* Server-rendered images that are available for arbitrary extents and
* resolutions.
* Note that any property set in the options is set as a {@link module:ol/Object~BaseObject}
* property on the layer object; for example, setting `title: 'My Title'` in the
* options means that `title` is observable, and has get/set accessors.
*
* @template {import("../source/Image.js").default} ImageSourceType
* @extends {BaseImageLayer<ImageSourceType, CanvasImageLayerRenderer>}
* @api
*/
class ImageLayer extends BaseImageLayer {
/**
* @param {import("./BaseImage.js").Options<ImageSourceType>} [opt_options] Layer options.
*/
constructor(opt_options) {
super(opt_options);
}
createRenderer() {
return new CanvasImageLayerRenderer(this);
}
/**
* Get data for a pixel location. A four element RGBA array will be returned. For requests outside the
* layer extent, `null` will be returned. Data for an image can only be retrieved if the
* source's `crossOrigin` property is set.
*
* ```js
* // display layer data on every pointer move
* map.on('pointermove', (event) => {
* console.log(layer.getData(event.pixel));
* });
* ```
* @param {import("../pixel").Pixel} pixel Pixel.
* @return {Uint8ClampedArray|Uint8Array|Float32Array|DataView|null} Pixel data.
* @api
*/
getData(pixel) {
return super.getData(pixel);
}
}
export default ImageLayer;

433
node_modules/ol/src/layer/Layer.js generated vendored Normal file
View File

@@ -0,0 +1,433 @@
/**
* @module ol/layer/Layer
*/
import BaseLayer from './Base.js';
import EventType from '../events/EventType.js';
import LayerProperty from './Property.js';
import RenderEventType from '../render/EventType.js';
import {assert} from '../asserts.js';
import {assign} from '../obj.js';
import {listen, unlistenByKey} from '../events.js';
/**
* @typedef {function(import("../PluggableMap.js").FrameState):HTMLElement} RenderFunction
*/
/***
* @template Return
* @typedef {import("../Observable").OnSignature<import("../Observable").EventTypes, import("../events/Event.js").default, Return> &
* import("../Observable").OnSignature<import("./Base").BaseLayerObjectEventTypes|
* 'change:source', import("../Object").ObjectEvent, Return> &
* import("../Observable").OnSignature<import("../render/EventType").LayerRenderEventTypes, import("../render/Event").default, Return> &
* import("../Observable").CombinedOnSignature<import("../Observable").EventTypes|import("./Base").BaseLayerObjectEventTypes|'change:source'|
* import("../render/EventType").LayerRenderEventTypes, Return>} LayerOnSignature
*/
/**
* @template {import("../source/Source.js").default} [SourceType=import("../source/Source.js").default]
* @typedef {Object} Options
* @property {string} [className='ol-layer'] A CSS class name to set to the layer element.
* @property {number} [opacity=1] Opacity (0, 1).
* @property {boolean} [visible=true] Visibility.
* @property {import("../extent.js").Extent} [extent] The bounding extent for layer rendering. The layer will not be
* rendered outside of this extent.
* @property {number} [zIndex] The z-index for layer rendering. At rendering time, the layers
* will be ordered, first by Z-index and then by position. When `undefined`, a `zIndex` of 0 is assumed
* for layers that are added to the map's `layers` collection, or `Infinity` when the layer's `setMap()`
* method was used.
* @property {number} [minResolution] The minimum resolution (inclusive) at which this layer will be
* visible.
* @property {number} [maxResolution] The maximum resolution (exclusive) below which this layer will
* be visible.
* @property {number} [minZoom] The minimum view zoom level (exclusive) above which this layer will be
* visible.
* @property {number} [maxZoom] The maximum view zoom level (inclusive) at which this layer will
* be visible.
* @property {SourceType} [source] Source for this layer. If not provided to the constructor,
* the source can be set by calling {@link module:ol/layer/Layer~Layer#setSource layer.setSource(source)} after
* construction.
* @property {import("../PluggableMap.js").default|null} [map] Map.
* @property {RenderFunction} [render] Render function. Takes the frame state as input and is expected to return an
* HTML element. Will overwrite the default rendering for the layer.
* @property {Object<string, *>} [properties] Arbitrary observable properties. Can be accessed with `#get()` and `#set()`.
*/
/**
* @typedef {Object} State
* @property {import("./Layer.js").default} layer Layer.
* @property {number} opacity Opacity, the value is rounded to two digits to appear after the decimal point.
* @property {boolean} visible Visible.
* @property {boolean} managed Managed.
* @property {import("../extent.js").Extent} [extent] Extent.
* @property {number} zIndex ZIndex.
* @property {number} maxResolution Maximum resolution.
* @property {number} minResolution Minimum resolution.
* @property {number} minZoom Minimum zoom.
* @property {number} maxZoom Maximum zoom.
*/
/**
* @classdesc
* Base class from which all layer types are derived. This should only be instantiated
* in the case where a custom layer is added to the map with a custom `render` function.
* Such a function can be specified in the `options` object, and is expected to return an HTML element.
*
* A visual representation of raster or vector map data.
* Layers group together those properties that pertain to how the data is to be
* displayed, irrespective of the source of that data.
*
* Layers are usually added to a map with {@link import("../PluggableMap.js").default#addLayer map.addLayer()}. Components
* like {@link module:ol/interaction/Draw~Draw} use unmanaged layers
* internally. These unmanaged layers are associated with the map using
* {@link module:ol/layer/Layer~Layer#setMap} instead.
*
* A generic `change` event is fired when the state of the source changes.
*
* Please note that for performance reasons several layers might get rendered to
* the same HTML element, which will cause {@link import("../PluggableMap.js").default#forEachLayerAtPixel map.forEachLayerAtPixel()} to
* give false positives. To avoid this, apply different `className` properties to the
* layers at creation time.
*
* @fires import("../render/Event.js").RenderEvent#prerender
* @fires import("../render/Event.js").RenderEvent#postrender
*
* @template {import("../source/Source.js").default} [SourceType=import("../source/Source.js").default]
* @template {import("../renderer/Layer.js").default} [RendererType=import("../renderer/Layer.js").default]
* @api
*/
class Layer extends BaseLayer {
/**
* @param {Options<SourceType>} options Layer options.
*/
constructor(options) {
const baseOptions = assign({}, options);
delete baseOptions.source;
super(baseOptions);
/***
* @type {LayerOnSignature<import("../events").EventsKey>}
*/
this.on;
/***
* @type {LayerOnSignature<import("../events").EventsKey>}
*/
this.once;
/***
* @type {LayerOnSignature<void>}
*/
this.un;
/**
* @private
* @type {?import("../events.js").EventsKey}
*/
this.mapPrecomposeKey_ = null;
/**
* @private
* @type {?import("../events.js").EventsKey}
*/
this.mapRenderKey_ = null;
/**
* @private
* @type {?import("../events.js").EventsKey}
*/
this.sourceChangeKey_ = null;
/**
* @private
* @type {RendererType}
*/
this.renderer_ = null;
/**
* @protected
* @type {boolean}
*/
this.rendered = false;
// Overwrite default render method with a custom one
if (options.render) {
this.render = options.render;
}
if (options.map) {
this.setMap(options.map);
}
this.addChangeListener(
LayerProperty.SOURCE,
this.handleSourcePropertyChange_
);
const source = options.source
? /** @type {SourceType} */ (options.source)
: null;
this.setSource(source);
}
/**
* @param {Array<import("./Layer.js").default>} [opt_array] Array of layers (to be modified in place).
* @return {Array<import("./Layer.js").default>} Array of layers.
*/
getLayersArray(opt_array) {
const array = opt_array ? opt_array : [];
array.push(this);
return array;
}
/**
* @param {Array<import("./Layer.js").State>} [opt_states] Optional list of layer states (to be modified in place).
* @return {Array<import("./Layer.js").State>} List of layer states.
*/
getLayerStatesArray(opt_states) {
const states = opt_states ? opt_states : [];
states.push(this.getLayerState());
return states;
}
/**
* Get the layer source.
* @return {SourceType|null} The layer source (or `null` if not yet set).
* @observable
* @api
*/
getSource() {
return /** @type {SourceType} */ (this.get(LayerProperty.SOURCE)) || null;
}
/**
* @return {SourceType|null} The source being rendered.
*/
getRenderSource() {
return this.getSource();
}
/**
* @return {import("../source/Source.js").State} Source state.
*/
getSourceState() {
const source = this.getSource();
return !source ? 'undefined' : source.getState();
}
/**
* @private
*/
handleSourceChange_() {
this.changed();
}
/**
* @private
*/
handleSourcePropertyChange_() {
if (this.sourceChangeKey_) {
unlistenByKey(this.sourceChangeKey_);
this.sourceChangeKey_ = null;
}
const source = this.getSource();
if (source) {
this.sourceChangeKey_ = listen(
source,
EventType.CHANGE,
this.handleSourceChange_,
this
);
}
this.changed();
}
/**
* @param {import("../pixel").Pixel} pixel Pixel.
* @return {Promise<Array<import("../Feature").default>>} Promise that resolves with
* an array of features.
*/
getFeatures(pixel) {
if (!this.renderer_) {
return new Promise((resolve) => resolve([]));
}
return this.renderer_.getFeatures(pixel);
}
/**
* @param {import("../pixel").Pixel} pixel Pixel.
* @return {Uint8ClampedArray|Uint8Array|Float32Array|DataView|null} Pixel data.
*/
getData(pixel) {
if (!this.renderer_ || !this.rendered) {
return null;
}
return this.renderer_.getData(pixel);
}
/**
* In charge to manage the rendering of the layer. One layer type is
* bounded with one layer renderer.
* @param {?import("../PluggableMap.js").FrameState} frameState Frame state.
* @param {HTMLElement} target Target which the renderer may (but need not) use
* for rendering its content.
* @return {HTMLElement} The rendered element.
*/
render(frameState, target) {
const layerRenderer = this.getRenderer();
if (layerRenderer.prepareFrame(frameState)) {
this.rendered = true;
return layerRenderer.renderFrame(frameState, target);
}
}
/**
* Called when a layer is not visible during a map render.
*/
unrender() {
this.rendered = false;
}
/**
* For use inside the library only.
* @param {import("../PluggableMap.js").default|null} map Map.
*/
setMapInternal(map) {
if (!map) {
this.unrender();
}
this.set(LayerProperty.MAP, map);
}
/**
* For use inside the library only.
* @return {import("../PluggableMap.js").default|null} Map.
*/
getMapInternal() {
return this.get(LayerProperty.MAP);
}
/**
* Sets the layer to be rendered on top of other layers on a map. The map will
* not manage this layer in its layers collection, and the callback in
* {@link module:ol/Map~Map#forEachLayerAtPixel} will receive `null` as layer. This
* is useful for temporary layers. To remove an unmanaged layer from the map,
* use `#setMap(null)`.
*
* To add the layer to a map and have it managed by the map, use
* {@link module:ol/Map~Map#addLayer} instead.
* @param {import("../PluggableMap.js").default|null} map Map.
* @api
*/
setMap(map) {
if (this.mapPrecomposeKey_) {
unlistenByKey(this.mapPrecomposeKey_);
this.mapPrecomposeKey_ = null;
}
if (!map) {
this.changed();
}
if (this.mapRenderKey_) {
unlistenByKey(this.mapRenderKey_);
this.mapRenderKey_ = null;
}
if (map) {
this.mapPrecomposeKey_ = listen(
map,
RenderEventType.PRECOMPOSE,
function (evt) {
const renderEvent =
/** @type {import("../render/Event.js").default} */ (evt);
const layerStatesArray = renderEvent.frameState.layerStatesArray;
const layerState = this.getLayerState(false);
// A layer can only be added to the map once. Use either `layer.setMap()` or `map.addLayer()`, not both.
assert(
!layerStatesArray.some(function (arrayLayerState) {
return arrayLayerState.layer === layerState.layer;
}),
67
);
layerStatesArray.push(layerState);
},
this
);
this.mapRenderKey_ = listen(this, EventType.CHANGE, map.render, map);
this.changed();
}
}
/**
* Set the layer source.
* @param {SourceType|null} source The layer source.
* @observable
* @api
*/
setSource(source) {
this.set(LayerProperty.SOURCE, source);
}
/**
* Get the renderer for this layer.
* @return {RendererType|null} The layer renderer.
*/
getRenderer() {
if (!this.renderer_) {
this.renderer_ = this.createRenderer();
}
return this.renderer_;
}
/**
* @return {boolean} The layer has a renderer.
*/
hasRenderer() {
return !!this.renderer_;
}
/**
* Create a renderer for this layer.
* @return {RendererType} A layer renderer.
* @protected
*/
createRenderer() {
return null;
}
/**
* Clean up.
*/
disposeInternal() {
if (this.renderer_) {
this.renderer_.dispose();
delete this.renderer_;
}
this.setSource(null);
super.disposeInternal();
}
}
/**
* Return `true` if the layer is visible and if the provided view state
* has resolution and zoom levels that are in range of the layer's min/max.
* @param {State} layerState Layer state.
* @param {import("../View.js").State} viewState View state.
* @return {boolean} The layer is visible at the given view state.
*/
export function inView(layerState, viewState) {
if (!layerState.visible) {
return false;
}
const resolution = viewState.resolution;
if (
resolution < layerState.minResolution ||
resolution >= layerState.maxResolution
) {
return false;
}
const zoom = viewState.zoom;
return zoom > layerState.minZoom && zoom <= layerState.maxZoom;
}
export default Layer;

196
node_modules/ol/src/layer/MapboxVector.js generated vendored Normal file
View File

@@ -0,0 +1,196 @@
/**
* @module ol/layer/MapboxVector
*/
import BaseEvent from '../events/Event.js';
import EventType from '../events/EventType.js';
import MVT from '../format/MVT.js';
import VectorTileLayer from '../layer/VectorTile.js';
import VectorTileSource from '../source/VectorTile.js';
import {applyBackground, applyStyle} from 'ol-mapbox-style';
/**
* @classdesc
* Event emitted on configuration or loading error.
*/
class ErrorEvent extends BaseEvent {
/**
* @param {Error} error error object.
*/
constructor(error) {
super(EventType.ERROR);
/**
* @type {Error}
*/
this.error = error;
}
}
/**
* @typedef {Object} Options
* @property {string} styleUrl The URL of the Mapbox style object to use for this layer. For a
* style created with Mapbox Studio and hosted on Mapbox, this will look like
* 'mapbox://styles/you/your-style'.
* @property {string} [accessToken] The access token for your Mapbox style. This has to be provided
* for `mapbox://` style urls. For `https://` and other urls, any access key must be the last query
* parameter of the style url.
* @property {string} [source] If your style uses more than one source, you need to use either the
* `source` property or the `layers` property to limit rendering to a single vector source. The
* `source` property corresponds to the id of a vector source in your Mapbox style.
* @property {Array<string>} [layers] Limit rendering to the list of included layers. All layers
* must share the same vector source. If your style uses more than one source, you need to use
* either the `source` property or the `layers` property to limit rendering to a single vector
* source.
* @property {boolean} [declutter=true] Declutter images and text. Decluttering is applied to all
* image and text styles of all Vector and VectorTile layers that have set this to `true`. The priority
* is defined by the z-index of the layer, the `zIndex` of the style and the render order of features.
* Higher z-index means higher priority. Within the same z-index, a feature rendered before another has
* higher priority.
*
* As an optimization decluttered features from layers with the same `className` are rendered above
* the fill and stroke styles of all of those layers regardless of z-index. To opt out of this
* behavior and place declutterd features with their own layer configure the layer with a `className`
* other than `ol-layer`.
* @property {import("./Base.js").BackgroundColor|false} [background] Background color for the layer.
* If not specified, the background from the Mapbox style object will be used. Set to `false` to prevent
* the Mapbox style's background from being used.
* @property {string} [className='ol-layer'] A CSS class name to set to the layer element.
* @property {number} [opacity=1] Opacity (0, 1).
* @property {boolean} [visible=true] Visibility.
* @property {import("../extent.js").Extent} [extent] The bounding extent for layer rendering. The layer will not be
* rendered outside of this extent.
* @property {number} [zIndex] The z-index for layer rendering. At rendering time, the layers
* will be ordered, first by Z-index and then by position. When `undefined`, a `zIndex` of 0 is assumed
* for layers that are added to the map's `layers` collection, or `Infinity` when the layer's `setMap()`
* method was used.
* @property {number} [minResolution] The minimum resolution (inclusive) at which this layer will be
* visible.
* @property {number} [maxResolution] The maximum resolution (exclusive) below which this layer will
* be visible. If neither `maxResolution` nor `minZoom` are defined, the layer's `maxResolution` will
* match the style source's `minzoom`.
* @property {number} [minZoom] The minimum view zoom level (exclusive) above which this layer will
* be visible. If neither `maxResolution` nor `minZoom` are defined, the layer's `minZoom` will match
* the style source's `minzoom`.
* @property {number} [maxZoom] The maximum view zoom level (inclusive) at which this layer will
* be visible.
* @property {import("../render.js").OrderFunction} [renderOrder] Render order. Function to be used when sorting
* features before rendering. By default features are drawn in the order that they are created. Use
* `null` to avoid the sort, but get an undefined draw order.
* @property {number} [renderBuffer=100] The buffer in pixels around the tile extent used by the
* renderer when getting features from the vector tile for the rendering or hit-detection.
* Recommended value: Vector tiles are usually generated with a buffer, so this value should match
* the largest possible buffer of the used tiles. It should be at least the size of the largest
* point symbol or line width.
* @property {import("./VectorTileRenderType.js").default|string} [renderMode='hybrid'] Render mode for vector tiles:
* * `'hybrid'`: Polygon and line elements are rendered as images, so pixels are scaled during zoom
* animations. Point symbols and texts are accurately rendered as vectors and can stay upright on
* rotated views.
* * `'vector'`: Everything is rendered as vectors. Use this mode for improved performance on vector
* tile layers with only a few rendered features (e.g. for highlighting a subset of features of
* another layer with the same source).
* @property {import("../PluggableMap.js").default} [map] Sets the layer as overlay on a map. The map will not manage
* this layer in its layers collection, and the layer will be rendered on top. This is useful for
* temporary layers. The standard way to add a layer to a map and have it managed by the map is to
* use {@link import("../PluggableMap.js").default#addLayer map.addLayer()}.
* @property {boolean} [updateWhileAnimating=false] When set to `true`, feature batches will be
* recreated during animations. This means that no vectors will be shown clipped, but the setting
* will have a performance impact for large amounts of vector data. When set to `false`, batches
* will be recreated when no animation is active.
* @property {boolean} [updateWhileInteracting=false] When set to `true`, feature batches will be
* recreated during interactions. See also `updateWhileAnimating`.
* @property {number} [preload=0] Preload. Load low-resolution tiles up to `preload` levels. `0`
* means no preloading.
* @property {boolean} [useInterimTilesOnError=true] Use interim tiles on error.
* @property {Object<string, *>} [properties] Arbitrary observable properties. Can be accessed with `#get()` and `#set()`.
*/
/**
* @classdesc
* A vector tile layer based on a Mapbox style that uses a single vector source. Configure
* the layer with the `styleUrl` and `accessToken` shown in Mapbox Studio's share panel.
* If the style uses more than one source, use the `source` property to choose a single
* vector source. If you want to render a subset of the layers in the style, use the `layers`
* property (all layers must share the same vector source). See the constructor options for
* more detail.
*
* var map = new Map({
* view: new View({
* center: [0, 0],
* zoom: 1
* }),
* layers: [
* new MapboxVectorLayer({
* styleUrl: 'mapbox://styles/mapbox/bright-v9',
* accessToken: 'your-mapbox-access-token-here'
* })
* ],
* target: 'map'
* });
*
* On configuration or loading error, the layer will trigger an `'error'` event. Listeners
* will receive an object with an `error` property that can be used to diagnose the problem.
*
* @param {Options} options Options.
* @extends {VectorTileLayer}
* @fires module:ol/events/Event~BaseEvent#event:error
* @api
*/
class MapboxVectorLayer extends VectorTileLayer {
/**
* @param {Options} options Layer options. At a minimum, `styleUrl` and `accessToken`
* must be provided.
*/
constructor(options) {
const declutter = 'declutter' in options ? options.declutter : true;
const source = new VectorTileSource({
state: 'loading',
format: new MVT(),
});
super({
source: source,
background: options.background,
declutter: declutter,
className: options.className,
opacity: options.opacity,
visible: options.visible,
zIndex: options.zIndex,
minResolution: options.minResolution,
maxResolution: options.maxResolution,
minZoom: options.minZoom,
maxZoom: options.maxZoom,
renderOrder: options.renderOrder,
renderBuffer: options.renderBuffer,
renderMode: options.renderMode,
map: options.map,
updateWhileAnimating: options.updateWhileAnimating,
updateWhileInteracting: options.updateWhileInteracting,
preload: options.preload,
useInterimTilesOnError: options.useInterimTilesOnError,
properties: options.properties,
});
if (options.accessToken) {
this.accessToken = options.accessToken;
}
const url = options.styleUrl;
applyStyle(this, url, options.layers || options.source, {
accessToken: this.accessToken,
})
.then(() => {
source.setState('ready');
})
.catch((error) => {
this.dispatchEvent(new ErrorEvent(error));
const source = this.getSource();
source.setState('error');
});
if (this.getBackground() === undefined) {
applyBackground(this, options.styleUrl, {
accessToken: this.accessToken,
});
}
}
}
export default MapboxVectorLayer;

19
node_modules/ol/src/layer/Property.js generated vendored Normal file
View File

@@ -0,0 +1,19 @@
/**
* @module ol/layer/Property
*/
/**
* @enum {string}
*/
export default {
OPACITY: 'opacity',
VISIBLE: 'visible',
EXTENT: 'extent',
Z_INDEX: 'zIndex',
MAX_RESOLUTION: 'maxResolution',
MIN_RESOLUTION: 'minResolution',
MAX_ZOOM: 'maxZoom',
MIN_ZOOM: 'minZoom',
SOURCE: 'source',
MAP: 'map',
};

32
node_modules/ol/src/layer/Tile.js generated vendored Normal file
View File

@@ -0,0 +1,32 @@
/**
* @module ol/layer/Tile
*/
import BaseTileLayer from './BaseTile.js';
import CanvasTileLayerRenderer from '../renderer/canvas/TileLayer.js';
/**
* @classdesc
* For layer sources that provide pre-rendered, tiled images in grids that are
* organized by zoom levels for specific resolutions.
* Note that any property set in the options is set as a {@link module:ol/Object~BaseObject}
* property on the layer object; for example, setting `title: 'My Title'` in the
* options means that `title` is observable, and has get/set accessors.
*
* @template {import("../source/Tile.js").default} TileSourceType
* @extends BaseTileLayer<TileSourceType, CanvasTileLayerRenderer>
* @api
*/
class TileLayer extends BaseTileLayer {
/**
* @param {import("./BaseTile.js").Options<TileSourceType>} [opt_options] Tile layer options.
*/
constructor(opt_options) {
super(opt_options);
}
createRenderer() {
return new CanvasTileLayerRenderer(this);
}
}
export default TileLayer;

11
node_modules/ol/src/layer/TileProperty.js generated vendored Normal file
View File

@@ -0,0 +1,11 @@
/**
* @module ol/layer/TileProperty
*/
/**
* @enum {string}
*/
export default {
PRELOAD: 'preload',
USE_INTERIM_TILES_ON_ERROR: 'useInterimTilesOnError',
};

35
node_modules/ol/src/layer/Vector.js generated vendored Normal file
View File

@@ -0,0 +1,35 @@
/**
* @module ol/layer/Vector
*/
import BaseVectorLayer from './BaseVector.js';
import CanvasVectorLayerRenderer from '../renderer/canvas/VectorLayer.js';
/**
* @classdesc
* Vector data is rendered client-side, as vectors. This layer type provides most accurate rendering
* even during animations. Points and labels stay upright on rotated views. For very large
* amounts of vector data, performance may suffer during pan and zoom animations. In this case,
* try {@link module:ol/layer/VectorImage~VectorImageLayer}.
*
* Note that any property set in the options is set as a {@link module:ol/Object~BaseObject}
* property on the layer object; for example, setting `title: 'My Title'` in the
* options means that `title` is observable, and has get/set accessors.
*
* @template {import("../source/Vector.js").default} VectorSourceType
* @extends {BaseVectorLayer<VectorSourceType, CanvasVectorLayerRenderer>}
* @api
*/
class VectorLayer extends BaseVectorLayer {
/**
* @param {import("./BaseVector.js").Options<VectorSourceType>} [opt_options] Options.
*/
constructor(opt_options) {
super(opt_options);
}
createRenderer() {
return new CanvasVectorLayerRenderer(this);
}
}
export default VectorLayer;

96
node_modules/ol/src/layer/VectorImage.js generated vendored Normal file
View File

@@ -0,0 +1,96 @@
/**
* @module ol/layer/VectorImage
*/
import BaseVectorLayer from './BaseVector.js';
import CanvasVectorImageLayerRenderer from '../renderer/canvas/VectorImageLayer.js';
import {assign} from '../obj.js';
/**
* @template {import("../source/Vector.js").default} VectorSourceType
* @typedef {Object} Options
* @property {string} [className='ol-layer'] A CSS class name to set to the layer element.
* @property {number} [opacity=1] Opacity (0, 1).
* @property {boolean} [visible=true] Visibility.
* @property {import("../extent.js").Extent} [extent] The bounding extent for layer rendering. The layer will not be
* rendered outside of this extent.
* @property {number} [zIndex] The z-index for layer rendering. At rendering time, the layers
* will be ordered, first by Z-index and then by position. When `undefined`, a `zIndex` of 0 is assumed
* for layers that are added to the map's `layers` collection, or `Infinity` when the layer's `setMap()`
* method was used.
* @property {number} [minResolution] The minimum resolution (inclusive) at which this layer will be
* visible.
* @property {number} [maxResolution] The maximum resolution (exclusive) below which this layer will
* be visible.
* @property {number} [minZoom] The minimum view zoom level (exclusive) above which this layer will be
* visible.
* @property {number} [maxZoom] The maximum view zoom level (inclusive) at which this layer will
* be visible.
* @property {import("../render.js").OrderFunction} [renderOrder] Render order. Function to be used when sorting
* features before rendering. By default features are drawn in the order that they are created. Use
* `null` to avoid the sort, but get an undefined draw order.
* @property {number} [renderBuffer=100] The buffer in pixels around the viewport extent used by the
* renderer when getting features from the vector source for the rendering or hit-detection.
* Recommended value: the size of the largest symbol, line width or label.
* @property {VectorSourceType} [source] Source.
* @property {import("../PluggableMap.js").default} [map] Sets the layer as overlay on a map. The map will not manage
* this layer in its layers collection, and the layer will be rendered on top. This is useful for
* temporary layers. The standard way to add a layer to a map and have it managed by the map is to
* use {@link import("../PluggableMap.js").default#addLayer map.addLayer()}.
* @property {boolean} [declutter=false] Declutter images and text on this layer. The priority is defined
* by the `zIndex` of the style and the render order of features. Higher z-index means higher priority.
* Within the same z-index, a feature rendered before another has higher priority.
* @property {import("../style/Style.js").StyleLike|null} [style] Layer style. When set to `null`, only
* features that have their own style will be rendered. See {@link module:ol/style/Style~Style} for the default style
* which will be used if this is not set.
* @property {number} [imageRatio=1] Ratio by which the rendered extent should be larger than the
* viewport extent. A larger ratio avoids cut images during panning, but will cause a decrease in performance.
* @property {Object<string, *>} [properties] Arbitrary observable properties. Can be accessed with `#get()` and `#set()`.
*/
/**
* @classdesc
* Vector data is rendered client-side, to an image. This layer type provides great performance
* during panning and zooming, but point symbols and texts are always rotated with the view and
* pixels are scaled during zoom animations. For more accurate rendering of vector data, use
* {@link module:ol/layer/Vector~VectorLayer} instead.
*
* Note that any property set in the options is set as a {@link module:ol/Object~BaseObject}
* property on the layer object; for example, setting `title: 'My Title'` in the
* options means that `title` is observable, and has get/set accessors.
*
* @template {import("../source/Vector.js").default} VectorSourceType
* @extends {BaseVectorLayer<VectorSourceType, CanvasVectorImageLayerRenderer>}
* @api
*/
class VectorImageLayer extends BaseVectorLayer {
/**
* @param {Options<VectorSourceType>} [opt_options] Options.
*/
constructor(opt_options) {
const options = opt_options ? opt_options : {};
const baseOptions = assign({}, options);
delete baseOptions.imageRatio;
super(baseOptions);
/**
* @type {number}
* @private
*/
this.imageRatio_ =
options.imageRatio !== undefined ? options.imageRatio : 1;
}
/**
* @return {number} Ratio between rendered extent size and viewport extent size.
*/
getImageRatio() {
return this.imageRatio_;
}
createRenderer() {
return new CanvasVectorImageLayerRenderer(this);
}
}
export default VectorImageLayer;

243
node_modules/ol/src/layer/VectorTile.js generated vendored Normal file
View File

@@ -0,0 +1,243 @@
/**
* @module ol/layer/VectorTile
*/
import BaseVectorLayer from './BaseVector.js';
import CanvasVectorTileLayerRenderer from '../renderer/canvas/VectorTileLayer.js';
import TileProperty from './TileProperty.js';
import VectorTileRenderType from './VectorTileRenderType.js';
import {assert} from '../asserts.js';
import {assign} from '../obj.js';
/***
* @template Return
* @typedef {import("../Observable").OnSignature<import("../Observable").EventTypes, import("../events/Event.js").default, Return> &
* import("../Observable").OnSignature<import("./Base").BaseLayerObjectEventTypes|
* 'change:source'|'change:preload'|'change:useInterimTilesOnError', import("../Object").ObjectEvent, Return> &
* import("../Observable").OnSignature<import("../render/EventType").LayerRenderEventTypes, import("../render/Event").default, Return> &
* import("../Observable").CombinedOnSignature<import("../Observable").EventTypes|import("./Base").BaseLayerObjectEventTypes|
* 'change:source'|'change:preload'|'change:useInterimTilesOnError'|import("../render/EventType").LayerRenderEventTypes, Return>} VectorTileLayerOnSignature
*/
/**
* @typedef {Object} Options
* @property {string} [className='ol-layer'] A CSS class name to set to the layer element.
* @property {number} [opacity=1] Opacity (0, 1).
* @property {boolean} [visible=true] Visibility.
* @property {import("../extent.js").Extent} [extent] The bounding extent for layer rendering. The layer will not be
* rendered outside of this extent.
* @property {number} [zIndex] The z-index for layer rendering. At rendering time, the layers
* will be ordered, first by Z-index and then by position. When `undefined`, a `zIndex` of 0 is assumed
* for layers that are added to the map's `layers` collection, or `Infinity` when the layer's `setMap()`
* method was used.
* @property {number} [minResolution] The minimum resolution (inclusive) at which this layer will be
* visible.
* @property {number} [maxResolution] The maximum resolution (exclusive) below which this layer will
* be visible.
* @property {number} [minZoom] The minimum view zoom level (exclusive) above which this layer will be
* visible.
* @property {number} [maxZoom] The maximum view zoom level (inclusive) at which this layer will
* be visible.
* @property {import("../render.js").OrderFunction} [renderOrder] Render order. Function to be used when sorting
* features before rendering. By default features are drawn in the order that they are created. Use
* `null` to avoid the sort, but get an undefined draw order.
* @property {number} [renderBuffer=100] The buffer in pixels around the tile extent used by the
* renderer when getting features from the vector tile for the rendering or hit-detection.
* Recommended value: Vector tiles are usually generated with a buffer, so this value should match
* the largest possible buffer of the used tiles. It should be at least the size of the largest
* point symbol or line width.
* @property {import("./VectorTileRenderType.js").default|string} [renderMode='hybrid'] Render mode for vector tiles:
* * `'hybrid'`: Polygon and line elements are rendered as images, so pixels are scaled during zoom
* animations. Point symbols and texts are accurately rendered as vectors and can stay upright on
* rotated views.
* * `'vector'`: Everything is rendered as vectors. Use this mode for improved performance on vector
* tile layers with only a few rendered features (e.g. for highlighting a subset of features of
* another layer with the same source).
* @property {import("../source/VectorTile.js").default} [source] Source.
* @property {import("../PluggableMap.js").default} [map] Sets the layer as overlay on a map. The map will not manage
* this layer in its layers collection, and the layer will be rendered on top. This is useful for
* temporary layers. The standard way to add a layer to a map and have it managed by the map is to
* use {@link import("../PluggableMap.js").default#addLayer map.addLayer()}.
* @property {boolean} [declutter=false] Declutter images and text. Decluttering is applied to all
* image and text styles of all Vector and VectorTile layers that have set this to `true`. The priority
* is defined by the z-index of the layer, the `zIndex` of the style and the render order of features.
* Higher z-index means higher priority. Within the same z-index, a feature rendered before another has
* higher priority.
*
* As an optimization decluttered features from layers with the same `className` are rendered above
* the fill and stroke styles of all of those layers regardless of z-index. To opt out of this
* behavior and place declutterd features with their own layer configure the layer with a `className`
* other than `ol-layer`.
* @property {import("../style/Style.js").StyleLike|null} [style] Layer style. When set to `null`, only
* features that have their own style will be rendered. See {@link module:ol/style/Style~Style} for the default style
* which will be used if this is not set.
* @property {import("./Base.js").BackgroundColor|false} [background] Background color for the layer. If not specified, no
* background will be rendered.
* @property {boolean} [updateWhileAnimating=false] When set to `true`, feature batches will be
* recreated during animations. This means that no vectors will be shown clipped, but the setting
* will have a performance impact for large amounts of vector data. When set to `false`, batches
* will be recreated when no animation is active.
* @property {boolean} [updateWhileInteracting=false] When set to `true`, feature batches will be
* recreated during interactions. See also `updateWhileAnimating`.
* @property {number} [preload=0] Preload. Load low-resolution tiles up to `preload` levels. `0`
* means no preloading.
* @property {boolean} [useInterimTilesOnError=true] Use interim tiles on error.
* @property {Object<string, *>} [properties] Arbitrary observable properties. Can be accessed with `#get()` and `#set()`.
*/
/**
* @classdesc
* Layer for vector tile data that is rendered client-side.
* Note that any property set in the options is set as a {@link module:ol/Object~BaseObject BaseObject}
* property on the layer object; for example, setting `title: 'My Title'` in the
* options means that `title` is observable, and has get/set accessors.
*
* @param {Options} [opt_options] Options.
* @extends {BaseVectorLayer<import("../source/VectorTile.js").default, CanvasVectorTileLayerRenderer>}
* @api
*/
class VectorTileLayer extends BaseVectorLayer {
/**
* @param {Options} [opt_options] Options.
*/
constructor(opt_options) {
const options = opt_options ? opt_options : {};
const baseOptions = /** @type {Object} */ (assign({}, options));
delete baseOptions.preload;
delete baseOptions.useInterimTilesOnError;
super(
/** @type {import("./BaseVector.js").Options<import("../source/VectorTile.js").default>} */ (
baseOptions
)
);
/***
* @type {VectorTileLayerOnSignature<import("../events").EventsKey>}
*/
this.on;
/***
* @type {VectorTileLayerOnSignature<import("../events").EventsKey>}
*/
this.once;
/***
* @type {VectorTileLayerOnSignature<void>}
*/
this.un;
if (options.renderMode === VectorTileRenderType.IMAGE) {
//FIXME deprecated - remove this check in v7.
//eslint-disable-next-line
console.warn('renderMode: "image" is deprecated. Option ignored.')
options.renderMode = undefined;
}
const renderMode = options.renderMode || VectorTileRenderType.HYBRID;
assert(
renderMode == VectorTileRenderType.HYBRID ||
renderMode == VectorTileRenderType.VECTOR,
28
); // `renderMode` must be `'hybrid'` or `'vector'`.
/**
* @private
* @type {import("./VectorTileRenderType.js").default}
*/
this.renderMode_ = renderMode;
this.setPreload(options.preload ? options.preload : 0);
this.setUseInterimTilesOnError(
options.useInterimTilesOnError !== undefined
? options.useInterimTilesOnError
: true
);
/**
* @return {import("./Base.js").BackgroundColor} Background color.
* @function
* @api
*/
this.getBackground;
/**
* @param {import("./Base.js").BackgroundColor} background Background color.
* @function
* @api
*/
this.setBackground;
}
createRenderer() {
return new CanvasVectorTileLayerRenderer(this);
}
/**
* 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 {@link import("../PluggableMap.js").default#getFeaturesAtPixel map.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").default>>} Promise that resolves with an array of features.
* @api
*/
getFeatures(pixel) {
return super.getFeatures(pixel);
}
/**
* @return {import("./VectorTileRenderType.js").default} 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.PRELOAD));
}
/**
* Whether we use interim tiles on error.
* @return {boolean} Use interim tiles on error.
* @observable
* @api
*/
getUseInterimTilesOnError() {
return /** @type {boolean} */ (
this.get(TileProperty.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.PRELOAD, preload);
}
/**
* Set whether we use interim tiles on error.
* @param {boolean} useInterimTilesOnError Use interim tiles on error.
* @observable
* @api
*/
setUseInterimTilesOnError(useInterimTilesOnError) {
this.set(TileProperty.USE_INTERIM_TILES_ON_ERROR, useInterimTilesOnError);
}
}
export default VectorTileLayer;

34
node_modules/ol/src/layer/VectorTileRenderType.js generated vendored Normal file
View File

@@ -0,0 +1,34 @@
/**
* @module ol/layer/VectorTileRenderType
*/
/**
* @enum {string}
* Render mode for vector tiles:
* @api
*/
export default {
/**
* Vector tiles are rendered as images. Great performance, but
* point symbols and texts are always rotated with the view and pixels are
* scaled during zoom animations
* @api
* @deprecated
*/
IMAGE: 'image',
/**
* Polygon and line elements are rendered as images, so pixels
* are scaled during zoom animations. Point symbols and texts are accurately
* rendered as vectors and can stay upright on rotated views.
* @api
*/
HYBRID: 'hybrid',
/**
* Everything is rendered as vectors. Use this mode for improved
* performance on vector tile layers with only a few rendered features (e.g.
* for highlighting a subset of features of another layer with the same
* source).
* @api
*/
VECTOR: 'vector',
};

128
node_modules/ol/src/layer/WebGLPoints.js generated vendored Normal file
View File

@@ -0,0 +1,128 @@
/**
* @module ol/layer/WebGLPoints
*/
import Layer from './Layer.js';
import WebGLPointsLayerRenderer from '../renderer/webgl/PointsLayer.js';
import {assign} from '../obj.js';
import {parseLiteralStyle} from '../webgl/ShaderBuilder.js';
/**
* @template {import("../source/Vector.js").default<import("../geom/Point.js").default>} VectorSourceType
* @typedef {Object} Options
* @property {import('../style/literal.js').LiteralStyle} style Literal style to apply to the layer features.
* @property {string} [className='ol-layer'] A CSS class name to set to the layer element.
* @property {number} [opacity=1] Opacity (0, 1).
* @property {boolean} [visible=true] Visibility.
* @property {import("../extent.js").Extent} [extent] The bounding extent for layer rendering. The layer will not be
* rendered outside of this extent.
* @property {number} [zIndex] The z-index for layer rendering. At rendering time, the layers
* will be ordered, first by Z-index and then by position. When `undefined`, a `zIndex` of 0 is assumed
* for layers that are added to the map's `layers` collection, or `Infinity` when the layer's `setMap()`
* method was used.
* @property {number} [minResolution] The minimum resolution (inclusive) at which this layer will be
* visible.
* @property {number} [maxResolution] The maximum resolution (exclusive) below which this layer will
* be visible.
* @property {number} [minZoom] The minimum view zoom level (exclusive) above which this layer will be
* visible.
* @property {number} [maxZoom] The maximum view zoom level (inclusive) at which this layer will
* be visible.
* @property {VectorSourceType} [source] Point source.
* @property {boolean} [disableHitDetection=false] Setting this to true will provide a slight performance boost, but will
* prevent all hit detection on the layer.
* @property {Object<string, *>} [properties] Arbitrary observable properties. Can be accessed with `#get()` and `#set()`.
*/
/**
* @classdesc
* Layer optimized for rendering large point datasets. Takes a `style` property which
* is a serializable JSON object describing how the layer should be rendered.
*
* Here are a few samples of literal style objects:
* ```js
* const style = {
* symbol: {
* symbolType: 'circle',
* size: 8,
* color: '#33AAFF',
* opacity: 0.9
* }
* }
* ```
*
* ```js
* const style = {
* symbol: {
* symbolType: 'image',
* offset: [0, 12],
* size: [4, 8],
* src: '../static/exclamation-mark.png'
* }
* }
* ```
*
* **Important: a `WebGLPoints` layer must be manually disposed when removed, otherwise the underlying WebGL context
* will not be garbage collected.**
*
* Note that any property set in the options is set as a {@link module:ol/Object~BaseObject}
* property on the layer object; for example, setting `title: 'My Title'` in the
* options means that `title` is observable, and has get/set accessors.
*
* @template {import("../source/Vector.js").default<import("../geom/Point.js").default>} VectorSourceType
* @extends {Layer<VectorSourceType, WebGLPointsLayerRenderer>}
* @fires import("../render/Event.js").RenderEvent
*/
class WebGLPointsLayer extends Layer {
/**
* @param {Options<VectorSourceType>} options Options.
*/
constructor(options) {
const baseOptions = assign({}, options);
super(baseOptions);
/**
* @private
* @type {import('../webgl/ShaderBuilder.js').StyleParseResult}
*/
this.parseResult_ = parseLiteralStyle(options.style);
/**
* @type {Object<string, (string|number)>}
* @private
*/
this.styleVariables_ = options.style.variables || {};
/**
* @private
* @type {boolean}
*/
this.hitDetectionDisabled_ = !!options.disableHitDetection;
}
createRenderer() {
return new WebGLPointsLayerRenderer(this, {
vertexShader: this.parseResult_.builder.getSymbolVertexShader(),
fragmentShader: this.parseResult_.builder.getSymbolFragmentShader(),
hitVertexShader:
!this.hitDetectionDisabled_ &&
this.parseResult_.builder.getSymbolVertexShader(true),
hitFragmentShader:
!this.hitDetectionDisabled_ &&
this.parseResult_.builder.getSymbolFragmentShader(true),
uniforms: this.parseResult_.uniforms,
attributes: this.parseResult_.attributes,
});
}
/**
* Update any variables used by the layer style and trigger a re-render.
* @param {Object<string, number>} variables Variables to update.
*/
updateStyleVariables(variables) {
assign(this.styleVariables_, variables);
this.changed();
}
}
export default WebGLPointsLayer;

526
node_modules/ol/src/layer/WebGLTile.js generated vendored Normal file
View File

@@ -0,0 +1,526 @@
/**
* @module ol/layer/WebGLTile
*/
import BaseTileLayer from './BaseTile.js';
import LayerProperty from '../layer/Property.js';
import WebGLTileLayerRenderer, {
Attributes,
Uniforms,
} from '../renderer/webgl/TileLayer.js';
import {
PALETTE_TEXTURE_ARRAY,
ValueTypes,
expressionToGlsl,
getStringNumberEquivalent,
uniformNameForVariable,
} from '../style/expressions.js';
import {assign} from '../obj.js';
/**
* @typedef {import("../source/DataTile.js").default|import("../source/TileImage.js").default} SourceType
*/
/**
* @typedef {Object} Style
* Translates tile data to rendered pixels.
*
* @property {Object<string, (string|number)>} [variables] Style variables. Each variable must hold a number or string. These
* variables can be used in the `color`, `brightness`, `contrast`, `exposure`, `saturation` and `gamma`
* {@link import("../style/expressions.js").ExpressionValue expressions}, using the `['var', 'varName']` operator.
* To update style variables, use the {@link import("./WebGLTile.js").default#updateStyleVariables} method.
* @property {import("../style/expressions.js").ExpressionValue} [color] An expression applied to color values.
* @property {import("../style/expressions.js").ExpressionValue} [brightness=0] Value used to decrease or increase
* the layer brightness. Values range from -1 to 1.
* @property {import("../style/expressions.js").ExpressionValue} [contrast=0] Value used to decrease or increase
* the layer contrast. Values range from -1 to 1.
* @property {import("../style/expressions.js").ExpressionValue} [exposure=0] Value used to decrease or increase
* the layer exposure. Values range from -1 to 1.
* @property {import("../style/expressions.js").ExpressionValue} [saturation=0] Value used to decrease or increase
* the layer saturation. Values range from -1 to 1.
* @property {import("../style/expressions.js").ExpressionValue} [gamma=1] Apply a gamma correction to the layer.
* Values range from 0 to infinity.
*/
/**
* @typedef {Object} Options
* @property {Style} [style] Style to apply to the layer.
* @property {string} [className='ol-layer'] A CSS class name to set to the layer element.
* @property {number} [opacity=1] Opacity (0, 1).
* @property {boolean} [visible=true] Visibility.
* @property {import("../extent.js").Extent} [extent] The bounding extent for layer rendering. The layer will not be
* rendered outside of this extent.
* @property {number} [zIndex] The z-index for layer rendering. At rendering time, the layers
* will be ordered, first by Z-index and then by position. When `undefined`, a `zIndex` of 0 is assumed
* for layers that are added to the map's `layers` collection, or `Infinity` when the layer's `setMap()`
* method was used.
* @property {number} [minResolution] The minimum resolution (inclusive) at which this layer will be
* visible.
* @property {number} [maxResolution] The maximum resolution (exclusive) below which this layer will
* be visible.
* @property {number} [minZoom] The minimum view zoom level (exclusive) above which this layer will be
* visible.
* @property {number} [maxZoom] The maximum view zoom level (inclusive) at which this layer will
* be visible.
* @property {number} [preload=0] Preload. Load low-resolution tiles up to `preload` levels. `0`
* means no preloading.
* @property {SourceType} [source] Source for this layer.
* @property {Array<SourceType>|function(import("../extent.js").Extent, number):Array<SourceType>} [sources] Array
* of sources for this layer. Takes precedence over `source`. Can either be an array of sources, or a function that
* expects an extent and a resolution (in view projection units per pixel) and returns an array of sources. See
* {@link module:ol/source.sourcesFromTileGrid} for a helper function to generate sources that are organized in a
* pyramid following the same pattern as a tile grid. **Note:** All sources must have the same band count and content.
* @property {import("../PluggableMap.js").default} [map] Sets the layer as overlay on a map. The map will not manage
* this layer in its layers collection, and the layer will be rendered on top. This is useful for
* temporary layers. The standard way to add a layer to a map and have it managed by the map is to
* use {@link module:ol/Map~Map#addLayer}.
* @property {boolean} [useInterimTilesOnError=true] Use interim tiles on error.
* @property {number} [cacheSize=512] The internal texture cache size. This needs to be large enough to render
* two zoom levels worth of tiles.
*/
/**
* @typedef {Object} ParsedStyle
* @property {string} vertexShader The vertex shader.
* @property {string} fragmentShader The fragment shader.
* @property {Object<string,import("../webgl/Helper.js").UniformValue>} uniforms Uniform definitions.
* @property {Array<import("../webgl/PaletteTexture.js").default>} paletteTextures Palette textures.
*/
/**
* @param {Style} style The layer style.
* @param {number} [bandCount] The number of bands.
* @return {ParsedStyle} Shaders and uniforms generated from the style.
*/
function parseStyle(style, bandCount) {
const vertexShader = `
attribute vec2 ${Attributes.TEXTURE_COORD};
uniform mat4 ${Uniforms.TILE_TRANSFORM};
uniform float ${Uniforms.TEXTURE_PIXEL_WIDTH};
uniform float ${Uniforms.TEXTURE_PIXEL_HEIGHT};
uniform float ${Uniforms.TEXTURE_RESOLUTION};
uniform float ${Uniforms.TEXTURE_ORIGIN_X};
uniform float ${Uniforms.TEXTURE_ORIGIN_Y};
uniform float ${Uniforms.DEPTH};
varying vec2 v_textureCoord;
varying vec2 v_mapCoord;
void main() {
v_textureCoord = ${Attributes.TEXTURE_COORD};
v_mapCoord = vec2(
${Uniforms.TEXTURE_ORIGIN_X} + ${Uniforms.TEXTURE_RESOLUTION} * ${Uniforms.TEXTURE_PIXEL_WIDTH} * v_textureCoord[0],
${Uniforms.TEXTURE_ORIGIN_Y} - ${Uniforms.TEXTURE_RESOLUTION} * ${Uniforms.TEXTURE_PIXEL_HEIGHT} * v_textureCoord[1]
);
gl_Position = ${Uniforms.TILE_TRANSFORM} * vec4(${Attributes.TEXTURE_COORD}, ${Uniforms.DEPTH}, 1.0);
}
`;
/**
* @type {import("../style/expressions.js").ParsingContext}
*/
const context = {
inFragmentShader: true,
variables: [],
attributes: [],
stringLiteralsMap: {},
functions: {},
bandCount: bandCount,
};
const pipeline = [];
if (style.color !== undefined) {
const color = expressionToGlsl(context, style.color, ValueTypes.COLOR);
pipeline.push(`color = ${color};`);
}
if (style.contrast !== undefined) {
const contrast = expressionToGlsl(
context,
style.contrast,
ValueTypes.NUMBER
);
pipeline.push(
`color.rgb = clamp((${contrast} + 1.0) * color.rgb - (${contrast} / 2.0), vec3(0.0, 0.0, 0.0), vec3(1.0, 1.0, 1.0));`
);
}
if (style.exposure !== undefined) {
const exposure = expressionToGlsl(
context,
style.exposure,
ValueTypes.NUMBER
);
pipeline.push(
`color.rgb = clamp((${exposure} + 1.0) * color.rgb, vec3(0.0, 0.0, 0.0), vec3(1.0, 1.0, 1.0));`
);
}
if (style.saturation !== undefined) {
const saturation = expressionToGlsl(
context,
style.saturation,
ValueTypes.NUMBER
);
pipeline.push(`
float saturation = ${saturation} + 1.0;
float sr = (1.0 - saturation) * 0.2126;
float sg = (1.0 - saturation) * 0.7152;
float sb = (1.0 - saturation) * 0.0722;
mat3 saturationMatrix = mat3(
sr + saturation, sr, sr,
sg, sg + saturation, sg,
sb, sb, sb + saturation
);
color.rgb = clamp(saturationMatrix * color.rgb, vec3(0.0, 0.0, 0.0), vec3(1.0, 1.0, 1.0));
`);
}
if (style.gamma !== undefined) {
const gamma = expressionToGlsl(context, style.gamma, ValueTypes.NUMBER);
pipeline.push(`color.rgb = pow(color.rgb, vec3(1.0 / ${gamma}));`);
}
if (style.brightness !== undefined) {
const brightness = expressionToGlsl(
context,
style.brightness,
ValueTypes.NUMBER
);
pipeline.push(
`color.rgb = clamp(color.rgb + ${brightness}, vec3(0.0, 0.0, 0.0), vec3(1.0, 1.0, 1.0));`
);
}
/** @type {Object<string,import("../webgl/Helper").UniformValue>} */
const uniforms = {};
const numVariables = context.variables.length;
if (numVariables > 1 && !style.variables) {
throw new Error(
`Missing variables in style (expected ${context.variables})`
);
}
for (let i = 0; i < numVariables; ++i) {
const variableName = context.variables[i];
if (!(variableName in style.variables)) {
throw new Error(`Missing '${variableName}' in style variables`);
}
const uniformName = uniformNameForVariable(variableName);
uniforms[uniformName] = function () {
let value = style.variables[variableName];
if (typeof value === 'string') {
value = getStringNumberEquivalent(context, value);
}
return value !== undefined ? value : -9999999; // to avoid matching with the first string literal
};
}
const uniformDeclarations = Object.keys(uniforms).map(function (name) {
return `uniform float ${name};`;
});
const textureCount = Math.ceil(bandCount / 4);
uniformDeclarations.push(
`uniform sampler2D ${Uniforms.TILE_TEXTURE_ARRAY}[${textureCount}];`
);
if (context.paletteTextures) {
uniformDeclarations.push(
`uniform sampler2D ${PALETTE_TEXTURE_ARRAY}[${context.paletteTextures.length}];`
);
}
const functionDefintions = Object.keys(context.functions).map(function (
name
) {
return context.functions[name];
});
const fragmentShader = `
#ifdef GL_FRAGMENT_PRECISION_HIGH
precision highp float;
#else
precision mediump float;
#endif
varying vec2 v_textureCoord;
varying vec2 v_mapCoord;
uniform vec4 ${Uniforms.RENDER_EXTENT};
uniform float ${Uniforms.TRANSITION_ALPHA};
uniform float ${Uniforms.TEXTURE_PIXEL_WIDTH};
uniform float ${Uniforms.TEXTURE_PIXEL_HEIGHT};
uniform float ${Uniforms.RESOLUTION};
uniform float ${Uniforms.ZOOM};
${uniformDeclarations.join('\n')}
${functionDefintions.join('\n')}
void main() {
if (
v_mapCoord[0] < ${Uniforms.RENDER_EXTENT}[0] ||
v_mapCoord[1] < ${Uniforms.RENDER_EXTENT}[1] ||
v_mapCoord[0] > ${Uniforms.RENDER_EXTENT}[2] ||
v_mapCoord[1] > ${Uniforms.RENDER_EXTENT}[3]
) {
discard;
}
vec4 color = texture2D(${
Uniforms.TILE_TEXTURE_ARRAY
}[0], v_textureCoord);
${pipeline.join('\n')}
if (color.a == 0.0) {
discard;
}
gl_FragColor = color;
gl_FragColor.rgb *= gl_FragColor.a;
gl_FragColor *= ${Uniforms.TRANSITION_ALPHA};
}`;
return {
vertexShader: vertexShader,
fragmentShader: fragmentShader,
uniforms: uniforms,
paletteTextures: context.paletteTextures,
};
}
/**
* @classdesc
* For layer sources that provide pre-rendered, tiled images in grids that are
* organized by zoom levels for specific resolutions.
* Note that any property set in the options is set as a {@link module:ol/Object~BaseObject}
* property on the layer object; for example, setting `title: 'My Title'` in the
* options means that `title` is observable, and has get/set accessors.
*
* @extends BaseTileLayer<SourceType, WebGLTileLayerRenderer>
* @fires import("../render/Event.js").RenderEvent
* @api
*/
class WebGLTileLayer extends BaseTileLayer {
/**
* @param {Options} opt_options Tile layer options.
*/
constructor(opt_options) {
const options = opt_options ? assign({}, opt_options) : {};
const style = options.style || {};
delete options.style;
const cacheSize = options.cacheSize;
delete options.cacheSize;
super(options);
/**
* @type {Array<SourceType>|function(import("../extent.js").Extent, number):Array<SourceType>}
* @private
*/
this.sources_ = options.sources;
/**
* @type {SourceType|null}
* @private
*/
this.renderedSource_ = null;
/**
* @type {number}
* @private
*/
this.renderedResolution_ = NaN;
/**
* @type {Style}
* @private
*/
this.style_ = style;
/**
* @type {number}
* @private
*/
this.cacheSize_ = cacheSize;
/**
* @type {Object<string, (string|number)>}
* @private
*/
this.styleVariables_ = this.style_.variables || {};
this.addChangeListener(LayerProperty.SOURCE, this.handleSourceUpdate_);
}
/**
* Gets the sources for this layer, for a given extent and resolution.
* @param {import("../extent.js").Extent} extent Extent.
* @param {number} resolution Resolution.
* @return {Array<SourceType>} Sources.
*/
getSources(extent, resolution) {
const source = this.getSource();
return this.sources_
? typeof this.sources_ === 'function'
? this.sources_(extent, resolution)
: this.sources_
: source
? [source]
: [];
}
/**
* @return {SourceType} The source being rendered.
*/
getRenderSource() {
return this.renderedSource_ || this.getSource();
}
/**
* @return {import("../source/Source.js").State} Source state.
*/
getSourceState() {
const source = this.getRenderSource();
return source ? source.getState() : 'undefined';
}
/**
* @private
*/
handleSourceUpdate_() {
if (this.getSource()) {
this.setStyle(this.style_);
}
}
/**
* @private
* @return {number} The number of source bands.
*/
getSourceBandCount_() {
const max = Number.MAX_SAFE_INTEGER;
const sources = this.getSources([-max, -max, max, max], max);
return sources && sources.length && 'bandCount' in sources[0]
? sources[0].bandCount
: 4;
}
createRenderer() {
const parsedStyle = parseStyle(this.style_, this.getSourceBandCount_());
return new WebGLTileLayerRenderer(this, {
vertexShader: parsedStyle.vertexShader,
fragmentShader: parsedStyle.fragmentShader,
uniforms: parsedStyle.uniforms,
cacheSize: this.cacheSize_,
paletteTextures: parsedStyle.paletteTextures,
});
}
/**
* @param {import("../PluggableMap").FrameState} frameState Frame state.
* @param {Array<SourceType>} sources Sources.
* @return {HTMLElement} Canvas.
*/
renderSources(frameState, sources) {
const layerRenderer = this.getRenderer();
let canvas;
for (let i = 0, ii = sources.length; i < ii; ++i) {
this.renderedSource_ = sources[i];
if (layerRenderer.prepareFrame(frameState)) {
canvas = layerRenderer.renderFrame(frameState);
}
}
return canvas;
}
/**
* @param {?import("../PluggableMap.js").FrameState} frameState Frame state.
* @param {HTMLElement} target Target which the renderer may (but need not) use
* for rendering its content.
* @return {HTMLElement} The rendered element.
*/
render(frameState, target) {
this.rendered = true;
const viewState = frameState.viewState;
const sources = this.getSources(frameState.extent, viewState.resolution);
let ready = true;
for (let i = 0, ii = sources.length; i < ii; ++i) {
const source = sources[i];
const sourceState = source.getState();
if (sourceState == 'loading') {
const onChange = () => {
if (source.getState() == 'ready') {
source.removeEventListener('change', onChange);
this.changed();
}
};
source.addEventListener('change', onChange);
}
ready = ready && sourceState == 'ready';
}
const canvas = this.renderSources(frameState, sources);
if (this.getRenderer().renderComplete && ready) {
// Fully rendered, done.
this.renderedResolution_ = viewState.resolution;
return canvas;
}
// Render sources from previously fully rendered frames
if (this.renderedResolution_ > 0.5 * viewState.resolution) {
const altSources = this.getSources(
frameState.extent,
this.renderedResolution_
).filter((source) => !sources.includes(source));
if (altSources.length > 0) {
return this.renderSources(frameState, altSources);
}
}
return canvas;
}
/**
* Update the layer style. The `updateStyleVariables` function is a more efficient
* way to update layer rendering. In cases where the whole style needs to be updated,
* this method may be called instead. Note that calling this method will also replace
* any previously set variables, so the new style also needs to include new variables,
* if needed.
* @param {Style} style The new style.
*/
setStyle(style) {
this.styleVariables_ = style.variables || {};
this.style_ = style;
const parsedStyle = parseStyle(this.style_, this.getSourceBandCount_());
const renderer = this.getRenderer();
renderer.reset({
vertexShader: parsedStyle.vertexShader,
fragmentShader: parsedStyle.fragmentShader,
uniforms: parsedStyle.uniforms,
paletteTextures: parsedStyle.paletteTextures,
});
this.changed();
}
/**
* Update any variables used by the layer style and trigger a re-render.
* @param {Object<string, number>} variables Variables to update.
* @api
*/
updateStyleVariables(variables) {
assign(this.styleVariables_, variables);
this.changed();
}
}
/**
* Clean up underlying WebGL resources.
* @function
* @api
*/
WebGLTileLayer.prototype.dispose;
export default WebGLTileLayer;