UNPKG

wind-layer

Version:

a openlayers ol bmap amap maptalks extension to windjs

1,378 lines (1,352 loc) 129 kB
/*! * author: sakitam-fdd <smilefdd@gmail.com> * wind-layer v0.1.2 * build-time: 2020-2-23 16:31 * LICENSE: MIT * (c) 2017-2020 https://sakitam-fdd.github.io/wind-layer */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('ol/layer'), require('ol')) : typeof define === 'function' && define.amd ? define(['ol/layer', 'ol'], factory) : (global = global || self, global.Ol6Windy = factory(global.ol.layer, global.ol)); }(this, function (layer, ol) { 'use strict'; /** * @module ol/util */ /** * @return {?} Any return. */ function abstract() { return /** @type {?} */ ((function () { throw new Error('Unimplemented abstract method.'); })()); } /** * Counter for getUid. * @type {number} * @private */ var uidCounter_ = 0; /** * Gets a unique ID for an object. This mutates the object so that further calls * with the same object as a parameter returns the same value. Unique IDs are generated * as a strictly increasing sequence. Adapted from goog.getUid. * * @param {Object} obj The object to get the unique ID for. * @return {string} The unique ID for the object. * @api */ function getUid(obj) { return obj.ol_uid || (obj.ol_uid = String(++uidCounter_)); } /** * OpenLayers version. * @type {string} */ var VERSION = '6.2.1'; var __extends = (undefined && undefined.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) { if (b.hasOwnProperty(p)) { d[p] = b[p]; } } }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); /** * Error object thrown when an assertion failed. This is an ECMA-262 Error, * extended with a `code` property. * See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error. */ var AssertionError = /** @class */ (function (_super) { __extends(AssertionError, _super); /** * @param {number} code Error code. */ function AssertionError(code) { var _this = this; var path = 'v' + VERSION.split('-')[0]; var message = 'Assertion failed. See https://openlayers.org/en/' + path + '/doc/errors/#' + code + ' for details.'; _this = _super.call(this, message) || this; /** * Error code. The meaning of the code can be found on * https://openlayers.org/en/latest/doc/errors/ (replace `latest` with * the version found in the OpenLayers script's header comment if a version * other than the latest is used). * @type {number} * @api */ _this.code = code; /** * @type {string} */ _this.name = 'AssertionError'; // Re-assign message, see https://github.com/Rich-Harris/buble/issues/40 _this.message = message; return _this; } return AssertionError; }(Error)); /** * @module ol/asserts */ /** * @param {*} assertion Assertion we expected to be truthy. * @param {number} errorCode Error code. */ function assert(assertion, errorCode) { if (!assertion) { throw new AssertionError(errorCode); } } /** * @module ol/extent/Corner */ /** * @module ol/extent/Relationship */ /** * @module ol/extent */ /** * @param {Array<number>} xs Xs. * @param {Array<number>} ys Ys. * @param {Extent=} opt_extent Destination extent. * @private * @return {Extent} Extent. */ function _boundingExtentXYs(xs, ys, opt_extent) { var minX = Math.min.apply(null, xs); var minY = Math.min.apply(null, ys); var maxX = Math.max.apply(null, xs); var maxY = Math.max.apply(null, ys); return createOrUpdate(minX, minY, maxX, maxY, opt_extent); } /** * Check if one extent contains another. * * An extent is deemed contained if it lies completely within the other extent, * including if they share one or more edges. * * @param {Extent} extent1 Extent 1. * @param {Extent} extent2 Extent 2. * @return {boolean} The second extent is contained by or on the edge of the * first. * @api */ function containsExtent(extent1, extent2) { return extent1[0] <= extent2[0] && extent2[2] <= extent1[2] && extent1[1] <= extent2[1] && extent2[3] <= extent1[3]; } /** * Create an empty extent. * @return {Extent} Empty extent. * @api */ function createEmpty() { return [Infinity, Infinity, -Infinity, -Infinity]; } /** * Create a new extent or update the provided extent. * @param {number} minX Minimum X. * @param {number} minY Minimum Y. * @param {number} maxX Maximum X. * @param {number} maxY Maximum Y. * @param {Extent=} opt_extent Destination extent. * @return {Extent} Extent. */ function createOrUpdate(minX, minY, maxX, maxY, opt_extent) { if (opt_extent) { opt_extent[0] = minX; opt_extent[1] = minY; opt_extent[2] = maxX; opt_extent[3] = maxY; return opt_extent; } else { return [minX, minY, maxX, maxY]; } } /** * Create a new empty extent or make the provided one empty. * @param {Extent=} opt_extent Extent. * @return {Extent} Extent. */ function createOrUpdateEmpty(opt_extent) { return createOrUpdate(Infinity, Infinity, -Infinity, -Infinity, opt_extent); } /** * Get the bottom left coordinate of an extent. * @param {Extent} extent Extent. * @return {import("./coordinate.js").Coordinate} Bottom left coordinate. * @api */ function getBottomLeft(extent) { return [extent[0], extent[1]]; } /** * Get the bottom right coordinate of an extent. * @param {Extent} extent Extent. * @return {import("./coordinate.js").Coordinate} Bottom right coordinate. * @api */ function getBottomRight(extent) { return [extent[2], extent[1]]; } /** * Get the intersection of two extents. * @param {Extent} extent1 Extent 1. * @param {Extent} extent2 Extent 2. * @param {Extent=} opt_extent Optional extent to populate with intersection. * @return {Extent} Intersecting extent. * @api */ function getIntersection(extent1, extent2, opt_extent) { var intersection = opt_extent ? opt_extent : createEmpty(); if (intersects(extent1, extent2)) { if (extent1[0] > extent2[0]) { intersection[0] = extent1[0]; } else { intersection[0] = extent2[0]; } if (extent1[1] > extent2[1]) { intersection[1] = extent1[1]; } else { intersection[1] = extent2[1]; } if (extent1[2] < extent2[2]) { intersection[2] = extent1[2]; } else { intersection[2] = extent2[2]; } if (extent1[3] < extent2[3]) { intersection[3] = extent1[3]; } else { intersection[3] = extent2[3]; } } else { createOrUpdateEmpty(intersection); } return intersection; } /** * Get the top left coordinate of an extent. * @param {Extent} extent Extent. * @return {import("./coordinate.js").Coordinate} Top left coordinate. * @api */ function getTopLeft(extent) { return [extent[0], extent[3]]; } /** * Get the top right coordinate of an extent. * @param {Extent} extent Extent. * @return {import("./coordinate.js").Coordinate} Top right coordinate. * @api */ function getTopRight(extent) { return [extent[2], extent[3]]; } /** * Determine if one extent intersects another. * @param {Extent} extent1 Extent 1. * @param {Extent} extent2 Extent. * @return {boolean} The two extents intersect. * @api */ function intersects(extent1, extent2) { return extent1[0] <= extent2[2] && extent1[2] >= extent2[0] && extent1[1] <= extent2[3] && extent1[3] >= extent2[1]; } /** * Determine if an extent is empty. * @param {Extent} extent Extent. * @return {boolean} Is empty. * @api */ function isEmpty(extent) { return extent[2] < extent[0] || extent[3] < extent[1]; } /** * Apply a transform function to the extent. * @param {Extent} extent Extent. * @param {import("./proj.js").TransformFunction} transformFn Transform function. * Called with `[minX, minY, maxX, maxY]` extent coordinates. * @param {Extent=} opt_extent Destination extent. * @return {Extent} Extent. * @api */ function applyTransform(extent, transformFn, opt_extent) { var coordinates = [ extent[0], extent[1], extent[0], extent[3], extent[2], extent[1], extent[2], extent[3] ]; transformFn(coordinates, coordinates, 2); var xs = [coordinates[0], coordinates[2], coordinates[4], coordinates[6]]; var ys = [coordinates[1], coordinates[3], coordinates[5], coordinates[7]]; return _boundingExtentXYs(xs, ys, opt_extent); } /** * @module ol/dom */ /** * Create an html canvas element and returns its 2d context. * @param {number=} opt_width Canvas width. * @param {number=} opt_height Canvas height. * @param {Array<HTMLCanvasElement>=} opt_canvasPool Canvas pool to take existing canvas from. * @return {CanvasRenderingContext2D} The context. */ function createCanvasContext2D(opt_width, opt_height, opt_canvasPool) { var canvas = opt_canvasPool && opt_canvasPool.length ? opt_canvasPool.shift() : document.createElement('canvas'); if (opt_width) { canvas.width = opt_width; } if (opt_height) { canvas.height = opt_height; } return canvas.getContext('2d'); } /** * @module ol/events/Event */ /** * @classdesc * Stripped down implementation of the W3C DOM Level 2 Event interface. * See https://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-interface. * * This implementation only provides `type` and `target` properties, and * `stopPropagation` and `preventDefault` methods. It is meant as base class * for higher level events defined in the library, and works with * {@link module:ol/events/Target~Target}. */ var BaseEvent = /** @class */ (function () { /** * @param {string} type Type. */ function BaseEvent(type) { /** * @type {boolean} */ this.propagationStopped; /** * The event type. * @type {string} * @api */ this.type = type; /** * The event target. * @type {Object} * @api */ this.target = null; } /** * Stop event propagation. * @api */ BaseEvent.prototype.preventDefault = function () { this.propagationStopped = true; }; /** * Stop event propagation. * @api */ BaseEvent.prototype.stopPropagation = function () { this.propagationStopped = true; }; return BaseEvent; }()); /** * @module ol/render/Event */ var __extends$1 = (undefined && undefined.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) { if (b.hasOwnProperty(p)) { d[p] = b[p]; } } }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var RenderEvent = /** @class */ (function (_super) { __extends$1(RenderEvent, _super); /** * @param {import("./EventType.js").default} type Type. * @param {import("../transform.js").Transform=} opt_inversePixelTransform Transform for * CSS pixels to rendered pixels. * @param {import("../PluggableMap.js").FrameState=} opt_frameState Frame state. * @param {?CanvasRenderingContext2D=} opt_context Context. */ function RenderEvent(type, opt_inversePixelTransform, opt_frameState, opt_context) { var _this = _super.call(this, type) || this; /** * Transform from CSS pixels (relative to the top-left corner of the map viewport) * to rendered pixels on this event's `context`. * @type {import("../transform.js").Transform|undefined} * @api */ _this.inversePixelTransform = opt_inversePixelTransform; /** * An object representing the current render frame state. * @type {import("../PluggableMap.js").FrameState|undefined} * @api */ _this.frameState = opt_frameState; /** * Canvas context. Not available when the event is dispatched by the map. Only available * when a Canvas renderer is used, null otherwise. * @type {CanvasRenderingContext2D|null|undefined} * @api */ _this.context = opt_context; return _this; } return RenderEvent; }(BaseEvent)); /** * @module ol/render/EventType */ /** * @enum {string} */ var RenderEventType = { /** * Triggered before a layer is rendered. * @event module:ol/render/Event~RenderEvent#prerender * @api */ PRERENDER: 'prerender', /** * Triggered after a layer is rendered. * @event module:ol/render/Event~RenderEvent#postrender * @api */ POSTRENDER: 'postrender', /** * Triggered before layers are rendered. * The event object will not have a `context` set. * @event module:ol/render/Event~RenderEvent#precompose * @api */ PRECOMPOSE: 'precompose', /** * Triggered after all layers are rendered. * The event object will not have a `context` set. * @event module:ol/render/Event~RenderEvent#postcompose * @api */ POSTCOMPOSE: 'postcompose', /** * Triggered when rendering is complete, i.e. all sources and tiles have * finished loading for the current viewport, and all tiles are faded in. * The event object will not have a `context` set. * @event module:ol/render/Event~RenderEvent#rendercomplete * @api */ RENDERCOMPLETE: 'rendercomplete' }; /** * @module ol/css */ /** * @module ol/obj */ /** * Polyfill for Object.assign(). Assigns enumerable and own properties from * one or more source objects to a target object. * See https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/assign. * * @param {!Object} target The target object. * @param {...Object} var_sources The source object(s). * @return {!Object} The modified target object. */ var assign = (typeof Object.assign === 'function') ? Object.assign : function (target, var_sources) { var arguments$1 = arguments; if (target === undefined || target === null) { throw new TypeError('Cannot convert undefined or null to object'); } var output = Object(target); for (var i = 1, ii = arguments.length; i < ii; ++i) { var source = arguments$1[i]; if (source !== undefined && source !== null) { for (var key in source) { if (source.hasOwnProperty(key)) { output[key] = source[key]; } } } } return output; }; /** * Removes all properties from an object. * @param {Object} object The object to clear. */ function clear(object) { for (var property in object) { delete object[property]; } } /** * @module ol/ObjectEventType */ /** * @enum {string} */ var ObjectEventType = { /** * Triggered when a property is changed. * @event module:ol/Object.ObjectEvent#propertychange * @api */ PROPERTYCHANGE: 'propertychange' }; /** * @module ol/events */ /** * Key to use with {@link module:ol/Observable~Observable#unByKey}. * @typedef {Object} EventsKey * @property {ListenerFunction} listener * @property {import("./events/Target.js").EventTargetLike} target * @property {string} type * @api */ /** * Listener function. This function is called with an event object as argument. * When the function returns `false`, event propagation will stop. * * @typedef {function((Event|import("./events/Event.js").default)): (void|boolean)} ListenerFunction * @api */ /** * Registers an event listener on an event target. Inspired by * https://google.github.io/closure-library/api/source/closure/goog/events/events.js.src.html * * This function efficiently binds a `listener` to a `this` object, and returns * a key for use with {@link module:ol/events~unlistenByKey}. * * @param {import("./events/Target.js").EventTargetLike} target Event target. * @param {string} type Event type. * @param {ListenerFunction} listener Listener. * @param {Object=} opt_this Object referenced by the `this` keyword in the * listener. Default is the `target`. * @param {boolean=} opt_once If true, add the listener as one-off listener. * @return {EventsKey} Unique key for the listener. */ function listen(target, type, listener, opt_this, opt_once) { if (opt_this && opt_this !== target) { listener = listener.bind(opt_this); } if (opt_once) { var originalListener_1 = listener; listener = function () { target.removeEventListener(type, listener); originalListener_1.apply(this, arguments); }; } var eventsKey = { target: target, type: type, listener: listener }; target.addEventListener(type, listener); return eventsKey; } /** * Registers a one-off event listener on an event target. Inspired by * https://google.github.io/closure-library/api/source/closure/goog/events/events.js.src.html * * This function efficiently binds a `listener` as self-unregistering listener * to a `this` object, and returns a key for use with * {@link module:ol/events~unlistenByKey} in case the listener needs to be * unregistered before it is called. * * When {@link module:ol/events~listen} is called with the same arguments after this * function, the self-unregistering listener will be turned into a permanent * listener. * * @param {import("./events/Target.js").EventTargetLike} target Event target. * @param {string} type Event type. * @param {ListenerFunction} listener Listener. * @param {Object=} opt_this Object referenced by the `this` keyword in the * listener. Default is the `target`. * @return {EventsKey} Key for unlistenByKey. */ function listenOnce(target, type, listener, opt_this) { return listen(target, type, listener, opt_this, true); } /** * @module ol/Disposable */ /** * @classdesc * Objects that need to clean up after themselves. */ var Disposable = /** @class */ (function () { function Disposable() { /** * The object has already been disposed. * @type {boolean} * @private */ this.disposed_ = false; } /** * Clean up. */ Disposable.prototype.dispose = function () { if (!this.disposed_) { this.disposed_ = true; this.disposeInternal(); } }; /** * Extension point for disposable objects. * @protected */ Disposable.prototype.disposeInternal = function () { }; return Disposable; }()); /** * @module ol/array */ /** * @module ol/functions */ /** * A reusable function, used e.g. as a default for callbacks. * * @return {void} Nothing. */ function VOID() { } var __extends$2 = (undefined && undefined.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) { if (b.hasOwnProperty(p)) { d[p] = b[p]; } } }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); /** * @typedef {EventTarget|Target} EventTargetLike */ /** * @classdesc * A simplified implementation of the W3C DOM Level 2 EventTarget interface. * See https://www.w3.org/TR/2000/REC-DOM-Level-2-Events-20001113/events.html#Events-EventTarget. * * There are two important simplifications compared to the specification: * * 1. The handling of `useCapture` in `addEventListener` and * `removeEventListener`. There is no real capture model. * 2. The handling of `stopPropagation` and `preventDefault` on `dispatchEvent`. * There is no event target hierarchy. When a listener calls * `stopPropagation` or `preventDefault` on an event object, it means that no * more listeners after this one will be called. Same as when the listener * returns false. */ var Target = /** @class */ (function (_super) { __extends$2(Target, _super); /** * @param {*=} opt_target Default event target for dispatched events. */ function Target(opt_target) { var _this = _super.call(this) || this; /** * @private * @type {*} */ _this.eventTarget_ = opt_target; /** * @private * @type {!Object<string, number>} */ _this.pendingRemovals_ = {}; /** * @private * @type {!Object<string, number>} */ _this.dispatching_ = {}; /** * @private * @type {!Object<string, Array<import("../events.js").ListenerFunction>>} */ _this.listeners_ = {}; return _this; } /** * @param {string} type Type. * @param {import("../events.js").ListenerFunction} listener Listener. */ Target.prototype.addEventListener = function (type, listener) { if (!type || !listener) { return; } var listeners = this.listeners_[type]; if (!listeners) { listeners = []; this.listeners_[type] = listeners; } if (listeners.indexOf(listener) === -1) { listeners.push(listener); } }; /** * Dispatches an event and calls all listeners listening for events * of this type. The event parameter can either be a string or an * Object with a `type` property. * * @param {{type: string, * target: (EventTargetLike|undefined), * propagationStopped: (boolean|undefined)}| * import("./Event.js").default|string} event Event object. * @return {boolean|undefined} `false` if anyone called preventDefault on the * event object or if any of the listeners returned false. * @api */ Target.prototype.dispatchEvent = function (event) { var evt = typeof event === 'string' ? new BaseEvent(event) : event; var type = evt.type; if (!evt.target) { evt.target = this.eventTarget_ || this; } var listeners = this.listeners_[type]; var propagate; if (listeners) { if (!(type in this.dispatching_)) { this.dispatching_[type] = 0; this.pendingRemovals_[type] = 0; } ++this.dispatching_[type]; for (var i = 0, ii = listeners.length; i < ii; ++i) { if (listeners[i].call(this, evt) === false || evt.propagationStopped) { propagate = false; break; } } --this.dispatching_[type]; if (this.dispatching_[type] === 0) { var pendingRemovals = this.pendingRemovals_[type]; delete this.pendingRemovals_[type]; while (pendingRemovals--) { this.removeEventListener(type, VOID); } delete this.dispatching_[type]; } return propagate; } }; /** * @inheritDoc */ Target.prototype.disposeInternal = function () { clear(this.listeners_); }; /** * Get the listeners for a specified event type. Listeners are returned in the * order that they will be called in. * * @param {string} type Type. * @return {Array<import("../events.js").ListenerFunction>} Listeners. */ Target.prototype.getListeners = function (type) { return this.listeners_[type]; }; /** * @param {string=} opt_type Type. If not provided, * `true` will be returned if this event target has any listeners. * @return {boolean} Has listeners. */ Target.prototype.hasListener = function (opt_type) { return opt_type ? opt_type in this.listeners_ : Object.keys(this.listeners_).length > 0; }; /** * @param {string} type Type. * @param {import("../events.js").ListenerFunction} listener Listener. */ Target.prototype.removeEventListener = function (type, listener) { var listeners = this.listeners_[type]; if (listeners) { var index = listeners.indexOf(listener); if (index !== -1) { if (type in this.pendingRemovals_) { // make listener a no-op, and remove later in #dispatchEvent() listeners[index] = VOID; ++this.pendingRemovals_[type]; } else { listeners.splice(index, 1); if (listeners.length === 0) { delete this.listeners_[type]; } } } } }; return Target; }(Disposable)); /** * @module ol/events/EventType */ /** * @enum {string} * @const */ var EventType = { /** * Generic change event. Triggered when the revision counter is increased. * @event module:ol/events/Event~BaseEvent#change * @api */ CHANGE: 'change', /** * Generic error event. Triggered when an error occurs. * @event module:ol/events/Event~BaseEvent#error * @api */ ERROR: 'error', BLUR: 'blur', CLEAR: 'clear', CONTEXTMENU: 'contextmenu', CLICK: 'click', DBLCLICK: 'dblclick', DRAGENTER: 'dragenter', DRAGOVER: 'dragover', DROP: 'drop', FOCUS: 'focus', KEYDOWN: 'keydown', KEYPRESS: 'keypress', LOAD: 'load', RESIZE: 'resize', TOUCHMOVE: 'touchmove', WHEEL: 'wheel' }; var __extends$3 = (undefined && undefined.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) { if (b.hasOwnProperty(p)) { d[p] = b[p]; } } }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); /** * @classdesc * Abstract base class; normally only used for creating subclasses and not * instantiated in apps. * An event target providing convenient methods for listener registration * and unregistration. A generic `change` event is always available through * {@link module:ol/Observable~Observable#changed}. * * @fires import("./events/Event.js").default * @api */ var Observable = /** @class */ (function (_super) { __extends$3(Observable, _super); function Observable() { var _this = _super.call(this) || this; /** * @private * @type {number} */ _this.revision_ = 0; return _this; } /** * Increases the revision counter and dispatches a 'change' event. * @api */ Observable.prototype.changed = function () { ++this.revision_; this.dispatchEvent(EventType.CHANGE); }; /** * Get the version number for this object. Each time the object is modified, * its version number will be incremented. * @return {number} Revision. * @api */ Observable.prototype.getRevision = function () { return this.revision_; }; /** * Listen for a certain type of event. * @param {string|Array<string>} type The event type or array of event types. * @param {function(?): ?} listener The listener function. * @return {import("./events.js").EventsKey|Array<import("./events.js").EventsKey>} Unique key for the listener. If * called with an array of event types as the first argument, the return * will be an array of keys. * @api */ Observable.prototype.on = function (type, listener) { if (Array.isArray(type)) { var len = type.length; var keys = new Array(len); for (var i = 0; i < len; ++i) { keys[i] = listen(this, type[i], listener); } return keys; } else { return listen(this, /** @type {string} */ (type), listener); } }; /** * Listen once for a certain type of event. * @param {string|Array<string>} type The event type or array of event types. * @param {function(?): ?} listener The listener function. * @return {import("./events.js").EventsKey|Array<import("./events.js").EventsKey>} Unique key for the listener. If * called with an array of event types as the first argument, the return * will be an array of keys. * @api */ Observable.prototype.once = function (type, listener) { if (Array.isArray(type)) { var len = type.length; var keys = new Array(len); for (var i = 0; i < len; ++i) { keys[i] = listenOnce(this, type[i], listener); } return keys; } else { return listenOnce(this, /** @type {string} */ (type), listener); } }; /** * Unlisten for a certain type of event. * @param {string|Array<string>} type The event type or array of event types. * @param {function(?): ?} listener The listener function. * @api */ Observable.prototype.un = function (type, listener) { if (Array.isArray(type)) { for (var i = 0, ii = type.length; i < ii; ++i) { this.removeEventListener(type[i], listener); } } else { this.removeEventListener(type, listener); } }; return Observable; }(Target)); var __extends$4 = (undefined && undefined.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) { if (b.hasOwnProperty(p)) { d[p] = b[p]; } } }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); /** * @classdesc * Events emitted by {@link module:ol/Object~BaseObject} instances are instances of this type. */ var ObjectEvent = /** @class */ (function (_super) { __extends$4(ObjectEvent, _super); /** * @param {string} type The event type. * @param {string} key The property name. * @param {*} oldValue The old value for `key`. */ function ObjectEvent(type, key, oldValue) { var _this = _super.call(this, type) || this; /** * The name of the property whose value is changing. * @type {string} * @api */ _this.key = key; /** * The old value. To get the new value use `e.target.get(e.key)` where * `e` is the event object. * @type {*} * @api */ _this.oldValue = oldValue; return _this; } return ObjectEvent; }(BaseEvent)); /** * @classdesc * Abstract base class; normally only used for creating subclasses and not * instantiated in apps. * Most non-trivial classes inherit from this. * * This extends {@link module:ol/Observable} with observable * properties, where each property is observable as well as the object as a * whole. * * Classes that inherit from this have pre-defined properties, to which you can * add your owns. The pre-defined properties are listed in this documentation as * 'Observable Properties', and have their own accessors; for example, * {@link module:ol/Map~Map} has a `target` property, accessed with * `getTarget()` and changed with `setTarget()`. Not all properties are however * settable. There are also general-purpose accessors `get()` and `set()`. For * example, `get('target')` is equivalent to `getTarget()`. * * The `set` accessors trigger a change event, and you can monitor this by * registering a listener. For example, {@link module:ol/View~View} has a * `center` property, so `view.on('change:center', function(evt) {...});` would * call the function whenever the value of the center property changes. Within * the function, `evt.target` would be the view, so `evt.target.getCenter()` * would return the new center. * * You can add your own observable properties with * `object.set('prop', 'value')`, and retrieve that with `object.get('prop')`. * You can listen for changes on that property value with * `object.on('change:prop', listener)`. You can get a list of all * properties with {@link module:ol/Object~BaseObject#getProperties}. * * Note that the observable properties are separate from standard JS properties. * You can, for example, give your map object a title with * `map.title='New title'` and with `map.set('title', 'Another title')`. The * first will be a `hasOwnProperty`; the second will appear in * `getProperties()`. Only the second is observable. * * Properties can be deleted by using the unset method. E.g. * object.unset('foo'). * * @fires ObjectEvent * @api */ var BaseObject = /** @class */ (function (_super) { __extends$4(BaseObject, _super); /** * @param {Object<string, *>=} opt_values An object with key-value pairs. */ function BaseObject(opt_values) { var _this = _super.call(this) || this; // Call {@link module:ol/util~getUid} to ensure that the order of objects' ids is // the same as the order in which they were created. This also helps to // ensure that object properties are always added in the same order, which // helps many JavaScript engines generate faster code. getUid(_this); /** * @private * @type {!Object<string, *>} */ _this.values_ = {}; if (opt_values !== undefined) { _this.setProperties(opt_values); } return _this; } /** * Gets a value. * @param {string} key Key name. * @return {*} Value. * @api */ BaseObject.prototype.get = function (key) { var value; if (this.values_.hasOwnProperty(key)) { value = this.values_[key]; } return value; }; /** * Get a list of object property names. * @return {Array<string>} List of property names. * @api */ BaseObject.prototype.getKeys = function () { return Object.keys(this.values_); }; /** * Get an object of all property names and values. * @return {Object<string, *>} Object. * @api */ BaseObject.prototype.getProperties = function () { return assign({}, this.values_); }; /** * @param {string} key Key name. * @param {*} oldValue Old value. */ BaseObject.prototype.notify = function (key, oldValue) { var eventType; eventType = getChangeEventType(key); this.dispatchEvent(new ObjectEvent(eventType, key, oldValue)); eventType = ObjectEventType.PROPERTYCHANGE; this.dispatchEvent(new ObjectEvent(eventType, key, oldValue)); }; /** * Sets a value. * @param {string} key Key name. * @param {*} value Value. * @param {boolean=} opt_silent Update without triggering an event. * @api */ BaseObject.prototype.set = function (key, value, opt_silent) { if (opt_silent) { this.values_[key] = value; } else { var oldValue = this.values_[key]; this.values_[key] = value; if (oldValue !== value) { this.notify(key, oldValue); } } }; /** * Sets a collection of key-value pairs. Note that this changes any existing * properties and adds new ones (it does not remove any existing properties). * @param {Object<string, *>} values Values. * @param {boolean=} opt_silent Update without triggering an event. * @api */ BaseObject.prototype.setProperties = function (values, opt_silent) { for (var key in values) { this.set(key, values[key], opt_silent); } }; /** * Unsets a property. * @param {string} key Key name. * @param {boolean=} opt_silent Unset without triggering an event. * @api */ BaseObject.prototype.unset = function (key, opt_silent) { if (key in this.values_) { var oldValue = this.values_[key]; delete this.values_[key]; if (!opt_silent) { this.notify(key, oldValue); } } }; return BaseObject; }(Observable)); /** * @type {Object<string, string>} */ var changeEventTypeCache = {}; /** * @param {string} key Key name. * @return {string} Change name. */ function getChangeEventType(key) { return changeEventTypeCache.hasOwnProperty(key) ? changeEventTypeCache[key] : (changeEventTypeCache[key] = 'change:' + key); } /** * @module ol/render/canvas */ /** * @type {BaseObject} */ var checkedFonts = new BaseObject(); /** * The label cache for text rendering. To change the default cache size of 2048 * entries, use {@link module:ol/structs/LRUCache#setSize}. * Deprecated - there is no label cache any more. * @type {?} * @api * @deprecated */ var labelCache = new Target(); labelCache.setSize = function () { console.warn('labelCache is deprecated.'); //eslint-disable-line }; /** * @param {CanvasRenderingContext2D} context Context. * @param {number} rotation Rotation. * @param {number} offsetX X offset. * @param {number} offsetY Y offset. */ function rotateAtOffset(context, rotation, offsetX, offsetY) { if (rotation !== 0) { context.translate(offsetX, offsetY); context.rotate(rotation); context.translate(-offsetX, -offsetY); } } /** * @module ol/ImageState */ /** * @enum {number} */ var ImageState = { IDLE: 0, LOADING: 1, LOADED: 2, ERROR: 3, EMPTY: 4 }; /** * @module ol/source/State */ /** * @enum {string} * State of the source, one of 'undefined', 'loading', 'ready' or 'error'. */ var SourceState = { UNDEFINED: 'undefined', LOADING: 'loading', READY: 'ready', ERROR: 'error' }; var __extends$5 = (undefined && undefined.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) { if (b.hasOwnProperty(p)) { d[p] = b[p]; } } }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); /** * @template {import("../layer/Layer.js").default} LayerType */ var LayerRenderer = /** @class */ (function (_super) { __extends$5(LayerRenderer, _super); /** * @param {LayerType} layer Layer. */ function LayerRenderer(layer) { var _this = _super.call(this) || this; /** @private */ _this.boundHandleImageChange_ = _this.handleImageChange_.bind(_this); /** * @private * @type {LayerType} */ _this.layer_ = layer; return _this; } /** * Asynchronous layer level hit detection. * @param {import("../pixel.js").Pixel} pixel Pixel. * @return {Promise<Array<import("../Feature").default>>} Promise that resolves with * an array of features. */ LayerRenderer.prototype.getFeatures = function (pixel) { return abstract(); }; /** * Determine whether render should be called. * @abstract * @param {import("../PluggableMap.js").FrameState} frameState Frame state. * @return {boolean} Layer is ready to be rendered. */ LayerRenderer.prototype.prepareFrame = function (frameState) { return abstract(); }; /** * Render the layer. * @abstract * @param {import("../PluggableMap.js").FrameState} frameState Frame state. * @param {HTMLElement} target Target that may be used to render content to. * @return {HTMLElement} The rendered element. */ LayerRenderer.prototype.renderFrame = function (frameState, target) { return abstract(); }; /** * @param {Object<number, Object<string, import("../Tile.js").default>>} tiles Lookup of loaded tiles by zoom level. * @param {number} zoom Zoom level. * @param {import("../Tile.js").default} tile Tile. */ LayerRenderer.prototype.loadedTileCallback = function (tiles, zoom, tile) { if (!tiles[zoom]) { tiles[zoom] = {}; } tiles[zoom][tile.tileCoord.toString()] = tile; }; /** * Create a function that adds loaded tiles to the tile lookup. * @param {import("../source/Tile.js").default} source Tile source. * @param {import("../proj/Projection.js").default} projection Projection of the tiles. * @param {Object<number, Object<string, import("../Tile.js").default>>} tiles Lookup of loaded tiles by zoom level. * @return {function(number, import("../TileRange.js").default):boolean} A function that can be * called with a zoom level and a tile range to add loaded tiles to the lookup. * @protected */ LayerRenderer.prototype.createLoadedTileFinder = function (source, projection, tiles) { return ( /** * @param {number} zoom Zoom level. * @param {import("../TileRange.js").default} tileRange Tile range. * @return {boolean} The tile range is fully loaded. * @this {LayerRenderer} */ function (zoom, tileRange) { var callback = this.loadedTileCallback.bind(this, tiles, zoom); return source.forEachLoadedTile(projection, zoom, tileRange, callback); }).bind(this); }; /** * @abstract * @param {import("../coordinate.js").Coordinate} coordinate Coordinate. * @param {import("../PluggableMap.js").FrameState} frameState Frame state. * @param {number} hitTolerance Hit tolerance in pixels. * @param {function(import("../Feature.js").FeatureLike, import("../layer/Layer.js").default): T} callback Feature callback. * @param {Array<import("../Feature.js").FeatureLike>} declutteredFeatures Decluttered features. * @return {T|void} Callback result. * @template T */ LayerRenderer.prototype.forEachFeatureAtCoordinate = function (coordinate, frameState, hitTolerance, callback, declutteredFeatures) { }; /** * @abstract * @param {import("../pixel.js").Pixel} pixel Pixel. * @param {import("../PluggableMap.js").FrameState} frameState FrameState. * @param {number} hitTolerance Hit tolerance in pixels. * @return {Uint8ClampedArray|Uint8Array} The result. If there is no data at the pixel * location, null will be returned. If there is data, but pixel values cannot be * returned, and empty array will be returned. */ LayerRenderer.prototype.getDataAtPixel = function (pixel, frameState, hitTolerance) { return abstract(); }; /** * @return {LayerType} Layer. */ LayerRenderer.prototype.getLayer = function ()