This commit is contained in:
82
node_modules/ol/src/style/Circle.js
generated
vendored
Normal file
82
node_modules/ol/src/style/Circle.js
generated
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
* @module ol/style/Circle
|
||||
*/
|
||||
|
||||
import RegularShape from './RegularShape.js';
|
||||
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
* @property {import("./Fill.js").default} [fill] Fill style.
|
||||
* @property {number} radius Circle radius.
|
||||
* @property {import("./Stroke.js").default} [stroke] Stroke style.
|
||||
* @property {Array<number>} [displacement=[0,0]] displacement
|
||||
* @property {number|import("../size.js").Size} [scale=1] Scale. A two dimensional scale will produce an ellipse.
|
||||
* Unless two dimensional scaling is required a better result may be obtained with an appropriate setting for `radius`.
|
||||
* @property {number} [rotation=0] Rotation in radians
|
||||
* (positive rotation clockwise, meaningful only when used in conjunction with a two dimensional scale).
|
||||
* @property {boolean} [rotateWithView=false] Whether to rotate the shape with the view
|
||||
* (meaningful only when used in conjunction with a two dimensional scale).
|
||||
* @property {"declutter"|"obstacle"|"none"|undefined} [declutterMode] Declutter mode
|
||||
*/
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Set circle style for vector features.
|
||||
* @api
|
||||
*/
|
||||
class CircleStyle extends RegularShape {
|
||||
/**
|
||||
* @param {Options} [opt_options] Options.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
const options = opt_options ? opt_options : {};
|
||||
|
||||
super({
|
||||
points: Infinity,
|
||||
fill: options.fill,
|
||||
radius: options.radius,
|
||||
stroke: options.stroke,
|
||||
scale: options.scale !== undefined ? options.scale : 1,
|
||||
rotation: options.rotation !== undefined ? options.rotation : 0,
|
||||
rotateWithView:
|
||||
options.rotateWithView !== undefined ? options.rotateWithView : false,
|
||||
displacement:
|
||||
options.displacement !== undefined ? options.displacement : [0, 0],
|
||||
declutterMode: options.declutterMode,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Clones the style.
|
||||
* @return {CircleStyle} The cloned style.
|
||||
* @api
|
||||
*/
|
||||
clone() {
|
||||
const scale = this.getScale();
|
||||
const style = new CircleStyle({
|
||||
fill: this.getFill() ? this.getFill().clone() : undefined,
|
||||
stroke: this.getStroke() ? this.getStroke().clone() : undefined,
|
||||
radius: this.getRadius(),
|
||||
scale: Array.isArray(scale) ? scale.slice() : scale,
|
||||
rotation: this.getRotation(),
|
||||
rotateWithView: this.getRotateWithView(),
|
||||
displacement: this.getDisplacement().slice(),
|
||||
declutterMode: this.getDeclutterMode(),
|
||||
});
|
||||
style.setOpacity(this.getOpacity());
|
||||
return style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the circle radius.
|
||||
*
|
||||
* @param {number} radius Circle radius.
|
||||
* @api
|
||||
*/
|
||||
setRadius(radius) {
|
||||
this.radius_ = radius;
|
||||
this.render();
|
||||
}
|
||||
}
|
||||
|
||||
export default CircleStyle;
|
||||
63
node_modules/ol/src/style/Fill.js
generated
vendored
Normal file
63
node_modules/ol/src/style/Fill.js
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* @module ol/style/Fill
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
* @property {import("../color.js").Color|import("../colorlike.js").ColorLike|null} [color=null] A color, gradient or pattern.
|
||||
* See {@link module:ol/color~Color} and {@link module:ol/colorlike~ColorLike} for possible formats.
|
||||
* Default null; if null, the Canvas/renderer default black will be used.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Set fill style for vector features.
|
||||
* @api
|
||||
*/
|
||||
class Fill {
|
||||
/**
|
||||
* @param {Options} [opt_options] Options.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
const options = opt_options || {};
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("../color.js").Color|import("../colorlike.js").ColorLike|null}
|
||||
*/
|
||||
this.color_ = options.color !== undefined ? options.color : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clones the style. The color is not cloned if it is an {@link module:ol/colorlike~ColorLike}.
|
||||
* @return {Fill} The cloned style.
|
||||
* @api
|
||||
*/
|
||||
clone() {
|
||||
const color = this.getColor();
|
||||
return new Fill({
|
||||
color: Array.isArray(color) ? color.slice() : color || undefined,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the fill color.
|
||||
* @return {import("../color.js").Color|import("../colorlike.js").ColorLike|null} Color.
|
||||
* @api
|
||||
*/
|
||||
getColor() {
|
||||
return this.color_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the color.
|
||||
*
|
||||
* @param {import("../color.js").Color|import("../colorlike.js").ColorLike|null} color Color.
|
||||
* @api
|
||||
*/
|
||||
setColor(color) {
|
||||
this.color_ = color;
|
||||
}
|
||||
}
|
||||
|
||||
export default Fill;
|
||||
440
node_modules/ol/src/style/Icon.js
generated
vendored
Normal file
440
node_modules/ol/src/style/Icon.js
generated
vendored
Normal file
@@ -0,0 +1,440 @@
|
||||
/**
|
||||
* @module ol/style/Icon
|
||||
*/
|
||||
import EventType from '../events/EventType.js';
|
||||
import IconAnchorUnits from './IconAnchorUnits.js';
|
||||
import IconOrigin from './IconOrigin.js';
|
||||
import ImageState from '../ImageState.js';
|
||||
import ImageStyle from './Image.js';
|
||||
import {asArray} from '../color.js';
|
||||
import {assert} from '../asserts.js';
|
||||
import {get as getIconImage} from './IconImage.js';
|
||||
import {getUid} from '../util.js';
|
||||
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
* @property {Array<number>} [anchor=[0.5, 0.5]] Anchor. Default value is the icon center.
|
||||
* @property {import("./IconOrigin.js").default} [anchorOrigin='top-left'] Origin of the anchor: `bottom-left`, `bottom-right`,
|
||||
* `top-left` or `top-right`.
|
||||
* @property {import("./IconAnchorUnits.js").default} [anchorXUnits='fraction'] Units in which the anchor x value is
|
||||
* specified. A value of `'fraction'` indicates the x value is a fraction of the icon. A value of `'pixels'` indicates
|
||||
* the x value in pixels.
|
||||
* @property {import("./IconAnchorUnits.js").default} [anchorYUnits='fraction'] Units in which the anchor y value is
|
||||
* specified. A value of `'fraction'` indicates the y value is a fraction of the icon. A value of `'pixels'` indicates
|
||||
* the y value in pixels.
|
||||
* @property {import("../color.js").Color|string} [color] Color to tint the icon. If not specified,
|
||||
* the icon will be left as is.
|
||||
* @property {null|string} [crossOrigin] The `crossOrigin` attribute for loaded images. Note that you must provide a
|
||||
* `crossOrigin` value if you want to access pixel data with the Canvas renderer.
|
||||
* See https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image for more detail.
|
||||
* @property {HTMLImageElement|HTMLCanvasElement} [img] Image object for the icon. If the `src` option is not provided then the
|
||||
* provided image must already be loaded. And in that case, it is required
|
||||
* to provide the size of the image, with the `imgSize` option.
|
||||
* @property {Array<number>} [offset=[0, 0]] Offset, which, together with the size and the offset origin, define the
|
||||
* sub-rectangle to use from the original icon image.
|
||||
* @property {Array<number>} [displacement=[0,0]] Displacement of the icon.
|
||||
* @property {import("./IconOrigin.js").default} [offsetOrigin='top-left'] Origin of the offset: `bottom-left`, `bottom-right`,
|
||||
* `top-left` or `top-right`.
|
||||
* @property {number} [opacity=1] Opacity of the icon.
|
||||
* @property {number|import("../size.js").Size} [scale=1] Scale.
|
||||
* @property {boolean} [rotateWithView=false] Whether to rotate the icon with the view.
|
||||
* @property {number} [rotation=0] Rotation in radians (positive rotation clockwise).
|
||||
* @property {import("../size.js").Size} [size] Icon size in pixel. Can be used together with `offset` to define the
|
||||
* sub-rectangle to use from the origin (sprite) icon image.
|
||||
* @property {import("../size.js").Size} [imgSize] Image size in pixels. Only required if `img` is set and `src` is not, and
|
||||
* for SVG images in Internet Explorer 11. The provided `imgSize` needs to match the actual size of the image.
|
||||
* @property {string} [src] Image source URI.
|
||||
* @property {"declutter"|"obstacle"|"none"|undefined} [declutterMode] Declutter mode
|
||||
*/
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Set icon style for vector features.
|
||||
* @api
|
||||
*/
|
||||
class Icon extends ImageStyle {
|
||||
/**
|
||||
* @param {Options} [opt_options] Options.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
const options = opt_options || {};
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
const opacity = options.opacity !== undefined ? options.opacity : 1;
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
const rotation = options.rotation !== undefined ? options.rotation : 0;
|
||||
|
||||
/**
|
||||
* @type {number|import("../size.js").Size}
|
||||
*/
|
||||
const scale = options.scale !== undefined ? options.scale : 1;
|
||||
|
||||
/**
|
||||
* @type {boolean}
|
||||
*/
|
||||
const rotateWithView =
|
||||
options.rotateWithView !== undefined ? options.rotateWithView : false;
|
||||
|
||||
super({
|
||||
opacity: opacity,
|
||||
rotation: rotation,
|
||||
scale: scale,
|
||||
displacement:
|
||||
options.displacement !== undefined ? options.displacement : [0, 0],
|
||||
rotateWithView: rotateWithView,
|
||||
declutterMode: options.declutterMode,
|
||||
});
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array<number>}
|
||||
*/
|
||||
this.anchor_ = options.anchor !== undefined ? options.anchor : [0.5, 0.5];
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array<number>}
|
||||
*/
|
||||
this.normalizedAnchor_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("./IconOrigin.js").default}
|
||||
*/
|
||||
this.anchorOrigin_ =
|
||||
options.anchorOrigin !== undefined
|
||||
? options.anchorOrigin
|
||||
: IconOrigin.TOP_LEFT;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("./IconAnchorUnits.js").default}
|
||||
*/
|
||||
this.anchorXUnits_ =
|
||||
options.anchorXUnits !== undefined
|
||||
? options.anchorXUnits
|
||||
: IconAnchorUnits.FRACTION;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("./IconAnchorUnits.js").default}
|
||||
*/
|
||||
this.anchorYUnits_ =
|
||||
options.anchorYUnits !== undefined
|
||||
? options.anchorYUnits
|
||||
: IconAnchorUnits.FRACTION;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {?string}
|
||||
*/
|
||||
this.crossOrigin_ =
|
||||
options.crossOrigin !== undefined ? options.crossOrigin : null;
|
||||
|
||||
/**
|
||||
* @type {HTMLImageElement|HTMLCanvasElement}
|
||||
*/
|
||||
const image = options.img !== undefined ? options.img : null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("../size.js").Size|undefined}
|
||||
*/
|
||||
this.imgSize_ = options.imgSize;
|
||||
|
||||
/**
|
||||
* @type {string|undefined}
|
||||
*/
|
||||
let src = options.src;
|
||||
|
||||
assert(!(src !== undefined && image), 4); // `image` and `src` cannot be provided at the same time
|
||||
assert(!image || (image && this.imgSize_), 5); // `imgSize` must be set when `image` is provided
|
||||
|
||||
if ((src === undefined || src.length === 0) && image) {
|
||||
src = /** @type {HTMLImageElement} */ (image).src || getUid(image);
|
||||
}
|
||||
assert(src !== undefined && src.length > 0, 6); // A defined and non-empty `src` or `image` must be provided
|
||||
|
||||
/**
|
||||
* @type {import("../ImageState.js").default}
|
||||
*/
|
||||
const imageState =
|
||||
options.src !== undefined ? ImageState.IDLE : ImageState.LOADED;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("../color.js").Color}
|
||||
*/
|
||||
this.color_ = options.color !== undefined ? asArray(options.color) : null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("./IconImage.js").default}
|
||||
*/
|
||||
this.iconImage_ = getIconImage(
|
||||
image,
|
||||
/** @type {string} */ (src),
|
||||
this.imgSize_ !== undefined ? this.imgSize_ : null,
|
||||
this.crossOrigin_,
|
||||
imageState,
|
||||
this.color_
|
||||
);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array<number>}
|
||||
*/
|
||||
this.offset_ = options.offset !== undefined ? options.offset : [0, 0];
|
||||
/**
|
||||
* @private
|
||||
* @type {import("./IconOrigin.js").default}
|
||||
*/
|
||||
this.offsetOrigin_ =
|
||||
options.offsetOrigin !== undefined
|
||||
? options.offsetOrigin
|
||||
: IconOrigin.TOP_LEFT;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array<number>}
|
||||
*/
|
||||
this.origin_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("../size.js").Size}
|
||||
*/
|
||||
this.size_ = options.size !== undefined ? options.size : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clones the style. The underlying Image/HTMLCanvasElement is not cloned.
|
||||
* @return {Icon} The cloned style.
|
||||
* @api
|
||||
*/
|
||||
clone() {
|
||||
const scale = this.getScale();
|
||||
return new Icon({
|
||||
anchor: this.anchor_.slice(),
|
||||
anchorOrigin: this.anchorOrigin_,
|
||||
anchorXUnits: this.anchorXUnits_,
|
||||
anchorYUnits: this.anchorYUnits_,
|
||||
color:
|
||||
this.color_ && this.color_.slice
|
||||
? this.color_.slice()
|
||||
: this.color_ || undefined,
|
||||
crossOrigin: this.crossOrigin_,
|
||||
imgSize: this.imgSize_,
|
||||
offset: this.offset_.slice(),
|
||||
offsetOrigin: this.offsetOrigin_,
|
||||
opacity: this.getOpacity(),
|
||||
rotateWithView: this.getRotateWithView(),
|
||||
rotation: this.getRotation(),
|
||||
scale: Array.isArray(scale) ? scale.slice() : scale,
|
||||
size: this.size_ !== null ? this.size_.slice() : undefined,
|
||||
src: this.getSrc(),
|
||||
displacement: this.getDisplacement().slice(),
|
||||
declutterMode: this.getDeclutterMode(),
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the anchor point in pixels. The anchor determines the center point for the
|
||||
* symbolizer.
|
||||
* @return {Array<number>} Anchor.
|
||||
* @api
|
||||
*/
|
||||
getAnchor() {
|
||||
let anchor = this.normalizedAnchor_;
|
||||
if (!anchor) {
|
||||
anchor = this.anchor_;
|
||||
const size = this.getSize();
|
||||
if (
|
||||
this.anchorXUnits_ == IconAnchorUnits.FRACTION ||
|
||||
this.anchorYUnits_ == IconAnchorUnits.FRACTION
|
||||
) {
|
||||
if (!size) {
|
||||
return null;
|
||||
}
|
||||
anchor = this.anchor_.slice();
|
||||
if (this.anchorXUnits_ == IconAnchorUnits.FRACTION) {
|
||||
anchor[0] *= size[0];
|
||||
}
|
||||
if (this.anchorYUnits_ == IconAnchorUnits.FRACTION) {
|
||||
anchor[1] *= size[1];
|
||||
}
|
||||
}
|
||||
|
||||
if (this.anchorOrigin_ != IconOrigin.TOP_LEFT) {
|
||||
if (!size) {
|
||||
return null;
|
||||
}
|
||||
if (anchor === this.anchor_) {
|
||||
anchor = this.anchor_.slice();
|
||||
}
|
||||
if (
|
||||
this.anchorOrigin_ == IconOrigin.TOP_RIGHT ||
|
||||
this.anchorOrigin_ == IconOrigin.BOTTOM_RIGHT
|
||||
) {
|
||||
anchor[0] = -anchor[0] + size[0];
|
||||
}
|
||||
if (
|
||||
this.anchorOrigin_ == IconOrigin.BOTTOM_LEFT ||
|
||||
this.anchorOrigin_ == IconOrigin.BOTTOM_RIGHT
|
||||
) {
|
||||
anchor[1] = -anchor[1] + size[1];
|
||||
}
|
||||
}
|
||||
this.normalizedAnchor_ = anchor;
|
||||
}
|
||||
const displacement = this.getDisplacement();
|
||||
return [anchor[0] - displacement[0], anchor[1] + displacement[1]];
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the anchor point. The anchor determines the center point for the
|
||||
* symbolizer.
|
||||
*
|
||||
* @param {Array<number>} anchor Anchor.
|
||||
* @api
|
||||
*/
|
||||
setAnchor(anchor) {
|
||||
this.anchor_ = anchor;
|
||||
this.normalizedAnchor_ = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the icon color.
|
||||
* @return {import("../color.js").Color} Color.
|
||||
* @api
|
||||
*/
|
||||
getColor() {
|
||||
return this.color_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the image icon.
|
||||
* @param {number} pixelRatio Pixel ratio.
|
||||
* @return {HTMLImageElement|HTMLCanvasElement} Image or Canvas element.
|
||||
* @api
|
||||
*/
|
||||
getImage(pixelRatio) {
|
||||
return this.iconImage_.getImage(pixelRatio);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the pixel ratio.
|
||||
* @param {number} pixelRatio Pixel ratio.
|
||||
* @return {number} The pixel ratio of the image.
|
||||
* @api
|
||||
*/
|
||||
getPixelRatio(pixelRatio) {
|
||||
return this.iconImage_.getPixelRatio(pixelRatio);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {import("../size.js").Size} Image size.
|
||||
*/
|
||||
getImageSize() {
|
||||
return this.iconImage_.getSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {import("../ImageState.js").default} Image state.
|
||||
*/
|
||||
getImageState() {
|
||||
return this.iconImage_.getImageState();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {HTMLImageElement|HTMLCanvasElement} Image element.
|
||||
*/
|
||||
getHitDetectionImage() {
|
||||
return this.iconImage_.getHitDetectionImage();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the origin of the symbolizer.
|
||||
* @return {Array<number>} Origin.
|
||||
* @api
|
||||
*/
|
||||
getOrigin() {
|
||||
if (this.origin_) {
|
||||
return this.origin_;
|
||||
}
|
||||
let offset = this.offset_;
|
||||
|
||||
if (this.offsetOrigin_ != IconOrigin.TOP_LEFT) {
|
||||
const size = this.getSize();
|
||||
const iconImageSize = this.iconImage_.getSize();
|
||||
if (!size || !iconImageSize) {
|
||||
return null;
|
||||
}
|
||||
offset = offset.slice();
|
||||
if (
|
||||
this.offsetOrigin_ == IconOrigin.TOP_RIGHT ||
|
||||
this.offsetOrigin_ == IconOrigin.BOTTOM_RIGHT
|
||||
) {
|
||||
offset[0] = iconImageSize[0] - size[0] - offset[0];
|
||||
}
|
||||
if (
|
||||
this.offsetOrigin_ == IconOrigin.BOTTOM_LEFT ||
|
||||
this.offsetOrigin_ == IconOrigin.BOTTOM_RIGHT
|
||||
) {
|
||||
offset[1] = iconImageSize[1] - size[1] - offset[1];
|
||||
}
|
||||
}
|
||||
this.origin_ = offset;
|
||||
return this.origin_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the image URL.
|
||||
* @return {string|undefined} Image src.
|
||||
* @api
|
||||
*/
|
||||
getSrc() {
|
||||
return this.iconImage_.getSrc();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size of the icon (in pixels).
|
||||
* @return {import("../size.js").Size} Image size.
|
||||
* @api
|
||||
*/
|
||||
getSize() {
|
||||
return !this.size_ ? this.iconImage_.getSize() : this.size_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {function(import("../events/Event.js").default): void} listener Listener function.
|
||||
*/
|
||||
listenImageChange(listener) {
|
||||
this.iconImage_.addEventListener(EventType.CHANGE, listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load not yet loaded URI.
|
||||
* When rendering a feature with an icon style, the vector renderer will
|
||||
* automatically call this method. However, you might want to call this
|
||||
* method yourself for preloading or other purposes.
|
||||
* @api
|
||||
*/
|
||||
load() {
|
||||
this.iconImage_.load();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {function(import("../events/Event.js").default): void} listener Listener function.
|
||||
*/
|
||||
unlistenImageChange(listener) {
|
||||
this.iconImage_.removeEventListener(EventType.CHANGE, listener);
|
||||
}
|
||||
}
|
||||
|
||||
export default Icon;
|
||||
20
node_modules/ol/src/style/IconAnchorUnits.js
generated
vendored
Normal file
20
node_modules/ol/src/style/IconAnchorUnits.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
/**
|
||||
* @module ol/style/IconAnchorUnits
|
||||
*/
|
||||
|
||||
/**
|
||||
* Icon anchor units. One of 'fraction', 'pixels'.
|
||||
* @enum {string}
|
||||
*/
|
||||
export default {
|
||||
/**
|
||||
* Anchor is a fraction
|
||||
* @api
|
||||
*/
|
||||
FRACTION: 'fraction',
|
||||
/**
|
||||
* Anchor is in pixels
|
||||
* @api
|
||||
*/
|
||||
PIXELS: 'pixels',
|
||||
};
|
||||
299
node_modules/ol/src/style/IconImage.js
generated
vendored
Normal file
299
node_modules/ol/src/style/IconImage.js
generated
vendored
Normal file
@@ -0,0 +1,299 @@
|
||||
/**
|
||||
* @module ol/style/IconImage
|
||||
*/
|
||||
|
||||
import EventTarget from '../events/Target.js';
|
||||
import EventType from '../events/EventType.js';
|
||||
import ImageState from '../ImageState.js';
|
||||
import {asString} from '../color.js';
|
||||
import {createCanvasContext2D} from '../dom.js';
|
||||
import {shared as iconImageCache} from './IconImageCache.js';
|
||||
import {listenImage} from '../Image.js';
|
||||
|
||||
/**
|
||||
* @type {CanvasRenderingContext2D}
|
||||
*/
|
||||
let taintedTestContext = null;
|
||||
|
||||
class IconImage extends EventTarget {
|
||||
/**
|
||||
* @param {HTMLImageElement|HTMLCanvasElement} image Image.
|
||||
* @param {string|undefined} src Src.
|
||||
* @param {import("../size.js").Size} size Size.
|
||||
* @param {?string} crossOrigin Cross origin.
|
||||
* @param {import("../ImageState.js").default} imageState Image state.
|
||||
* @param {import("../color.js").Color} color Color.
|
||||
*/
|
||||
constructor(image, src, size, crossOrigin, imageState, color) {
|
||||
super();
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {HTMLImageElement|HTMLCanvasElement}
|
||||
*/
|
||||
this.hitDetectionImage_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {HTMLImageElement|HTMLCanvasElement}
|
||||
*/
|
||||
this.image_ = !image ? new Image() : image;
|
||||
|
||||
if (crossOrigin !== null) {
|
||||
/** @type {HTMLImageElement} */ (this.image_).crossOrigin = crossOrigin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Object<number, HTMLCanvasElement>}
|
||||
*/
|
||||
this.canvas_ = {};
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("../color.js").Color}
|
||||
*/
|
||||
this.color_ = color;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {?function():void}
|
||||
*/
|
||||
this.unlisten_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("../ImageState.js").default}
|
||||
*/
|
||||
this.imageState_ = imageState;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("../size.js").Size}
|
||||
*/
|
||||
this.size_ = size;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string|undefined}
|
||||
*/
|
||||
this.src_ = src;
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
this.tainted_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @return {boolean} The image canvas is tainted.
|
||||
*/
|
||||
isTainted_() {
|
||||
if (this.tainted_ === undefined && this.imageState_ === ImageState.LOADED) {
|
||||
if (!taintedTestContext) {
|
||||
taintedTestContext = createCanvasContext2D(1, 1);
|
||||
}
|
||||
taintedTestContext.drawImage(this.image_, 0, 0);
|
||||
try {
|
||||
taintedTestContext.getImageData(0, 0, 1, 1);
|
||||
this.tainted_ = false;
|
||||
} catch (e) {
|
||||
taintedTestContext = null;
|
||||
this.tainted_ = true;
|
||||
}
|
||||
}
|
||||
return this.tainted_ === true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
dispatchChangeEvent_() {
|
||||
this.dispatchEvent(EventType.CHANGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
handleImageError_() {
|
||||
this.imageState_ = ImageState.ERROR;
|
||||
this.unlistenImage_();
|
||||
this.dispatchChangeEvent_();
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
handleImageLoad_() {
|
||||
this.imageState_ = ImageState.LOADED;
|
||||
if (this.size_) {
|
||||
this.image_.width = this.size_[0];
|
||||
this.image_.height = this.size_[1];
|
||||
} else {
|
||||
this.size_ = [this.image_.width, this.image_.height];
|
||||
}
|
||||
this.unlistenImage_();
|
||||
this.dispatchChangeEvent_();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} pixelRatio Pixel ratio.
|
||||
* @return {HTMLImageElement|HTMLCanvasElement} Image or Canvas element.
|
||||
*/
|
||||
getImage(pixelRatio) {
|
||||
this.replaceColor_(pixelRatio);
|
||||
return this.canvas_[pixelRatio] ? this.canvas_[pixelRatio] : this.image_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} pixelRatio Pixel ratio.
|
||||
* @return {number} Image or Canvas element.
|
||||
*/
|
||||
getPixelRatio(pixelRatio) {
|
||||
this.replaceColor_(pixelRatio);
|
||||
return this.canvas_[pixelRatio] ? pixelRatio : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {import("../ImageState.js").default} Image state.
|
||||
*/
|
||||
getImageState() {
|
||||
return this.imageState_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {HTMLImageElement|HTMLCanvasElement} Image element.
|
||||
*/
|
||||
getHitDetectionImage() {
|
||||
if (!this.hitDetectionImage_) {
|
||||
if (this.isTainted_()) {
|
||||
const width = this.size_[0];
|
||||
const height = this.size_[1];
|
||||
const context = createCanvasContext2D(width, height);
|
||||
context.fillRect(0, 0, width, height);
|
||||
this.hitDetectionImage_ = context.canvas;
|
||||
} else {
|
||||
this.hitDetectionImage_ = this.image_;
|
||||
}
|
||||
}
|
||||
return this.hitDetectionImage_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size of the icon (in pixels).
|
||||
* @return {import("../size.js").Size} Image size.
|
||||
*/
|
||||
getSize() {
|
||||
return this.size_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {string|undefined} Image src.
|
||||
*/
|
||||
getSrc() {
|
||||
return this.src_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load not yet loaded URI.
|
||||
*/
|
||||
load() {
|
||||
if (this.imageState_ == ImageState.IDLE) {
|
||||
this.imageState_ = ImageState.LOADING;
|
||||
try {
|
||||
/** @type {HTMLImageElement} */ (this.image_).src = this.src_;
|
||||
} catch (e) {
|
||||
this.handleImageError_();
|
||||
}
|
||||
this.unlisten_ = listenImage(
|
||||
this.image_,
|
||||
this.handleImageLoad_.bind(this),
|
||||
this.handleImageError_.bind(this)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} pixelRatio Pixel ratio.
|
||||
* @private
|
||||
*/
|
||||
replaceColor_(pixelRatio) {
|
||||
if (
|
||||
!this.color_ ||
|
||||
this.canvas_[pixelRatio] ||
|
||||
this.imageState_ !== ImageState.LOADED
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
const canvas = document.createElement('canvas');
|
||||
this.canvas_[pixelRatio] = canvas;
|
||||
|
||||
canvas.width = Math.ceil(this.image_.width * pixelRatio);
|
||||
canvas.height = Math.ceil(this.image_.height * pixelRatio);
|
||||
|
||||
const ctx = canvas.getContext('2d');
|
||||
ctx.scale(pixelRatio, pixelRatio);
|
||||
ctx.drawImage(this.image_, 0, 0);
|
||||
|
||||
ctx.globalCompositeOperation = 'multiply';
|
||||
// Internet Explorer 11 does not support the multiply operation.
|
||||
// If the canvas is tainted in Internet Explorer this still produces
|
||||
// a solid color image with the shape of the icon.
|
||||
if (ctx.globalCompositeOperation === 'multiply' || this.isTainted_()) {
|
||||
ctx.fillStyle = asString(this.color_);
|
||||
ctx.fillRect(0, 0, canvas.width / pixelRatio, canvas.height / pixelRatio);
|
||||
|
||||
ctx.globalCompositeOperation = 'destination-in';
|
||||
ctx.drawImage(this.image_, 0, 0);
|
||||
} else {
|
||||
const imgData = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
||||
const data = imgData.data;
|
||||
const r = this.color_[0] / 255.0;
|
||||
const g = this.color_[1] / 255.0;
|
||||
const b = this.color_[2] / 255.0;
|
||||
const a = this.color_[3];
|
||||
|
||||
for (let i = 0, ii = data.length; i < ii; i += 4) {
|
||||
data[i] *= r;
|
||||
data[i + 1] *= g;
|
||||
data[i + 2] *= b;
|
||||
data[i + 3] *= a;
|
||||
}
|
||||
ctx.putImageData(imgData, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Discards event handlers which listen for load completion or errors.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
unlistenImage_() {
|
||||
if (this.unlisten_) {
|
||||
this.unlisten_();
|
||||
this.unlisten_ = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {HTMLImageElement|HTMLCanvasElement} image Image.
|
||||
* @param {string} src Src.
|
||||
* @param {import("../size.js").Size} size Size.
|
||||
* @param {?string} crossOrigin Cross origin.
|
||||
* @param {import("../ImageState.js").default} imageState Image state.
|
||||
* @param {import("../color.js").Color} color Color.
|
||||
* @return {IconImage} Icon image.
|
||||
*/
|
||||
export function get(image, src, size, crossOrigin, imageState, color) {
|
||||
let iconImage = iconImageCache.get(src, crossOrigin, color);
|
||||
if (!iconImage) {
|
||||
iconImage = new IconImage(image, src, size, crossOrigin, imageState, color);
|
||||
iconImageCache.set(src, crossOrigin, color, iconImage);
|
||||
}
|
||||
return iconImage;
|
||||
}
|
||||
|
||||
export default IconImage;
|
||||
116
node_modules/ol/src/style/IconImageCache.js
generated
vendored
Normal file
116
node_modules/ol/src/style/IconImageCache.js
generated
vendored
Normal file
@@ -0,0 +1,116 @@
|
||||
/**
|
||||
* @module ol/style/IconImageCache
|
||||
*/
|
||||
import {asString} from '../color.js';
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Singleton class. Available through {@link module:ol/style/IconImageCache.shared}.
|
||||
*/
|
||||
class IconImageCache {
|
||||
constructor() {
|
||||
/**
|
||||
* @type {!Object<string, import("./IconImage.js").default>}
|
||||
* @private
|
||||
*/
|
||||
this.cache_ = {};
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
* @private
|
||||
*/
|
||||
this.cacheSize_ = 0;
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
* @private
|
||||
*/
|
||||
this.maxCacheSize_ = 32;
|
||||
}
|
||||
|
||||
/**
|
||||
* FIXME empty description for jsdoc
|
||||
*/
|
||||
clear() {
|
||||
this.cache_ = {};
|
||||
this.cacheSize_ = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {boolean} Can expire cache.
|
||||
*/
|
||||
canExpireCache() {
|
||||
return this.cacheSize_ > this.maxCacheSize_;
|
||||
}
|
||||
|
||||
/**
|
||||
* FIXME empty description for jsdoc
|
||||
*/
|
||||
expire() {
|
||||
if (this.canExpireCache()) {
|
||||
let i = 0;
|
||||
for (const key in this.cache_) {
|
||||
const iconImage = this.cache_[key];
|
||||
if ((i++ & 3) === 0 && !iconImage.hasListener()) {
|
||||
delete this.cache_[key];
|
||||
--this.cacheSize_;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} src Src.
|
||||
* @param {?string} crossOrigin Cross origin.
|
||||
* @param {import("../color.js").Color} color Color.
|
||||
* @return {import("./IconImage.js").default} Icon image.
|
||||
*/
|
||||
get(src, crossOrigin, color) {
|
||||
const key = getKey(src, crossOrigin, color);
|
||||
return key in this.cache_ ? this.cache_[key] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} src Src.
|
||||
* @param {?string} crossOrigin Cross origin.
|
||||
* @param {import("../color.js").Color} color Color.
|
||||
* @param {import("./IconImage.js").default} iconImage Icon image.
|
||||
*/
|
||||
set(src, crossOrigin, color, iconImage) {
|
||||
const key = getKey(src, crossOrigin, color);
|
||||
this.cache_[key] = iconImage;
|
||||
++this.cacheSize_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the cache size of the icon cache. Default is `32`. Change this value when
|
||||
* your map uses more than 32 different icon images and you are not caching icon
|
||||
* styles on the application level.
|
||||
* @param {number} maxCacheSize Cache max size.
|
||||
* @api
|
||||
*/
|
||||
setSize(maxCacheSize) {
|
||||
this.maxCacheSize_ = maxCacheSize;
|
||||
this.expire();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} src Src.
|
||||
* @param {?string} crossOrigin Cross origin.
|
||||
* @param {import("../color.js").Color} color Color.
|
||||
* @return {string} Cache key.
|
||||
*/
|
||||
function getKey(src, crossOrigin, color) {
|
||||
const colorString = color ? asString(color) : 'null';
|
||||
return crossOrigin + ':' + src + ':' + colorString;
|
||||
}
|
||||
|
||||
export default IconImageCache;
|
||||
|
||||
/**
|
||||
* The {@link module:ol/style/IconImageCache~IconImageCache} for
|
||||
* {@link module:ol/style/Icon~Icon} images.
|
||||
* @api
|
||||
*/
|
||||
export const shared = new IconImageCache();
|
||||
30
node_modules/ol/src/style/IconOrigin.js
generated
vendored
Normal file
30
node_modules/ol/src/style/IconOrigin.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* @module ol/style/IconOrigin
|
||||
*/
|
||||
|
||||
/**
|
||||
* Icon origin. One of 'bottom-left', 'bottom-right', 'top-left', 'top-right'.
|
||||
* @enum {string}
|
||||
*/
|
||||
export default {
|
||||
/**
|
||||
* Origin is at bottom left
|
||||
* @api
|
||||
*/
|
||||
BOTTOM_LEFT: 'bottom-left',
|
||||
/**
|
||||
* Origin is at bottom right
|
||||
* @api
|
||||
*/
|
||||
BOTTOM_RIGHT: 'bottom-right',
|
||||
/**
|
||||
* Origin is at top left
|
||||
* @api
|
||||
*/
|
||||
TOP_LEFT: 'top-left',
|
||||
/**
|
||||
* Origin is at top right
|
||||
* @api
|
||||
*/
|
||||
TOP_RIGHT: 'top-right',
|
||||
};
|
||||
297
node_modules/ol/src/style/Image.js
generated
vendored
Normal file
297
node_modules/ol/src/style/Image.js
generated
vendored
Normal file
@@ -0,0 +1,297 @@
|
||||
/**
|
||||
* @module ol/style/Image
|
||||
*/
|
||||
import {abstract} from '../util.js';
|
||||
import {toSize} from '../size.js';
|
||||
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
* @property {number} opacity Opacity.
|
||||
* @property {boolean} rotateWithView If the image should get rotated with the view.
|
||||
* @property {number} rotation Rotation.
|
||||
* @property {number|import("../size.js").Size} scale Scale.
|
||||
* @property {Array<number>} displacement Displacement.
|
||||
* @property {"declutter"|"obstacle"|"none"|undefined} declutterMode Declutter mode: `declutter`, `obstacle`, 'none */
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* A base class used for creating subclasses and not instantiated in
|
||||
* apps. Base class for {@link module:ol/style/Icon~Icon}, {@link module:ol/style/Circle~CircleStyle} and
|
||||
* {@link module:ol/style/RegularShape~RegularShape}.
|
||||
* @abstract
|
||||
* @api
|
||||
*/
|
||||
class ImageStyle {
|
||||
/**
|
||||
* @param {Options} options Options.
|
||||
*/
|
||||
constructor(options) {
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.opacity_ = options.opacity;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.rotateWithView_ = options.rotateWithView;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.rotation_ = options.rotation;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number|import("../size.js").Size}
|
||||
*/
|
||||
this.scale_ = options.scale;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("../size.js").Size}
|
||||
*/
|
||||
this.scaleArray_ = toSize(options.scale);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array<number>}
|
||||
*/
|
||||
this.displacement_ = options.displacement;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {"declutter"|"obstacle"|"none"|undefined}
|
||||
*/
|
||||
this.declutterMode_ = options.declutterMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clones the style.
|
||||
* @return {ImageStyle} The cloned style.
|
||||
* @api
|
||||
*/
|
||||
clone() {
|
||||
const scale = this.getScale();
|
||||
return new ImageStyle({
|
||||
opacity: this.getOpacity(),
|
||||
scale: Array.isArray(scale) ? scale.slice() : scale,
|
||||
rotation: this.getRotation(),
|
||||
rotateWithView: this.getRotateWithView(),
|
||||
displacement: this.getDisplacement().slice(),
|
||||
declutterMode: this.getDeclutterMode(),
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the symbolizer opacity.
|
||||
* @return {number} Opacity.
|
||||
* @api
|
||||
*/
|
||||
getOpacity() {
|
||||
return this.opacity_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the symbolizer rotates with the map.
|
||||
* @return {boolean} Rotate with map.
|
||||
* @api
|
||||
*/
|
||||
getRotateWithView() {
|
||||
return this.rotateWithView_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the symoblizer rotation.
|
||||
* @return {number} Rotation.
|
||||
* @api
|
||||
*/
|
||||
getRotation() {
|
||||
return this.rotation_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the symbolizer scale.
|
||||
* @return {number|import("../size.js").Size} Scale.
|
||||
* @api
|
||||
*/
|
||||
getScale() {
|
||||
return this.scale_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the symbolizer scale array.
|
||||
* @return {import("../size.js").Size} Scale array.
|
||||
*/
|
||||
getScaleArray() {
|
||||
return this.scaleArray_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the displacement of the shape
|
||||
* @return {Array<number>} Shape's center displacement
|
||||
* @api
|
||||
*/
|
||||
getDisplacement() {
|
||||
return this.displacement_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the declutter mode of the shape
|
||||
* @return {"declutter"|"obstacle"|"none"|undefined} Shape's declutter mode
|
||||
* @api
|
||||
*/
|
||||
getDeclutterMode() {
|
||||
return this.declutterMode_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the anchor point in pixels. The anchor determines the center point for the
|
||||
* symbolizer.
|
||||
* @abstract
|
||||
* @return {Array<number>} Anchor.
|
||||
*/
|
||||
getAnchor() {
|
||||
return abstract();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the image element for the symbolizer.
|
||||
* @abstract
|
||||
* @param {number} pixelRatio Pixel ratio.
|
||||
* @return {HTMLCanvasElement|HTMLVideoElement|HTMLImageElement} Image element.
|
||||
*/
|
||||
getImage(pixelRatio) {
|
||||
return abstract();
|
||||
}
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @return {HTMLCanvasElement|HTMLVideoElement|HTMLImageElement} Image element.
|
||||
*/
|
||||
getHitDetectionImage() {
|
||||
return abstract();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the image pixel ratio.
|
||||
* @param {number} pixelRatio Pixel ratio.
|
||||
* @return {number} Pixel ratio.
|
||||
*/
|
||||
getPixelRatio(pixelRatio) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @return {import("../ImageState.js").default} Image state.
|
||||
*/
|
||||
getImageState() {
|
||||
return abstract();
|
||||
}
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @return {import("../size.js").Size} Image size.
|
||||
*/
|
||||
getImageSize() {
|
||||
return abstract();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the origin of the symbolizer.
|
||||
* @abstract
|
||||
* @return {Array<number>} Origin.
|
||||
*/
|
||||
getOrigin() {
|
||||
return abstract();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size of the symbolizer (in pixels).
|
||||
* @abstract
|
||||
* @return {import("../size.js").Size} Size.
|
||||
*/
|
||||
getSize() {
|
||||
return abstract();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the displacement.
|
||||
*
|
||||
* @param {Array<number>} displacement Displacement.
|
||||
* @api
|
||||
*/
|
||||
setDisplacement(displacement) {
|
||||
this.displacement_ = displacement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the opacity.
|
||||
*
|
||||
* @param {number} opacity Opacity.
|
||||
* @api
|
||||
*/
|
||||
setOpacity(opacity) {
|
||||
this.opacity_ = opacity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether to rotate the style with the view.
|
||||
*
|
||||
* @param {boolean} rotateWithView Rotate with map.
|
||||
* @api
|
||||
*/
|
||||
setRotateWithView(rotateWithView) {
|
||||
this.rotateWithView_ = rotateWithView;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the rotation.
|
||||
*
|
||||
* @param {number} rotation Rotation.
|
||||
* @api
|
||||
*/
|
||||
setRotation(rotation) {
|
||||
this.rotation_ = rotation;
|
||||
}
|
||||
/**
|
||||
* Set the scale.
|
||||
*
|
||||
* @param {number|import("../size.js").Size} scale Scale.
|
||||
* @api
|
||||
*/
|
||||
setScale(scale) {
|
||||
this.scale_ = scale;
|
||||
this.scaleArray_ = toSize(scale);
|
||||
}
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {function(import("../events/Event.js").default): void} listener Listener function.
|
||||
*/
|
||||
listenImageChange(listener) {
|
||||
abstract();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load not yet loaded URI.
|
||||
* @abstract
|
||||
*/
|
||||
load() {
|
||||
abstract();
|
||||
}
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
* @param {function(import("../events/Event.js").default): void} listener Listener function.
|
||||
*/
|
||||
unlistenImageChange(listener) {
|
||||
abstract();
|
||||
}
|
||||
}
|
||||
|
||||
export default ImageStyle;
|
||||
617
node_modules/ol/src/style/RegularShape.js
generated
vendored
Normal file
617
node_modules/ol/src/style/RegularShape.js
generated
vendored
Normal file
@@ -0,0 +1,617 @@
|
||||
/**
|
||||
* @module ol/style/RegularShape
|
||||
*/
|
||||
|
||||
import ImageState from '../ImageState.js';
|
||||
import ImageStyle from './Image.js';
|
||||
import {asArray} from '../color.js';
|
||||
import {asColorLike} from '../colorlike.js';
|
||||
import {createCanvasContext2D} from '../dom.js';
|
||||
import {
|
||||
defaultFillStyle,
|
||||
defaultLineJoin,
|
||||
defaultLineWidth,
|
||||
defaultMiterLimit,
|
||||
defaultStrokeStyle,
|
||||
} from '../render/canvas.js';
|
||||
|
||||
/**
|
||||
* Specify radius for regular polygons, or radius1 and radius2 for stars.
|
||||
* @typedef {Object} Options
|
||||
* @property {import("./Fill.js").default} [fill] Fill style.
|
||||
* @property {number} points Number of points for stars and regular polygons. In case of a polygon, the number of points
|
||||
* is the number of sides.
|
||||
* @property {number} [radius] Radius of a regular polygon.
|
||||
* @property {number} [radius1] First radius of a star. Ignored if radius is set.
|
||||
* @property {number} [radius2] Second radius of a star.
|
||||
* @property {number} [angle=0] Shape's angle in radians. A value of 0 will have one of the shape's point facing up.
|
||||
* @property {Array<number>} [displacement=[0,0]] Displacement of the shape
|
||||
* @property {import("./Stroke.js").default} [stroke] Stroke style.
|
||||
* @property {number} [rotation=0] Rotation in radians (positive rotation clockwise).
|
||||
* @property {boolean} [rotateWithView=false] Whether to rotate the shape with the view.
|
||||
* @property {number|import("../size.js").Size} [scale=1] Scale. Unless two dimensional scaling is required a better
|
||||
* result may be obtained with appropriate settings for `radius`, `radius1` and `radius2`.
|
||||
* @property {"declutter"|"obstacle"|"none"|undefined} [declutterMode] Declutter mode
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} RenderOptions
|
||||
* @property {import("../colorlike.js").ColorLike} [strokeStyle] StrokeStyle.
|
||||
* @property {number} strokeWidth StrokeWidth.
|
||||
* @property {number} size Size.
|
||||
* @property {Array<number>} lineDash LineDash.
|
||||
* @property {number} lineDashOffset LineDashOffset.
|
||||
* @property {CanvasLineJoin} lineJoin LineJoin.
|
||||
* @property {number} miterLimit MiterLimit.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Set regular shape style for vector features. The resulting shape will be
|
||||
* a regular polygon when `radius` is provided, or a star when `radius1` and
|
||||
* `radius2` are provided.
|
||||
* @api
|
||||
*/
|
||||
class RegularShape extends ImageStyle {
|
||||
/**
|
||||
* @param {Options} options Options.
|
||||
*/
|
||||
constructor(options) {
|
||||
/**
|
||||
* @type {boolean}
|
||||
*/
|
||||
const rotateWithView =
|
||||
options.rotateWithView !== undefined ? options.rotateWithView : false;
|
||||
|
||||
super({
|
||||
opacity: 1,
|
||||
rotateWithView: rotateWithView,
|
||||
rotation: options.rotation !== undefined ? options.rotation : 0,
|
||||
scale: options.scale !== undefined ? options.scale : 1,
|
||||
displacement:
|
||||
options.displacement !== undefined ? options.displacement : [0, 0],
|
||||
declutterMode: options.declutterMode,
|
||||
});
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Object<number, HTMLCanvasElement>}
|
||||
*/
|
||||
this.canvas_ = undefined;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {HTMLCanvasElement}
|
||||
*/
|
||||
this.hitDetectionCanvas_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("./Fill.js").default}
|
||||
*/
|
||||
this.fill_ = options.fill !== undefined ? options.fill : null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array<number>}
|
||||
*/
|
||||
this.origin_ = [0, 0];
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.points_ = options.points;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {number}
|
||||
*/
|
||||
this.radius_ =
|
||||
options.radius !== undefined ? options.radius : options.radius1;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number|undefined}
|
||||
*/
|
||||
this.radius2_ = options.radius2;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.angle_ = options.angle !== undefined ? options.angle : 0;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("./Stroke.js").default}
|
||||
*/
|
||||
this.stroke_ = options.stroke !== undefined ? options.stroke : null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("../size.js").Size}
|
||||
*/
|
||||
this.size_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {RenderOptions}
|
||||
*/
|
||||
this.renderOptions_ = null;
|
||||
|
||||
this.render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clones the style.
|
||||
* @return {RegularShape} The cloned style.
|
||||
* @api
|
||||
*/
|
||||
clone() {
|
||||
const scale = this.getScale();
|
||||
const style = new RegularShape({
|
||||
fill: this.getFill() ? this.getFill().clone() : undefined,
|
||||
points: this.getPoints(),
|
||||
radius: this.getRadius(),
|
||||
radius2: this.getRadius2(),
|
||||
angle: this.getAngle(),
|
||||
stroke: this.getStroke() ? this.getStroke().clone() : undefined,
|
||||
rotation: this.getRotation(),
|
||||
rotateWithView: this.getRotateWithView(),
|
||||
scale: Array.isArray(scale) ? scale.slice() : scale,
|
||||
displacement: this.getDisplacement().slice(),
|
||||
declutterMode: this.getDeclutterMode(),
|
||||
});
|
||||
style.setOpacity(this.getOpacity());
|
||||
return style;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the anchor point in pixels. The anchor determines the center point for the
|
||||
* symbolizer.
|
||||
* @return {Array<number>} Anchor.
|
||||
* @api
|
||||
*/
|
||||
getAnchor() {
|
||||
const size = this.size_;
|
||||
if (!size) {
|
||||
return null;
|
||||
}
|
||||
const displacement = this.getDisplacement();
|
||||
return [size[0] / 2 - displacement[0], size[1] / 2 + displacement[1]];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the angle used in generating the shape.
|
||||
* @return {number} Shape's rotation in radians.
|
||||
* @api
|
||||
*/
|
||||
getAngle() {
|
||||
return this.angle_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the fill style for the shape.
|
||||
* @return {import("./Fill.js").default} Fill style.
|
||||
* @api
|
||||
*/
|
||||
getFill() {
|
||||
return this.fill_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the fill style.
|
||||
* @param {import("./Fill.js").default} fill Fill style.
|
||||
* @api
|
||||
*/
|
||||
setFill(fill) {
|
||||
this.fill_ = fill;
|
||||
this.render();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {HTMLCanvasElement} Image element.
|
||||
*/
|
||||
getHitDetectionImage() {
|
||||
if (!this.hitDetectionCanvas_) {
|
||||
this.createHitDetectionCanvas_(this.renderOptions_);
|
||||
}
|
||||
return this.hitDetectionCanvas_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the image icon.
|
||||
* @param {number} pixelRatio Pixel ratio.
|
||||
* @return {HTMLCanvasElement} Image or Canvas element.
|
||||
* @api
|
||||
*/
|
||||
getImage(pixelRatio) {
|
||||
let image = this.canvas_[pixelRatio];
|
||||
if (!image) {
|
||||
const renderOptions = this.renderOptions_;
|
||||
const context = createCanvasContext2D(
|
||||
renderOptions.size * pixelRatio,
|
||||
renderOptions.size * pixelRatio
|
||||
);
|
||||
this.draw_(renderOptions, context, pixelRatio);
|
||||
|
||||
image = context.canvas;
|
||||
this.canvas_[pixelRatio] = image;
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the image pixel ratio.
|
||||
* @param {number} pixelRatio Pixel ratio.
|
||||
* @return {number} Pixel ratio.
|
||||
*/
|
||||
getPixelRatio(pixelRatio) {
|
||||
return pixelRatio;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {import("../size.js").Size} Image size.
|
||||
*/
|
||||
getImageSize() {
|
||||
return this.size_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {import("../ImageState.js").default} Image state.
|
||||
*/
|
||||
getImageState() {
|
||||
return ImageState.LOADED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the origin of the symbolizer.
|
||||
* @return {Array<number>} Origin.
|
||||
* @api
|
||||
*/
|
||||
getOrigin() {
|
||||
return this.origin_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of points for generating the shape.
|
||||
* @return {number} Number of points for stars and regular polygons.
|
||||
* @api
|
||||
*/
|
||||
getPoints() {
|
||||
return this.points_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the (primary) radius for the shape.
|
||||
* @return {number} Radius.
|
||||
* @api
|
||||
*/
|
||||
getRadius() {
|
||||
return this.radius_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the secondary radius for the shape.
|
||||
* @return {number|undefined} Radius2.
|
||||
* @api
|
||||
*/
|
||||
getRadius2() {
|
||||
return this.radius2_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size of the symbolizer (in pixels).
|
||||
* @return {import("../size.js").Size} Size.
|
||||
* @api
|
||||
*/
|
||||
getSize() {
|
||||
return this.size_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the stroke style for the shape.
|
||||
* @return {import("./Stroke.js").default} Stroke style.
|
||||
* @api
|
||||
*/
|
||||
getStroke() {
|
||||
return this.stroke_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the stroke style.
|
||||
* @param {import("./Stroke.js").default} stroke Stroke style.
|
||||
* @api
|
||||
*/
|
||||
setStroke(stroke) {
|
||||
this.stroke_ = stroke;
|
||||
this.render();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {function(import("../events/Event.js").default): void} listener Listener function.
|
||||
*/
|
||||
listenImageChange(listener) {}
|
||||
|
||||
/**
|
||||
* Load not yet loaded URI.
|
||||
*/
|
||||
load() {}
|
||||
|
||||
/**
|
||||
* @param {function(import("../events/Event.js").default): void} listener Listener function.
|
||||
*/
|
||||
unlistenImageChange(listener) {}
|
||||
|
||||
/**
|
||||
* Calculate additional canvas size needed for the miter.
|
||||
* @param {string} lineJoin Line join
|
||||
* @param {number} strokeWidth Stroke width
|
||||
* @param {number} miterLimit Miter limit
|
||||
* @return {number} Additional canvas size needed
|
||||
* @private
|
||||
*/
|
||||
calculateLineJoinSize_(lineJoin, strokeWidth, miterLimit) {
|
||||
if (
|
||||
strokeWidth === 0 ||
|
||||
this.points_ === Infinity ||
|
||||
(lineJoin !== 'bevel' && lineJoin !== 'miter')
|
||||
) {
|
||||
return strokeWidth;
|
||||
}
|
||||
// m | ^
|
||||
// i | |\ .
|
||||
// t >| #\
|
||||
// e | |\ \ .
|
||||
// r \s\
|
||||
// | \t\ . .
|
||||
// \r\ . .
|
||||
// | \o\ . . . . .
|
||||
// e \k\ . . . .
|
||||
// | \e\ . . . . .
|
||||
// d \ \ . . . .
|
||||
// | _ _a_ _\# . . .
|
||||
// r1 / ` . .
|
||||
// | . .
|
||||
// b / . .
|
||||
// | . .
|
||||
// / r2 . .
|
||||
// | . .
|
||||
// / . .
|
||||
// |α . .
|
||||
// / . .
|
||||
// ° center
|
||||
let r1 = this.radius_;
|
||||
let r2 = this.radius2_ === undefined ? r1 : this.radius2_;
|
||||
if (r1 < r2) {
|
||||
const tmp = r1;
|
||||
r1 = r2;
|
||||
r2 = tmp;
|
||||
}
|
||||
const points =
|
||||
this.radius2_ === undefined ? this.points_ : this.points_ * 2;
|
||||
const alpha = (2 * Math.PI) / points;
|
||||
const a = r2 * Math.sin(alpha);
|
||||
const b = Math.sqrt(r2 * r2 - a * a);
|
||||
const d = r1 - b;
|
||||
const e = Math.sqrt(a * a + d * d);
|
||||
const miterRatio = e / a;
|
||||
if (lineJoin === 'miter' && miterRatio <= miterLimit) {
|
||||
return miterRatio * strokeWidth;
|
||||
}
|
||||
// Calculate the distnce from center to the stroke corner where
|
||||
// it was cut short because of the miter limit.
|
||||
// l
|
||||
// ----+---- <= distance from center to here is maxr
|
||||
// /####|k ##\
|
||||
// /#####^#####\
|
||||
// /#### /+\# s #\
|
||||
// /### h/+++\# t #\
|
||||
// /### t/+++++\# r #\
|
||||
// /### a/+++++++\# o #\
|
||||
// /### p/++ fill +\# k #\
|
||||
///#### /+++++^+++++\# e #\
|
||||
//#####/+++++/+\+++++\#####\
|
||||
const k = strokeWidth / 2 / miterRatio;
|
||||
const l = (strokeWidth / 2) * (d / e);
|
||||
const maxr = Math.sqrt((r1 + k) * (r1 + k) + l * l);
|
||||
const bevelAdd = maxr - r1;
|
||||
if (this.radius2_ === undefined || lineJoin === 'bevel') {
|
||||
return bevelAdd * 2;
|
||||
}
|
||||
// If outer miter is over the miter limit the inner miter may reach through the
|
||||
// center and be longer than the bevel, same calculation as above but swap r1 / r2.
|
||||
const aa = r1 * Math.sin(alpha);
|
||||
const bb = Math.sqrt(r1 * r1 - aa * aa);
|
||||
const dd = r2 - bb;
|
||||
const ee = Math.sqrt(aa * aa + dd * dd);
|
||||
const innerMiterRatio = ee / aa;
|
||||
if (innerMiterRatio <= miterLimit) {
|
||||
const innerLength = (innerMiterRatio * strokeWidth) / 2 - r2 - r1;
|
||||
return 2 * Math.max(bevelAdd, innerLength);
|
||||
}
|
||||
return bevelAdd * 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {RenderOptions} The render options
|
||||
* @protected
|
||||
*/
|
||||
createRenderOptions() {
|
||||
let lineJoin = defaultLineJoin;
|
||||
let miterLimit = 0;
|
||||
let lineDash = null;
|
||||
let lineDashOffset = 0;
|
||||
let strokeStyle;
|
||||
let strokeWidth = 0;
|
||||
|
||||
if (this.stroke_) {
|
||||
strokeStyle = this.stroke_.getColor();
|
||||
if (strokeStyle === null) {
|
||||
strokeStyle = defaultStrokeStyle;
|
||||
}
|
||||
strokeStyle = asColorLike(strokeStyle);
|
||||
strokeWidth = this.stroke_.getWidth();
|
||||
if (strokeWidth === undefined) {
|
||||
strokeWidth = defaultLineWidth;
|
||||
}
|
||||
lineDash = this.stroke_.getLineDash();
|
||||
lineDashOffset = this.stroke_.getLineDashOffset();
|
||||
lineJoin = this.stroke_.getLineJoin();
|
||||
if (lineJoin === undefined) {
|
||||
lineJoin = defaultLineJoin;
|
||||
}
|
||||
miterLimit = this.stroke_.getMiterLimit();
|
||||
if (miterLimit === undefined) {
|
||||
miterLimit = defaultMiterLimit;
|
||||
}
|
||||
}
|
||||
|
||||
const add = this.calculateLineJoinSize_(lineJoin, strokeWidth, miterLimit);
|
||||
const maxRadius = Math.max(this.radius_, this.radius2_ || 0);
|
||||
const size = Math.ceil(2 * maxRadius + add);
|
||||
|
||||
return {
|
||||
strokeStyle: strokeStyle,
|
||||
strokeWidth: strokeWidth,
|
||||
size: size,
|
||||
lineDash: lineDash,
|
||||
lineDashOffset: lineDashOffset,
|
||||
lineJoin: lineJoin,
|
||||
miterLimit: miterLimit,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @protected
|
||||
*/
|
||||
render() {
|
||||
this.renderOptions_ = this.createRenderOptions();
|
||||
const size = this.renderOptions_.size;
|
||||
this.canvas_ = {};
|
||||
this.size_ = [size, size];
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {RenderOptions} renderOptions Render options.
|
||||
* @param {CanvasRenderingContext2D} context The rendering context.
|
||||
* @param {number} pixelRatio The pixel ratio.
|
||||
*/
|
||||
draw_(renderOptions, context, pixelRatio) {
|
||||
context.scale(pixelRatio, pixelRatio);
|
||||
// set origin to canvas center
|
||||
context.translate(renderOptions.size / 2, renderOptions.size / 2);
|
||||
|
||||
this.createPath_(context);
|
||||
|
||||
if (this.fill_) {
|
||||
let color = this.fill_.getColor();
|
||||
if (color === null) {
|
||||
color = defaultFillStyle;
|
||||
}
|
||||
context.fillStyle = asColorLike(color);
|
||||
context.fill();
|
||||
}
|
||||
if (this.stroke_) {
|
||||
context.strokeStyle = renderOptions.strokeStyle;
|
||||
context.lineWidth = renderOptions.strokeWidth;
|
||||
if (context.setLineDash && renderOptions.lineDash) {
|
||||
context.setLineDash(renderOptions.lineDash);
|
||||
context.lineDashOffset = renderOptions.lineDashOffset;
|
||||
}
|
||||
context.lineJoin = renderOptions.lineJoin;
|
||||
context.miterLimit = renderOptions.miterLimit;
|
||||
context.stroke();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {RenderOptions} renderOptions Render options.
|
||||
*/
|
||||
createHitDetectionCanvas_(renderOptions) {
|
||||
if (this.fill_) {
|
||||
let color = this.fill_.getColor();
|
||||
|
||||
// determine if fill is transparent (or pattern or gradient)
|
||||
let opacity = 0;
|
||||
if (typeof color === 'string') {
|
||||
color = asArray(color);
|
||||
}
|
||||
if (color === null) {
|
||||
opacity = 1;
|
||||
} else if (Array.isArray(color)) {
|
||||
opacity = color.length === 4 ? color[3] : 1;
|
||||
}
|
||||
if (opacity === 0) {
|
||||
// if a transparent fill style is set, create an extra hit-detection image
|
||||
// with a default fill style
|
||||
const context = createCanvasContext2D(
|
||||
renderOptions.size,
|
||||
renderOptions.size
|
||||
);
|
||||
this.hitDetectionCanvas_ = context.canvas;
|
||||
|
||||
this.drawHitDetectionCanvas_(renderOptions, context);
|
||||
}
|
||||
}
|
||||
if (!this.hitDetectionCanvas_) {
|
||||
this.hitDetectionCanvas_ = this.getImage(1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {CanvasRenderingContext2D} context The context to draw in.
|
||||
*/
|
||||
createPath_(context) {
|
||||
let points = this.points_;
|
||||
const radius = this.radius_;
|
||||
if (points === Infinity) {
|
||||
context.arc(0, 0, radius, 0, 2 * Math.PI);
|
||||
} else {
|
||||
const radius2 = this.radius2_ === undefined ? radius : this.radius2_;
|
||||
if (this.radius2_ !== undefined) {
|
||||
points *= 2;
|
||||
}
|
||||
const startAngle = this.angle_ - Math.PI / 2;
|
||||
const step = (2 * Math.PI) / points;
|
||||
for (let i = 0; i < points; i++) {
|
||||
const angle0 = startAngle + i * step;
|
||||
const radiusC = i % 2 === 0 ? radius : radius2;
|
||||
context.lineTo(radiusC * Math.cos(angle0), radiusC * Math.sin(angle0));
|
||||
}
|
||||
context.closePath();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {RenderOptions} renderOptions Render options.
|
||||
* @param {CanvasRenderingContext2D} context The context.
|
||||
*/
|
||||
drawHitDetectionCanvas_(renderOptions, context) {
|
||||
// set origin to canvas center
|
||||
context.translate(renderOptions.size / 2, renderOptions.size / 2);
|
||||
|
||||
this.createPath_(context);
|
||||
|
||||
context.fillStyle = defaultFillStyle;
|
||||
context.fill();
|
||||
if (this.stroke_) {
|
||||
context.strokeStyle = renderOptions.strokeStyle;
|
||||
context.lineWidth = renderOptions.strokeWidth;
|
||||
if (renderOptions.lineDash) {
|
||||
context.setLineDash(renderOptions.lineDash);
|
||||
context.lineDashOffset = renderOptions.lineDashOffset;
|
||||
}
|
||||
context.lineJoin = renderOptions.lineJoin;
|
||||
context.miterLimit = renderOptions.miterLimit;
|
||||
context.stroke();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default RegularShape;
|
||||
236
node_modules/ol/src/style/Stroke.js
generated
vendored
Normal file
236
node_modules/ol/src/style/Stroke.js
generated
vendored
Normal file
@@ -0,0 +1,236 @@
|
||||
/**
|
||||
* @module ol/style/Stroke
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
* @property {import("../color.js").Color|import("../colorlike.js").ColorLike} [color] A color, gradient or pattern.
|
||||
* See {@link module:ol/color~Color} and {@link module:ol/colorlike~ColorLike} for possible formats.
|
||||
* Default null; if null, the Canvas/renderer default black will be used.
|
||||
* @property {CanvasLineCap} [lineCap='round'] Line cap style: `butt`, `round`, or `square`.
|
||||
* @property {CanvasLineJoin} [lineJoin='round'] Line join style: `bevel`, `round`, or `miter`.
|
||||
* @property {Array<number>} [lineDash] Line dash pattern. Default is `null` (no dash).
|
||||
* Please note that Internet Explorer 10 and lower do not support the `setLineDash` method on
|
||||
* the `CanvasRenderingContext2D` and therefore this option will have no visual effect in these browsers.
|
||||
* @property {number} [lineDashOffset=0] Line dash offset.
|
||||
* @property {number} [miterLimit=10] Miter limit.
|
||||
* @property {number} [width] Width.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Set stroke style for vector features.
|
||||
* Note that the defaults given are the Canvas defaults, which will be used if
|
||||
* option is not defined. The `get` functions return whatever was entered in
|
||||
* the options; they will not return the default.
|
||||
* @api
|
||||
*/
|
||||
class Stroke {
|
||||
/**
|
||||
* @param {Options} [opt_options] Options.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
const options = opt_options || {};
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("../color.js").Color|import("../colorlike.js").ColorLike}
|
||||
*/
|
||||
this.color_ = options.color !== undefined ? options.color : null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {CanvasLineCap|undefined}
|
||||
*/
|
||||
this.lineCap_ = options.lineCap;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array<number>}
|
||||
*/
|
||||
this.lineDash_ = options.lineDash !== undefined ? options.lineDash : null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number|undefined}
|
||||
*/
|
||||
this.lineDashOffset_ = options.lineDashOffset;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {CanvasLineJoin|undefined}
|
||||
*/
|
||||
this.lineJoin_ = options.lineJoin;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number|undefined}
|
||||
*/
|
||||
this.miterLimit_ = options.miterLimit;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number|undefined}
|
||||
*/
|
||||
this.width_ = options.width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clones the style.
|
||||
* @return {Stroke} The cloned style.
|
||||
* @api
|
||||
*/
|
||||
clone() {
|
||||
const color = this.getColor();
|
||||
return new Stroke({
|
||||
color: Array.isArray(color) ? color.slice() : color || undefined,
|
||||
lineCap: this.getLineCap(),
|
||||
lineDash: this.getLineDash() ? this.getLineDash().slice() : undefined,
|
||||
lineDashOffset: this.getLineDashOffset(),
|
||||
lineJoin: this.getLineJoin(),
|
||||
miterLimit: this.getMiterLimit(),
|
||||
width: this.getWidth(),
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the stroke color.
|
||||
* @return {import("../color.js").Color|import("../colorlike.js").ColorLike} Color.
|
||||
* @api
|
||||
*/
|
||||
getColor() {
|
||||
return this.color_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line cap type for the stroke.
|
||||
* @return {CanvasLineCap|undefined} Line cap.
|
||||
* @api
|
||||
*/
|
||||
getLineCap() {
|
||||
return this.lineCap_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line dash style for the stroke.
|
||||
* @return {Array<number>} Line dash.
|
||||
* @api
|
||||
*/
|
||||
getLineDash() {
|
||||
return this.lineDash_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line dash offset for the stroke.
|
||||
* @return {number|undefined} Line dash offset.
|
||||
* @api
|
||||
*/
|
||||
getLineDashOffset() {
|
||||
return this.lineDashOffset_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the line join type for the stroke.
|
||||
* @return {CanvasLineJoin|undefined} Line join.
|
||||
* @api
|
||||
*/
|
||||
getLineJoin() {
|
||||
return this.lineJoin_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the miter limit for the stroke.
|
||||
* @return {number|undefined} Miter limit.
|
||||
* @api
|
||||
*/
|
||||
getMiterLimit() {
|
||||
return this.miterLimit_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the stroke width.
|
||||
* @return {number|undefined} Width.
|
||||
* @api
|
||||
*/
|
||||
getWidth() {
|
||||
return this.width_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the color.
|
||||
*
|
||||
* @param {import("../color.js").Color|import("../colorlike.js").ColorLike} color Color.
|
||||
* @api
|
||||
*/
|
||||
setColor(color) {
|
||||
this.color_ = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the line cap.
|
||||
*
|
||||
* @param {CanvasLineCap|undefined} lineCap Line cap.
|
||||
* @api
|
||||
*/
|
||||
setLineCap(lineCap) {
|
||||
this.lineCap_ = lineCap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the line dash.
|
||||
*
|
||||
* Please note that Internet Explorer 10 and lower [do not support][mdn] the
|
||||
* `setLineDash` method on the `CanvasRenderingContext2D` and therefore this
|
||||
* property will have no visual effect in these browsers.
|
||||
*
|
||||
* [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/setLineDash#Browser_compatibility
|
||||
*
|
||||
* @param {Array<number>} lineDash Line dash.
|
||||
* @api
|
||||
*/
|
||||
setLineDash(lineDash) {
|
||||
this.lineDash_ = lineDash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the line dash offset.
|
||||
*
|
||||
* @param {number|undefined} lineDashOffset Line dash offset.
|
||||
* @api
|
||||
*/
|
||||
setLineDashOffset(lineDashOffset) {
|
||||
this.lineDashOffset_ = lineDashOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the line join.
|
||||
*
|
||||
* @param {CanvasLineJoin|undefined} lineJoin Line join.
|
||||
* @api
|
||||
*/
|
||||
setLineJoin(lineJoin) {
|
||||
this.lineJoin_ = lineJoin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the miter limit.
|
||||
*
|
||||
* @param {number|undefined} miterLimit Miter limit.
|
||||
* @api
|
||||
*/
|
||||
setMiterLimit(miterLimit) {
|
||||
this.miterLimit_ = miterLimit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the width.
|
||||
*
|
||||
* @param {number|undefined} width Width.
|
||||
* @api
|
||||
*/
|
||||
setWidth(width) {
|
||||
this.width_ = width;
|
||||
}
|
||||
}
|
||||
|
||||
export default Stroke;
|
||||
566
node_modules/ol/src/style/Style.js
generated
vendored
Normal file
566
node_modules/ol/src/style/Style.js
generated
vendored
Normal file
@@ -0,0 +1,566 @@
|
||||
/**
|
||||
* @module ol/style/Style
|
||||
*/
|
||||
|
||||
import CircleStyle from './Circle.js';
|
||||
import Fill from './Fill.js';
|
||||
import Stroke from './Stroke.js';
|
||||
import {assert} from '../asserts.js';
|
||||
|
||||
/**
|
||||
* A function that takes an {@link module:ol/Feature~Feature} and a `{number}`
|
||||
* representing the view's resolution. The function should return a
|
||||
* {@link module:ol/style/Style~Style} or an array of them. This way e.g. a
|
||||
* vector layer can be styled. If the function returns `undefined`, the
|
||||
* feature will not be rendered.
|
||||
*
|
||||
* @typedef {function(import("../Feature.js").FeatureLike, number):(Style|Array<Style>|void)} StyleFunction
|
||||
*/
|
||||
|
||||
/**
|
||||
* A {@link Style}, an array of {@link Style}, or a {@link StyleFunction}.
|
||||
* @typedef {Style|Array<Style>|StyleFunction} StyleLike
|
||||
*/
|
||||
|
||||
/**
|
||||
* A function that takes an {@link module:ol/Feature~Feature} as argument and returns an
|
||||
* {@link module:ol/geom/Geometry~Geometry} that will be rendered and styled for the feature.
|
||||
*
|
||||
* @typedef {function(import("../Feature.js").FeatureLike):
|
||||
* (import("../geom/Geometry.js").default|import("../render/Feature.js").default|undefined)} GeometryFunction
|
||||
*/
|
||||
|
||||
/**
|
||||
* Custom renderer function. Takes two arguments:
|
||||
*
|
||||
* 1. The pixel coordinates of the geometry in GeoJSON notation.
|
||||
* 2. The {@link module:ol/render~State} of the layer renderer.
|
||||
*
|
||||
* @typedef {function((import("../coordinate.js").Coordinate|Array<import("../coordinate.js").Coordinate>|Array<Array<import("../coordinate.js").Coordinate>>),import("../render.js").State): void} RenderFunction
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
* @property {string|import("../geom/Geometry.js").default|GeometryFunction} [geometry] Feature property or geometry
|
||||
* or function returning a geometry to render for this style.
|
||||
* @property {import("./Fill.js").default} [fill] Fill style.
|
||||
* @property {import("./Image.js").default} [image] Image style.
|
||||
* @property {RenderFunction} [renderer] Custom renderer. When configured, `fill`, `stroke` and `image` will be
|
||||
* ignored, and the provided function will be called with each render frame for each geometry.
|
||||
* @property {RenderFunction} [hitDetectionRenderer] Custom renderer for hit detection. If provided will be used
|
||||
* in hit detection rendering.
|
||||
* @property {import("./Stroke.js").default} [stroke] Stroke style.
|
||||
* @property {import("./Text.js").default} [text] Text style.
|
||||
* @property {number} [zIndex] Z index.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Container for vector feature rendering styles. Any changes made to the style
|
||||
* or its children through `set*()` methods will not take effect until the
|
||||
* feature or layer that uses the style is re-rendered.
|
||||
*
|
||||
* ## Feature styles
|
||||
*
|
||||
* If no style is defined, the following default style is used:
|
||||
* ```js
|
||||
* import {Circle, Fill, Stroke, Style} from 'ol/style';
|
||||
*
|
||||
* const fill = new Fill({
|
||||
* color: 'rgba(255,255,255,0.4)',
|
||||
* });
|
||||
* const stroke = new Stroke({
|
||||
* color: '#3399CC',
|
||||
* width: 1.25,
|
||||
* });
|
||||
* const styles = [
|
||||
* new Style({
|
||||
* image: new Circle({
|
||||
* fill: fill,
|
||||
* stroke: stroke,
|
||||
* radius: 5,
|
||||
* }),
|
||||
* fill: fill,
|
||||
* stroke: stroke,
|
||||
* }),
|
||||
* ];
|
||||
* ```
|
||||
*
|
||||
* A separate editing style has the following defaults:
|
||||
* ```js
|
||||
* import {Circle, Fill, Stroke, Style} from 'ol/style';
|
||||
*
|
||||
* const styles = {};
|
||||
* const white = [255, 255, 255, 1];
|
||||
* const blue = [0, 153, 255, 1];
|
||||
* const width = 3;
|
||||
* styles['Polygon'] = [
|
||||
* new Style({
|
||||
* fill: new Fill({
|
||||
* color: [255, 255, 255, 0.5],
|
||||
* }),
|
||||
* }),
|
||||
* ];
|
||||
* styles['MultiPolygon'] =
|
||||
* styles['Polygon'];
|
||||
* styles['LineString'] = [
|
||||
* new Style({
|
||||
* stroke: new Stroke({
|
||||
* color: white,
|
||||
* width: width + 2,
|
||||
* }),
|
||||
* }),
|
||||
* new Style({
|
||||
* stroke: new Stroke({
|
||||
* color: blue,
|
||||
* width: width,
|
||||
* }),
|
||||
* }),
|
||||
* ];
|
||||
* styles['MultiLineString'] = styles['LineString'];
|
||||
*
|
||||
* styles['Circle'] = styles['Polygon'].concat(
|
||||
* styles['LineString']
|
||||
* );
|
||||
*
|
||||
* styles['Point'] = [
|
||||
* new Style({
|
||||
* image: new Circle({
|
||||
* radius: width * 2,
|
||||
* fill: new Fill({
|
||||
* color: blue,
|
||||
* }),
|
||||
* stroke: new Stroke({
|
||||
* color: white,
|
||||
* width: width / 2,
|
||||
* }),
|
||||
* }),
|
||||
* zIndex: Infinity,
|
||||
* }),
|
||||
* ];
|
||||
* styles['MultiPoint'] =
|
||||
* styles['Point'];
|
||||
* styles['GeometryCollection'] =
|
||||
* styles['Polygon'].concat(
|
||||
* styles['LineString'],
|
||||
* styles['Point']
|
||||
* );
|
||||
* ```
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
class Style {
|
||||
/**
|
||||
* @param {Options} [opt_options] Style options.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
const options = opt_options || {};
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string|import("../geom/Geometry.js").default|GeometryFunction}
|
||||
*/
|
||||
this.geometry_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {!GeometryFunction}
|
||||
*/
|
||||
this.geometryFunction_ = defaultGeometryFunction;
|
||||
|
||||
if (options.geometry !== undefined) {
|
||||
this.setGeometry(options.geometry);
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("./Fill.js").default}
|
||||
*/
|
||||
this.fill_ = options.fill !== undefined ? options.fill : null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("./Image.js").default}
|
||||
*/
|
||||
this.image_ = options.image !== undefined ? options.image : null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {RenderFunction|null}
|
||||
*/
|
||||
this.renderer_ = options.renderer !== undefined ? options.renderer : null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {RenderFunction|null}
|
||||
*/
|
||||
this.hitDetectionRenderer_ =
|
||||
options.hitDetectionRenderer !== undefined
|
||||
? options.hitDetectionRenderer
|
||||
: null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("./Stroke.js").default}
|
||||
*/
|
||||
this.stroke_ = options.stroke !== undefined ? options.stroke : null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("./Text.js").default}
|
||||
*/
|
||||
this.text_ = options.text !== undefined ? options.text : null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number|undefined}
|
||||
*/
|
||||
this.zIndex_ = options.zIndex;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clones the style.
|
||||
* @return {Style} The cloned style.
|
||||
* @api
|
||||
*/
|
||||
clone() {
|
||||
let geometry = this.getGeometry();
|
||||
if (geometry && typeof geometry === 'object') {
|
||||
geometry = /** @type {import("../geom/Geometry.js").default} */ (
|
||||
geometry
|
||||
).clone();
|
||||
}
|
||||
return new Style({
|
||||
geometry: geometry,
|
||||
fill: this.getFill() ? this.getFill().clone() : undefined,
|
||||
image: this.getImage() ? this.getImage().clone() : undefined,
|
||||
renderer: this.getRenderer(),
|
||||
stroke: this.getStroke() ? this.getStroke().clone() : undefined,
|
||||
text: this.getText() ? this.getText().clone() : undefined,
|
||||
zIndex: this.getZIndex(),
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the custom renderer function that was configured with
|
||||
* {@link #setRenderer} or the `renderer` constructor option.
|
||||
* @return {RenderFunction|null} Custom renderer function.
|
||||
* @api
|
||||
*/
|
||||
getRenderer() {
|
||||
return this.renderer_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a custom renderer function for this style. When set, `fill`, `stroke`
|
||||
* and `image` options of the style will be ignored.
|
||||
* @param {RenderFunction|null} renderer Custom renderer function.
|
||||
* @api
|
||||
*/
|
||||
setRenderer(renderer) {
|
||||
this.renderer_ = renderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a custom renderer function for this style used
|
||||
* in hit detection.
|
||||
* @param {RenderFunction|null} renderer Custom renderer function.
|
||||
* @api
|
||||
*/
|
||||
setHitDetectionRenderer(renderer) {
|
||||
this.hitDetectionRenderer_ = renderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the custom renderer function that was configured with
|
||||
* {@link #setHitDetectionRenderer} or the `hitDetectionRenderer` constructor option.
|
||||
* @return {RenderFunction|null} Custom renderer function.
|
||||
* @api
|
||||
*/
|
||||
getHitDetectionRenderer() {
|
||||
return this.hitDetectionRenderer_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the geometry to be rendered.
|
||||
* @return {string|import("../geom/Geometry.js").default|GeometryFunction}
|
||||
* Feature property or geometry or function that returns the geometry that will
|
||||
* be rendered with this style.
|
||||
* @api
|
||||
*/
|
||||
getGeometry() {
|
||||
return this.geometry_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the function used to generate a geometry for rendering.
|
||||
* @return {!GeometryFunction} Function that is called with a feature
|
||||
* and returns the geometry to render instead of the feature's geometry.
|
||||
* @api
|
||||
*/
|
||||
getGeometryFunction() {
|
||||
return this.geometryFunction_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the fill style.
|
||||
* @return {import("./Fill.js").default} Fill style.
|
||||
* @api
|
||||
*/
|
||||
getFill() {
|
||||
return this.fill_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the fill style.
|
||||
* @param {import("./Fill.js").default} fill Fill style.
|
||||
* @api
|
||||
*/
|
||||
setFill(fill) {
|
||||
this.fill_ = fill;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the image style.
|
||||
* @return {import("./Image.js").default} Image style.
|
||||
* @api
|
||||
*/
|
||||
getImage() {
|
||||
return this.image_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the image style.
|
||||
* @param {import("./Image.js").default} image Image style.
|
||||
* @api
|
||||
*/
|
||||
setImage(image) {
|
||||
this.image_ = image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the stroke style.
|
||||
* @return {import("./Stroke.js").default} Stroke style.
|
||||
* @api
|
||||
*/
|
||||
getStroke() {
|
||||
return this.stroke_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the stroke style.
|
||||
* @param {import("./Stroke.js").default} stroke Stroke style.
|
||||
* @api
|
||||
*/
|
||||
setStroke(stroke) {
|
||||
this.stroke_ = stroke;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the text style.
|
||||
* @return {import("./Text.js").default} Text style.
|
||||
* @api
|
||||
*/
|
||||
getText() {
|
||||
return this.text_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the text style.
|
||||
* @param {import("./Text.js").default} text Text style.
|
||||
* @api
|
||||
*/
|
||||
setText(text) {
|
||||
this.text_ = text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the z-index for the style.
|
||||
* @return {number|undefined} ZIndex.
|
||||
* @api
|
||||
*/
|
||||
getZIndex() {
|
||||
return this.zIndex_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a geometry that is rendered instead of the feature's geometry.
|
||||
*
|
||||
* @param {string|import("../geom/Geometry.js").default|GeometryFunction} geometry
|
||||
* Feature property or geometry or function returning a geometry to render
|
||||
* for this style.
|
||||
* @api
|
||||
*/
|
||||
setGeometry(geometry) {
|
||||
if (typeof geometry === 'function') {
|
||||
this.geometryFunction_ = geometry;
|
||||
} else if (typeof geometry === 'string') {
|
||||
this.geometryFunction_ = function (feature) {
|
||||
return /** @type {import("../geom/Geometry.js").default} */ (
|
||||
feature.get(geometry)
|
||||
);
|
||||
};
|
||||
} else if (!geometry) {
|
||||
this.geometryFunction_ = defaultGeometryFunction;
|
||||
} else if (geometry !== undefined) {
|
||||
this.geometryFunction_ = function () {
|
||||
return /** @type {import("../geom/Geometry.js").default} */ (geometry);
|
||||
};
|
||||
}
|
||||
this.geometry_ = geometry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the z-index.
|
||||
*
|
||||
* @param {number|undefined} zIndex ZIndex.
|
||||
* @api
|
||||
*/
|
||||
setZIndex(zIndex) {
|
||||
this.zIndex_ = zIndex;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the provided object into a style function. Functions passed through
|
||||
* unchanged. Arrays of Style or single style objects wrapped in a
|
||||
* new style function.
|
||||
* @param {StyleFunction|Array<Style>|Style} obj
|
||||
* A style function, a single style, or an array of styles.
|
||||
* @return {StyleFunction} A style function.
|
||||
*/
|
||||
export function toFunction(obj) {
|
||||
let styleFunction;
|
||||
|
||||
if (typeof obj === 'function') {
|
||||
styleFunction = obj;
|
||||
} else {
|
||||
/**
|
||||
* @type {Array<Style>}
|
||||
*/
|
||||
let styles;
|
||||
if (Array.isArray(obj)) {
|
||||
styles = obj;
|
||||
} else {
|
||||
assert(typeof (/** @type {?} */ (obj).getZIndex) === 'function', 41); // Expected an `Style` or an array of `Style`
|
||||
const style = /** @type {Style} */ (obj);
|
||||
styles = [style];
|
||||
}
|
||||
styleFunction = function () {
|
||||
return styles;
|
||||
};
|
||||
}
|
||||
return styleFunction;
|
||||
}
|
||||
|
||||
/**
|
||||
* @type {Array<Style>|null}
|
||||
*/
|
||||
let defaultStyles = null;
|
||||
|
||||
/**
|
||||
* @param {import("../Feature.js").FeatureLike} feature Feature.
|
||||
* @param {number} resolution Resolution.
|
||||
* @return {Array<Style>} Style.
|
||||
*/
|
||||
export function createDefaultStyle(feature, resolution) {
|
||||
// We don't use an immediately-invoked function
|
||||
// and a closure so we don't get an error at script evaluation time in
|
||||
// browsers that do not support Canvas. (import("./Circle.js").CircleStyle does
|
||||
// canvas.getContext('2d') at construction time, which will cause an.error
|
||||
// in such browsers.)
|
||||
if (!defaultStyles) {
|
||||
const fill = new Fill({
|
||||
color: 'rgba(255,255,255,0.4)',
|
||||
});
|
||||
const stroke = new Stroke({
|
||||
color: '#3399CC',
|
||||
width: 1.25,
|
||||
});
|
||||
defaultStyles = [
|
||||
new Style({
|
||||
image: new CircleStyle({
|
||||
fill: fill,
|
||||
stroke: stroke,
|
||||
radius: 5,
|
||||
}),
|
||||
fill: fill,
|
||||
stroke: stroke,
|
||||
}),
|
||||
];
|
||||
}
|
||||
return defaultStyles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default styles for editing features.
|
||||
* @return {Object<import("../geom/Geometry.js").Type, Array<Style>>} Styles
|
||||
*/
|
||||
export function createEditingStyle() {
|
||||
/** @type {Object<import("../geom/Geometry.js").Type, Array<Style>>} */
|
||||
const styles = {};
|
||||
const white = [255, 255, 255, 1];
|
||||
const blue = [0, 153, 255, 1];
|
||||
const width = 3;
|
||||
styles['Polygon'] = [
|
||||
new Style({
|
||||
fill: new Fill({
|
||||
color: [255, 255, 255, 0.5],
|
||||
}),
|
||||
}),
|
||||
];
|
||||
styles['MultiPolygon'] = styles['Polygon'];
|
||||
|
||||
styles['LineString'] = [
|
||||
new Style({
|
||||
stroke: new Stroke({
|
||||
color: white,
|
||||
width: width + 2,
|
||||
}),
|
||||
}),
|
||||
new Style({
|
||||
stroke: new Stroke({
|
||||
color: blue,
|
||||
width: width,
|
||||
}),
|
||||
}),
|
||||
];
|
||||
styles['MultiLineString'] = styles['LineString'];
|
||||
|
||||
styles['Circle'] = styles['Polygon'].concat(styles['LineString']);
|
||||
|
||||
styles['Point'] = [
|
||||
new Style({
|
||||
image: new CircleStyle({
|
||||
radius: width * 2,
|
||||
fill: new Fill({
|
||||
color: blue,
|
||||
}),
|
||||
stroke: new Stroke({
|
||||
color: white,
|
||||
width: width / 2,
|
||||
}),
|
||||
}),
|
||||
zIndex: Infinity,
|
||||
}),
|
||||
];
|
||||
styles['MultiPoint'] = styles['Point'];
|
||||
|
||||
styles['GeometryCollection'] = styles['Polygon'].concat(
|
||||
styles['LineString'],
|
||||
styles['Point']
|
||||
);
|
||||
|
||||
return styles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function that is called with a feature and returns its default geometry.
|
||||
* @param {import("../Feature.js").FeatureLike} feature Feature to get the geometry for.
|
||||
* @return {import("../geom/Geometry.js").default|import("../render/Feature.js").default|undefined} Geometry to render.
|
||||
*/
|
||||
function defaultGeometryFunction(feature) {
|
||||
return feature.getGeometry();
|
||||
}
|
||||
|
||||
export default Style;
|
||||
575
node_modules/ol/src/style/Text.js
generated
vendored
Normal file
575
node_modules/ol/src/style/Text.js
generated
vendored
Normal file
@@ -0,0 +1,575 @@
|
||||
/**
|
||||
* @module ol/style/Text
|
||||
*/
|
||||
import Fill from './Fill.js';
|
||||
import TextPlacement from './TextPlacement.js';
|
||||
import {toSize} from '../size.js';
|
||||
|
||||
/**
|
||||
* The default fill color to use if no fill was set at construction time; a
|
||||
* blackish `#333`.
|
||||
*
|
||||
* @const {string}
|
||||
*/
|
||||
const DEFAULT_FILL_COLOR = '#333';
|
||||
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
* @property {string} [font] Font style as CSS 'font' value, see:
|
||||
* https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/font. Default is '10px sans-serif'
|
||||
* @property {number} [maxAngle=Math.PI/4] When `placement` is set to `'line'`, allow a maximum angle between adjacent characters.
|
||||
* The expected value is in radians, and the default is 45° (`Math.PI / 4`).
|
||||
* @property {number} [offsetX=0] Horizontal text offset in pixels. A positive will shift the text right.
|
||||
* @property {number} [offsetY=0] Vertical text offset in pixels. A positive will shift the text down.
|
||||
* @property {boolean} [overflow=false] For polygon labels or when `placement` is set to `'line'`, allow text to exceed
|
||||
* the width of the polygon at the label position or the length of the path that it follows.
|
||||
* @property {import("./TextPlacement.js").default|string} [placement='point'] Text placement.
|
||||
* @property {number|import("../size.js").Size} [scale] Scale.
|
||||
* @property {boolean} [rotateWithView=false] Whether to rotate the text with the view.
|
||||
* @property {number} [rotation=0] Rotation in radians (positive rotation clockwise).
|
||||
* @property {string|Array<string>} [text] Text content or rich text content. For plain text provide a string, which can
|
||||
* contain line breaks (`\n`). For rich text provide an array of text/font tuples. A tuple consists of the text to
|
||||
* render and the font to use (or `''` to use the text style's font). A line break has to be a separate tuple (i.e. `'\n', ''`).
|
||||
* **Example:** `['foo', 'bold 10px sans-serif', ' bar', 'italic 10px sans-serif', ' baz', '']` will yield "**foo** *bar* baz".
|
||||
* **Note:** Rich text is not supported for the immediate rendering API.
|
||||
* @property {string} [textAlign] Text alignment. Possible values: 'left', 'right', 'center', 'end' or 'start'.
|
||||
* Default is 'center' for `placement: 'point'`. For `placement: 'line'`, the default is to let the renderer choose a
|
||||
* placement where `maxAngle` is not exceeded.
|
||||
* @property {string} [justify] Text justification within the text box.
|
||||
* If not set, text is justified towards the `textAlign` anchor.
|
||||
* Otherwise, use options `'left'`, `'center'`, or `'right'` to justify the text within the text box.
|
||||
* **Note:** `justify` is ignored for immediate rendering and also for `placement: 'line'`.
|
||||
* @property {string} [textBaseline='middle'] Text base line. Possible values: 'bottom', 'top', 'middle', 'alphabetic',
|
||||
* 'hanging', 'ideographic'.
|
||||
* @property {import("./Fill.js").default} [fill] Fill style. If none is provided, we'll use a dark fill-style (#333).
|
||||
* @property {import("./Stroke.js").default} [stroke] Stroke style.
|
||||
* @property {import("./Fill.js").default} [backgroundFill] Fill style for the text background when `placement` is
|
||||
* `'point'`. Default is no fill.
|
||||
* @property {import("./Stroke.js").default} [backgroundStroke] Stroke style for the text background when `placement`
|
||||
* is `'point'`. Default is no stroke.
|
||||
* @property {Array<number>} [padding=[0, 0, 0, 0]] Padding in pixels around the text for decluttering and background. The order of
|
||||
* values in the array is `[top, right, bottom, left]`.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Set text style for vector features.
|
||||
* @api
|
||||
*/
|
||||
class Text {
|
||||
/**
|
||||
* @param {Options} [opt_options] Options.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
const options = opt_options || {};
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string|undefined}
|
||||
*/
|
||||
this.font_ = options.font;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number|undefined}
|
||||
*/
|
||||
this.rotation_ = options.rotation;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean|undefined}
|
||||
*/
|
||||
this.rotateWithView_ = options.rotateWithView;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number|import("../size.js").Size|undefined}
|
||||
*/
|
||||
this.scale_ = options.scale;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("../size.js").Size}
|
||||
*/
|
||||
this.scaleArray_ = toSize(options.scale !== undefined ? options.scale : 1);
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string|Array<string>|undefined}
|
||||
*/
|
||||
this.text_ = options.text;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string|undefined}
|
||||
*/
|
||||
this.textAlign_ = options.textAlign;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string|undefined}
|
||||
*/
|
||||
this.justify_ = options.justify;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {string|undefined}
|
||||
*/
|
||||
this.textBaseline_ = options.textBaseline;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("./Fill.js").default}
|
||||
*/
|
||||
this.fill_ =
|
||||
options.fill !== undefined
|
||||
? options.fill
|
||||
: new Fill({color: DEFAULT_FILL_COLOR});
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.maxAngle_ =
|
||||
options.maxAngle !== undefined ? options.maxAngle : Math.PI / 4;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("./TextPlacement.js").default|string}
|
||||
*/
|
||||
this.placement_ =
|
||||
options.placement !== undefined ? options.placement : TextPlacement.POINT;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.overflow_ = !!options.overflow;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("./Stroke.js").default}
|
||||
*/
|
||||
this.stroke_ = options.stroke !== undefined ? options.stroke : null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.offsetX_ = options.offsetX !== undefined ? options.offsetX : 0;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
*/
|
||||
this.offsetY_ = options.offsetY !== undefined ? options.offsetY : 0;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("./Fill.js").default}
|
||||
*/
|
||||
this.backgroundFill_ = options.backgroundFill
|
||||
? options.backgroundFill
|
||||
: null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {import("./Stroke.js").default}
|
||||
*/
|
||||
this.backgroundStroke_ = options.backgroundStroke
|
||||
? options.backgroundStroke
|
||||
: null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array<number>|null}
|
||||
*/
|
||||
this.padding_ = options.padding === undefined ? null : options.padding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clones the style.
|
||||
* @return {Text} The cloned style.
|
||||
* @api
|
||||
*/
|
||||
clone() {
|
||||
const scale = this.getScale();
|
||||
return new Text({
|
||||
font: this.getFont(),
|
||||
placement: this.getPlacement(),
|
||||
maxAngle: this.getMaxAngle(),
|
||||
overflow: this.getOverflow(),
|
||||
rotation: this.getRotation(),
|
||||
rotateWithView: this.getRotateWithView(),
|
||||
scale: Array.isArray(scale) ? scale.slice() : scale,
|
||||
text: this.getText(),
|
||||
textAlign: this.getTextAlign(),
|
||||
justify: this.getJustify(),
|
||||
textBaseline: this.getTextBaseline(),
|
||||
fill: this.getFill() ? this.getFill().clone() : undefined,
|
||||
stroke: this.getStroke() ? this.getStroke().clone() : undefined,
|
||||
offsetX: this.getOffsetX(),
|
||||
offsetY: this.getOffsetY(),
|
||||
backgroundFill: this.getBackgroundFill()
|
||||
? this.getBackgroundFill().clone()
|
||||
: undefined,
|
||||
backgroundStroke: this.getBackgroundStroke()
|
||||
? this.getBackgroundStroke().clone()
|
||||
: undefined,
|
||||
padding: this.getPadding() || undefined,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the `overflow` configuration.
|
||||
* @return {boolean} Let text overflow the length of the path they follow.
|
||||
* @api
|
||||
*/
|
||||
getOverflow() {
|
||||
return this.overflow_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the font name.
|
||||
* @return {string|undefined} Font.
|
||||
* @api
|
||||
*/
|
||||
getFont() {
|
||||
return this.font_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the maximum angle between adjacent characters.
|
||||
* @return {number} Angle in radians.
|
||||
* @api
|
||||
*/
|
||||
getMaxAngle() {
|
||||
return this.maxAngle_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the label placement.
|
||||
* @return {import("./TextPlacement.js").default|string} Text placement.
|
||||
* @api
|
||||
*/
|
||||
getPlacement() {
|
||||
return this.placement_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the x-offset for the text.
|
||||
* @return {number} Horizontal text offset.
|
||||
* @api
|
||||
*/
|
||||
getOffsetX() {
|
||||
return this.offsetX_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the y-offset for the text.
|
||||
* @return {number} Vertical text offset.
|
||||
* @api
|
||||
*/
|
||||
getOffsetY() {
|
||||
return this.offsetY_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the fill style for the text.
|
||||
* @return {import("./Fill.js").default} Fill style.
|
||||
* @api
|
||||
*/
|
||||
getFill() {
|
||||
return this.fill_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the text rotates with the map.
|
||||
* @return {boolean|undefined} Rotate with map.
|
||||
* @api
|
||||
*/
|
||||
getRotateWithView() {
|
||||
return this.rotateWithView_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the text rotation.
|
||||
* @return {number|undefined} Rotation.
|
||||
* @api
|
||||
*/
|
||||
getRotation() {
|
||||
return this.rotation_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the text scale.
|
||||
* @return {number|import("../size.js").Size|undefined} Scale.
|
||||
* @api
|
||||
*/
|
||||
getScale() {
|
||||
return this.scale_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the symbolizer scale array.
|
||||
* @return {import("../size.js").Size} Scale array.
|
||||
*/
|
||||
getScaleArray() {
|
||||
return this.scaleArray_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the stroke style for the text.
|
||||
* @return {import("./Stroke.js").default} Stroke style.
|
||||
* @api
|
||||
*/
|
||||
getStroke() {
|
||||
return this.stroke_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the text to be rendered.
|
||||
* @return {string|Array<string>|undefined} Text.
|
||||
* @api
|
||||
*/
|
||||
getText() {
|
||||
return this.text_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the text alignment.
|
||||
* @return {string|undefined} Text align.
|
||||
* @api
|
||||
*/
|
||||
getTextAlign() {
|
||||
return this.textAlign_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the justification.
|
||||
* @return {string|undefined} Justification.
|
||||
* @api
|
||||
*/
|
||||
getJustify() {
|
||||
return this.justify_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the text baseline.
|
||||
* @return {string|undefined} Text baseline.
|
||||
* @api
|
||||
*/
|
||||
getTextBaseline() {
|
||||
return this.textBaseline_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the background fill style for the text.
|
||||
* @return {import("./Fill.js").default} Fill style.
|
||||
* @api
|
||||
*/
|
||||
getBackgroundFill() {
|
||||
return this.backgroundFill_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the background stroke style for the text.
|
||||
* @return {import("./Stroke.js").default} Stroke style.
|
||||
* @api
|
||||
*/
|
||||
getBackgroundStroke() {
|
||||
return this.backgroundStroke_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the padding for the text.
|
||||
* @return {Array<number>|null} Padding.
|
||||
* @api
|
||||
*/
|
||||
getPadding() {
|
||||
return this.padding_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the `overflow` property.
|
||||
*
|
||||
* @param {boolean} overflow Let text overflow the path that it follows.
|
||||
* @api
|
||||
*/
|
||||
setOverflow(overflow) {
|
||||
this.overflow_ = overflow;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the font.
|
||||
*
|
||||
* @param {string|undefined} font Font.
|
||||
* @api
|
||||
*/
|
||||
setFont(font) {
|
||||
this.font_ = font;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the maximum angle between adjacent characters.
|
||||
*
|
||||
* @param {number} maxAngle Angle in radians.
|
||||
* @api
|
||||
*/
|
||||
setMaxAngle(maxAngle) {
|
||||
this.maxAngle_ = maxAngle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the x offset.
|
||||
*
|
||||
* @param {number} offsetX Horizontal text offset.
|
||||
* @api
|
||||
*/
|
||||
setOffsetX(offsetX) {
|
||||
this.offsetX_ = offsetX;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the y offset.
|
||||
*
|
||||
* @param {number} offsetY Vertical text offset.
|
||||
* @api
|
||||
*/
|
||||
setOffsetY(offsetY) {
|
||||
this.offsetY_ = offsetY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the text placement.
|
||||
*
|
||||
* @param {import("./TextPlacement.js").default|string} placement Placement.
|
||||
* @api
|
||||
*/
|
||||
setPlacement(placement) {
|
||||
this.placement_ = placement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether to rotate the text with the view.
|
||||
*
|
||||
* @param {boolean} rotateWithView Rotate with map.
|
||||
* @api
|
||||
*/
|
||||
setRotateWithView(rotateWithView) {
|
||||
this.rotateWithView_ = rotateWithView;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the fill.
|
||||
*
|
||||
* @param {import("./Fill.js").default} fill Fill style.
|
||||
* @api
|
||||
*/
|
||||
setFill(fill) {
|
||||
this.fill_ = fill;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the rotation.
|
||||
*
|
||||
* @param {number|undefined} rotation Rotation.
|
||||
* @api
|
||||
*/
|
||||
setRotation(rotation) {
|
||||
this.rotation_ = rotation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the scale.
|
||||
*
|
||||
* @param {number|import("../size.js").Size|undefined} scale Scale.
|
||||
* @api
|
||||
*/
|
||||
setScale(scale) {
|
||||
this.scale_ = scale;
|
||||
this.scaleArray_ = toSize(scale !== undefined ? scale : 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the stroke.
|
||||
*
|
||||
* @param {import("./Stroke.js").default} stroke Stroke style.
|
||||
* @api
|
||||
*/
|
||||
setStroke(stroke) {
|
||||
this.stroke_ = stroke;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the text.
|
||||
*
|
||||
* @param {string|Array<string>|undefined} text Text.
|
||||
* @api
|
||||
*/
|
||||
setText(text) {
|
||||
this.text_ = text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the text alignment.
|
||||
*
|
||||
* @param {string|undefined} textAlign Text align.
|
||||
* @api
|
||||
*/
|
||||
setTextAlign(textAlign) {
|
||||
this.textAlign_ = textAlign;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the justification.
|
||||
*
|
||||
* @param {string|undefined} justify Justification.
|
||||
* @api
|
||||
*/
|
||||
setJustify(justify) {
|
||||
this.justify_ = justify;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the text baseline.
|
||||
*
|
||||
* @param {string|undefined} textBaseline Text baseline.
|
||||
* @api
|
||||
*/
|
||||
setTextBaseline(textBaseline) {
|
||||
this.textBaseline_ = textBaseline;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the background fill.
|
||||
*
|
||||
* @param {import("./Fill.js").default} fill Fill style.
|
||||
* @api
|
||||
*/
|
||||
setBackgroundFill(fill) {
|
||||
this.backgroundFill_ = fill;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the background stroke.
|
||||
*
|
||||
* @param {import("./Stroke.js").default} stroke Stroke style.
|
||||
* @api
|
||||
*/
|
||||
setBackgroundStroke(stroke) {
|
||||
this.backgroundStroke_ = stroke;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the padding (`[top, right, bottom, left]`).
|
||||
*
|
||||
* @param {Array<number>|null} padding Padding.
|
||||
* @api
|
||||
*/
|
||||
setPadding(padding) {
|
||||
this.padding_ = padding;
|
||||
}
|
||||
}
|
||||
|
||||
export default Text;
|
||||
15
node_modules/ol/src/style/TextPlacement.js
generated
vendored
Normal file
15
node_modules/ol/src/style/TextPlacement.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* @module ol/style/TextPlacement
|
||||
*/
|
||||
|
||||
/**
|
||||
* Text placement. One of `'point'`, `'line'`. Default is `'point'`. Note that
|
||||
* `'line'` requires the underlying geometry to be a {@link module:ol/geom/LineString~LineString},
|
||||
* {@link module:ol/geom/Polygon~Polygon}, {@link module:ol/geom/MultiLineString~MultiLineString} or
|
||||
* {@link module:ol/geom/MultiPolygon~MultiPolygon}.
|
||||
* @enum {string}
|
||||
*/
|
||||
export default {
|
||||
POINT: 'point',
|
||||
LINE: 'line',
|
||||
};
|
||||
1045
node_modules/ol/src/style/expressions.js
generated
vendored
Normal file
1045
node_modules/ol/src/style/expressions.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
42
node_modules/ol/src/style/literal.js
generated
vendored
Normal file
42
node_modules/ol/src/style/literal.js
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* Literal style objects differ from standard styles in that they cannot
|
||||
* be functions and are made up of simple objects instead of classes.
|
||||
* @module ol/style/literal
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {import("./expressions.js").ExpressionValue} ExpressionValue
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} LiteralStyle
|
||||
* @property {ExpressionValue} [filter] Filter expression. If it resolves to a number strictly greater than 0, the
|
||||
* point will be displayed. If undefined, all points will show.
|
||||
* @property {Object<string, number>} [variables] Style variables; each variable must hold a number.
|
||||
* Note: **this object is meant to be mutated**: changes to the values will immediately be visible on the rendered features
|
||||
* @property {LiteralSymbolStyle} [symbol] Symbol representation.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @enum {string}
|
||||
*/
|
||||
export const SymbolType = {
|
||||
CIRCLE: 'circle',
|
||||
SQUARE: 'square',
|
||||
TRIANGLE: 'triangle',
|
||||
IMAGE: 'image',
|
||||
};
|
||||
|
||||
/**
|
||||
* @typedef {Object} LiteralSymbolStyle
|
||||
* @property {ExpressionValue|Array<ExpressionValue>} size Size, mandatory.
|
||||
* @property {SymbolType} symbolType Symbol type to use, either a regular shape or an image.
|
||||
* @property {string} [src] Path to the image to be used for the symbol. Only required with `symbolType: 'image'`.
|
||||
* @property {string} [crossOrigin='anonymous'] The `crossOrigin` attribute for loading `src`.
|
||||
* @property {import("../color.js").Color|Array<ExpressionValue>|string} [color='#FFFFFF'] Color used for the representation (either fill, line or symbol).
|
||||
* @property {ExpressionValue} [opacity=1] Opacity.
|
||||
* @property {ExpressionValue} [rotation=0] Symbol rotation in radians.
|
||||
* @property {Array<ExpressionValue, ExpressionValue>} [offset] Offset on X and Y axis for symbols. If not specified, the symbol will be centered.
|
||||
* @property {Array<ExpressionValue, ExpressionValue, ExpressionValue, ExpressionValue>} [textureCoord] Texture coordinates. If not specified, the whole texture will be used (range for 0 to 1 on both axes).
|
||||
* @property {boolean} [rotateWithView=false] Specify whether the symbol must rotate with the view or stay upwards.
|
||||
*/
|
||||
Reference in New Issue
Block a user