Merge branch 'main' of https://github.com/openlayers/openlayers into main
This commit is contained in:
@@ -22,8 +22,8 @@ const Property = {
|
||||
export class CollectionEvent extends Event {
|
||||
/**
|
||||
* @param {import("./CollectionEventType.js").default} type Type.
|
||||
* @param {*=} opt_element Element.
|
||||
* @param {number=} opt_index The index of the added or removed element.
|
||||
* @param {*} [opt_element] Element.
|
||||
* @param {number} [opt_index] The index of the added or removed element.
|
||||
*/
|
||||
constructor(type, opt_element, opt_index) {
|
||||
super(type);
|
||||
@@ -65,8 +65,8 @@ export class CollectionEvent extends Event {
|
||||
*/
|
||||
class Collection extends BaseObject {
|
||||
/**
|
||||
* @param {Array<T>=} opt_array Array.
|
||||
* @param {Options=} opt_options Collection options.
|
||||
* @param {Array<T>} [opt_array] Array.
|
||||
* @param {Options} [opt_options] Collection options.
|
||||
*/
|
||||
constructor(opt_array, opt_options) {
|
||||
super();
|
||||
@@ -277,7 +277,7 @@ class Collection extends BaseObject {
|
||||
/**
|
||||
* @private
|
||||
* @param {T} elem Element.
|
||||
* @param {number=} opt_except Optional index to ignore.
|
||||
* @param {number} [opt_except] Optional index to ignore.
|
||||
*/
|
||||
assertUnique_(elem, opt_except) {
|
||||
for (let i = 0, ii = this.array_.length; i < ii; ++i) {
|
||||
|
||||
@@ -61,7 +61,7 @@ import {listen, unlistenByKey} from './events.js';
|
||||
*/
|
||||
class Feature extends BaseObject {
|
||||
/**
|
||||
* @param {Geometry|Object<string, *>=} opt_geometryOrProperties
|
||||
* @param {Geometry|Object<string, *>} [opt_geometryOrProperties]
|
||||
* You may pass a Geometry object directly, or an object literal containing
|
||||
* properties. If you pass an object literal, you may include a Geometry
|
||||
* associated with a `geometry` key.
|
||||
@@ -240,7 +240,7 @@ class Feature extends BaseObject {
|
||||
* single style object, an array of styles, or a function that takes a
|
||||
* resolution and returns an array of styles. To unset the feature style, call
|
||||
* `setStyle()` without arguments or a falsey value.
|
||||
* @param {import("./style/Style.js").StyleLike=} opt_style Style for this feature.
|
||||
* @param {import("./style/Style.js").StyleLike} [opt_style] Style for this feature.
|
||||
* @api
|
||||
* @fires module:ol/events/Event~BaseEvent#event:change
|
||||
*/
|
||||
|
||||
@@ -34,7 +34,7 @@ const Property = {
|
||||
*/
|
||||
class GeolocationError extends BaseEvent {
|
||||
/**
|
||||
* @param {PositionError} error error object.
|
||||
* @param {GeolocationPositionError} error error object.
|
||||
*/
|
||||
constructor(error) {
|
||||
super(EventType.ERROR);
|
||||
@@ -56,7 +56,7 @@ class GeolocationError extends BaseEvent {
|
||||
* @property {boolean} [tracking=false] Start Tracking right after
|
||||
* instantiation.
|
||||
* @property {PositionOptions} [trackingOptions] Tracking options.
|
||||
* See http://www.w3.org/TR/geolocation-API/#position_options_interface.
|
||||
* See https://www.w3.org/TR/geolocation-API/#position_options_interface.
|
||||
* @property {import("./proj.js").ProjectionLike} [projection] The projection the position
|
||||
* is reported in.
|
||||
*/
|
||||
@@ -64,7 +64,7 @@ class GeolocationError extends BaseEvent {
|
||||
/**
|
||||
* @classdesc
|
||||
* Helper class for providing HTML5 Geolocation capabilities.
|
||||
* The [Geolocation API](http://www.w3.org/TR/geolocation-API/)
|
||||
* The [Geolocation API](https://www.w3.org/TR/geolocation-API/)
|
||||
* is used to locate a user's position.
|
||||
*
|
||||
* To get notified of position changes, register a listener for the generic
|
||||
@@ -86,7 +86,7 @@ class GeolocationError extends BaseEvent {
|
||||
*/
|
||||
class Geolocation extends BaseObject {
|
||||
/**
|
||||
* @param {Options=} opt_options Options.
|
||||
* @param {Options} [opt_options] Options.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
super();
|
||||
@@ -176,7 +176,7 @@ class Geolocation extends BaseObject {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {Position} position position event.
|
||||
* @param {GeolocationPosition} position position event.
|
||||
*/
|
||||
positionChange_(position) {
|
||||
const coords = position.coords;
|
||||
@@ -210,7 +210,7 @@ class Geolocation extends BaseObject {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {PositionError} error error object.
|
||||
* @param {GeolocationPositionError} error error object.
|
||||
*/
|
||||
positionError_(error) {
|
||||
this.dispatchEvent(new GeolocationError(error));
|
||||
@@ -324,10 +324,10 @@ class Geolocation extends BaseObject {
|
||||
|
||||
/**
|
||||
* Get the tracking options.
|
||||
* See http://www.w3.org/TR/geolocation-API/#position-options.
|
||||
* See https://www.w3.org/TR/geolocation-API/#position-options.
|
||||
* @return {PositionOptions|undefined} PositionOptions as defined by
|
||||
* the [HTML5 Geolocation spec
|
||||
* ](http://www.w3.org/TR/geolocation-API/#position_options_interface).
|
||||
* ](https://www.w3.org/TR/geolocation-API/#position_options_interface).
|
||||
* @observable
|
||||
* @api
|
||||
*/
|
||||
|
||||
@@ -19,7 +19,7 @@ class ImageCanvas extends ImageBase {
|
||||
* @param {number} resolution Resolution.
|
||||
* @param {number} pixelRatio Pixel ratio.
|
||||
* @param {HTMLCanvasElement} canvas Canvas.
|
||||
* @param {Loader=} opt_loader Optional loader function to
|
||||
* @param {Loader} [opt_loader] Optional loader function to
|
||||
* support asynchronous canvas drawing.
|
||||
*/
|
||||
constructor(extent, resolution, pixelRatio, canvas, opt_loader) {
|
||||
@@ -58,7 +58,7 @@ class ImageCanvas extends ImageBase {
|
||||
|
||||
/**
|
||||
* Handle async drawing complete.
|
||||
* @param {Error=} err Any error during drawing.
|
||||
* @param {Error} [err] Any error during drawing.
|
||||
* @private
|
||||
*/
|
||||
handleLoad_(err) {
|
||||
|
||||
@@ -13,7 +13,7 @@ class ImageTile extends Tile {
|
||||
* @param {string} src Image source URI.
|
||||
* @param {?string} crossOrigin Cross origin.
|
||||
* @param {import("./Tile.js").LoadFunction} tileLoadFunction Tile load function.
|
||||
* @param {import("./Tile.js").Options=} opt_options Tile options.
|
||||
* @param {import("./Tile.js").Options} [opt_options] Tile options.
|
||||
*/
|
||||
constructor(
|
||||
tileCoord,
|
||||
@@ -39,6 +39,8 @@ class ImageTile extends Tile {
|
||||
*/
|
||||
this.src_ = src;
|
||||
|
||||
this.key = src;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {HTMLImageElement|HTMLCanvasElement}
|
||||
@@ -70,13 +72,6 @@ class ImageTile extends Tile {
|
||||
return this.image_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {string} Key.
|
||||
*/
|
||||
getKey() {
|
||||
return this.src_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tracks loading or read errors.
|
||||
*
|
||||
|
||||
@@ -7,15 +7,15 @@ import MapEvent from './MapEvent.js';
|
||||
* @classdesc
|
||||
* Events emitted as map browser events are instances of this type.
|
||||
* See {@link module:ol/PluggableMap~PluggableMap} for which events trigger a map browser event.
|
||||
* @template {UIEvent} EVENT
|
||||
* @template {UIEvent|import("./MapBrowserEventHandler").PointerEventData} EVENT
|
||||
*/
|
||||
class MapBrowserEvent extends MapEvent {
|
||||
/**
|
||||
* @param {string} type Event type.
|
||||
* @param {import("./PluggableMap.js").default} map Map.
|
||||
* @param {EVENT} originalEvent Original event.
|
||||
* @param {boolean=} opt_dragging Is the map currently being dragged?
|
||||
* @param {?import("./PluggableMap.js").FrameState=} opt_frameState Frame state.
|
||||
* @param {boolean} [opt_dragging] Is the map currently being dragged?
|
||||
* @param {?import("./PluggableMap.js").FrameState} [opt_frameState] Frame state.
|
||||
*/
|
||||
constructor(type, map, originalEvent, opt_dragging, opt_frameState) {
|
||||
super(type, map, opt_frameState);
|
||||
@@ -88,7 +88,9 @@ class MapBrowserEvent extends MapEvent {
|
||||
*/
|
||||
preventDefault() {
|
||||
super.preventDefault();
|
||||
this.originalEvent.preventDefault();
|
||||
if ('preventDefault' in this.originalEvent) {
|
||||
/** @type {UIEvent} */ (this.originalEvent).preventDefault();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,7 +100,9 @@ class MapBrowserEvent extends MapEvent {
|
||||
*/
|
||||
stopPropagation() {
|
||||
super.stopPropagation();
|
||||
this.originalEvent.stopPropagation();
|
||||
if ('stopPropagation' in this.originalEvent) {
|
||||
/** @type {UIEvent} */ (this.originalEvent).stopPropagation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,18 +2,26 @@
|
||||
* @module ol/MapBrowserEventHandler
|
||||
*/
|
||||
|
||||
import EventTarget from './events/Target.js';
|
||||
import EventType from './events/EventType.js';
|
||||
import MapBrowserEvent from './MapBrowserEvent.js';
|
||||
import MapBrowserEventType from './MapBrowserEventType.js';
|
||||
import PointerEventType from './pointer/EventType.js';
|
||||
import Target from './events/Target.js';
|
||||
import {DEVICE_PIXEL_RATIO, PASSIVE_EVENT_LISTENERS} from './has.js';
|
||||
import {listen, unlistenByKey} from './events.js';
|
||||
|
||||
class MapBrowserEventHandler extends EventTarget {
|
||||
/**
|
||||
* @typedef {Object} PointerEventData
|
||||
* @property {string} type
|
||||
* @property {number} clientX
|
||||
* @property {number} clientY
|
||||
* @property {EventTarget} target
|
||||
*/
|
||||
|
||||
class MapBrowserEventHandler extends Target {
|
||||
/**
|
||||
* @param {import("./PluggableMap.js").default} map The map with the viewport to listen to events on.
|
||||
* @param {number=} moveTolerance The minimal distance the pointer must travel to trigger a move.
|
||||
* @param {number} [moveTolerance] The minimal distance the pointer must travel to trigger a move.
|
||||
*/
|
||||
constructor(map, moveTolerance) {
|
||||
super(map);
|
||||
@@ -31,6 +39,12 @@ class MapBrowserEventHandler extends EventTarget {
|
||||
*/
|
||||
this.clickTimeoutId_;
|
||||
|
||||
/**
|
||||
* Emulate dblclick and singleclick. Will be true when only one pointer is active.
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.emulateClicks_ = false;
|
||||
|
||||
/**
|
||||
* @type {boolean}
|
||||
* @private
|
||||
@@ -54,7 +68,7 @@ class MapBrowserEventHandler extends EventTarget {
|
||||
/**
|
||||
* The most recent "down" type event (or null if none have occurred).
|
||||
* Set on pointerdown.
|
||||
* @type {PointerEvent}
|
||||
* @type {PointerEventData}
|
||||
* @private
|
||||
*/
|
||||
this.down_ = null;
|
||||
@@ -116,7 +130,7 @@ class MapBrowserEventHandler extends EventTarget {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {PointerEvent} pointerEvent Pointer
|
||||
* @param {PointerEventData} pointerEvent Pointer
|
||||
* event.
|
||||
* @private
|
||||
*/
|
||||
@@ -140,6 +154,7 @@ class MapBrowserEventHandler extends EventTarget {
|
||||
} else {
|
||||
// click
|
||||
this.clickTimeoutId_ = setTimeout(
|
||||
/** @this {MapBrowserEventHandler} */
|
||||
function () {
|
||||
this.clickTimeoutId_ = undefined;
|
||||
const newEvent = new MapBrowserEvent(
|
||||
@@ -196,6 +211,7 @@ class MapBrowserEventHandler extends EventTarget {
|
||||
// We only fire click, singleclick, and doubleclick if nobody has called
|
||||
// event.stopPropagation() or event.preventDefault().
|
||||
if (
|
||||
this.emulateClicks_ &&
|
||||
!newEvent.propagationStopped &&
|
||||
!this.dragging_ &&
|
||||
this.isMouseActionButton_(pointerEvent)
|
||||
@@ -227,6 +243,7 @@ class MapBrowserEventHandler extends EventTarget {
|
||||
* @private
|
||||
*/
|
||||
handlePointerDown_(pointerEvent) {
|
||||
this.emulateClicks_ = this.activePointers_ === 0;
|
||||
this.updateActivePointers_(pointerEvent);
|
||||
const newEvent = new MapBrowserEvent(
|
||||
MapBrowserEventType.POINTERDOWN,
|
||||
@@ -235,22 +252,23 @@ class MapBrowserEventHandler extends EventTarget {
|
||||
);
|
||||
this.dispatchEvent(newEvent);
|
||||
|
||||
this.down_ = pointerEvent;
|
||||
this.down_ = {
|
||||
type: pointerEvent.type,
|
||||
clientX: pointerEvent.clientX,
|
||||
clientY: pointerEvent.clientY,
|
||||
target: pointerEvent.target,
|
||||
};
|
||||
|
||||
if (this.dragListenerKeys_.length === 0) {
|
||||
const doc = this.map_.getOwnerDocument();
|
||||
this.dragListenerKeys_.push(
|
||||
listen(
|
||||
document,
|
||||
doc,
|
||||
MapBrowserEventType.POINTERMOVE,
|
||||
this.handlePointerMove_,
|
||||
this
|
||||
),
|
||||
listen(
|
||||
document,
|
||||
MapBrowserEventType.POINTERUP,
|
||||
this.handlePointerUp_,
|
||||
this
|
||||
),
|
||||
listen(doc, MapBrowserEventType.POINTERUP, this.handlePointerUp_, this),
|
||||
/* Note that the listener for `pointercancel is set up on
|
||||
* `pointerEventHandler_` and not `documentPointerEventHandler_` like
|
||||
* the `pointerup` and `pointermove` listeners.
|
||||
@@ -271,10 +289,7 @@ class MapBrowserEventHandler extends EventTarget {
|
||||
this
|
||||
)
|
||||
);
|
||||
if (
|
||||
this.element_.getRootNode &&
|
||||
this.element_.getRootNode() !== document
|
||||
) {
|
||||
if (this.element_.getRootNode && this.element_.getRootNode() !== doc) {
|
||||
this.dragListenerKeys_.push(
|
||||
listen(
|
||||
this.element_.getRootNode(),
|
||||
@@ -334,9 +349,10 @@ class MapBrowserEventHandler extends EventTarget {
|
||||
handleTouchMove_(event) {
|
||||
// Due to https://github.com/mpizenberg/elm-pep/issues/2, `this.originalPointerMoveEvent_`
|
||||
// may not be initialized yet when we get here on a platform without native pointer events.
|
||||
const originalEvent = this.originalPointerMoveEvent_;
|
||||
if (
|
||||
!this.originalPointerMoveEvent_ ||
|
||||
this.originalPointerMoveEvent_.defaultPrevented
|
||||
(!originalEvent || originalEvent.defaultPrevented) &&
|
||||
(typeof event.cancelable !== 'boolean' || event.cancelable === true)
|
||||
) {
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ class MapEvent extends Event {
|
||||
/**
|
||||
* @param {string} type Event type.
|
||||
* @param {import("./PluggableMap.js").default} map Map.
|
||||
* @param {?import("./PluggableMap.js").FrameState=} opt_frameState Frame state.
|
||||
* @param {?import("./PluggableMap.js").FrameState} [opt_frameState] Frame state.
|
||||
*/
|
||||
constructor(type, map, opt_frameState) {
|
||||
super(type);
|
||||
|
||||
@@ -82,7 +82,7 @@ export class ObjectEvent extends Event {
|
||||
*/
|
||||
class BaseObject extends Observable {
|
||||
/**
|
||||
* @param {Object<string, *>=} opt_values An object with key-value pairs.
|
||||
* @param {Object<string, *>} [opt_values] An object with key-value pairs.
|
||||
*/
|
||||
constructor(opt_values) {
|
||||
super();
|
||||
@@ -159,7 +159,7 @@ class BaseObject extends Observable {
|
||||
* Sets a value.
|
||||
* @param {string} key Key name.
|
||||
* @param {*} value Value.
|
||||
* @param {boolean=} opt_silent Update without triggering an event.
|
||||
* @param {boolean} [opt_silent] Update without triggering an event.
|
||||
* @api
|
||||
*/
|
||||
set(key, value, opt_silent) {
|
||||
@@ -179,7 +179,7 @@ class BaseObject extends Observable {
|
||||
* 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.
|
||||
* @param {boolean} [opt_silent] Update without triggering an event.
|
||||
* @api
|
||||
*/
|
||||
setProperties(values, opt_silent) {
|
||||
@@ -188,10 +188,22 @@ class BaseObject extends Observable {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply any properties from another object without triggering events.
|
||||
* @param {BaseObject} source The source object.
|
||||
* @protected
|
||||
*/
|
||||
applyProperties(source) {
|
||||
if (!source.values_) {
|
||||
return;
|
||||
}
|
||||
assign(this.values_ || (this.values_ = {}), source.values_);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsets a property.
|
||||
* @param {string} key Key name.
|
||||
* @param {boolean=} opt_silent Unset without triggering an event.
|
||||
* @param {boolean} [opt_silent] Unset without triggering an event.
|
||||
* @api
|
||||
*/
|
||||
unset(key, opt_silent) {
|
||||
|
||||
@@ -396,7 +396,7 @@ class Overlay extends BaseObject {
|
||||
}
|
||||
|
||||
/**
|
||||
* Pan the map so that the overlay is entirely visisble in the current viewport
|
||||
* Pan the map so that the overlay is entirely visible in the current viewport
|
||||
* (if necessary) using the configured autoPan parameters
|
||||
* @protected
|
||||
*/
|
||||
@@ -409,7 +409,7 @@ class Overlay extends BaseObject {
|
||||
/**
|
||||
* Pan the map so that the overlay is entirely visible in the current viewport
|
||||
* (if necessary).
|
||||
* @param {PanIntoViewOptions=} opt_panIntoViewOptions Options for the pan action
|
||||
* @param {PanIntoViewOptions} [opt_panIntoViewOptions] Options for the pan action
|
||||
* @api
|
||||
*/
|
||||
panIntoView(opt_panIntoViewOptions) {
|
||||
@@ -458,6 +458,9 @@ class Overlay extends BaseObject {
|
||||
.getView()
|
||||
.getCenterInternal());
|
||||
const centerPx = map.getPixelFromCoordinateInternal(center);
|
||||
if (!centerPx) {
|
||||
return;
|
||||
}
|
||||
const newCenterPx = [centerPx[0] + delta[0], centerPx[1] + delta[1]];
|
||||
|
||||
const panOptions = panIntoViewOptions.animation || {};
|
||||
|
||||
@@ -48,26 +48,20 @@ import {removeNode} from './dom.js';
|
||||
* @property {number} pixelRatio The pixel ratio of the frame.
|
||||
* @property {number} time The time when rendering of the frame was requested.
|
||||
* @property {import("./View.js").State} viewState The state of the current view.
|
||||
* @property {boolean} animate
|
||||
* @property {import("./transform.js").Transform} coordinateToPixelTransform
|
||||
* @property {null|import("./extent.js").Extent} extent
|
||||
* @property {Array<DeclutterItems>} declutterItems
|
||||
* @property {number} index
|
||||
* @property {Array<import("./layer/Layer.js").State>} layerStatesArray
|
||||
* @property {number} layerIndex
|
||||
* @property {import("./transform.js").Transform} pixelToCoordinateTransform
|
||||
* @property {Array<PostRenderFunction>} postRenderFunctions
|
||||
* @property {import("./size.js").Size} size
|
||||
* @property {TileQueue} tileQueue
|
||||
* @property {!Object<string, Object<string, boolean>>} usedTiles
|
||||
* @property {Array<number>} viewHints
|
||||
* @property {!Object<string, Object<string, boolean>>} wantedTiles
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} DeclutterItems
|
||||
* @property {Array<*>} items Declutter items of an executor.
|
||||
* @property {number} opacity Layer opacity.
|
||||
* @property {boolean} animate Animate.
|
||||
* @property {import("./transform.js").Transform} coordinateToPixelTransform CoordinateToPixelTransform.
|
||||
* @property {import("rbush").default} declutterTree DeclutterTree.
|
||||
* @property {null|import("./extent.js").Extent} extent Extent.
|
||||
* @property {number} index Index.
|
||||
* @property {Array<import("./layer/Layer.js").State>} layerStatesArray LayerStatesArray.
|
||||
* @property {number} layerIndex LayerIndex.
|
||||
* @property {import("./transform.js").Transform} pixelToCoordinateTransform PixelToCoordinateTransform.
|
||||
* @property {Array<PostRenderFunction>} postRenderFunctions PostRenderFunctions.
|
||||
* @property {import("./size.js").Size} size Size.
|
||||
* @property {TileQueue} tileQueue TileQueue.
|
||||
* @property {!Object<string, Object<string, boolean>>} usedTiles UsedTiles.
|
||||
* @property {Array<number>} viewHints ViewHints.
|
||||
* @property {!Object<string, Object<string, boolean>>} wantedTiles WantedTiles.
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -81,7 +75,7 @@ import {removeNode} from './dom.js';
|
||||
* {@link module:ol/layer/Layer layer-candidate} and it should return a boolean value.
|
||||
* Only layers which are visible and for which this function returns `true`
|
||||
* will be tested for features. By default, all visible layers will be tested.
|
||||
* @property {number} [hitTolerance=0] Hit-detection tolerance in pixels. Pixels
|
||||
* @property {number} [hitTolerance=0] Hit-detection tolerance in css pixels. Pixels
|
||||
* inside the radius around the given position will be checked for features.
|
||||
* @property {boolean} [checkWrapped=true] Check-Wrapped Will check for for wrapped geometries inside the range of
|
||||
* +/- 1 world width. Works only if a projection is used that can be wrapped.
|
||||
@@ -89,11 +83,11 @@ import {removeNode} from './dom.js';
|
||||
|
||||
/**
|
||||
* @typedef {Object} MapOptionsInternal
|
||||
* @property {Collection<import("./control/Control.js").default>} [controls]
|
||||
* @property {Collection<import("./interaction/Interaction.js").default>} [interactions]
|
||||
* @property {HTMLElement|Document} keyboardEventTarget
|
||||
* @property {Collection<import("./Overlay.js").default>} overlays
|
||||
* @property {Object<string, *>} values
|
||||
* @property {Collection<import("./control/Control.js").default>} [controls] Controls.
|
||||
* @property {Collection<import("./interaction/Interaction.js").default>} [interactions] Interactions.
|
||||
* @property {HTMLElement|Document} keyboardEventTarget KeyboardEventTarget.
|
||||
* @property {Collection<import("./Overlay.js").default>} overlays Overlays.
|
||||
* @property {Object<string, *>} values Values.
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -130,7 +124,7 @@ import {removeNode} from './dom.js';
|
||||
* @property {HTMLElement|string} [target] The container for the map, either the
|
||||
* element itself or the `id` of the element. If not specified at construction
|
||||
* time, {@link module:ol/Map~Map#setTarget} must be called for the map to be
|
||||
* rendered.
|
||||
* rendered. If passed by element, the container can be in a secondary document.
|
||||
* @property {View} [view] The map's view. No layer sources will be
|
||||
* fetched unless this is specified at construction time or through
|
||||
* {@link module:ol/Map~Map#setView}.
|
||||
@@ -187,7 +181,7 @@ class PluggableMap extends BaseObject {
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
this.animationDelay_ = function () {
|
||||
this.animationDelay_ = /** @this {PluggableMap} */ function () {
|
||||
this.animationDelayKey_ = undefined;
|
||||
this.renderFrame_(Date.now());
|
||||
}.bind(this);
|
||||
@@ -544,15 +538,14 @@ class PluggableMap extends BaseObject {
|
||||
* callback with each intersecting feature. Layers included in the detection can
|
||||
* be configured through the `layerFilter` option in `opt_options`.
|
||||
* @param {import("./pixel.js").Pixel} pixel Pixel.
|
||||
* @param {function(this: S, import("./Feature.js").FeatureLike,
|
||||
* import("./layer/Layer.js").default): T} callback Feature callback. The callback will be
|
||||
* @param {function(import("./Feature.js").FeatureLike, import("./layer/Layer.js").default, import("./geom/SimpleGeometry.js").default): T} callback Feature callback. The callback will be
|
||||
* called with two arguments. The first argument is one
|
||||
* {@link module:ol/Feature feature} or
|
||||
* {@link module:ol/render/Feature render feature} at the pixel, the second is
|
||||
* the {@link module:ol/layer/Layer layer} of the feature and will be null for
|
||||
* unmanaged layers. To stop detection, callback functions can return a
|
||||
* truthy value.
|
||||
* @param {AtPixelOptions=} opt_options Optional options.
|
||||
* @param {AtPixelOptions} [opt_options] Optional options.
|
||||
* @return {T|undefined} Callback result, i.e. the return value of last
|
||||
* callback execution, or the first truthy callback return value.
|
||||
* @template S,T
|
||||
@@ -565,9 +558,7 @@ class PluggableMap extends BaseObject {
|
||||
const coordinate = this.getCoordinateFromPixelInternal(pixel);
|
||||
opt_options = opt_options !== undefined ? opt_options : {};
|
||||
const hitTolerance =
|
||||
opt_options.hitTolerance !== undefined
|
||||
? opt_options.hitTolerance * this.frameState_.pixelRatio
|
||||
: 0;
|
||||
opt_options.hitTolerance !== undefined ? opt_options.hitTolerance : 0;
|
||||
const layerFilter =
|
||||
opt_options.layerFilter !== undefined ? opt_options.layerFilter : TRUE;
|
||||
const checkWrapped = opt_options.checkWrapped !== false;
|
||||
@@ -586,7 +577,7 @@ class PluggableMap extends BaseObject {
|
||||
/**
|
||||
* Get all features that intersect a pixel on the viewport.
|
||||
* @param {import("./pixel.js").Pixel} pixel Pixel.
|
||||
* @param {AtPixelOptions=} opt_options Optional options.
|
||||
* @param {AtPixelOptions} [opt_options] Optional options.
|
||||
* @return {Array<import("./Feature.js").FeatureLike>} The detected features or
|
||||
* an empty array if none were found.
|
||||
* @api
|
||||
@@ -618,7 +609,7 @@ class PluggableMap extends BaseObject {
|
||||
* [R, G, B, A] pixel values (0 - 255) and will be `null` for layer types
|
||||
* that do not currently support this argument. To stop detection, callback
|
||||
* functions can return a truthy value.
|
||||
* @param {AtPixelOptions=} opt_options Configuration options.
|
||||
* @param {AtPixelOptions} [opt_options] Configuration options.
|
||||
* @return {T|undefined} Callback result, i.e. the return value of last
|
||||
* callback execution, or the first truthy callback return value.
|
||||
* @template S,T
|
||||
@@ -630,9 +621,7 @@ class PluggableMap extends BaseObject {
|
||||
}
|
||||
const options = opt_options || {};
|
||||
const hitTolerance =
|
||||
options.hitTolerance !== undefined
|
||||
? options.hitTolerance * this.frameState_.pixelRatio
|
||||
: 0;
|
||||
options.hitTolerance !== undefined ? options.hitTolerance : 0;
|
||||
const layerFilter = options.layerFilter || TRUE;
|
||||
return this.renderer_.forEachLayerAtPixel(
|
||||
pixel,
|
||||
@@ -647,7 +636,7 @@ class PluggableMap extends BaseObject {
|
||||
* Detect if features intersect a pixel on the viewport. Layers included in the
|
||||
* detection can be configured through `opt_layerFilter`.
|
||||
* @param {import("./pixel.js").Pixel} pixel Pixel.
|
||||
* @param {AtPixelOptions=} opt_options Optional options.
|
||||
* @param {AtPixelOptions} [opt_options] Optional options.
|
||||
* @return {boolean} Is there a feature at the given pixel?
|
||||
* @api
|
||||
*/
|
||||
@@ -660,9 +649,7 @@ class PluggableMap extends BaseObject {
|
||||
const layerFilter =
|
||||
opt_options.layerFilter !== undefined ? opt_options.layerFilter : TRUE;
|
||||
const hitTolerance =
|
||||
opt_options.hitTolerance !== undefined
|
||||
? opt_options.hitTolerance * this.frameState_.pixelRatio
|
||||
: 0;
|
||||
opt_options.hitTolerance !== undefined ? opt_options.hitTolerance : 0;
|
||||
const checkWrapped = opt_options.checkWrapped !== false;
|
||||
return this.renderer_.hasFeatureAtCoordinate(
|
||||
coordinate,
|
||||
@@ -695,7 +682,7 @@ class PluggableMap extends BaseObject {
|
||||
|
||||
/**
|
||||
* Returns the map pixel position for a browser event relative to the viewport.
|
||||
* @param {UIEvent} event Event.
|
||||
* @param {UIEvent|import("./MapBrowserEventHandler").PointerEventData} event Event.
|
||||
* @return {import("./pixel.js").Pixel} Pixel.
|
||||
* @api
|
||||
*/
|
||||
@@ -953,6 +940,14 @@ class PluggableMap extends BaseObject {
|
||||
return this.overlayContainerStopEvent_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {!Document} The document where the map is displayed.
|
||||
*/
|
||||
getOwnerDocument() {
|
||||
const targetElement = this.getTargetElement();
|
||||
return targetElement ? targetElement.ownerDocument : document;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("./Tile.js").default} tile Tile.
|
||||
* @param {string} tileSourceKey Tile source key.
|
||||
@@ -972,7 +967,7 @@ class PluggableMap extends BaseObject {
|
||||
|
||||
/**
|
||||
* @param {UIEvent} browserEvent Browser event.
|
||||
* @param {string=} opt_type Type.
|
||||
* @param {string} [opt_type] Type.
|
||||
*/
|
||||
handleBrowserEvent(browserEvent, opt_type) {
|
||||
const type = opt_type || browserEvent.type;
|
||||
@@ -996,16 +991,7 @@ class PluggableMap extends BaseObject {
|
||||
eventType === EventType.WHEEL ||
|
||||
eventType === EventType.KEYDOWN
|
||||
) {
|
||||
const rootNode = this.viewport_.getRootNode
|
||||
? this.viewport_.getRootNode()
|
||||
: document;
|
||||
const target =
|
||||
rootNode === document
|
||||
? /** @type {Node} */ (originalEvent.target)
|
||||
: /** @type {ShadowRoot} */ (rootNode).elementFromPoint(
|
||||
originalEvent.clientX,
|
||||
originalEvent.clientY
|
||||
);
|
||||
const target = /** @type {Node} */ (originalEvent.target);
|
||||
if (
|
||||
// Abort if the target is a child of the container for elements whose events are not meant
|
||||
// to be handled by map interactions.
|
||||
@@ -1014,23 +1000,25 @@ class PluggableMap extends BaseObject {
|
||||
// It's possible for the target to no longer be in the page if it has been removed in an
|
||||
// event listener, this might happen in a Control that recreates it's content based on
|
||||
// user interaction either manually or via a render in something like https://reactjs.org/
|
||||
!(rootNode === document ? document.documentElement : rootNode).contains(
|
||||
target
|
||||
)
|
||||
!this.getOwnerDocument().contains(target)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
mapBrowserEvent.frameState = this.frameState_;
|
||||
const interactionsArray = this.getInteractions().getArray();
|
||||
if (this.dispatchEvent(mapBrowserEvent) !== false) {
|
||||
const interactionsArray = this.getInteractions().getArray().slice();
|
||||
for (let i = interactionsArray.length - 1; i >= 0; i--) {
|
||||
const interaction = interactionsArray[i];
|
||||
if (!interaction.getActive()) {
|
||||
if (
|
||||
interaction.getMap() !== this ||
|
||||
!interaction.getActive() ||
|
||||
!this.getTargetElement()
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
const cont = interaction.handleEvent(mapBrowserEvent);
|
||||
if (!cont) {
|
||||
if (!cont || mapBrowserEvent.propagationStopped) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1141,6 +1129,7 @@ class PluggableMap extends BaseObject {
|
||||
if (!targetElement) {
|
||||
if (this.renderer_) {
|
||||
clearTimeout(this.postRenderTimeoutHandle_);
|
||||
this.postRenderTimeoutHandle_ = undefined;
|
||||
this.postRenderFunctions_.length = 0;
|
||||
this.renderer_.dispose();
|
||||
this.renderer_ = null;
|
||||
@@ -1375,9 +1364,7 @@ class PluggableMap extends BaseObject {
|
||||
frameState = {
|
||||
animate: false,
|
||||
coordinateToPixelTransform: this.coordinateToPixelTransform_,
|
||||
declutterItems: previousFrameState
|
||||
? previousFrameState.declutterItems
|
||||
: [],
|
||||
declutterTree: null,
|
||||
extent: getForViewAndSize(
|
||||
viewState.center,
|
||||
viewState.resolution,
|
||||
@@ -1441,10 +1428,12 @@ class PluggableMap extends BaseObject {
|
||||
|
||||
this.dispatchEvent(new MapEvent(MapEventType.POSTRENDER, this, frameState));
|
||||
|
||||
this.postRenderTimeoutHandle_ = setTimeout(
|
||||
this.handlePostRender.bind(this),
|
||||
0
|
||||
);
|
||||
if (!this.postRenderTimeoutHandle_) {
|
||||
this.postRenderTimeoutHandle_ = setTimeout(() => {
|
||||
this.postRenderTimeoutHandle_ = undefined;
|
||||
this.handlePostRender();
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1500,18 +1489,25 @@ class PluggableMap extends BaseObject {
|
||||
this.setSize(undefined);
|
||||
} else {
|
||||
const computedStyle = getComputedStyle(targetElement);
|
||||
this.setSize([
|
||||
const width =
|
||||
targetElement.offsetWidth -
|
||||
parseFloat(computedStyle['borderLeftWidth']) -
|
||||
parseFloat(computedStyle['paddingLeft']) -
|
||||
parseFloat(computedStyle['paddingRight']) -
|
||||
parseFloat(computedStyle['borderRightWidth']),
|
||||
parseFloat(computedStyle['borderLeftWidth']) -
|
||||
parseFloat(computedStyle['paddingLeft']) -
|
||||
parseFloat(computedStyle['paddingRight']) -
|
||||
parseFloat(computedStyle['borderRightWidth']);
|
||||
const height =
|
||||
targetElement.offsetHeight -
|
||||
parseFloat(computedStyle['borderTopWidth']) -
|
||||
parseFloat(computedStyle['paddingTop']) -
|
||||
parseFloat(computedStyle['paddingBottom']) -
|
||||
parseFloat(computedStyle['borderBottomWidth']),
|
||||
]);
|
||||
parseFloat(computedStyle['borderTopWidth']) -
|
||||
parseFloat(computedStyle['paddingTop']) -
|
||||
parseFloat(computedStyle['paddingBottom']) -
|
||||
parseFloat(computedStyle['borderBottomWidth']);
|
||||
if (height === 0 || width === 0) {
|
||||
// eslint-disable-next-line
|
||||
console.warn(
|
||||
"No map visible because the map container's width or height are 0."
|
||||
);
|
||||
}
|
||||
this.setSize([width, height]);
|
||||
}
|
||||
|
||||
this.updateViewportSize_();
|
||||
|
||||
@@ -76,7 +76,7 @@ class Tile extends EventTarget {
|
||||
/**
|
||||
* @param {import("./tilecoord.js").TileCoord} tileCoord Tile coordinate.
|
||||
* @param {import("./TileState.js").default} state State.
|
||||
* @param {Options=} opt_options Tile options.
|
||||
* @param {Options} [opt_options] Tile options.
|
||||
*/
|
||||
constructor(tileCoord, state, opt_options) {
|
||||
super();
|
||||
|
||||
@@ -136,7 +136,7 @@ class TileRange {
|
||||
* @param {number} maxX Maximum X.
|
||||
* @param {number} minY Minimum Y.
|
||||
* @param {number} maxY Maximum Y.
|
||||
* @param {TileRange=} tileRange TileRange.
|
||||
* @param {TileRange} [tileRange] TileRange.
|
||||
* @return {TileRange} Tile range.
|
||||
*/
|
||||
export function createOrUpdate(minX, maxX, minY, maxY, tileRange) {
|
||||
|
||||
@@ -7,14 +7,14 @@ import {getUid} from './util.js';
|
||||
|
||||
/**
|
||||
* @typedef {Object} ReplayState
|
||||
* @property {boolean} dirty
|
||||
* @property {null|import("./render.js").OrderFunction} renderedRenderOrder
|
||||
* @property {number} renderedTileRevision
|
||||
* @property {number} renderedResolution
|
||||
* @property {number} renderedRevision
|
||||
* @property {number} renderedZ
|
||||
* @property {number} renderedTileResolution
|
||||
* @property {number} renderedTileZ
|
||||
* @property {boolean} dirty Dirty.
|
||||
* @property {null|import("./render.js").OrderFunction} renderedRenderOrder RenderedRenderOrder.
|
||||
* @property {number} renderedTileRevision RenderedTileRevision.
|
||||
* @property {number} renderedResolution RenderedResolution.
|
||||
* @property {number} renderedRevision RenderedRevision.
|
||||
* @property {number} renderedZ RenderedZ.
|
||||
* @property {number} renderedTileResolution RenderedTileResolution.
|
||||
* @property {number} renderedTileZ RenderedTileZ.
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -45,6 +45,12 @@ class VectorRenderTile extends Tile {
|
||||
*/
|
||||
this.executorGroups = {};
|
||||
|
||||
/**
|
||||
* Executor groups for decluttering, by layer uid. Entries are read/written by the renderer.
|
||||
* @type {Object<string, Array<import("./render/canvas/ExecutorGroup.js").default>>}
|
||||
*/
|
||||
this.declutterExecutorGroups = {};
|
||||
|
||||
/**
|
||||
* Number of loading source tiles. Read/written by the source.
|
||||
* @type {number}
|
||||
@@ -164,6 +170,7 @@ class VectorRenderTile extends Tile {
|
||||
release() {
|
||||
for (const key in this.context_) {
|
||||
canvasPool.push(this.context_[key].canvas);
|
||||
delete this.context_[key];
|
||||
}
|
||||
super.release();
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ class VectorTile extends Tile {
|
||||
* @param {string} src Data source url.
|
||||
* @param {import("./format/Feature.js").default} format Feature format.
|
||||
* @param {import("./Tile.js").LoadFunction} tileLoadFunction Tile load function.
|
||||
* @param {import("./Tile.js").Options=} opt_options Tile options.
|
||||
* @param {import("./Tile.js").Options} [opt_options] Tile options.
|
||||
*/
|
||||
constructor(tileCoord, state, src, format, tileLoadFunction, opt_options) {
|
||||
super(tileCoord, state, opt_options);
|
||||
@@ -63,6 +63,8 @@ class VectorTile extends Tile {
|
||||
* @type {string}
|
||||
*/
|
||||
this.url_ = src;
|
||||
|
||||
this.key = src;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,13 +85,6 @@ class VectorTile extends Tile {
|
||||
return this.features_;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {string} Key.
|
||||
*/
|
||||
getKey() {
|
||||
return this.url_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load not yet loaded URI.
|
||||
*/
|
||||
|
||||
282
src/ol/View.js
282
src/ol/View.js
@@ -54,25 +54,25 @@ import {fromExtent as polygonFromExtent} from './geom/Polygon.js';
|
||||
* An animation configuration
|
||||
*
|
||||
* @typedef {Object} Animation
|
||||
* @property {import("./coordinate.js").Coordinate} [sourceCenter]
|
||||
* @property {import("./coordinate.js").Coordinate} [targetCenter]
|
||||
* @property {number} [sourceResolution]
|
||||
* @property {number} [targetResolution]
|
||||
* @property {number} [sourceRotation]
|
||||
* @property {number} [targetRotation]
|
||||
* @property {import("./coordinate.js").Coordinate} [anchor]
|
||||
* @property {number} start
|
||||
* @property {number} duration
|
||||
* @property {boolean} complete
|
||||
* @property {function(number):number} easing
|
||||
* @property {function(boolean):void} callback
|
||||
* @property {import("./coordinate.js").Coordinate} [sourceCenter] Source center.
|
||||
* @property {import("./coordinate.js").Coordinate} [targetCenter] Target center.
|
||||
* @property {number} [sourceResolution] Source resolution.
|
||||
* @property {number} [targetResolution] Target resolution.
|
||||
* @property {number} [sourceRotation] Source rotation.
|
||||
* @property {number} [targetRotation] Target rotation.
|
||||
* @property {import("./coordinate.js").Coordinate} [anchor] Anchor.
|
||||
* @property {number} start Start.
|
||||
* @property {number} duration Duration.
|
||||
* @property {boolean} complete Complete.
|
||||
* @property {function(number):number} easing Easing.
|
||||
* @property {function(boolean):void} callback Callback.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} Constraints
|
||||
* @property {import("./centerconstraint.js").Type} center
|
||||
* @property {import("./resolutionconstraint.js").Type} resolution
|
||||
* @property {import("./rotationconstraint.js").Type} rotation
|
||||
* @property {import("./centerconstraint.js").Type} center Center.
|
||||
* @property {import("./resolutionconstraint.js").Type} resolution Resolution.
|
||||
* @property {import("./rotationconstraint.js").Type} rotation Rotation.
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -175,6 +175,10 @@ import {fromExtent as polygonFromExtent} from './geom/Polygon.js';
|
||||
* level used to calculate the initial resolution for the view.
|
||||
* @property {number} [zoomFactor=2] The zoom factor used to compute the
|
||||
* corresponding resolution.
|
||||
* @property {!Array<number>} [padding=[0, 0, 0, 0]] Padding (in css pixels).
|
||||
* If the map viewport is partially covered with other content (overlays) along
|
||||
* its edges, this setting allows to shift the center of the viewport away from
|
||||
* that content. The order of the values is top, right, bottom, left.
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -199,11 +203,11 @@ import {fromExtent as polygonFromExtent} from './geom/Polygon.js';
|
||||
|
||||
/**
|
||||
* @typedef {Object} State
|
||||
* @property {import("./coordinate.js").Coordinate} center
|
||||
* @property {import("./proj/Projection.js").default} projection
|
||||
* @property {number} resolution
|
||||
* @property {number} rotation
|
||||
* @property {number} zoom
|
||||
* @property {import("./coordinate.js").Coordinate} center Center.
|
||||
* @property {import("./proj/Projection.js").default} projection Projection.
|
||||
* @property {number} resolution Resolution.
|
||||
* @property {number} rotation Rotation.
|
||||
* @property {number} zoom Zoom.
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -286,7 +290,7 @@ const DEFAULT_MIN_ZOOM = 0;
|
||||
*/
|
||||
class View extends BaseObject {
|
||||
/**
|
||||
* @param {ViewOptions=} opt_options View options.
|
||||
* @param {ViewOptions} [opt_options] View options.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
super();
|
||||
@@ -394,6 +398,12 @@ class View extends BaseObject {
|
||||
*/
|
||||
this.resolutions_ = options.resolutions;
|
||||
|
||||
/**
|
||||
* @type {Array<number>|undefined}
|
||||
* @private
|
||||
*/
|
||||
this.padding_ = options.padding;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {number}
|
||||
@@ -433,6 +443,36 @@ class View extends BaseObject {
|
||||
this.options_ = options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Padding (in css pixels).
|
||||
* If the map viewport is partially covered with other content (overlays) along
|
||||
* its edges, this setting allows to shift the center of the viewport away from that
|
||||
* content. The order of the values in the array is top, right, bottom, left.
|
||||
* The default is no padding, which is equivalent to `[0, 0, 0, 0]`.
|
||||
* @type {Array<number>|undefined}
|
||||
* @api
|
||||
*/
|
||||
get padding() {
|
||||
return this.padding_;
|
||||
}
|
||||
set padding(padding) {
|
||||
let oldPadding = this.padding_;
|
||||
this.padding_ = padding;
|
||||
const center = this.getCenter();
|
||||
if (center) {
|
||||
const newPadding = padding || [0, 0, 0, 0];
|
||||
oldPadding = oldPadding || [0, 0, 0, 0];
|
||||
const resolution = this.getResolution();
|
||||
const offsetX =
|
||||
(resolution / 2) *
|
||||
(newPadding[3] - oldPadding[3] + oldPadding[1] - newPadding[1]);
|
||||
const offsetY =
|
||||
(resolution / 2) *
|
||||
(newPadding[0] - oldPadding[0] + oldPadding[2] - newPadding[2]);
|
||||
this.setCenterInternal([center[0] + offsetX, center[1] - offsetY]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an updated version of the view options used to construct the view. The
|
||||
* current resolution (or zoom), center, and rotation are applied to any stored
|
||||
@@ -798,7 +838,7 @@ class View extends BaseObject {
|
||||
/**
|
||||
* Returns the current viewport size.
|
||||
* @private
|
||||
* @param {number=} opt_rotation Take into account the rotation of the viewport when giving the size
|
||||
* @param {number} [opt_rotation] Take into account the rotation of the viewport when giving the size
|
||||
* @return {import("./size.js").Size} Viewport size or `[100, 100]` when no viewport is found.
|
||||
*/
|
||||
getViewportSize_(opt_rotation) {
|
||||
@@ -822,7 +862,7 @@ class View extends BaseObject {
|
||||
* to avoid performance hit and layout reflow.
|
||||
* This should be done on map size change.
|
||||
* Note: the constraints are not resolved during an animation to avoid stopping it
|
||||
* @param {import("./size.js").Size=} opt_size Viewport size; if undefined, [100, 100] is assumed
|
||||
* @param {import("./size.js").Size} [opt_size] Viewport size; if undefined, [100, 100] is assumed
|
||||
*/
|
||||
setViewportSize(opt_size) {
|
||||
this.viewportSize_ = Array.isArray(opt_size)
|
||||
@@ -872,7 +912,7 @@ class View extends BaseObject {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Array<number>=} opt_hints Destination array.
|
||||
* @param {Array<number>} [opt_hints] Destination array.
|
||||
* @return {Array<number>} Hint.
|
||||
*/
|
||||
getHints(opt_hints) {
|
||||
@@ -890,7 +930,7 @@ class View extends BaseObject {
|
||||
* The size is the pixel dimensions of the box into which the calculated extent
|
||||
* should fit. In most cases you want to get the extent of the entire map,
|
||||
* that is `map.getSize()`.
|
||||
* @param {import("./size.js").Size=} opt_size Box pixel size. If not provided, the size
|
||||
* @param {import("./size.js").Size} [opt_size] Box pixel size. If not provided, the size
|
||||
* of the map that uses this view will be used.
|
||||
* @return {import("./extent.js").Extent} Extent.
|
||||
* @api
|
||||
@@ -901,12 +941,12 @@ class View extends BaseObject {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("./size.js").Size=} opt_size Box pixel size. If not provided, the size of the
|
||||
* first map that uses this view will be used.
|
||||
* @param {import("./size.js").Size} [opt_size] Box pixel size. If not provided,
|
||||
* the map's last known viewport size will be used.
|
||||
* @return {import("./extent.js").Extent} Extent.
|
||||
*/
|
||||
calculateExtentInternal(opt_size) {
|
||||
const size = opt_size || this.getViewportSize_();
|
||||
const size = opt_size || this.getViewportSizeMinusPadding_();
|
||||
const center = /** @type {!import("./coordinate.js").Coordinate} */ (this.getCenterInternal());
|
||||
assert(center, 1); // The view center is not defined
|
||||
const resolution = /** @type {!number} */ (this.getResolution());
|
||||
@@ -976,7 +1016,7 @@ class View extends BaseObject {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether the view shoud allow intermediary zoom levels.
|
||||
* Set whether the view should allow intermediary zoom levels.
|
||||
* @param {boolean} enabled Whether the resolution is constrained.
|
||||
* @api
|
||||
*/
|
||||
@@ -1016,7 +1056,7 @@ class View extends BaseObject {
|
||||
/**
|
||||
* Get the resolution for a provided extent (in map units) and size (in pixels).
|
||||
* @param {import("./extent.js").Extent} extent Extent.
|
||||
* @param {import("./size.js").Size=} opt_size Box pixel size.
|
||||
* @param {import("./size.js").Size} [opt_size] Box pixel size.
|
||||
* @return {number} The resolution at which the provided extent will render at
|
||||
* the given size.
|
||||
* @api
|
||||
@@ -1031,7 +1071,7 @@ class View extends BaseObject {
|
||||
/**
|
||||
* Get the resolution for a provided extent (in map units) and size (in pixels).
|
||||
* @param {import("./extent.js").Extent} extent Extent.
|
||||
* @param {import("./size.js").Size=} opt_size Box pixel size.
|
||||
* @param {import("./size.js").Size} [opt_size] Box pixel size.
|
||||
* @return {number} The resolution at which the provided extent will render at
|
||||
* the given size.
|
||||
*/
|
||||
@@ -1045,7 +1085,7 @@ class View extends BaseObject {
|
||||
/**
|
||||
* Return a function that returns a value between 0 and 1 for a
|
||||
* resolution. Exponential scaling is assumed.
|
||||
* @param {number=} opt_power Power.
|
||||
* @param {number} [opt_power] Power.
|
||||
* @return {function(number): number} Resolution for value function.
|
||||
*/
|
||||
getResolutionForValueFunction(opt_power) {
|
||||
@@ -1078,7 +1118,7 @@ class View extends BaseObject {
|
||||
/**
|
||||
* Return a function that returns a resolution for a value between
|
||||
* 0 and 1. Exponential scaling is assumed.
|
||||
* @param {number=} opt_power Power.
|
||||
* @param {number} [opt_power] Power.
|
||||
* @return {function(number): number} Value for resolution function.
|
||||
*/
|
||||
getValueForResolutionFunction(opt_power) {
|
||||
@@ -1098,14 +1138,43 @@ class View extends BaseObject {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the size of the viewport minus padding.
|
||||
* @private
|
||||
* @param {number} [opt_rotation] Take into account the rotation of the viewport when giving the size
|
||||
* @return {import("./size.js").Size} Viewport size reduced by the padding.
|
||||
*/
|
||||
getViewportSizeMinusPadding_(opt_rotation) {
|
||||
let size = this.getViewportSize_(opt_rotation);
|
||||
const padding = this.padding_;
|
||||
if (padding) {
|
||||
size = [
|
||||
size[0] - padding[1] - padding[3],
|
||||
size[1] - padding[0] - padding[2],
|
||||
];
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {State} View state.
|
||||
*/
|
||||
getState() {
|
||||
const center = /** @type {import("./coordinate.js").Coordinate} */ (this.getCenterInternal());
|
||||
const projection = this.getProjection();
|
||||
const resolution = /** @type {number} */ (this.getResolution());
|
||||
const rotation = this.getRotation();
|
||||
let center = /** @type {import("./coordinate.js").Coordinate} */ (this.getCenterInternal());
|
||||
const padding = this.padding_;
|
||||
if (padding) {
|
||||
const reducedSize = this.getViewportSizeMinusPadding_();
|
||||
center = calculateCenterOn(
|
||||
center,
|
||||
this.getViewportSize_(),
|
||||
[reducedSize[0] / 2 + padding[3], reducedSize[1] / 2 + padding[0]],
|
||||
resolution,
|
||||
rotation
|
||||
);
|
||||
}
|
||||
return {
|
||||
center: center.slice(0),
|
||||
projection: projection !== undefined ? projection : null,
|
||||
@@ -1192,12 +1261,10 @@ class View extends BaseObject {
|
||||
* Takes care of the map angle.
|
||||
* @param {import("./geom/SimpleGeometry.js").default|import("./extent.js").Extent} geometryOrExtent The geometry or
|
||||
* extent to fit the view to.
|
||||
* @param {FitOptions=} opt_options Options.
|
||||
* @param {FitOptions} [opt_options] Options.
|
||||
* @api
|
||||
*/
|
||||
fit(geometryOrExtent, opt_options) {
|
||||
const options = assign({size: this.getViewportSize_()}, opt_options || {});
|
||||
|
||||
/** @type {import("./geom/SimpleGeometry.js").default} */
|
||||
let geometry;
|
||||
assert(
|
||||
@@ -1228,18 +1295,18 @@ class View extends BaseObject {
|
||||
}
|
||||
}
|
||||
|
||||
this.fitInternal(geometry, options);
|
||||
this.fitInternal(geometry, opt_options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("./geom/SimpleGeometry.js").default} geometry The geometry.
|
||||
* @param {FitOptions=} opt_options Options.
|
||||
* @param {FitOptions} [opt_options] Options.
|
||||
*/
|
||||
fitInternal(geometry, opt_options) {
|
||||
const options = opt_options || {};
|
||||
let size = options.size;
|
||||
if (!size) {
|
||||
size = this.getViewportSize_();
|
||||
size = this.getViewportSizeMinusPadding_();
|
||||
}
|
||||
const padding =
|
||||
options.padding !== undefined ? options.padding : [0, 0, 0, 0];
|
||||
@@ -1290,14 +1357,14 @@ class View extends BaseObject {
|
||||
centerRotY += ((padding[0] - padding[2]) / 2) * resolution;
|
||||
const centerX = centerRotX * cosAngle - centerRotY * sinAngle;
|
||||
const centerY = centerRotY * cosAngle + centerRotX * sinAngle;
|
||||
const center = [centerX, centerY];
|
||||
const center = this.getConstrainedCenter([centerX, centerY], resolution);
|
||||
const callback = options.callback ? options.callback : VOID;
|
||||
|
||||
if (options.duration !== undefined) {
|
||||
this.animateInternal(
|
||||
{
|
||||
resolution: resolution,
|
||||
center: this.getConstrainedCenter(center, resolution),
|
||||
center: center,
|
||||
duration: options.duration,
|
||||
easing: options.easing,
|
||||
},
|
||||
@@ -1332,22 +1399,43 @@ class View extends BaseObject {
|
||||
* @param {import("./pixel.js").Pixel} position Position on the view to center on.
|
||||
*/
|
||||
centerOnInternal(coordinate, size, position) {
|
||||
// calculate rotated position
|
||||
const rotation = this.getRotation();
|
||||
const cosAngle = Math.cos(-rotation);
|
||||
let sinAngle = Math.sin(-rotation);
|
||||
let rotX = coordinate[0] * cosAngle - coordinate[1] * sinAngle;
|
||||
let rotY = coordinate[1] * cosAngle + coordinate[0] * sinAngle;
|
||||
const resolution = this.getResolution();
|
||||
rotX += (size[0] / 2 - position[0]) * resolution;
|
||||
rotY += (position[1] - size[1] / 2) * resolution;
|
||||
this.setCenterInternal(
|
||||
calculateCenterOn(
|
||||
coordinate,
|
||||
size,
|
||||
position,
|
||||
this.getResolution(),
|
||||
this.getRotation()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// go back to original angle
|
||||
sinAngle = -sinAngle; // go back to original rotation
|
||||
const centerX = rotX * cosAngle - rotY * sinAngle;
|
||||
const centerY = rotY * cosAngle + rotX * sinAngle;
|
||||
|
||||
this.setCenterInternal([centerX, centerY]);
|
||||
/**
|
||||
* Calculates the shift between map and viewport center.
|
||||
* @param {import("./coordinate.js").Coordinate} center Center.
|
||||
* @param {number} resolution Resolution.
|
||||
* @param {number} rotation Rotation.
|
||||
* @param {import("./size.js").Size} size Size.
|
||||
* @return {Array<number>|undefined} Center shift.
|
||||
*/
|
||||
calculateCenterShift(center, resolution, rotation, size) {
|
||||
let centerShift;
|
||||
const padding = this.padding_;
|
||||
if (padding && center) {
|
||||
const reducedSize = this.getViewportSizeMinusPadding_(-rotation);
|
||||
const shiftedCenter = calculateCenterOn(
|
||||
center,
|
||||
size,
|
||||
[reducedSize[0] / 2 + padding[3], reducedSize[1] / 2 + padding[0]],
|
||||
resolution,
|
||||
rotation
|
||||
);
|
||||
centerShift = [
|
||||
center[0] - shiftedCenter[0],
|
||||
center[1] - shiftedCenter[1],
|
||||
];
|
||||
}
|
||||
return centerShift;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1386,7 +1474,7 @@ class View extends BaseObject {
|
||||
* Multiply the view resolution by a ratio, optionally using an anchor. Any resolution
|
||||
* constraint will apply.
|
||||
* @param {number} ratio The ratio to apply on the view resolution.
|
||||
* @param {import("./coordinate.js").Coordinate=} opt_anchor The origin of the transformation.
|
||||
* @param {import("./coordinate.js").Coordinate} [opt_anchor] The origin of the transformation.
|
||||
* @api
|
||||
*/
|
||||
adjustResolution(ratio, opt_anchor) {
|
||||
@@ -1399,7 +1487,7 @@ class View extends BaseObject {
|
||||
* Multiply the view resolution by a ratio, optionally using an anchor. Any resolution
|
||||
* constraint will apply.
|
||||
* @param {number} ratio The ratio to apply on the view resolution.
|
||||
* @param {import("./coordinate.js").Coordinate=} opt_anchor The origin of the transformation.
|
||||
* @param {import("./coordinate.js").Coordinate} [opt_anchor] The origin of the transformation.
|
||||
*/
|
||||
adjustResolutionInternal(ratio, opt_anchor) {
|
||||
const isMoving = this.getAnimating() || this.getInteracting();
|
||||
@@ -1423,7 +1511,7 @@ class View extends BaseObject {
|
||||
* Adds a value to the view zoom level, optionally using an anchor. Any resolution
|
||||
* constraint will apply.
|
||||
* @param {number} delta Relative value to add to the zoom level.
|
||||
* @param {import("./coordinate.js").Coordinate=} opt_anchor The origin of the transformation.
|
||||
* @param {import("./coordinate.js").Coordinate} [opt_anchor] The origin of the transformation.
|
||||
* @api
|
||||
*/
|
||||
adjustZoom(delta, opt_anchor) {
|
||||
@@ -1434,7 +1522,7 @@ class View extends BaseObject {
|
||||
* Adds a value to the view rotation, optionally using an anchor. Any rotation
|
||||
* constraint will apply.
|
||||
* @param {number} delta Relative value to add to the zoom rotation, in radians.
|
||||
* @param {import("./coordinate.js").Coordinate=} opt_anchor The rotation center.
|
||||
* @param {import("./coordinate.js").Coordinate} [opt_anchor] The rotation center.
|
||||
* @api
|
||||
*/
|
||||
adjustRotation(delta, opt_anchor) {
|
||||
@@ -1446,7 +1534,7 @@ class View extends BaseObject {
|
||||
|
||||
/**
|
||||
* @param {number} delta Relative value to add to the zoom rotation, in radians.
|
||||
* @param {import("./coordinate.js").Coordinate=} opt_anchor The rotation center.
|
||||
* @param {import("./coordinate.js").Coordinate} [opt_anchor] The rotation center.
|
||||
*/
|
||||
adjustRotationInternal(delta, opt_anchor) {
|
||||
const isMoving = this.getAnimating() || this.getInteracting();
|
||||
@@ -1526,8 +1614,8 @@ class View extends BaseObject {
|
||||
* Recompute rotation/resolution/center based on target values.
|
||||
* Note: we have to compute rotation first, then resolution and center considering that
|
||||
* parameters can influence one another in case a view extent constraint is present.
|
||||
* @param {boolean=} opt_doNotCancelAnims Do not cancel animations.
|
||||
* @param {boolean=} opt_forceMoving Apply constraints as if the view is moving.
|
||||
* @param {boolean} [opt_doNotCancelAnims] Do not cancel animations.
|
||||
* @param {boolean} [opt_forceMoving] Apply constraints as if the view is moving.
|
||||
* @private
|
||||
*/
|
||||
applyTargetState_(opt_doNotCancelAnims, opt_forceMoving) {
|
||||
@@ -1550,7 +1638,13 @@ class View extends BaseObject {
|
||||
this.targetCenter_,
|
||||
newResolution,
|
||||
size,
|
||||
isMoving
|
||||
isMoving,
|
||||
this.calculateCenterShift(
|
||||
this.targetCenter_,
|
||||
newResolution,
|
||||
newRotation,
|
||||
size
|
||||
)
|
||||
);
|
||||
|
||||
if (this.get(ViewProperty.ROTATION) !== newRotation) {
|
||||
@@ -1577,9 +1671,9 @@ class View extends BaseObject {
|
||||
* This is typically done on interaction end.
|
||||
* Note: calling this with a duration of 0 will apply the constrained values straight away,
|
||||
* without animation.
|
||||
* @param {number=} opt_duration The animation duration in ms.
|
||||
* @param {number=} opt_resolutionDirection Which direction to zoom.
|
||||
* @param {import("./coordinate.js").Coordinate=} opt_anchor The origin of the transformation.
|
||||
* @param {number} [opt_duration] The animation duration in ms.
|
||||
* @param {number} [opt_resolutionDirection] Which direction to zoom.
|
||||
* @param {import("./coordinate.js").Coordinate} [opt_anchor] The origin of the transformation.
|
||||
*/
|
||||
resolveConstraints(opt_duration, opt_resolutionDirection, opt_anchor) {
|
||||
const duration = opt_duration !== undefined ? opt_duration : 200;
|
||||
@@ -1595,7 +1689,14 @@ class View extends BaseObject {
|
||||
const newCenter = this.constraints_.center(
|
||||
this.targetCenter_,
|
||||
newResolution,
|
||||
size
|
||||
size,
|
||||
false,
|
||||
this.calculateCenterShift(
|
||||
this.targetCenter_,
|
||||
newResolution,
|
||||
newRotation,
|
||||
size
|
||||
)
|
||||
);
|
||||
|
||||
if (duration === 0 && !this.cancelAnchor_) {
|
||||
@@ -1646,9 +1747,9 @@ class View extends BaseObject {
|
||||
/**
|
||||
* Notify the View that an interaction has ended. The view state will be resolved
|
||||
* to a stable one if needed (depending on its constraints).
|
||||
* @param {number=} opt_duration Animation duration in ms.
|
||||
* @param {number=} opt_resolutionDirection Which direction to zoom.
|
||||
* @param {import("./coordinate.js").Coordinate=} opt_anchor The origin of the transformation.
|
||||
* @param {number} [opt_duration] Animation duration in ms.
|
||||
* @param {number} [opt_resolutionDirection] Which direction to zoom.
|
||||
* @param {import("./coordinate.js").Coordinate} [opt_anchor] The origin of the transformation.
|
||||
* @api
|
||||
*/
|
||||
endInteraction(opt_duration, opt_resolutionDirection, opt_anchor) {
|
||||
@@ -1660,9 +1761,9 @@ class View extends BaseObject {
|
||||
/**
|
||||
* Notify the View that an interaction has ended. The view state will be resolved
|
||||
* to a stable one if needed (depending on its constraints).
|
||||
* @param {number=} opt_duration Animation duration in ms.
|
||||
* @param {number=} opt_resolutionDirection Which direction to zoom.
|
||||
* @param {import("./coordinate.js").Coordinate=} opt_anchor The origin of the transformation.
|
||||
* @param {number} [opt_duration] Animation duration in ms.
|
||||
* @param {number} [opt_resolutionDirection] Which direction to zoom.
|
||||
* @param {import("./coordinate.js").Coordinate} [opt_anchor] The origin of the transformation.
|
||||
*/
|
||||
endInteractionInternal(opt_duration, opt_resolutionDirection, opt_anchor) {
|
||||
this.setHint(ViewHint.INTERACTING, -1);
|
||||
@@ -1673,7 +1774,7 @@ class View extends BaseObject {
|
||||
/**
|
||||
* Get a valid position for the view center according to the current constraints.
|
||||
* @param {import("./coordinate.js").Coordinate|undefined} targetCenter Target center position.
|
||||
* @param {number=} opt_targetResolution Target resolution. If not supplied, the current one will be used.
|
||||
* @param {number} [opt_targetResolution] Target resolution. If not supplied, the current one will be used.
|
||||
* This is useful to guess a valid center position at a different zoom level.
|
||||
* @return {import("./coordinate.js").Coordinate|undefined} Valid center position.
|
||||
*/
|
||||
@@ -1689,7 +1790,7 @@ class View extends BaseObject {
|
||||
/**
|
||||
* Get a valid zoom level according to the current view constraints.
|
||||
* @param {number|undefined} targetZoom Target zoom.
|
||||
* @param {number=} [opt_direction=0] Indicate which resolution should be used
|
||||
* @param {number} [opt_direction=0] Indicate which resolution should be used
|
||||
* by a renderer if the view resolution does not match any resolution of the tile source.
|
||||
* If 0, the nearest resolution will be used. If 1, the nearest lower resolution
|
||||
* will be used. If -1, the nearest higher resolution will be used.
|
||||
@@ -1705,7 +1806,7 @@ class View extends BaseObject {
|
||||
/**
|
||||
* Get a valid resolution according to the current view constraints.
|
||||
* @param {number|undefined} targetResolution Target resolution.
|
||||
* @param {number=} [opt_direction=0] Indicate which resolution should be used
|
||||
* @param {number} [opt_direction=0] Indicate which resolution should be used
|
||||
* by a renderer if the view resolution does not match any resolution of the tile source.
|
||||
* If 0, the nearest resolution will be used. If 1, the nearest lower resolution
|
||||
* will be used. If -1, the nearest higher resolution will be used.
|
||||
@@ -1936,4 +2037,29 @@ export function isNoopAnimation(animation) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("./coordinate.js").Coordinate} coordinate Coordinate.
|
||||
* @param {import("./size.js").Size} size Box pixel size.
|
||||
* @param {import("./pixel.js").Pixel} position Position on the view to center on.
|
||||
* @param {number} resolution Resolution.
|
||||
* @param {number} rotation Rotation.
|
||||
* @return {import("./coordinate.js").Coordinate} Shifted center.
|
||||
*/
|
||||
function calculateCenterOn(coordinate, size, position, resolution, rotation) {
|
||||
// calculate rotated position
|
||||
const cosAngle = Math.cos(-rotation);
|
||||
let sinAngle = Math.sin(-rotation);
|
||||
let rotX = coordinate[0] * cosAngle - coordinate[1] * sinAngle;
|
||||
let rotY = coordinate[1] * cosAngle + coordinate[0] * sinAngle;
|
||||
rotX += (size[0] / 2 - position[0]) * resolution;
|
||||
rotY += (position[1] - size[1] / 2) * resolution;
|
||||
|
||||
// go back to original angle
|
||||
sinAngle = -sinAngle; // go back to original rotation
|
||||
const centerX = rotX * cosAngle - rotY * sinAngle;
|
||||
const centerY = rotY * cosAngle + rotX * sinAngle;
|
||||
|
||||
return [centerX, centerY];
|
||||
}
|
||||
|
||||
export default View;
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
* @param {Array<*>} haystack Items to search through.
|
||||
* @param {*} needle The item to look for.
|
||||
* @param {Function=} opt_comparator Comparator function.
|
||||
* @param {Function} [opt_comparator] Comparator function.
|
||||
* @return {number} The index of the item if found, -1 if not.
|
||||
*/
|
||||
export function binarySearch(haystack, needle, opt_comparator) {
|
||||
@@ -222,8 +222,8 @@ export function findIndex(arr, func) {
|
||||
|
||||
/**
|
||||
* @param {Array<*>} arr The array to test.
|
||||
* @param {Function=} opt_func Comparison function.
|
||||
* @param {boolean=} opt_strict Strictly sorted (default false).
|
||||
* @param {Function} [opt_func] Comparison function.
|
||||
* @param {boolean} [opt_strict] Strictly sorted (default false).
|
||||
* @return {boolean} Return index.
|
||||
*/
|
||||
export function isSorted(arr, opt_func, opt_strict) {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
import {clamp} from './math.js';
|
||||
|
||||
/**
|
||||
* @typedef {function((import("./coordinate.js").Coordinate|undefined), number, import("./size.js").Size, boolean=): (import("./coordinate.js").Coordinate|undefined)} Type
|
||||
* @typedef {function((import("./coordinate.js").Coordinate|undefined), number, import("./size.js").Size, boolean=, Array<number>=): (import("./coordinate.js").Coordinate|undefined)} Type
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -20,17 +20,20 @@ export function createExtent(extent, onlyCenter, smooth) {
|
||||
* @param {import("./coordinate.js").Coordinate|undefined} center Center.
|
||||
* @param {number} resolution Resolution.
|
||||
* @param {import("./size.js").Size} size Viewport size; unused if `onlyCenter` was specified.
|
||||
* @param {boolean=} opt_isMoving True if an interaction or animation is in progress.
|
||||
* @param {boolean} [opt_isMoving] True if an interaction or animation is in progress.
|
||||
* @param {Array<number>} [opt_centerShift] Shift between map center and viewport center.
|
||||
* @return {import("./coordinate.js").Coordinate|undefined} Center.
|
||||
*/
|
||||
function (center, resolution, size, opt_isMoving) {
|
||||
function (center, resolution, size, opt_isMoving, opt_centerShift) {
|
||||
if (center) {
|
||||
const viewWidth = onlyCenter ? 0 : size[0] * resolution;
|
||||
const viewHeight = onlyCenter ? 0 : size[1] * resolution;
|
||||
let minX = extent[0] + viewWidth / 2;
|
||||
let maxX = extent[2] - viewWidth / 2;
|
||||
let minY = extent[1] + viewHeight / 2;
|
||||
let maxY = extent[3] - viewHeight / 2;
|
||||
const shiftX = opt_centerShift ? opt_centerShift[0] : 0;
|
||||
const shiftY = opt_centerShift ? opt_centerShift[1] : 0;
|
||||
let minX = extent[0] + viewWidth / 2 + shiftX;
|
||||
let maxX = extent[2] - viewWidth / 2 + shiftX;
|
||||
let minY = extent[1] + viewHeight / 2 + shiftY;
|
||||
let maxY = extent[3] - viewHeight / 2 + shiftY;
|
||||
|
||||
// note: when zooming out of bounds, min and max values for x and y may
|
||||
// end up inverted (min > max); this has to be accounted for
|
||||
@@ -66,7 +69,7 @@ export function createExtent(extent, onlyCenter, smooth) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("./coordinate.js").Coordinate=} center Center.
|
||||
* @param {import("./coordinate.js").Coordinate} [center] Center.
|
||||
* @return {import("./coordinate.js").Coordinate|undefined} Center.
|
||||
*/
|
||||
export function none(center) {
|
||||
|
||||
@@ -41,7 +41,7 @@ export {default as ZoomToExtent} from './control/ZoomToExtent.js';
|
||||
* * {@link module:ol/control/Rotate~Rotate}
|
||||
* * {@link module:ol/control/Attribution~Attribution}
|
||||
*
|
||||
* @param {DefaultsOptions=} opt_options
|
||||
* @param {DefaultsOptions} [opt_options]
|
||||
* Defaults options.
|
||||
* @return {Collection<import("./control/Control.js").default>}
|
||||
* Controls.
|
||||
|
||||
@@ -23,9 +23,13 @@ import {removeChildren, replaceNode} from '../dom.js';
|
||||
* @property {string} [label='i'] Text label to use for the
|
||||
* collapsed attributions button.
|
||||
* Instead of text, also an element (e.g. a `span` element) can be used.
|
||||
* @property {string} [expandClassName=className + '-expand'] CSS class name for the
|
||||
* collapsed attributions button.
|
||||
* @property {string|HTMLElement} [collapseLabel='»'] Text label to use
|
||||
* for the expanded attributions button.
|
||||
* Instead of text, also an element (e.g. a `span` element) can be used.
|
||||
* @property {string} [collapseClassName=className + '-collapse'] CSS class name for the
|
||||
* expanded attributions button.
|
||||
* @property {function(import("../MapEvent.js").default):void} [render] Function called when
|
||||
* the control should be re-rendered. This is called in a `requestAnimationFrame`
|
||||
* callback.
|
||||
@@ -42,7 +46,7 @@ import {removeChildren, replaceNode} from '../dom.js';
|
||||
*/
|
||||
class Attribution extends Control {
|
||||
/**
|
||||
* @param {Options=} opt_options Attribution options.
|
||||
* @param {Options} [opt_options] Attribution options.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
const options = opt_options ? opt_options : {};
|
||||
@@ -66,6 +70,12 @@ class Attribution extends Control {
|
||||
this.collapsed_ =
|
||||
options.collapsed !== undefined ? options.collapsed : true;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.userCollapsed_ = this.collapsed_;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {boolean}
|
||||
@@ -89,9 +99,19 @@ class Attribution extends Control {
|
||||
const tipLabel =
|
||||
options.tipLabel !== undefined ? options.tipLabel : 'Attributions';
|
||||
|
||||
const expandClassName =
|
||||
options.expandClassName !== undefined
|
||||
? options.expandClassName
|
||||
: className + '-expand';
|
||||
|
||||
const collapseLabel =
|
||||
options.collapseLabel !== undefined ? options.collapseLabel : '\u00BB';
|
||||
|
||||
const collapseClassName =
|
||||
options.collapseClassName !== undefined
|
||||
? options.collapseClassName
|
||||
: className + '-collpase';
|
||||
|
||||
if (typeof collapseLabel === 'string') {
|
||||
/**
|
||||
* @private
|
||||
@@ -99,6 +119,7 @@ class Attribution extends Control {
|
||||
*/
|
||||
this.collapseLabel_ = document.createElement('span');
|
||||
this.collapseLabel_.textContent = collapseLabel;
|
||||
this.collapseLabel_.className = collapseClassName;
|
||||
} else {
|
||||
this.collapseLabel_ = collapseLabel;
|
||||
}
|
||||
@@ -112,6 +133,7 @@ class Attribution extends Control {
|
||||
*/
|
||||
this.label_ = document.createElement('span');
|
||||
this.label_.textContent = label;
|
||||
this.label_.className = expandClassName;
|
||||
} else {
|
||||
this.label_ = label;
|
||||
}
|
||||
@@ -175,6 +197,7 @@ class Attribution extends Control {
|
||||
*/
|
||||
const visibleAttributions = [];
|
||||
|
||||
let collapsible = true;
|
||||
const layerStatesArray = frameState.layerStatesArray;
|
||||
for (let i = 0, ii = layerStatesArray.length; i < ii; ++i) {
|
||||
const layerState = layerStatesArray[i];
|
||||
@@ -197,12 +220,8 @@ class Attribution extends Control {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (
|
||||
!this.overrideCollapsible_ &&
|
||||
source.getAttributionsCollapsible() === false
|
||||
) {
|
||||
this.setCollapsible(false);
|
||||
}
|
||||
collapsible =
|
||||
collapsible && source.getAttributionsCollapsible() !== false;
|
||||
|
||||
if (Array.isArray(attributions)) {
|
||||
for (let j = 0, jj = attributions.length; j < jj; ++j) {
|
||||
@@ -218,6 +237,9 @@ class Attribution extends Control {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!this.overrideCollapsible_) {
|
||||
this.setCollapsible(collapsible);
|
||||
}
|
||||
return visibleAttributions;
|
||||
}
|
||||
|
||||
@@ -265,6 +287,7 @@ class Attribution extends Control {
|
||||
handleClick_(event) {
|
||||
event.preventDefault();
|
||||
this.handleToggle_();
|
||||
this.userCollapsed_ = this.collapsed_;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -300,7 +323,7 @@ class Attribution extends Control {
|
||||
}
|
||||
this.collapsible_ = collapsible;
|
||||
this.element.classList.toggle('ol-uncollapsible');
|
||||
if (!collapsible && this.collapsed_) {
|
||||
if (this.userCollapsed_) {
|
||||
this.handleToggle_();
|
||||
}
|
||||
}
|
||||
@@ -313,6 +336,7 @@ class Attribution extends Control {
|
||||
* @api
|
||||
*/
|
||||
setCollapsed(collapsed) {
|
||||
this.userCollapsed_ = collapsed;
|
||||
if (!this.collapsible_ || this.collapsed_ === collapsed) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -39,6 +39,10 @@ const FullScreenEventType = {
|
||||
* Instead of text, also an element (e.g. a `span` element) can be used.
|
||||
* @property {string|Text} [labelActive='\u00d7'] Text label to use for the
|
||||
* button when full-screen is active.
|
||||
* @property {string} [activeClassName=className + '-true'] CSS class name for the button
|
||||
* when full-screen is active.
|
||||
* @property {string} [inactiveClassName=className + '-false'] CSS class name for the button
|
||||
* when full-screen is inactive.
|
||||
* Instead of text, also an element (e.g. a `span` element) can be used.
|
||||
* @property {string} [tipLabel='Toggle full-screen'] Text label to use for the button tip.
|
||||
* @property {boolean} [keys=false] Full keyboard access.
|
||||
@@ -57,7 +61,7 @@ const FullScreenEventType = {
|
||||
* element introduced using this parameter will be displayed in full screen.
|
||||
*
|
||||
* When in full screen mode, a close button is shown to exit full screen mode.
|
||||
* The [Fullscreen API](http://www.w3.org/TR/fullscreen/) is used to
|
||||
* The [Fullscreen API](https://www.w3.org/TR/fullscreen/) is used to
|
||||
* toggle the map in full screen mode.
|
||||
*
|
||||
* @fires FullScreenEventType#enterfullscreen
|
||||
@@ -66,7 +70,7 @@ const FullScreenEventType = {
|
||||
*/
|
||||
class FullScreen extends Control {
|
||||
/**
|
||||
* @param {Options=} opt_options Options.
|
||||
* @param {Options} [opt_options] Options.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
const options = opt_options ? opt_options : {};
|
||||
@@ -83,6 +87,24 @@ class FullScreen extends Control {
|
||||
this.cssClassName_ =
|
||||
options.className !== undefined ? options.className : 'ol-full-screen';
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array<string>}
|
||||
*/
|
||||
this.activeClassName_ =
|
||||
options.activeClassName !== undefined
|
||||
? options.activeClassName.split(' ')
|
||||
: [this.cssClassName_ + '-true'];
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array<string>}
|
||||
*/
|
||||
this.inactiveClassName_ =
|
||||
options.inactiveClassName !== undefined
|
||||
? options.inactiveClassName.split(' ')
|
||||
: [this.cssClassName_ + '-false'];
|
||||
|
||||
const label = options.label !== undefined ? options.label : '\u2922';
|
||||
|
||||
/**
|
||||
@@ -212,12 +234,12 @@ class FullScreen extends Control {
|
||||
* @private
|
||||
*/
|
||||
setClassName_(element, fullscreen) {
|
||||
const activeClassName = this.cssClassName_ + '-true';
|
||||
const inactiveClassName = this.cssClassName_ + '-false';
|
||||
const activeClassName = this.activeClassName_;
|
||||
const inactiveClassName = this.inactiveClassName_;
|
||||
const nextClassName = fullscreen ? activeClassName : inactiveClassName;
|
||||
element.classList.remove(activeClassName);
|
||||
element.classList.remove(inactiveClassName);
|
||||
element.classList.add(nextClassName);
|
||||
element.classList.remove(...activeClassName);
|
||||
element.classList.remove(...inactiveClassName);
|
||||
element.classList.add(...nextClassName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -54,7 +54,7 @@ const COORDINATE_FORMAT = 'coordinateFormat';
|
||||
*/
|
||||
class MousePosition extends Control {
|
||||
/**
|
||||
* @param {Options=} opt_options Mouse position options.
|
||||
* @param {Options} [opt_options] Mouse position options.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
const options = opt_options ? opt_options : {};
|
||||
|
||||
@@ -74,7 +74,7 @@ class ControlledMap extends PluggableMap {
|
||||
*/
|
||||
class OverviewMap extends Control {
|
||||
/**
|
||||
* @param {Options=} opt_options OverviewMap options.
|
||||
* @param {Options} [opt_options] OverviewMap options.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
const options = opt_options ? opt_options : {};
|
||||
|
||||
@@ -12,6 +12,7 @@ import {easeOut} from '../easing.js';
|
||||
* @property {string|HTMLElement} [label='⇧'] Text label to use for the rotate button.
|
||||
* Instead of text, also an element (e.g. a `span` element) can be used.
|
||||
* @property {string} [tipLabel='Reset rotation'] Text label to use for the rotate tip.
|
||||
* @property {string} [compassClassName='ol-compass'] CSS class name for the compass.
|
||||
* @property {number} [duration=250] Animation duration in milliseconds.
|
||||
* @property {boolean} [autoHide=true] Hide the control when rotation is 0.
|
||||
* @property {function(import("../MapEvent.js").default):void} [render] Function called when the control should
|
||||
@@ -32,7 +33,7 @@ import {easeOut} from '../easing.js';
|
||||
*/
|
||||
class Rotate extends Control {
|
||||
/**
|
||||
* @param {Options=} opt_options Rotate options.
|
||||
* @param {Options} [opt_options] Rotate options.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
const options = opt_options ? opt_options : {};
|
||||
@@ -48,6 +49,11 @@ class Rotate extends Control {
|
||||
|
||||
const label = options.label !== undefined ? options.label : '\u21E7';
|
||||
|
||||
const compassClassName =
|
||||
options.compassClassName !== undefined
|
||||
? options.compassClassName
|
||||
: 'ol-compass';
|
||||
|
||||
/**
|
||||
* @type {HTMLElement}
|
||||
* @private
|
||||
@@ -56,11 +62,11 @@ class Rotate extends Control {
|
||||
|
||||
if (typeof label === 'string') {
|
||||
this.label_ = document.createElement('span');
|
||||
this.label_.className = 'ol-compass';
|
||||
this.label_.className = compassClassName;
|
||||
this.label_.textContent = label;
|
||||
} else {
|
||||
this.label_ = label;
|
||||
this.label_.classList.add('ol-compass');
|
||||
this.label_.classList.add(compassClassName);
|
||||
}
|
||||
|
||||
const tipLabel = options.tipLabel ? options.tipLabel : 'Reset rotation';
|
||||
|
||||
@@ -73,7 +73,7 @@ const DEFAULT_DPI = 25.4 / 0.28;
|
||||
*/
|
||||
class ScaleLine extends Control {
|
||||
/**
|
||||
* @param {Options=} opt_options Scale line options.
|
||||
* @param {Options} [opt_options] Scale line options.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
const options = opt_options ? opt_options : {};
|
||||
@@ -329,7 +329,7 @@ class ScaleLine extends Control {
|
||||
* @param {number} width The current width of the scalebar.
|
||||
* @param {number} scale The current scale.
|
||||
* @param {string} suffix The suffix to append to the scale text.
|
||||
* @returns {string} The stringified HTML of the scalebar.
|
||||
* @return {string} The stringified HTML of the scalebar.
|
||||
*/
|
||||
createScaleBar(width, scale, suffix) {
|
||||
const mapScale =
|
||||
@@ -400,9 +400,9 @@ class ScaleLine extends Control {
|
||||
|
||||
/**
|
||||
* Creates a marker at given position
|
||||
* @param {string} position - The position, absolute or relative
|
||||
* @param {number} i - The iterator
|
||||
* @returns {string} The stringified div containing the marker
|
||||
* @param {string} position The position, absolute or relative
|
||||
* @param {number} i The iterator
|
||||
* @return {string} The stringified div containing the marker
|
||||
*/
|
||||
createMarker(position, i) {
|
||||
const top = position === 'absolute' ? 3 : -10;
|
||||
@@ -421,12 +421,12 @@ class ScaleLine extends Control {
|
||||
|
||||
/**
|
||||
* Creates the label for a marker marker at given position
|
||||
* @param {number} i - The iterator
|
||||
* @param {number} width - The width the scalebar will currently use
|
||||
* @param {boolean} isLast - Flag indicating if we add the last step text
|
||||
* @param {number} scale - The current scale for the whole scalebar
|
||||
* @param {string} suffix - The suffix for the scale
|
||||
* @returns {string} The stringified div containing the step text
|
||||
* @param {number} i The iterator
|
||||
* @param {number} width The width the scalebar will currently use
|
||||
* @param {boolean} isLast Flag indicating if we add the last step text
|
||||
* @param {number} scale The current scale for the whole scalebar
|
||||
* @param {string} suffix The suffix for the scale
|
||||
* @return {string} The stringified div containing the step text
|
||||
*/
|
||||
createStepText(i, width, isLast, scale, suffix) {
|
||||
const length =
|
||||
@@ -468,7 +468,7 @@ class ScaleLine extends Control {
|
||||
);
|
||||
const dpi = this.dpi_ || DEFAULT_DPI;
|
||||
const mpu = this.viewState_.projection.getMetersPerUnit();
|
||||
const inchesPerMeter = 39.37;
|
||||
const inchesPerMeter = 1000 / 25.4;
|
||||
return parseFloat(resolution.toString()) * mpu * inchesPerMeter * dpi;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@ import {easeOut} from '../easing.js';
|
||||
* @typedef {Object} Options
|
||||
* @property {number} [duration=250] Animation duration in milliseconds.
|
||||
* @property {string} [className='ol-zoom'] CSS class name.
|
||||
* @property {string} [zoomInClassName=className + '-in'] CSS class name for the zoom-in button.
|
||||
* @property {string} [zoomOutClassName=className + '-out'] CSS class name for the zoom-out button.
|
||||
* @property {string|HTMLElement} [zoomInLabel='+'] Text label to use for the zoom-in
|
||||
* button. Instead of text, also an element (e.g. a `span` element) can be used.
|
||||
* @property {string|HTMLElement} [zoomOutLabel='-'] Text label to use for the zoom-out button.
|
||||
@@ -31,7 +33,7 @@ import {easeOut} from '../easing.js';
|
||||
*/
|
||||
class Zoom extends Control {
|
||||
/**
|
||||
* @param {Options=} opt_options Zoom options.
|
||||
* @param {Options} [opt_options] Zoom options.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
const options = opt_options ? opt_options : {};
|
||||
@@ -46,6 +48,16 @@ class Zoom extends Control {
|
||||
|
||||
const delta = options.delta !== undefined ? options.delta : 1;
|
||||
|
||||
const zoomInClassName =
|
||||
options.zoomInClassName !== undefined
|
||||
? options.zoomInClassName
|
||||
: className + '-in';
|
||||
|
||||
const zoomOutClassName =
|
||||
options.zoomOutClassName !== undefined
|
||||
? options.zoomOutClassName
|
||||
: className + '-out';
|
||||
|
||||
const zoomInLabel =
|
||||
options.zoomInLabel !== undefined ? options.zoomInLabel : '+';
|
||||
const zoomOutLabel =
|
||||
@@ -59,7 +71,7 @@ class Zoom extends Control {
|
||||
: 'Zoom out';
|
||||
|
||||
const inElement = document.createElement('button');
|
||||
inElement.className = className + '-in';
|
||||
inElement.className = zoomInClassName;
|
||||
inElement.setAttribute('type', 'button');
|
||||
inElement.title = zoomInTipLabel;
|
||||
inElement.appendChild(
|
||||
@@ -75,7 +87,7 @@ class Zoom extends Control {
|
||||
);
|
||||
|
||||
const outElement = document.createElement('button');
|
||||
outElement.className = className + '-out';
|
||||
outElement.className = zoomOutClassName;
|
||||
outElement.setAttribute('type', 'button');
|
||||
outElement.title = zoomOutTipLabel;
|
||||
outElement.appendChild(
|
||||
|
||||
@@ -41,7 +41,7 @@ const Direction = {
|
||||
*/
|
||||
class ZoomSlider extends Control {
|
||||
/**
|
||||
* @param {Options=} opt_options Zoom slider options.
|
||||
* @param {Options} [opt_options] Zoom slider options.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
const options = opt_options ? opt_options : {};
|
||||
@@ -52,7 +52,7 @@ class ZoomSlider extends Control {
|
||||
});
|
||||
|
||||
/**
|
||||
* @type {!Array.<import("../events.js").EventsKey>}
|
||||
* @type {!Array<import("../events.js").EventsKey>}
|
||||
* @private
|
||||
*/
|
||||
this.dragListenerKeys_ = [];
|
||||
@@ -250,9 +250,10 @@ class ZoomSlider extends Control {
|
||||
if (this.dragListenerKeys_.length === 0) {
|
||||
const drag = this.handleDraggerDrag_;
|
||||
const end = this.handleDraggerEnd_;
|
||||
const doc = this.getMap().getOwnerDocument();
|
||||
this.dragListenerKeys_.push(
|
||||
listen(document, PointerEventType.POINTERMOVE, drag, this),
|
||||
listen(document, PointerEventType.POINTERUP, end, this)
|
||||
listen(doc, PointerEventType.POINTERMOVE, drag, this),
|
||||
listen(doc, PointerEventType.POINTERUP, end, this)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ import {fromExtent as polygonFromExtent} from '../geom/Polygon.js';
|
||||
*/
|
||||
class ZoomToExtent extends Control {
|
||||
/**
|
||||
* @param {Options=} opt_options Options.
|
||||
* @param {Options} [opt_options] Options.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
const options = opt_options ? opt_options : {};
|
||||
|
||||
@@ -135,7 +135,7 @@ export function closestOnSegment(coordinate, segment) {
|
||||
* var out = stringifyFunc(coord);
|
||||
* // out is now '7.85, 47.98'
|
||||
*
|
||||
* @param {number=} opt_fractionDigits The number of digits to include
|
||||
* @param {number} [opt_fractionDigits] The number of digits to include
|
||||
* after the decimal point. Default is `0`.
|
||||
* @return {CoordinateFormat} Coordinate format.
|
||||
* @api
|
||||
@@ -155,7 +155,7 @@ export function createStringXY(opt_fractionDigits) {
|
||||
/**
|
||||
* @param {string} hemispheres Hemispheres.
|
||||
* @param {number} degrees Degrees.
|
||||
* @param {number=} opt_fractionDigits The number of digits to include
|
||||
* @param {number} [opt_fractionDigits] The number of digits to include
|
||||
* after the decimal point. Default is `0`.
|
||||
* @return {string} String.
|
||||
*/
|
||||
@@ -219,7 +219,7 @@ export function degreesToStringHDMS(hemispheres, degrees, opt_fractionDigits) {
|
||||
* @param {Coordinate} coordinate Coordinate.
|
||||
* @param {string} template A template string with `{x}` and `{y}` placeholders
|
||||
* that will be replaced by first and second coordinate values.
|
||||
* @param {number=} opt_fractionDigits The number of digits to include
|
||||
* @param {number} [opt_fractionDigits] The number of digits to include
|
||||
* after the decimal point. Default is `0`.
|
||||
* @return {string} Formatted coordinate.
|
||||
* @api
|
||||
@@ -354,7 +354,7 @@ export function squaredDistanceToSegment(coordinate, segment) {
|
||||
* // out is now '47° 58′ 60.0″ N 7° 50′ 60.0″ E'
|
||||
*
|
||||
* @param {Coordinate} coordinate Coordinate.
|
||||
* @param {number=} opt_fractionDigits The number of digits to include
|
||||
* @param {number} [opt_fractionDigits] The number of digits to include
|
||||
* after the decimal point. Default is `0`.
|
||||
* @return {string} Hemisphere, degrees, minutes and seconds.
|
||||
* @api
|
||||
@@ -391,7 +391,7 @@ export function toStringHDMS(coordinate, opt_fractionDigits) {
|
||||
* // out is now '7.8, 48.0'
|
||||
*
|
||||
* @param {Coordinate} coordinate Coordinate.
|
||||
* @param {number=} opt_fractionDigits The number of digits to include
|
||||
* @param {number} [opt_fractionDigits] The number of digits to include
|
||||
* after the decimal point. Default is `0`.
|
||||
* @return {string} XY.
|
||||
* @api
|
||||
@@ -422,7 +422,7 @@ export function wrapX(coordinate, projection) {
|
||||
/**
|
||||
* @param {Coordinate} coordinate Coordinate.
|
||||
* @param {import("./proj/Projection.js").default} projection Projection.
|
||||
* @param {number=} opt_sourceExtentWidth Width of the source extent.
|
||||
* @param {number} [opt_sourceExtentWidth] Width of the source extent.
|
||||
* @return {number} Offset in world widths.
|
||||
*/
|
||||
export function getWorldsAway(coordinate, projection, opt_sourceExtentWidth) {
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
|
||||
/**
|
||||
* @typedef {Object} FontParameters
|
||||
* @property {string} style
|
||||
* @property {string} variant
|
||||
* @property {string} weight
|
||||
* @property {string} size
|
||||
* @property {string} lineHeight
|
||||
* @property {string} family
|
||||
* @property {Array<string>} families
|
||||
* @property {string} style Style.
|
||||
* @property {string} variant Variant.
|
||||
* @property {string} weight Weight.
|
||||
* @property {string} size Size.
|
||||
* @property {string} lineHeight LineHeight.
|
||||
* @property {string} family Family.
|
||||
* @property {Array<string>} families Families.
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -63,7 +63,7 @@ export const CLASS_CONTROL = 'ol-control';
|
||||
export const CLASS_COLLAPSED = 'ol-collapsed';
|
||||
|
||||
/**
|
||||
* From http://stackoverflow.com/questions/10135697/regex-to-parse-any-css-font
|
||||
* From https://stackoverflow.com/questions/10135697/regex-to-parse-any-css-font
|
||||
* @type {RegExp}
|
||||
*/
|
||||
const fontRegEx = new RegExp(
|
||||
|
||||
@@ -7,9 +7,9 @@ import {WORKER_OFFSCREEN_CANVAS} from './has.js';
|
||||
//FIXME Move this function to the canvas module
|
||||
/**
|
||||
* 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.
|
||||
* @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.
|
||||
*/
|
||||
export function createCanvasContext2D(opt_width, opt_height, opt_canvasPool) {
|
||||
@@ -72,7 +72,7 @@ export function replaceNode(newNode, oldNode) {
|
||||
|
||||
/**
|
||||
* @param {Node} node The node to remove.
|
||||
* @returns {Node} The node that was removed or null.
|
||||
* @return {Node} The node that was removed or null.
|
||||
*/
|
||||
export function removeNode(node) {
|
||||
return node && node.parentNode ? node.parentNode.removeChild(node) : null;
|
||||
|
||||
@@ -6,9 +6,9 @@ import {clear} from './obj.js';
|
||||
/**
|
||||
* 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
|
||||
* @property {ListenerFunction} listener Listener.
|
||||
* @property {import("./events/Target.js").EventTargetLike} target Target.
|
||||
* @property {string} type Type.
|
||||
* @api
|
||||
*/
|
||||
|
||||
@@ -22,7 +22,7 @@ import {clear} from './obj.js';
|
||||
|
||||
/**
|
||||
* @typedef {Object} ListenerObject
|
||||
* @property {ListenerFunction} handleEvent
|
||||
* @property {ListenerFunction} handleEvent HandleEvent listener function.
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -39,9 +39,9 @@ import {clear} from './obj.js';
|
||||
* @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
|
||||
* @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.
|
||||
* @param {boolean} [opt_once] If true, add the listener as one-off listener.
|
||||
* @return {EventsKey} Unique key for the listener.
|
||||
*/
|
||||
export function listen(target, type, listener, opt_this, opt_once) {
|
||||
@@ -80,7 +80,7 @@ export function listen(target, type, listener, opt_this, opt_once) {
|
||||
* @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
|
||||
* @param {Object} [opt_this] Object referenced by the `this` keyword in the
|
||||
* listener. Default is the `target`.
|
||||
* @return {EventsKey} Key for unlistenByKey.
|
||||
*/
|
||||
|
||||
@@ -27,7 +27,7 @@ import {clear} from '../obj.js';
|
||||
*/
|
||||
class Target extends Disposable {
|
||||
/**
|
||||
* @param {*=} opt_target Default event target for dispatched events.
|
||||
* @param {*} [opt_target] Default event target for dispatched events.
|
||||
*/
|
||||
constructor(opt_target) {
|
||||
super();
|
||||
@@ -147,7 +147,7 @@ class Target extends Disposable {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string=} opt_type Type. If not provided,
|
||||
* @param {string} [opt_type] Type. If not provided,
|
||||
* `true` will be returned if this event target has any listeners.
|
||||
* @return {boolean} Has listeners.
|
||||
*/
|
||||
|
||||
@@ -248,7 +248,7 @@ export const mouseOnly = function (mapBrowserEvent) {
|
||||
const pointerEvent = /** @type {import("../MapBrowserEvent").default} */ (mapBrowserEvent)
|
||||
.originalEvent;
|
||||
assert(pointerEvent !== undefined, 56); // mapBrowserEvent must originate from a pointer event
|
||||
// see http://www.w3.org/TR/pointerevents/#widl-PointerEvent-pointerType
|
||||
// see https://www.w3.org/TR/pointerevents/#widl-PointerEvent-pointerType
|
||||
return pointerEvent.pointerType == 'mouse';
|
||||
};
|
||||
|
||||
@@ -263,7 +263,7 @@ export const touchOnly = function (mapBrowserEvent) {
|
||||
const pointerEvt = /** @type {import("../MapBrowserEvent").default} */ (mapBrowserEvent)
|
||||
.originalEvent;
|
||||
assert(pointerEvt !== undefined, 56); // mapBrowserEvent must originate from a pointer event
|
||||
// see http://www.w3.org/TR/pointerevents/#widl-PointerEvent-pointerType
|
||||
// see https://www.w3.org/TR/pointerevents/#widl-PointerEvent-pointerType
|
||||
return pointerEvt.pointerType === 'touch';
|
||||
};
|
||||
|
||||
@@ -278,14 +278,14 @@ export const penOnly = function (mapBrowserEvent) {
|
||||
const pointerEvt = /** @type {import("../MapBrowserEvent").default} */ (mapBrowserEvent)
|
||||
.originalEvent;
|
||||
assert(pointerEvt !== undefined, 56); // mapBrowserEvent must originate from a pointer event
|
||||
// see http://www.w3.org/TR/pointerevents/#widl-PointerEvent-pointerType
|
||||
// see https://www.w3.org/TR/pointerevents/#widl-PointerEvent-pointerType
|
||||
return pointerEvt.pointerType === 'pen';
|
||||
};
|
||||
|
||||
/**
|
||||
* Return `true` if the event originates from a primary pointer in
|
||||
* contact with the surface or if the left mouse button is pressed.
|
||||
* See http://www.w3.org/TR/pointerevents/#button-states.
|
||||
* See https://www.w3.org/TR/pointerevents/#button-states.
|
||||
*
|
||||
* @param {import("../MapBrowserEvent.js").default} mapBrowserEvent Map browser event.
|
||||
* @return {boolean} True if the event originates from a primary pointer.
|
||||
|
||||
@@ -29,7 +29,7 @@ export function boundingExtent(coordinates) {
|
||||
/**
|
||||
* @param {Array<number>} xs Xs.
|
||||
* @param {Array<number>} ys Ys.
|
||||
* @param {Extent=} opt_extent Destination extent.
|
||||
* @param {Extent} [opt_extent] Destination extent.
|
||||
* @private
|
||||
* @return {Extent} Extent.
|
||||
*/
|
||||
@@ -45,7 +45,7 @@ function _boundingExtentXYs(xs, ys, opt_extent) {
|
||||
* Return extent increased by the provided value.
|
||||
* @param {Extent} extent Extent.
|
||||
* @param {number} value The amount by which the extent should be buffered.
|
||||
* @param {Extent=} opt_extent Extent.
|
||||
* @param {Extent} [opt_extent] Extent.
|
||||
* @return {Extent} Extent.
|
||||
* @api
|
||||
*/
|
||||
@@ -70,7 +70,7 @@ export function buffer(extent, value, opt_extent) {
|
||||
* Creates a clone of an extent.
|
||||
*
|
||||
* @param {Extent} extent Extent to clone.
|
||||
* @param {Extent=} opt_extent Extent.
|
||||
* @param {Extent} [opt_extent] Extent.
|
||||
* @return {Extent} The clone.
|
||||
*/
|
||||
export function clone(extent, opt_extent) {
|
||||
@@ -202,7 +202,7 @@ export function createEmpty() {
|
||||
* @param {number} minY Minimum Y.
|
||||
* @param {number} maxX Maximum X.
|
||||
* @param {number} maxY Maximum Y.
|
||||
* @param {Extent=} opt_extent Destination extent.
|
||||
* @param {Extent} [opt_extent] Destination extent.
|
||||
* @return {Extent} Extent.
|
||||
*/
|
||||
export function createOrUpdate(minX, minY, maxX, maxY, opt_extent) {
|
||||
@@ -219,7 +219,7 @@ export function createOrUpdate(minX, minY, maxX, maxY, opt_extent) {
|
||||
|
||||
/**
|
||||
* Create a new empty extent or make the provided one empty.
|
||||
* @param {Extent=} opt_extent Extent.
|
||||
* @param {Extent} [opt_extent] Extent.
|
||||
* @return {Extent} Extent.
|
||||
*/
|
||||
export function createOrUpdateEmpty(opt_extent) {
|
||||
@@ -228,7 +228,7 @@ export function createOrUpdateEmpty(opt_extent) {
|
||||
|
||||
/**
|
||||
* @param {import("./coordinate.js").Coordinate} coordinate Coordinate.
|
||||
* @param {Extent=} opt_extent Extent.
|
||||
* @param {Extent} [opt_extent] Extent.
|
||||
* @return {Extent} Extent.
|
||||
*/
|
||||
export function createOrUpdateFromCoordinate(coordinate, opt_extent) {
|
||||
@@ -239,7 +239,7 @@ export function createOrUpdateFromCoordinate(coordinate, opt_extent) {
|
||||
|
||||
/**
|
||||
* @param {Array<import("./coordinate.js").Coordinate>} coordinates Coordinates.
|
||||
* @param {Extent=} opt_extent Extent.
|
||||
* @param {Extent} [opt_extent] Extent.
|
||||
* @return {Extent} Extent.
|
||||
*/
|
||||
export function createOrUpdateFromCoordinates(coordinates, opt_extent) {
|
||||
@@ -252,7 +252,7 @@ export function createOrUpdateFromCoordinates(coordinates, opt_extent) {
|
||||
* @param {number} offset Offset.
|
||||
* @param {number} end End.
|
||||
* @param {number} stride Stride.
|
||||
* @param {Extent=} opt_extent Extent.
|
||||
* @param {Extent} [opt_extent] Extent.
|
||||
* @return {Extent} Extent.
|
||||
*/
|
||||
export function createOrUpdateFromFlatCoordinates(
|
||||
@@ -268,7 +268,7 @@ export function createOrUpdateFromFlatCoordinates(
|
||||
|
||||
/**
|
||||
* @param {Array<Array<import("./coordinate.js").Coordinate>>} rings Rings.
|
||||
* @param {Extent=} opt_extent Extent.
|
||||
* @param {Extent} [opt_extent] Extent.
|
||||
* @return {Extent} Extent.
|
||||
*/
|
||||
export function createOrUpdateFromRings(rings, opt_extent) {
|
||||
@@ -521,7 +521,7 @@ export function getEnlargedArea(extent1, extent2) {
|
||||
* @param {number} resolution Resolution.
|
||||
* @param {number} rotation Rotation.
|
||||
* @param {import("./size.js").Size} size Size.
|
||||
* @param {Extent=} opt_extent Destination extent.
|
||||
* @param {Extent} [opt_extent] Destination extent.
|
||||
* @return {Extent} Extent.
|
||||
*/
|
||||
export function getForViewAndSize(
|
||||
@@ -582,7 +582,7 @@ export function getIntersectionArea(extent1, extent2) {
|
||||
* 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.
|
||||
* @param {Extent} [opt_extent] Optional extent to populate with intersection.
|
||||
* @return {Extent} Intersecting extent.
|
||||
* @api
|
||||
*/
|
||||
@@ -691,7 +691,7 @@ export function isEmpty(extent) {
|
||||
|
||||
/**
|
||||
* @param {Extent} extent Extent.
|
||||
* @param {Extent=} opt_extent Extent.
|
||||
* @param {Extent} [opt_extent] Extent.
|
||||
* @return {Extent} Extent.
|
||||
*/
|
||||
export function returnOrUpdate(extent, opt_extent) {
|
||||
@@ -788,8 +788,8 @@ export function intersectsSegment(extent, start, end) {
|
||||
* @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.
|
||||
* @param {number=} opt_stops Number of stops per side used for the transform.
|
||||
* @param {Extent} [opt_extent] Destination extent.
|
||||
* @param {number} [opt_stops] Number of stops per side used for the transform.
|
||||
* By default only the corners are used.
|
||||
* @return {Extent} Extent.
|
||||
* @api
|
||||
|
||||
@@ -15,16 +15,22 @@ let withCredentials = false;
|
||||
* {@link module:ol/source/Vector} sources use a function of this type to
|
||||
* load features.
|
||||
*
|
||||
* This function takes an {@link module:ol/extent~Extent} representing the area to be loaded,
|
||||
* a `{number}` representing the resolution (map units per pixel) and an
|
||||
* {@link module:ol/proj/Projection} for the projection as
|
||||
* arguments. `this` within the function is bound to the
|
||||
* This function takes up to 5 arguments. These are an {@link module:ol/extent~Extent} representing
|
||||
* the area to be loaded, a `{number}` representing the resolution (map units per pixel), an
|
||||
* {@link module:ol/proj/Projection} for the projection, an optional success callback that should get
|
||||
* the loaded features passed as an argument and an optional failure callback with no arguments. If
|
||||
* the callbacks are not used, the corresponding vector source will not fire `'featuresloadend'` and
|
||||
* `'featuresloaderror'` events. `this` within the function is bound to the
|
||||
* {@link module:ol/source/Vector} it's called from.
|
||||
*
|
||||
* The function is responsible for loading the features and adding them to the
|
||||
* source.
|
||||
* @typedef {function(this:(import("./source/Vector").default|import("./VectorTile.js").default), import("./extent.js").Extent, number,
|
||||
* import("./proj/Projection.js").default): void} FeatureLoader
|
||||
* @typedef {function(this:(import("./source/Vector").default|import("./VectorTile.js").default),
|
||||
* import("./extent.js").Extent,
|
||||
* number,
|
||||
* import("./proj/Projection.js").default,
|
||||
* function(Array<import("./Feature.js").default>): void=,
|
||||
* function(): void=): void} FeatureLoader
|
||||
* @api
|
||||
*/
|
||||
|
||||
@@ -43,81 +49,77 @@ let withCredentials = false;
|
||||
/**
|
||||
* @param {string|FeatureUrlFunction} url Feature URL service.
|
||||
* @param {import("./format/Feature.js").default} format Feature format.
|
||||
* @param {function(this:import("./VectorTile.js").default, Array<import("./Feature.js").default>, import("./proj/Projection.js").default, import("./extent.js").Extent): void|function(this:import("./source/Vector").default, Array<import("./Feature.js").default>): void} success
|
||||
* Function called with the loaded features and optionally with the data
|
||||
* projection. Called with the vector tile or source as `this`.
|
||||
* @param {function(this:import("./VectorTile.js").default): void|function(this:import("./source/Vector").default): void} failure
|
||||
* Function called when loading failed. Called with the vector tile or
|
||||
* source as `this`.
|
||||
* @return {FeatureLoader} The feature loader.
|
||||
* @param {import("./extent.js").Extent} extent Extent.
|
||||
* @param {number} resolution Resolution.
|
||||
* @param {import("./proj/Projection.js").default} projection Projection.
|
||||
* @param {function(Array<import("./Feature.js").default>, import("./proj/Projection.js").default): void} success Success
|
||||
* Function called with the loaded features and optionally with the data projection.
|
||||
* @param {function(): void} failure Failure
|
||||
* Function called when loading failed.
|
||||
*/
|
||||
export function loadFeaturesXhr(url, format, success, failure) {
|
||||
return (
|
||||
/**
|
||||
* @param {import("./extent.js").Extent} extent Extent.
|
||||
* @param {number} resolution Resolution.
|
||||
* @param {import("./proj/Projection.js").default} projection Projection.
|
||||
* @this {import("./source/Vector").default|import("./VectorTile.js").default}
|
||||
*/
|
||||
function (extent, resolution, projection) {
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open(
|
||||
'GET',
|
||||
typeof url === 'function' ? url(extent, resolution, projection) : url,
|
||||
true
|
||||
);
|
||||
if (format.getType() == FormatType.ARRAY_BUFFER) {
|
||||
xhr.responseType = 'arraybuffer';
|
||||
}
|
||||
xhr.withCredentials = withCredentials;
|
||||
/**
|
||||
* @param {Event} event Event.
|
||||
* @private
|
||||
*/
|
||||
xhr.onload = function (event) {
|
||||
// status will be 0 for file:// urls
|
||||
if (!xhr.status || (xhr.status >= 200 && xhr.status < 300)) {
|
||||
const type = format.getType();
|
||||
/** @type {Document|Node|Object|string|undefined} */
|
||||
let source;
|
||||
if (type == FormatType.JSON || type == FormatType.TEXT) {
|
||||
source = xhr.responseText;
|
||||
} else if (type == FormatType.XML) {
|
||||
source = xhr.responseXML;
|
||||
if (!source) {
|
||||
source = new DOMParser().parseFromString(
|
||||
xhr.responseText,
|
||||
'application/xml'
|
||||
);
|
||||
}
|
||||
} else if (type == FormatType.ARRAY_BUFFER) {
|
||||
source = /** @type {ArrayBuffer} */ (xhr.response);
|
||||
}
|
||||
if (source) {
|
||||
success.call(
|
||||
this,
|
||||
format.readFeatures(source, {
|
||||
extent: extent,
|
||||
featureProjection: projection,
|
||||
}),
|
||||
format.readProjection(source)
|
||||
);
|
||||
} else {
|
||||
failure.call(this);
|
||||
}
|
||||
} else {
|
||||
failure.call(this);
|
||||
}
|
||||
}.bind(this);
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
xhr.onerror = function () {
|
||||
failure.call(this);
|
||||
}.bind(this);
|
||||
xhr.send();
|
||||
}
|
||||
export function loadFeaturesXhr(
|
||||
url,
|
||||
format,
|
||||
extent,
|
||||
resolution,
|
||||
projection,
|
||||
success,
|
||||
failure
|
||||
) {
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open(
|
||||
'GET',
|
||||
typeof url === 'function' ? url(extent, resolution, projection) : url,
|
||||
true
|
||||
);
|
||||
if (format.getType() == FormatType.ARRAY_BUFFER) {
|
||||
xhr.responseType = 'arraybuffer';
|
||||
}
|
||||
xhr.withCredentials = withCredentials;
|
||||
/**
|
||||
* @param {Event} event Event.
|
||||
* @private
|
||||
*/
|
||||
xhr.onload = function (event) {
|
||||
// status will be 0 for file:// urls
|
||||
if (!xhr.status || (xhr.status >= 200 && xhr.status < 300)) {
|
||||
const type = format.getType();
|
||||
/** @type {Document|Node|Object|string|undefined} */
|
||||
let source;
|
||||
if (type == FormatType.JSON || type == FormatType.TEXT) {
|
||||
source = xhr.responseText;
|
||||
} else if (type == FormatType.XML) {
|
||||
source = xhr.responseXML;
|
||||
if (!source) {
|
||||
source = new DOMParser().parseFromString(
|
||||
xhr.responseText,
|
||||
'application/xml'
|
||||
);
|
||||
}
|
||||
} else if (type == FormatType.ARRAY_BUFFER) {
|
||||
source = /** @type {ArrayBuffer} */ (xhr.response);
|
||||
}
|
||||
if (source) {
|
||||
success(
|
||||
/** @type {Array<import("./Feature.js").default>} */
|
||||
(format.readFeatures(source, {
|
||||
extent: extent,
|
||||
featureProjection: projection,
|
||||
})),
|
||||
format.readProjection(source)
|
||||
);
|
||||
} else {
|
||||
failure();
|
||||
}
|
||||
} else {
|
||||
failure();
|
||||
}
|
||||
};
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
xhr.onerror = failure;
|
||||
xhr.send();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -130,25 +132,38 @@ export function loadFeaturesXhr(url, format, success, failure) {
|
||||
* @api
|
||||
*/
|
||||
export function xhr(url, format) {
|
||||
return loadFeaturesXhr(
|
||||
url,
|
||||
format,
|
||||
/**
|
||||
* @param {Array<import("./Feature.js").default>} features The loaded features.
|
||||
* @param {import("./proj/Projection.js").default} dataProjection Data
|
||||
* projection.
|
||||
* @this {import("./source/Vector").default|import("./VectorTile.js").default}
|
||||
*/
|
||||
function (features, dataProjection) {
|
||||
const sourceOrTile = /** @type {?} */ (this);
|
||||
if (typeof sourceOrTile.addFeatures === 'function') {
|
||||
/** @type {import("./source/Vector").default} */ (sourceOrTile).addFeatures(
|
||||
features
|
||||
);
|
||||
}
|
||||
},
|
||||
/* FIXME handle error */ VOID
|
||||
);
|
||||
/**
|
||||
* @param {import("./extent.js").Extent} extent Extent.
|
||||
* @param {number} resolution Resolution.
|
||||
* @param {import("./proj/Projection.js").default} projection Projection.
|
||||
* @param {function(): void} [success] Success
|
||||
* Function called when loading succeeded.
|
||||
* @param {function(): void} [failure] Failure
|
||||
* Function called when loading failed.
|
||||
* @this {import("./source/Vector").default}
|
||||
*/
|
||||
return function (extent, resolution, projection, success, failure) {
|
||||
const source = /** @type {import("./source/Vector").default} */ (this);
|
||||
loadFeaturesXhr(
|
||||
url,
|
||||
format,
|
||||
extent,
|
||||
resolution,
|
||||
projection,
|
||||
/**
|
||||
* @param {Array<import("./Feature.js").default>} features The loaded features.
|
||||
* @param {import("./proj/Projection.js").default} dataProjection Data
|
||||
* projection.
|
||||
*/
|
||||
function (features, dataProjection) {
|
||||
if (success !== undefined) {
|
||||
success(features);
|
||||
}
|
||||
source.addFeatures(features);
|
||||
},
|
||||
/* FIXME handle error */ failure ? failure : VOID
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -78,7 +78,7 @@ GEOMETRY_WRITERS[GeometryType.MULTI_POLYGON] = writeMultiPolygonGeometry;
|
||||
*/
|
||||
class EsriJSON extends JSONFeature {
|
||||
/**
|
||||
* @param {Options=} opt_options Options.
|
||||
* @param {Options} [opt_options] Options.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
const options = opt_options ? opt_options : {};
|
||||
@@ -95,8 +95,8 @@ class EsriJSON extends JSONFeature {
|
||||
|
||||
/**
|
||||
* @param {Object} object Object.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
|
||||
* @param {string=} opt_idField Name of the field where to get the id from.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options.
|
||||
* @param {string} [opt_idField] Name of the field where to get the id from.
|
||||
* @protected
|
||||
* @return {import("../Feature.js").default} Feature.
|
||||
*/
|
||||
@@ -120,7 +120,7 @@ class EsriJSON extends JSONFeature {
|
||||
|
||||
/**
|
||||
* @param {Object} object Object.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options.
|
||||
* @protected
|
||||
* @return {Array<Feature>} Features.
|
||||
*/
|
||||
@@ -148,7 +148,7 @@ class EsriJSON extends JSONFeature {
|
||||
|
||||
/**
|
||||
* @param {EsriJSONGeometry} object Object.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options.
|
||||
* @protected
|
||||
* @return {import("../geom/Geometry.js").default} Geometry.
|
||||
*/
|
||||
@@ -180,7 +180,7 @@ class EsriJSON extends JSONFeature {
|
||||
* Encode a geometry as a EsriJSON object.
|
||||
*
|
||||
* @param {import("../geom/Geometry.js").default} geometry Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options.
|
||||
* @return {EsriJSONGeometry} Object.
|
||||
* @api
|
||||
*/
|
||||
@@ -192,7 +192,7 @@ class EsriJSON extends JSONFeature {
|
||||
* Encode a feature as a esriJSON Feature object.
|
||||
*
|
||||
* @param {import("../Feature.js").default} feature Feature.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options.
|
||||
* @return {Object} Object.
|
||||
* @api
|
||||
*/
|
||||
@@ -207,16 +207,14 @@ class EsriJSON extends JSONFeature {
|
||||
const geometry = feature.getGeometry();
|
||||
if (geometry) {
|
||||
object['geometry'] = writeGeometry(geometry, opt_options);
|
||||
if (opt_options && opt_options.featureProjection) {
|
||||
const projection =
|
||||
opt_options &&
|
||||
(opt_options.dataProjection || opt_options.featureProjection);
|
||||
if (projection) {
|
||||
object['geometry'][
|
||||
'spatialReference'
|
||||
] = /** @type {EsriJSONSpatialReferenceWkid} */ ({
|
||||
wkid: Number(
|
||||
getProjection(opt_options.featureProjection)
|
||||
.getCode()
|
||||
.split(':')
|
||||
.pop()
|
||||
),
|
||||
wkid: Number(getProjection(projection).getCode().split(':').pop()),
|
||||
});
|
||||
}
|
||||
delete properties[feature.getGeometryName()];
|
||||
@@ -233,7 +231,7 @@ class EsriJSON extends JSONFeature {
|
||||
* Encode an array of features as a EsriJSON object.
|
||||
*
|
||||
* @param {Array<import("../Feature.js").default>} features Features.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options.
|
||||
* @return {EsriJSONFeatureSet} EsriJSON Object.
|
||||
* @api
|
||||
*/
|
||||
@@ -251,7 +249,7 @@ class EsriJSON extends JSONFeature {
|
||||
|
||||
/**
|
||||
* @param {EsriJSONGeometry} object Object.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options.
|
||||
* @return {import("../geom/Geometry.js").default} Geometry.
|
||||
*/
|
||||
function readGeometry(object, opt_options) {
|
||||
@@ -431,7 +429,7 @@ function readPolygonGeometry(object) {
|
||||
|
||||
/**
|
||||
* @param {import("../geom/Point.js").default} geometry Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options.
|
||||
* @return {EsriJSONPoint} EsriJSON geometry.
|
||||
*/
|
||||
function writePointGeometry(geometry, opt_options) {
|
||||
@@ -483,7 +481,7 @@ function getHasZM(geometry) {
|
||||
|
||||
/**
|
||||
* @param {import("../geom/LineString.js").default} lineString Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options.
|
||||
* @return {EsriJSONPolyline} EsriJSON geometry.
|
||||
*/
|
||||
function writeLineStringGeometry(lineString, opt_options) {
|
||||
@@ -499,7 +497,7 @@ function writeLineStringGeometry(lineString, opt_options) {
|
||||
|
||||
/**
|
||||
* @param {import("../geom/Polygon.js").default} polygon Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options.
|
||||
* @return {EsriJSONPolygon} EsriJSON geometry.
|
||||
*/
|
||||
function writePolygonGeometry(polygon, opt_options) {
|
||||
@@ -516,7 +514,7 @@ function writePolygonGeometry(polygon, opt_options) {
|
||||
|
||||
/**
|
||||
* @param {import("../geom/MultiLineString.js").default} multiLineString Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options.
|
||||
* @return {EsriJSONPolyline} EsriJSON geometry.
|
||||
*/
|
||||
function writeMultiLineStringGeometry(multiLineString, opt_options) {
|
||||
@@ -530,7 +528,7 @@ function writeMultiLineStringGeometry(multiLineString, opt_options) {
|
||||
|
||||
/**
|
||||
* @param {import("../geom/MultiPoint.js").default} multiPoint Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options.
|
||||
* @return {EsriJSONMultipoint} EsriJSON geometry.
|
||||
*/
|
||||
function writeMultiPointGeometry(multiPoint, opt_options) {
|
||||
@@ -544,7 +542,7 @@ function writeMultiPointGeometry(multiPoint, opt_options) {
|
||||
|
||||
/**
|
||||
* @param {import("../geom/MultiPolygon.js").default} geometry Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options.
|
||||
* @return {EsriJSONPolygon} EsriJSON geometry.
|
||||
*/
|
||||
function writeMultiPolygonGeometry(geometry, opt_options) {
|
||||
@@ -565,7 +563,7 @@ function writeMultiPolygonGeometry(geometry, opt_options) {
|
||||
|
||||
/**
|
||||
* @param {import("../geom/Geometry.js").default} geometry Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options.
|
||||
* @return {EsriJSONGeometry} EsriJSON geometry.
|
||||
*/
|
||||
function writeGeometry(geometry, opt_options) {
|
||||
|
||||
@@ -67,21 +67,21 @@ class FeatureFormat {
|
||||
constructor() {
|
||||
/**
|
||||
* @protected
|
||||
* @type {import("../proj/Projection.js").default}
|
||||
* @type {import("../proj/Projection.js").default|undefined}
|
||||
*/
|
||||
this.dataProjection = null;
|
||||
this.dataProjection = undefined;
|
||||
|
||||
/**
|
||||
* @protected
|
||||
* @type {import("../proj/Projection.js").default}
|
||||
* @type {import("../proj/Projection.js").default|undefined}
|
||||
*/
|
||||
this.defaultFeatureProjection = null;
|
||||
this.defaultFeatureProjection = undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the data projection to the read options.
|
||||
* @param {Document|Element|Object|string} source Source.
|
||||
* @param {ReadOptions=} opt_options Options.
|
||||
* @param {ReadOptions} [opt_options] Options.
|
||||
* @return {ReadOptions|undefined} Options.
|
||||
* @protected
|
||||
*/
|
||||
@@ -139,7 +139,7 @@ class FeatureFormat {
|
||||
*
|
||||
* @abstract
|
||||
* @param {Document|Element|Object|string} source Source.
|
||||
* @param {ReadOptions=} opt_options Read options.
|
||||
* @param {ReadOptions} [opt_options] Read options.
|
||||
* @return {import("../Feature.js").FeatureLike} Feature.
|
||||
*/
|
||||
readFeature(source, opt_options) {
|
||||
@@ -151,7 +151,7 @@ class FeatureFormat {
|
||||
*
|
||||
* @abstract
|
||||
* @param {Document|Element|ArrayBuffer|Object|string} source Source.
|
||||
* @param {ReadOptions=} opt_options Read options.
|
||||
* @param {ReadOptions} [opt_options] Read options.
|
||||
* @return {Array<import("../Feature.js").FeatureLike>} Features.
|
||||
*/
|
||||
readFeatures(source, opt_options) {
|
||||
@@ -163,7 +163,7 @@ class FeatureFormat {
|
||||
*
|
||||
* @abstract
|
||||
* @param {Document|Element|Object|string} source Source.
|
||||
* @param {ReadOptions=} opt_options Read options.
|
||||
* @param {ReadOptions} [opt_options] Read options.
|
||||
* @return {import("../geom/Geometry.js").default} Geometry.
|
||||
*/
|
||||
readGeometry(source, opt_options) {
|
||||
@@ -175,7 +175,7 @@ class FeatureFormat {
|
||||
*
|
||||
* @abstract
|
||||
* @param {Document|Element|Object|string} source Source.
|
||||
* @return {import("../proj/Projection.js").default} Projection.
|
||||
* @return {import("../proj/Projection.js").default|undefined} Projection.
|
||||
*/
|
||||
readProjection(source) {
|
||||
return abstract();
|
||||
@@ -186,7 +186,7 @@ class FeatureFormat {
|
||||
*
|
||||
* @abstract
|
||||
* @param {import("../Feature.js").default} feature Feature.
|
||||
* @param {WriteOptions=} opt_options Write options.
|
||||
* @param {WriteOptions} [opt_options] Write options.
|
||||
* @return {string} Result.
|
||||
*/
|
||||
writeFeature(feature, opt_options) {
|
||||
@@ -198,7 +198,7 @@ class FeatureFormat {
|
||||
*
|
||||
* @abstract
|
||||
* @param {Array<import("../Feature.js").default>} features Features.
|
||||
* @param {WriteOptions=} opt_options Write options.
|
||||
* @param {WriteOptions} [opt_options] Write options.
|
||||
* @return {string} Result.
|
||||
*/
|
||||
writeFeatures(features, opt_options) {
|
||||
@@ -210,7 +210,7 @@ class FeatureFormat {
|
||||
*
|
||||
* @abstract
|
||||
* @param {import("../geom/Geometry.js").default} geometry Geometry.
|
||||
* @param {WriteOptions=} opt_options Write options.
|
||||
* @param {WriteOptions} [opt_options] Write options.
|
||||
* @return {string} Result.
|
||||
*/
|
||||
writeGeometry(geometry, opt_options) {
|
||||
@@ -223,7 +223,7 @@ export default FeatureFormat;
|
||||
/**
|
||||
* @param {import("../geom/Geometry.js").default} geometry Geometry.
|
||||
* @param {boolean} write Set to true for writing, false for reading.
|
||||
* @param {(WriteOptions|ReadOptions)=} opt_options Options.
|
||||
* @param {WriteOptions|ReadOptions} [opt_options] Options.
|
||||
* @return {import("../geom/Geometry.js").default} Transformed geometry.
|
||||
*/
|
||||
export function transformGeometryWithOptions(geometry, write, opt_options) {
|
||||
@@ -277,7 +277,7 @@ export function transformGeometryWithOptions(geometry, write, opt_options) {
|
||||
|
||||
/**
|
||||
* @param {import("../extent.js").Extent} extent Extent.
|
||||
* @param {ReadOptions=} opt_options Read options.
|
||||
* @param {ReadOptions} [opt_options] Read options.
|
||||
* @return {import("../extent.js").Extent} Transformed extent.
|
||||
*/
|
||||
export function transformExtentWithOptions(extent, opt_options) {
|
||||
|
||||
@@ -9,7 +9,7 @@ import GML3 from './GML3.js';
|
||||
* version 3.1.1.
|
||||
* Currently only supports GML 3.1.1 Simple Features profile.
|
||||
*
|
||||
* @param {import("./GMLBase.js").Options=} opt_options
|
||||
* @param {import("./GMLBase.js").Options} [opt_options]
|
||||
* Optional configuration object.
|
||||
* @api
|
||||
*/
|
||||
@@ -20,7 +20,7 @@ const GML = GML3;
|
||||
*
|
||||
* @function
|
||||
* @param {Array<import("../Feature.js").default>} features Features.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Options.
|
||||
* @return {string} Result.
|
||||
* @api
|
||||
*/
|
||||
@@ -31,7 +31,7 @@ GML.prototype.writeFeatures;
|
||||
*
|
||||
* @function
|
||||
* @param {Array<import("../Feature.js").default>} features Features.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Options.
|
||||
* @return {Node} Node.
|
||||
* @api
|
||||
*/
|
||||
|
||||
@@ -49,7 +49,7 @@ const MULTIGEOMETRY_TO_MEMBER_NODENAME = {
|
||||
*/
|
||||
class GML2 extends GMLBase {
|
||||
/**
|
||||
* @param {import("./GMLBase.js").Options=} opt_options Optional configuration object.
|
||||
* @param {import("./GMLBase.js").Options} [opt_options] Optional configuration object.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
const options =
|
||||
@@ -170,7 +170,7 @@ class GML2 extends GMLBase {
|
||||
* @const
|
||||
* @param {*} value Value.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
* @param {string=} opt_nodeName Node name.
|
||||
* @param {string} [opt_nodeName] Node name.
|
||||
* @return {Element|undefined} Node.
|
||||
* @private
|
||||
*/
|
||||
@@ -356,7 +356,7 @@ class GML2 extends GMLBase {
|
||||
|
||||
/**
|
||||
* @param {string} namespaceURI XML namespace.
|
||||
* @returns {Element} coordinates node.
|
||||
* @return {Element} coordinates node.
|
||||
* @private
|
||||
*/
|
||||
createCoordinatesNode_(namespaceURI) {
|
||||
@@ -434,7 +434,7 @@ class GML2 extends GMLBase {
|
||||
/**
|
||||
* @param {*} value Value.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
* @param {string=} opt_nodeName Node name.
|
||||
* @param {string} [opt_nodeName] Node name.
|
||||
* @return {Node} Node.
|
||||
* @private
|
||||
*/
|
||||
@@ -476,8 +476,8 @@ class GML2 extends GMLBase {
|
||||
|
||||
/**
|
||||
* @param {Array<number>} point Point geometry.
|
||||
* @param {string=} opt_srsName Optional srsName
|
||||
* @param {boolean=} opt_hasZ whether the geometry has a Z coordinate (is 3D) or not.
|
||||
* @param {string} [opt_srsName] Optional srsName
|
||||
* @param {boolean} [opt_hasZ] whether the geometry has a Z coordinate (is 3D) or not.
|
||||
* @return {string} The coords string.
|
||||
* @private
|
||||
*/
|
||||
@@ -636,7 +636,7 @@ class GML2 extends GMLBase {
|
||||
* @const
|
||||
* @param {*} value Value.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
* @param {string=} opt_nodeName Node name.
|
||||
* @param {string} [opt_nodeName] Node name.
|
||||
* @return {Node|undefined} Node.
|
||||
* @private
|
||||
*/
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/**
|
||||
* @module ol/format/GML3
|
||||
*/
|
||||
import GML2 from './GML2.js';
|
||||
import GMLBase, {GMLNS} from './GMLBase.js';
|
||||
import GeometryLayout from '../geom/GeometryLayout.js';
|
||||
import LineString from '../geom/LineString.js';
|
||||
@@ -61,7 +62,7 @@ const MULTIGEOMETRY_TO_MEMBER_NODENAME = {
|
||||
*/
|
||||
class GML3 extends GMLBase {
|
||||
/**
|
||||
* @param {import("./GMLBase.js").Options=} opt_options Optional configuration object.
|
||||
* @param {import("./GMLBase.js").Options} [opt_options] Optional configuration object.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
const options =
|
||||
@@ -465,8 +466,8 @@ class GML3 extends GMLBase {
|
||||
|
||||
/**
|
||||
* @param {Array<number>} point Point geometry.
|
||||
* @param {string=} opt_srsName Optional srsName
|
||||
* @param {boolean=} opt_hasZ whether the geometry has a Z coordinate (is 3D) or not.
|
||||
* @param {string} [opt_srsName] Optional srsName
|
||||
* @param {boolean} [opt_hasZ] whether the geometry has a Z coordinate (is 3D) or not.
|
||||
* @return {string} The coords string.
|
||||
* @private
|
||||
*/
|
||||
@@ -572,7 +573,7 @@ class GML3 extends GMLBase {
|
||||
/**
|
||||
* @param {*} value Value.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
* @param {string=} opt_nodeName Node name.
|
||||
* @param {string} [opt_nodeName] Node name.
|
||||
* @return {Node} Node.
|
||||
* @private
|
||||
*/
|
||||
@@ -919,7 +920,7 @@ class GML3 extends GMLBase {
|
||||
* @const
|
||||
* @param {*} value Value.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
* @param {string=} opt_nodeName Node name.
|
||||
* @param {string} [opt_nodeName] Node name.
|
||||
* @return {Node|undefined} Node.
|
||||
* @private
|
||||
*/
|
||||
@@ -935,7 +936,7 @@ class GML3 extends GMLBase {
|
||||
* @const
|
||||
* @param {*} value Value.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
* @param {string=} opt_nodeName Node name.
|
||||
* @param {string} [opt_nodeName] Node name.
|
||||
* @return {Element|undefined} Node.
|
||||
* @private
|
||||
*/
|
||||
@@ -967,7 +968,7 @@ class GML3 extends GMLBase {
|
||||
* Encode a geometry in GML 3.1.1 Simple Features.
|
||||
*
|
||||
* @param {import("../geom/Geometry.js").default} geometry Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Options.
|
||||
* @return {Node} Node.
|
||||
* @api
|
||||
*/
|
||||
@@ -994,7 +995,7 @@ class GML3 extends GMLBase {
|
||||
* Encode an array of features in the GML 3.1.1 format as an XML node.
|
||||
*
|
||||
* @param {Array<import("../Feature.js").default>} features Features.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Options.
|
||||
* @return {Element} Node.
|
||||
* @api
|
||||
*/
|
||||
@@ -1032,6 +1033,7 @@ GML3.prototype.GEOMETRY_FLAT_COORDINATES_PARSERS = {
|
||||
'http://www.opengis.net/gml': {
|
||||
'pos': makeReplacer(GML3.prototype.readFlatPos),
|
||||
'posList': makeReplacer(GML3.prototype.readFlatPosList),
|
||||
'coordinates': makeReplacer(GML2.prototype.readFlatCoordinates),
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1167,7 +1169,7 @@ GML3.prototype.SEGMENTS_PARSERS = {
|
||||
*
|
||||
* @function
|
||||
* @param {Array<import("../Feature.js").default>} features Features.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Options.
|
||||
* @return {string} Result.
|
||||
* @api
|
||||
*/
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/**
|
||||
* @module ol/format/GML32
|
||||
*/
|
||||
import GML2 from './GML2.js';
|
||||
import GML3 from './GML3.js';
|
||||
import GMLBase from './GMLBase.js';
|
||||
import {makeArrayPusher, makeChildAppender, makeReplacer} from '../xml.js';
|
||||
@@ -13,7 +14,7 @@ import {writeStringTextNode} from '../format/xsd.js';
|
||||
*/
|
||||
class GML32 extends GML3 {
|
||||
/**
|
||||
* @param {import("./GMLBase.js").Options=} opt_options Optional configuration object.
|
||||
* @param {import("./GMLBase.js").Options} [opt_options] Optional configuration object.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
const options = /** @type {import("./GMLBase.js").Options} */ (opt_options
|
||||
@@ -41,6 +42,7 @@ GML32.prototype.GEOMETRY_FLAT_COORDINATES_PARSERS = {
|
||||
'http://www.opengis.net/gml/3.2': {
|
||||
'pos': makeReplacer(GML3.prototype.readFlatPos),
|
||||
'posList': makeReplacer(GML3.prototype.readFlatPosList),
|
||||
'coordinates': makeReplacer(GML2.prototype.readFlatCoordinates),
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ const ONLY_WHITESPACE_RE = /^[\s\xa0]*$/;
|
||||
*/
|
||||
class GMLBase extends XMLFeature {
|
||||
/**
|
||||
* @param {Options=} opt_options Optional configuration object.
|
||||
* @param {Options} [opt_options] Optional configuration object.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
super();
|
||||
@@ -150,7 +150,11 @@ class GMLBase extends XMLFeature {
|
||||
objectStack,
|
||||
this
|
||||
);
|
||||
} else if (localName == 'featureMembers' || localName == 'featureMember') {
|
||||
} else if (
|
||||
localName == 'featureMembers' ||
|
||||
localName == 'featureMember' ||
|
||||
localName == 'member'
|
||||
) {
|
||||
const context = objectStack[0];
|
||||
let featureType = context['featureType'];
|
||||
let featureNS = context['featureNS'];
|
||||
@@ -214,7 +218,7 @@ class GMLBase extends XMLFeature {
|
||||
}
|
||||
parsersNS[featureNS[p]] = parsers;
|
||||
}
|
||||
if (localName == 'featureMember') {
|
||||
if (localName == 'featureMember' || localName == 'member') {
|
||||
features = pushParseAndPop(undefined, parsersNS, node, objectStack);
|
||||
} else {
|
||||
features = pushParseAndPop([], parsersNS, node, objectStack);
|
||||
@@ -528,7 +532,7 @@ class GMLBase extends XMLFeature {
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Options.
|
||||
* @protected
|
||||
* @return {import("../geom/Geometry.js").default|import("../extent.js").Extent} Geometry.
|
||||
*/
|
||||
@@ -542,7 +546,7 @@ class GMLBase extends XMLFeature {
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Options.
|
||||
* @return {Array<import("../Feature.js").default>} Features.
|
||||
*/
|
||||
readFeaturesFromNode(node, opt_options) {
|
||||
|
||||
@@ -109,8 +109,8 @@ const GPX_SERIALIZERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
|
||||
/**
|
||||
* @typedef {Object} LayoutOptions
|
||||
* @property {boolean} [hasZ]
|
||||
* @property {boolean} [hasM]
|
||||
* @property {boolean} [hasZ] HasZ.
|
||||
* @property {boolean} [hasM] HasM.
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -131,7 +131,7 @@ const GPX_SERIALIZERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
*/
|
||||
class GPX extends XMLFeature {
|
||||
/**
|
||||
* @param {Options=} opt_options Options.
|
||||
* @param {Options} [opt_options] Options.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
super();
|
||||
@@ -170,7 +170,7 @@ class GPX extends XMLFeature {
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Options.
|
||||
* @return {import("../Feature.js").default} Feature.
|
||||
*/
|
||||
readFeatureFromNode(node, opt_options) {
|
||||
@@ -193,7 +193,7 @@ class GPX extends XMLFeature {
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Options.
|
||||
* @return {Array<import("../Feature.js").default>} Features.
|
||||
*/
|
||||
readFeaturesFromNode(node, opt_options) {
|
||||
@@ -221,7 +221,7 @@ class GPX extends XMLFeature {
|
||||
* as tracks (`<trk>`).
|
||||
*
|
||||
* @param {Array<Feature>} features Features.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Options.
|
||||
* @return {Node} Node.
|
||||
* @api
|
||||
*/
|
||||
@@ -508,7 +508,7 @@ const GEOMETRY_TYPE_TO_NODENAME = {
|
||||
/**
|
||||
* @param {*} value Value.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
* @param {string=} opt_nodeName Node name.
|
||||
* @param {string} [opt_nodeName] Node name.
|
||||
* @return {Node|undefined} Node.
|
||||
*/
|
||||
function GPX_NODE_FACTORY(value, objectStack, opt_nodeName) {
|
||||
@@ -557,7 +557,7 @@ function appendCoordinate(flatCoordinates, layoutOptions, node, values) {
|
||||
*
|
||||
* @param {LayoutOptions} layoutOptions Layout options.
|
||||
* @param {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @param {Array<number>=} ends Ends.
|
||||
* @param {Array<number>} [ends] Ends.
|
||||
* @return {import("../geom/GeometryLayout.js").default} Layout.
|
||||
*/
|
||||
function applyLayoutOptions(layoutOptions, flatCoordinates, ends) {
|
||||
|
||||
@@ -51,7 +51,7 @@ import {transformGeometryWithOptions} from './Feature.js';
|
||||
*/
|
||||
class GeoJSON extends JSONFeature {
|
||||
/**
|
||||
* @param {Options=} opt_options Options.
|
||||
* @param {Options} [opt_options] Options.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
const options = opt_options ? opt_options : {};
|
||||
@@ -86,7 +86,7 @@ class GeoJSON extends JSONFeature {
|
||||
|
||||
/**
|
||||
* @param {Object} object Object.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options.
|
||||
* @protected
|
||||
* @return {import("../Feature.js").default} Feature.
|
||||
*/
|
||||
@@ -129,7 +129,7 @@ class GeoJSON extends JSONFeature {
|
||||
|
||||
/**
|
||||
* @param {Object} object Object.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options.
|
||||
* @protected
|
||||
* @return {Array<Feature>} Features.
|
||||
*/
|
||||
@@ -154,7 +154,7 @@ class GeoJSON extends JSONFeature {
|
||||
|
||||
/**
|
||||
* @param {GeoJSONGeometry} object Object.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options.
|
||||
* @protected
|
||||
* @return {import("../geom/Geometry.js").default} Geometry.
|
||||
*/
|
||||
@@ -188,7 +188,7 @@ class GeoJSON extends JSONFeature {
|
||||
* Encode a feature as a GeoJSON Feature object.
|
||||
*
|
||||
* @param {import("../Feature.js").default} feature Feature.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options.
|
||||
* @return {GeoJSONFeature} Object.
|
||||
* @api
|
||||
*/
|
||||
@@ -230,7 +230,7 @@ class GeoJSON extends JSONFeature {
|
||||
* Encode an array of features as a GeoJSON object.
|
||||
*
|
||||
* @param {Array<import("../Feature.js").default>} features Features.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options.
|
||||
* @return {GeoJSONFeatureCollection} GeoJSON Object.
|
||||
* @api
|
||||
*/
|
||||
@@ -250,7 +250,7 @@ class GeoJSON extends JSONFeature {
|
||||
* Encode a geometry as a GeoJSON object.
|
||||
*
|
||||
* @param {import("../geom/Geometry.js").default} geometry Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options.
|
||||
* @return {GeoJSONGeometry|GeoJSONGeometryCollection} Object.
|
||||
* @api
|
||||
*/
|
||||
@@ -261,7 +261,7 @@ class GeoJSON extends JSONFeature {
|
||||
|
||||
/**
|
||||
* @param {GeoJSONGeometry|GeoJSONGeometryCollection} object Object.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options.
|
||||
* @return {import("../geom/Geometry.js").default} Geometry.
|
||||
*/
|
||||
function readGeometry(object, opt_options) {
|
||||
@@ -321,7 +321,7 @@ function readGeometry(object, opt_options) {
|
||||
|
||||
/**
|
||||
* @param {GeoJSONGeometryCollection} object Object.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options.
|
||||
* @return {GeometryCollection} Geometry collection.
|
||||
*/
|
||||
function readGeometryCollectionGeometry(object, opt_options) {
|
||||
@@ -387,7 +387,7 @@ function readPolygonGeometry(object) {
|
||||
|
||||
/**
|
||||
* @param {import("../geom/Geometry.js").default} geometry Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options.
|
||||
* @return {GeoJSONGeometry} GeoJSON geometry.
|
||||
*/
|
||||
function writeGeometry(geometry, opt_options) {
|
||||
@@ -462,7 +462,7 @@ function writeGeometry(geometry, opt_options) {
|
||||
|
||||
/**
|
||||
* @param {GeometryCollection} geometry Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options.
|
||||
* @return {GeoJSONGeometryCollection} GeoJSON geometry collection.
|
||||
*/
|
||||
function writeGeometryCollectionGeometry(geometry, opt_options) {
|
||||
@@ -479,7 +479,7 @@ function writeGeometryCollectionGeometry(geometry, opt_options) {
|
||||
|
||||
/**
|
||||
* @param {LineString} geometry Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options.
|
||||
* @return {GeoJSONGeometry} GeoJSON geometry.
|
||||
*/
|
||||
function writeLineStringGeometry(geometry, opt_options) {
|
||||
@@ -491,7 +491,7 @@ function writeLineStringGeometry(geometry, opt_options) {
|
||||
|
||||
/**
|
||||
* @param {MultiLineString} geometry Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options.
|
||||
* @return {GeoJSONGeometry} GeoJSON geometry.
|
||||
*/
|
||||
function writeMultiLineStringGeometry(geometry, opt_options) {
|
||||
@@ -503,7 +503,7 @@ function writeMultiLineStringGeometry(geometry, opt_options) {
|
||||
|
||||
/**
|
||||
* @param {MultiPoint} geometry Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options.
|
||||
* @return {GeoJSONGeometry} GeoJSON geometry.
|
||||
*/
|
||||
function writeMultiPointGeometry(geometry, opt_options) {
|
||||
@@ -515,7 +515,7 @@ function writeMultiPointGeometry(geometry, opt_options) {
|
||||
|
||||
/**
|
||||
* @param {MultiPolygon} geometry Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options.
|
||||
* @return {GeoJSONGeometry} GeoJSON geometry.
|
||||
*/
|
||||
function writeMultiPolygonGeometry(geometry, opt_options) {
|
||||
@@ -531,7 +531,7 @@ function writeMultiPolygonGeometry(geometry, opt_options) {
|
||||
|
||||
/**
|
||||
* @param {Point} geometry Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options.
|
||||
* @return {GeoJSONGeometry} GeoJSON geometry.
|
||||
*/
|
||||
function writePointGeometry(geometry, opt_options) {
|
||||
@@ -543,7 +543,7 @@ function writePointGeometry(geometry, opt_options) {
|
||||
|
||||
/**
|
||||
* @param {Polygon} geometry Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options.
|
||||
* @return {GeoJSONGeometry} GeoJSON geometry.
|
||||
*/
|
||||
function writePolygonGeometry(geometry, opt_options) {
|
||||
|
||||
@@ -62,7 +62,7 @@ const NEWLINE_RE = /\r\n|\r|\n/;
|
||||
*/
|
||||
class IGC extends TextFeature {
|
||||
/**
|
||||
* @param {Options=} opt_options Options.
|
||||
* @param {Options} [opt_options] Options.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
super();
|
||||
@@ -86,7 +86,7 @@ class IGC extends TextFeature {
|
||||
/**
|
||||
* @protected
|
||||
* @param {string} text Text.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options.
|
||||
* @return {import("../Feature.js").default} Feature.
|
||||
*/
|
||||
readFeatureFromText(text, opt_options) {
|
||||
@@ -166,7 +166,7 @@ class IGC extends TextFeature {
|
||||
|
||||
/**
|
||||
* @param {string} text Text.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options.
|
||||
* @protected
|
||||
* @return {Array<Feature>} Features.
|
||||
*/
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
*/
|
||||
|
||||
import {assert} from '../asserts.js';
|
||||
import {includes} from '../array.js';
|
||||
|
||||
/**
|
||||
* @typedef {Object} PreferredOptions
|
||||
@@ -245,10 +246,10 @@ function generateVersion3Options(iiifInfo) {
|
||||
iiifInfo.imageInfo.preferredFormats.length > 0
|
||||
? iiifInfo.imageInfo.preferredFormats
|
||||
.filter(function (format) {
|
||||
return ['jpg', 'png', 'gif'].includes(format);
|
||||
return includes(['jpg', 'png', 'gif'], format);
|
||||
})
|
||||
.reduce(function (acc, format) {
|
||||
return acc === undefined && formats.includes(format)
|
||||
return acc === undefined && includes(formats, format)
|
||||
? format
|
||||
: acc;
|
||||
}, undefined)
|
||||
@@ -326,7 +327,7 @@ class IIIFInfo {
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {Versions} Major IIIF version.
|
||||
* @return {Versions} Major IIIF version.
|
||||
* @api
|
||||
*/
|
||||
getImageApiVersion() {
|
||||
@@ -363,7 +364,7 @@ class IIIFInfo {
|
||||
|
||||
/**
|
||||
* @param {Versions} version Optional IIIF image API version
|
||||
* @returns {string} Compliance level as it appears in the IIIF image information
|
||||
* @return {string} Compliance level as it appears in the IIIF image information
|
||||
* response.
|
||||
*/
|
||||
getComplianceLevelEntryFromProfile(version) {
|
||||
@@ -406,7 +407,7 @@ class IIIFInfo {
|
||||
|
||||
/**
|
||||
* @param {Versions} version Optional IIIF image API version
|
||||
* @returns {string} Compliance level, on of 'level0', 'level1' or 'level2' or undefined
|
||||
* @return {string} Compliance level, on of 'level0', 'level1' or 'level2' or undefined
|
||||
*/
|
||||
getComplianceLevelFromProfile(version) {
|
||||
const complianceLevel = this.getComplianceLevelEntryFromProfile(version);
|
||||
@@ -418,7 +419,7 @@ class IIIFInfo {
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {SupportedFeatures} Image formats, qualities and region / size calculation
|
||||
* @return {SupportedFeatures} Image formats, qualities and region / size calculation
|
||||
* methods that are supported by the IIIF service.
|
||||
*/
|
||||
getComplianceLevelSupportedFeatures() {
|
||||
@@ -434,8 +435,8 @@ class IIIFInfo {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {PreferredOptions=} opt_preferredOptions Optional options for preferred format and quality.
|
||||
* @returns {import("../source/IIIF.js").Options} IIIF tile source ready constructor options.
|
||||
* @param {PreferredOptions} [opt_preferredOptions] Optional options for preferred format and quality.
|
||||
* @return {import("../source/IIIF.js").Options} IIIF tile source ready constructor options.
|
||||
* @api
|
||||
*/
|
||||
getTileSourceOptions(opt_preferredOptions) {
|
||||
@@ -456,16 +457,16 @@ class IIIFInfo {
|
||||
sizes: imageOptions.sizes,
|
||||
format:
|
||||
options.format !== undefined &&
|
||||
imageOptions.formats.includes(options.format)
|
||||
includes(imageOptions.formats, options.format)
|
||||
? options.format
|
||||
: imageOptions.preferredFormat !== undefined
|
||||
? imageOptions.preferredFormat
|
||||
: 'jpg',
|
||||
supports: imageOptions.supports,
|
||||
quality:
|
||||
options.quality && imageOptions.qualities.includes(options.quality)
|
||||
options.quality && includes(imageOptions.qualities, options.quality)
|
||||
? options.quality
|
||||
: imageOptions.qualities.includes('native')
|
||||
: includes(imageOptions.qualities, 'native')
|
||||
? 'native'
|
||||
: 'default',
|
||||
resolutions: Array.isArray(imageOptions.resolutions)
|
||||
|
||||
@@ -30,7 +30,7 @@ class JSONFeature extends FeatureFormat {
|
||||
* read a feature collection.
|
||||
*
|
||||
* @param {ArrayBuffer|Document|Element|Object|string} source Source.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options.
|
||||
* @return {import("../Feature.js").default} Feature.
|
||||
* @api
|
||||
*/
|
||||
@@ -46,7 +46,7 @@ class JSONFeature extends FeatureFormat {
|
||||
* collection.
|
||||
*
|
||||
* @param {ArrayBuffer|Document|Element|Object|string} source Source.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options.
|
||||
* @return {Array<import("../Feature.js").default>} Features.
|
||||
* @api
|
||||
*/
|
||||
@@ -60,7 +60,7 @@ class JSONFeature extends FeatureFormat {
|
||||
/**
|
||||
* @abstract
|
||||
* @param {Object} object Object.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options.
|
||||
* @protected
|
||||
* @return {import("../Feature.js").default} Feature.
|
||||
*/
|
||||
@@ -71,7 +71,7 @@ class JSONFeature extends FeatureFormat {
|
||||
/**
|
||||
* @abstract
|
||||
* @param {Object} object Object.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options.
|
||||
* @protected
|
||||
* @return {Array<import("../Feature.js").default>} Features.
|
||||
*/
|
||||
@@ -83,7 +83,7 @@ class JSONFeature extends FeatureFormat {
|
||||
* Read a geometry.
|
||||
*
|
||||
* @param {ArrayBuffer|Document|Element|Object|string} source Source.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options.
|
||||
* @return {import("../geom/Geometry.js").default} Geometry.
|
||||
* @api
|
||||
*/
|
||||
@@ -97,7 +97,7 @@ class JSONFeature extends FeatureFormat {
|
||||
/**
|
||||
* @abstract
|
||||
* @param {Object} object Object.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options.
|
||||
* @protected
|
||||
* @return {import("../geom/Geometry.js").default} Geometry.
|
||||
*/
|
||||
@@ -130,7 +130,7 @@ class JSONFeature extends FeatureFormat {
|
||||
* Encode a feature as string.
|
||||
*
|
||||
* @param {import("../Feature.js").default} feature Feature.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options.
|
||||
* @return {string} Encoded feature.
|
||||
* @api
|
||||
*/
|
||||
@@ -141,7 +141,7 @@ class JSONFeature extends FeatureFormat {
|
||||
/**
|
||||
* @abstract
|
||||
* @param {import("../Feature.js").default} feature Feature.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options.
|
||||
* @return {Object} Object.
|
||||
*/
|
||||
writeFeatureObject(feature, opt_options) {
|
||||
@@ -152,7 +152,7 @@ class JSONFeature extends FeatureFormat {
|
||||
* Encode an array of features as string.
|
||||
*
|
||||
* @param {Array<import("../Feature.js").default>} features Features.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options.
|
||||
* @return {string} Encoded features.
|
||||
* @api
|
||||
*/
|
||||
@@ -163,7 +163,7 @@ class JSONFeature extends FeatureFormat {
|
||||
/**
|
||||
* @abstract
|
||||
* @param {Array<import("../Feature.js").default>} features Features.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options.
|
||||
* @return {Object} Object.
|
||||
*/
|
||||
writeFeaturesObject(features, opt_options) {
|
||||
@@ -174,7 +174,7 @@ class JSONFeature extends FeatureFormat {
|
||||
* Encode a geometry as string.
|
||||
*
|
||||
* @param {import("../geom/Geometry.js").default} geometry Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options.
|
||||
* @return {string} Encoded geometry.
|
||||
* @api
|
||||
*/
|
||||
@@ -185,7 +185,7 @@ class JSONFeature extends FeatureFormat {
|
||||
/**
|
||||
* @abstract
|
||||
* @param {import("../geom/Geometry.js").default} geometry Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options.
|
||||
* @return {Object} Object.
|
||||
*/
|
||||
writeGeometryObject(geometry, opt_options) {
|
||||
|
||||
@@ -56,17 +56,17 @@ import {transformGeometryWithOptions} from './Feature.js';
|
||||
|
||||
/**
|
||||
* @typedef {Object} Vec2
|
||||
* @property {number} x
|
||||
* @property {import("../style/IconAnchorUnits").default} xunits
|
||||
* @property {number} y
|
||||
* @property {import("../style/IconAnchorUnits").default} yunits
|
||||
* @property {import("../style/IconOrigin.js").default} origin
|
||||
* @property {number} x X coordinate.
|
||||
* @property {import("../style/IconAnchorUnits").default} xunits Units of x.
|
||||
* @property {number} y Y coordinate.
|
||||
* @property {import("../style/IconAnchorUnits").default} yunits Units of Y.
|
||||
* @property {import("../style/IconOrigin.js").default} origin Origin.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} GxTrackObject
|
||||
* @property {Array<number>} flatCoordinates
|
||||
* @property {Array<number>} whens
|
||||
* @property {Array<number>} flatCoordinates Flat coordinates.
|
||||
* @property {Array<number>} whens Whens.
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -126,7 +126,7 @@ const PLACEMARK_PARSERS = makeStructureNS(
|
||||
'name': makeObjectPropertySetter(readString),
|
||||
'open': makeObjectPropertySetter(readBoolean),
|
||||
'phoneNumber': makeObjectPropertySetter(readString),
|
||||
'styleUrl': makeObjectPropertySetter(readURI),
|
||||
'styleUrl': makeObjectPropertySetter(readStyleURL),
|
||||
'visibility': makeObjectPropertySetter(readBoolean),
|
||||
},
|
||||
makeStructureNS(GX_NAMESPACE_URIS, {
|
||||
@@ -378,6 +378,24 @@ function createStyleDefaults() {
|
||||
*/
|
||||
let TEXTAREA;
|
||||
|
||||
/**
|
||||
* A function that takes a url `{string}` and returns a url `{string}`.
|
||||
* Might be used to change an icon path or to substitute a
|
||||
* data url obtained from a KMZ array buffer.
|
||||
*
|
||||
* @typedef {function(string):string} IconUrlFunction
|
||||
* @api
|
||||
*/
|
||||
|
||||
/**
|
||||
* Function that returns a url unchanged.
|
||||
* @param {string} href Input url.
|
||||
* @return {string} Output url.
|
||||
*/
|
||||
function defaultIconUrlFunction(href) {
|
||||
return href;
|
||||
}
|
||||
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
* @property {boolean} [extractStyles=true] Extract styles from the KML.
|
||||
@@ -387,6 +405,8 @@ let TEXTAREA;
|
||||
* @property {boolean} [writeStyles=true] Write styles into KML.
|
||||
* @property {null|string} [crossOrigin='anonymous'] 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.
|
||||
* @property {IconUrlFunction} [iconUrlFunction] Function that takes a url string and returns a url string.
|
||||
* Might be used to change an icon path or to substitute a data url obtained from a KMZ array buffer.
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -407,7 +427,7 @@ let TEXTAREA;
|
||||
*/
|
||||
class KML extends XMLFeature {
|
||||
/**
|
||||
* @param {Options=} opt_options Options.
|
||||
* @param {Options} [opt_options] Options.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
super();
|
||||
@@ -462,6 +482,13 @@ class KML extends XMLFeature {
|
||||
*/
|
||||
this.crossOrigin_ =
|
||||
options.crossOrigin !== undefined ? options.crossOrigin : 'anonymous';
|
||||
|
||||
/**
|
||||
* @type {IconUrlFunction}
|
||||
*/
|
||||
this.iconUrlFunction_ = options.iconUrlFunction
|
||||
? options.iconUrlFunction
|
||||
: defaultIconUrlFunction;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -597,7 +624,7 @@ class KML extends XMLFeature {
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Options.
|
||||
* @return {import("../Feature.js").default} Feature.
|
||||
*/
|
||||
readFeatureFromNode(node, opt_options) {
|
||||
@@ -617,7 +644,7 @@ class KML extends XMLFeature {
|
||||
/**
|
||||
* @protected
|
||||
* @param {Element} node Node.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Options.
|
||||
* @return {Array<import("../Feature.js").default>} Features.
|
||||
*/
|
||||
readFeaturesFromNode(node, opt_options) {
|
||||
@@ -859,7 +886,7 @@ class KML extends XMLFeature {
|
||||
* MultiPoints, MultiLineStrings, and MultiPolygons are output as MultiGeometries.
|
||||
*
|
||||
* @param {Array<Feature>} features Features.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Options.
|
||||
* @return {Node} Node.
|
||||
* @api
|
||||
*/
|
||||
@@ -1047,12 +1074,6 @@ function findStyle(styleValue, defaultStyle, sharedStyles) {
|
||||
if (Array.isArray(styleValue)) {
|
||||
return styleValue;
|
||||
} else if (typeof styleValue === 'string') {
|
||||
// KML files in the wild occasionally forget the leading `#` on styleUrls
|
||||
// defined in the same document. Add a leading `#` if it enables to find
|
||||
// a style.
|
||||
if (!(styleValue in sharedStyles) && '#' + styleValue in sharedStyles) {
|
||||
styleValue = '#' + styleValue;
|
||||
}
|
||||
return findStyle(sharedStyles[styleValue], defaultStyle, sharedStyles);
|
||||
} else {
|
||||
return defaultStyle;
|
||||
@@ -1090,7 +1111,8 @@ export function readFlatCoordinates(node) {
|
||||
const flatCoordinates = [];
|
||||
// The KML specification states that coordinate tuples should not include
|
||||
// spaces, but we tolerate them.
|
||||
const re = /^\s*([+\-]?\d*\.?\d+(?:e[+\-]?\d+)?)\s*,\s*([+\-]?\d*\.?\d+(?:e[+\-]?\d+)?)(?:\s*,\s*([+\-]?\d*\.?\d+(?:e[+\-]?\d+)?))?\s*/i;
|
||||
s = s.replace(/\s*,\s*/g, ',');
|
||||
const re = /^\s*([+\-]?\d*\.?\d+(?:e[+\-]?\d+)?),([+\-]?\d*\.?\d+(?:e[+\-]?\d+)?)(?:\s+|,|$)(?:([+\-]?\d*\.?\d+(?:e[+\-]?\d+)?)(?:\s+|$))?\s*/i;
|
||||
let m;
|
||||
while ((m = re.exec(s))) {
|
||||
const x = parseFloat(m[1]);
|
||||
@@ -1123,6 +1145,28 @@ function readURI(node) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Node} node Node.
|
||||
* @return {string} URI.
|
||||
*/
|
||||
function readStyleURL(node) {
|
||||
// KML files in the wild occasionally forget the leading
|
||||
// `#` on styleUrlsdefined in the same document.
|
||||
const s = getAllTextContent(node, false)
|
||||
.trim()
|
||||
.replace(/^(?!.*#)/, '#');
|
||||
let baseURI = node.baseURI;
|
||||
if (!baseURI || baseURI == 'about:blank') {
|
||||
baseURI = window.location.href;
|
||||
}
|
||||
if (baseURI) {
|
||||
const url = new URL(s, baseURI);
|
||||
return url.href;
|
||||
} else {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @return {Vec2} Vec2.
|
||||
@@ -1282,7 +1326,7 @@ function iconStyleParser(node, objectStack) {
|
||||
rotation: rotation,
|
||||
scale: scale,
|
||||
size: size,
|
||||
src: src,
|
||||
src: this.iconUrlFunction_(src),
|
||||
color: color,
|
||||
});
|
||||
styleObject['imageStyle'] = imageStyle;
|
||||
@@ -1993,7 +2037,7 @@ function regionParser(node, objectStack) {
|
||||
const PAIR_PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
'Style': makeObjectPropertySetter(readStyle),
|
||||
'key': makeObjectPropertySetter(readString),
|
||||
'styleUrl': makeObjectPropertySetter(readURI),
|
||||
'styleUrl': makeObjectPropertySetter(readStyleURL),
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -2359,7 +2403,7 @@ const DOCUMENT_SERIALIZERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
* @const
|
||||
* @param {*} value Value.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
* @param {string=} opt_nodeName Node name.
|
||||
* @param {string} [opt_nodeName] Node name.
|
||||
* @return {Node|undefined} Node.
|
||||
*/
|
||||
const DOCUMENT_NODE_FACTORY = function (value, objectStack, opt_nodeName) {
|
||||
@@ -2448,7 +2492,7 @@ const ICON_SERIALIZERS = makeStructureNS(
|
||||
* @const
|
||||
* @param {*} value Value.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
* @param {string=} opt_nodeName Node name.
|
||||
* @param {string} [opt_nodeName] Node name.
|
||||
* @return {Node|undefined} Node.
|
||||
*/
|
||||
const GX_NODE_FACTORY = function (value, objectStack, opt_nodeName) {
|
||||
@@ -2687,7 +2731,7 @@ const GEOMETRY_TYPE_TO_NODENAME = {
|
||||
* @const
|
||||
* @param {*} value Value.
|
||||
* @param {Array<*>} objectStack Object stack.
|
||||
* @param {string=} opt_nodeName Node name.
|
||||
* @param {string} [opt_nodeName] Node name.
|
||||
* @return {Node|undefined} Node.
|
||||
*/
|
||||
const GEOMETRY_NODE_FACTORY = function (value, objectStack, opt_nodeName) {
|
||||
|
||||
@@ -38,12 +38,12 @@ import {linearRingIsClockwise} from '../geom/flat/orient.js';
|
||||
* @classdesc
|
||||
* Feature format for reading data in the Mapbox MVT format.
|
||||
*
|
||||
* @param {Options=} opt_options Options.
|
||||
* @param {Options} [opt_options] Options.
|
||||
* @api
|
||||
*/
|
||||
class MVT extends FeatureFormat {
|
||||
/**
|
||||
* @param {Options=} opt_options Options.
|
||||
* @param {Options} [opt_options] Options.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
super();
|
||||
@@ -194,7 +194,7 @@ class MVT extends FeatureFormat {
|
||||
values,
|
||||
id
|
||||
);
|
||||
feature.transform(options.dataProjection, options.featureProjection);
|
||||
feature.transform(options.dataProjection);
|
||||
} else {
|
||||
let geom;
|
||||
if (geometryType == GeometryType.POLYGON) {
|
||||
@@ -260,7 +260,7 @@ class MVT extends FeatureFormat {
|
||||
* Read all features.
|
||||
*
|
||||
* @param {ArrayBuffer} source Source.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options.
|
||||
* @return {Array<import("../Feature.js").FeatureLike>} Features.
|
||||
* @api
|
||||
*/
|
||||
|
||||
@@ -43,7 +43,7 @@ const PARSERS = makeStructureNS(NAMESPACE_URIS, {
|
||||
/**
|
||||
* @classdesc
|
||||
* Feature format for reading data in the
|
||||
* [OSMXML format](http://wiki.openstreetmap.org/wiki/OSM_XML).
|
||||
* [OSMXML format](https://wiki.openstreetmap.org/wiki/OSM_XML).
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
@@ -60,7 +60,7 @@ class OSMXML extends XMLFeature {
|
||||
/**
|
||||
* @protected
|
||||
* @param {Element} node Node.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Options.
|
||||
* @return {Array<import("../Feature.js").default>} Features.
|
||||
*/
|
||||
readFeaturesFromNode(node, opt_options) {
|
||||
|
||||
@@ -35,7 +35,7 @@ import {transformGeometryWithOptions} from './Feature.js';
|
||||
*/
|
||||
class Polyline extends TextFeature {
|
||||
/**
|
||||
* @param {Options=} opt_options Optional configuration object.
|
||||
* @param {Options} [opt_options] Optional configuration object.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
super();
|
||||
@@ -65,7 +65,7 @@ class Polyline extends TextFeature {
|
||||
/**
|
||||
* @protected
|
||||
* @param {string} text Text.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options.
|
||||
* @return {import("../Feature.js").default} Feature.
|
||||
*/
|
||||
readFeatureFromText(text, opt_options) {
|
||||
@@ -75,7 +75,7 @@ class Polyline extends TextFeature {
|
||||
|
||||
/**
|
||||
* @param {string} text Text.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options.
|
||||
* @protected
|
||||
* @return {Array<Feature>} Features.
|
||||
*/
|
||||
@@ -86,7 +86,7 @@ class Polyline extends TextFeature {
|
||||
|
||||
/**
|
||||
* @param {string} text Text.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options.
|
||||
* @protected
|
||||
* @return {import("../geom/Geometry.js").default} Geometry.
|
||||
*/
|
||||
@@ -111,7 +111,7 @@ class Polyline extends TextFeature {
|
||||
|
||||
/**
|
||||
* @param {import("../Feature.js").default} feature Features.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options.
|
||||
* @protected
|
||||
* @return {string} Text.
|
||||
*/
|
||||
@@ -127,7 +127,7 @@ class Polyline extends TextFeature {
|
||||
|
||||
/**
|
||||
* @param {Array<import("../Feature.js").default>} features Features.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options.
|
||||
* @protected
|
||||
* @return {string} Text.
|
||||
*/
|
||||
@@ -137,7 +137,7 @@ class Polyline extends TextFeature {
|
||||
|
||||
/**
|
||||
* @param {LineString} geometry Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options.
|
||||
* @protected
|
||||
* @return {string} Text.
|
||||
*/
|
||||
@@ -163,7 +163,7 @@ class Polyline extends TextFeature {
|
||||
*
|
||||
* @param {Array<number>} numbers A list of n-dimensional points.
|
||||
* @param {number} stride The number of dimension of the points in the list.
|
||||
* @param {number=} opt_factor The factor by which the numbers will be
|
||||
* @param {number} [opt_factor] The factor by which the numbers will be
|
||||
* multiplied. The remaining decimal places will get rounded away.
|
||||
* Default is `1e5`.
|
||||
* @return {string} The encoded string.
|
||||
@@ -197,7 +197,7 @@ export function encodeDeltas(numbers, stride, opt_factor) {
|
||||
* @param {string} encoded An encoded string.
|
||||
* @param {number} stride The number of dimension of the points in the
|
||||
* encoded string.
|
||||
* @param {number=} opt_factor The factor by which the resulting numbers will
|
||||
* @param {number} [opt_factor] The factor by which the resulting numbers will
|
||||
* be divided. Default is `1e5`.
|
||||
* @return {Array<number>} A list of n-dimensional points.
|
||||
* @api
|
||||
@@ -231,7 +231,7 @@ export function decodeDeltas(encoded, stride, opt_factor) {
|
||||
* Attention: This function will modify the passed array!
|
||||
*
|
||||
* @param {Array<number>} numbers A list of floating point numbers.
|
||||
* @param {number=} opt_factor The factor by which the numbers will be
|
||||
* @param {number} [opt_factor] The factor by which the numbers will be
|
||||
* multiplied. The remaining decimal places will get rounded away.
|
||||
* Default is `1e5`.
|
||||
* @return {string} The encoded string.
|
||||
@@ -250,7 +250,7 @@ export function encodeFloats(numbers, opt_factor) {
|
||||
* Decode a list of floating point numbers from an encoded string
|
||||
*
|
||||
* @param {string} encoded An encoded string.
|
||||
* @param {number=} opt_factor The factor by which the result will be divided.
|
||||
* @param {number} [opt_factor] The factor by which the result will be divided.
|
||||
* Default is `1e5`.
|
||||
* @return {Array<number>} A list of floating point numbers.
|
||||
* @api
|
||||
|
||||
@@ -29,7 +29,7 @@ class TextFeature extends FeatureFormat {
|
||||
* Read the feature from the source.
|
||||
*
|
||||
* @param {Document|Element|Object|string} source Source.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options.
|
||||
* @return {import("../Feature.js").default} Feature.
|
||||
* @api
|
||||
*/
|
||||
@@ -43,7 +43,7 @@ class TextFeature extends FeatureFormat {
|
||||
/**
|
||||
* @abstract
|
||||
* @param {string} text Text.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options.
|
||||
* @protected
|
||||
* @return {import("../Feature.js").default} Feature.
|
||||
*/
|
||||
@@ -55,7 +55,7 @@ class TextFeature extends FeatureFormat {
|
||||
* Read the features from the source.
|
||||
*
|
||||
* @param {Document|Element|Object|string} source Source.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options.
|
||||
* @return {Array<import("../Feature.js").default>} Features.
|
||||
* @api
|
||||
*/
|
||||
@@ -69,7 +69,7 @@ class TextFeature extends FeatureFormat {
|
||||
/**
|
||||
* @abstract
|
||||
* @param {string} text Text.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options.
|
||||
* @protected
|
||||
* @return {Array<import("../Feature.js").default>} Features.
|
||||
*/
|
||||
@@ -81,7 +81,7 @@ class TextFeature extends FeatureFormat {
|
||||
* Read the geometry from the source.
|
||||
*
|
||||
* @param {Document|Element|Object|string} source Source.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options.
|
||||
* @return {import("../geom/Geometry.js").default} Geometry.
|
||||
* @api
|
||||
*/
|
||||
@@ -95,7 +95,7 @@ class TextFeature extends FeatureFormat {
|
||||
/**
|
||||
* @abstract
|
||||
* @param {string} text Text.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options.
|
||||
* @protected
|
||||
* @return {import("../geom/Geometry.js").default} Geometry.
|
||||
*/
|
||||
@@ -107,7 +107,7 @@ class TextFeature extends FeatureFormat {
|
||||
* Read the projection from the source.
|
||||
*
|
||||
* @param {Document|Element|Object|string} source Source.
|
||||
* @return {import("../proj/Projection.js").default} Projection.
|
||||
* @return {import("../proj/Projection.js").default|undefined} Projection.
|
||||
* @api
|
||||
*/
|
||||
readProjection(source) {
|
||||
@@ -117,7 +117,7 @@ class TextFeature extends FeatureFormat {
|
||||
/**
|
||||
* @param {string} text Text.
|
||||
* @protected
|
||||
* @return {import("../proj/Projection.js").default} Projection.
|
||||
* @return {import("../proj/Projection.js").default|undefined} Projection.
|
||||
*/
|
||||
readProjectionFromText(text) {
|
||||
return this.dataProjection;
|
||||
@@ -127,7 +127,7 @@ class TextFeature extends FeatureFormat {
|
||||
* Encode a feature as a string.
|
||||
*
|
||||
* @param {import("../Feature.js").default} feature Feature.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options.
|
||||
* @return {string} Encoded feature.
|
||||
* @api
|
||||
*/
|
||||
@@ -138,7 +138,7 @@ class TextFeature extends FeatureFormat {
|
||||
/**
|
||||
* @abstract
|
||||
* @param {import("../Feature.js").default} feature Features.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options.
|
||||
* @protected
|
||||
* @return {string} Text.
|
||||
*/
|
||||
@@ -150,7 +150,7 @@ class TextFeature extends FeatureFormat {
|
||||
* Encode an array of features as string.
|
||||
*
|
||||
* @param {Array<import("../Feature.js").default>} features Features.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options.
|
||||
* @return {string} Encoded features.
|
||||
* @api
|
||||
*/
|
||||
@@ -161,7 +161,7 @@ class TextFeature extends FeatureFormat {
|
||||
/**
|
||||
* @abstract
|
||||
* @param {Array<import("../Feature.js").default>} features Features.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options.
|
||||
* @protected
|
||||
* @return {string} Text.
|
||||
*/
|
||||
@@ -173,7 +173,7 @@ class TextFeature extends FeatureFormat {
|
||||
* Write a single geometry.
|
||||
*
|
||||
* @param {import("../geom/Geometry.js").default} geometry Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options.
|
||||
* @return {string} Geometry.
|
||||
* @api
|
||||
*/
|
||||
@@ -184,7 +184,7 @@ class TextFeature extends FeatureFormat {
|
||||
/**
|
||||
* @abstract
|
||||
* @param {import("../geom/Geometry.js").default} geometry Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options.
|
||||
* @protected
|
||||
* @return {string} Text.
|
||||
*/
|
||||
|
||||
@@ -56,7 +56,7 @@ import {transformGeometryWithOptions} from './Feature.js';
|
||||
*/
|
||||
class TopoJSON extends JSONFeature {
|
||||
/**
|
||||
* @param {Options=} opt_options Options.
|
||||
* @param {Options} [opt_options] Options.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
super();
|
||||
@@ -85,7 +85,7 @@ class TopoJSON extends JSONFeature {
|
||||
|
||||
/**
|
||||
* @param {Object} object Object.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options.
|
||||
* @protected
|
||||
* @return {Array<Feature>} Features.
|
||||
*/
|
||||
@@ -318,7 +318,7 @@ function readMultiPolygonGeometry(object, arcs) {
|
||||
* @param {string|undefined} property Property to set the `GeometryCollection`'s parent
|
||||
* object to.
|
||||
* @param {string} name Name of the `Topology`'s child object.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options.
|
||||
* @return {Array<Feature>} Array of features.
|
||||
*/
|
||||
function readFeaturesFromGeometryCollection(
|
||||
@@ -356,7 +356,7 @@ function readFeaturesFromGeometryCollection(
|
||||
* @param {string|undefined} property Property to set the `GeometryCollection`'s parent
|
||||
* object to.
|
||||
* @param {string} name Name of the `Topology`'s child object.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options.
|
||||
* @return {Feature} Feature.
|
||||
*/
|
||||
function readFeatureFromGeometry(
|
||||
@@ -368,18 +368,18 @@ function readFeatureFromGeometry(
|
||||
name,
|
||||
opt_options
|
||||
) {
|
||||
let geometry;
|
||||
let geometry = null;
|
||||
const type = object.type;
|
||||
const geometryReader = GEOMETRY_READERS[type];
|
||||
if (type === 'Point' || type === 'MultiPoint') {
|
||||
geometry = geometryReader(object, scale, translate);
|
||||
} else {
|
||||
geometry = geometryReader(object, arcs);
|
||||
if (type) {
|
||||
const geometryReader = GEOMETRY_READERS[type];
|
||||
if (type === 'Point' || type === 'MultiPoint') {
|
||||
geometry = geometryReader(object, scale, translate);
|
||||
} else {
|
||||
geometry = geometryReader(object, arcs);
|
||||
}
|
||||
geometry = transformGeometryWithOptions(geometry, false, opt_options);
|
||||
}
|
||||
const feature = new Feature();
|
||||
feature.setGeometry(
|
||||
transformGeometryWithOptions(geometry, false, opt_options)
|
||||
);
|
||||
const feature = new Feature({geometry: geometry});
|
||||
if (object.id !== undefined) {
|
||||
feature.setId(object.id);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -35,9 +35,9 @@ const GeometryConstructor = {
|
||||
|
||||
/**
|
||||
* @typedef {Object} Token
|
||||
* @property {number} type
|
||||
* @property {number|string} [value]
|
||||
* @property {number} position
|
||||
* @property {number} type Type.
|
||||
* @property {number|string} [value] Value.
|
||||
* @property {number} position Position.
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -69,6 +69,7 @@ const ZM = 'ZM';
|
||||
* @enum {number}
|
||||
*/
|
||||
const TokenType = {
|
||||
START: 0,
|
||||
TEXT: 1,
|
||||
LEFT_PAREN: 2,
|
||||
RIGHT_PAREN: 3,
|
||||
@@ -117,7 +118,7 @@ class Lexer {
|
||||
|
||||
/**
|
||||
* @param {string} c Character.
|
||||
* @param {boolean=} opt_decimal Whether the string number
|
||||
* @param {boolean} [opt_decimal] Whether the string number
|
||||
* contains a dot, i.e. is a decimal number.
|
||||
* @return {boolean} Whether the character is numeric.
|
||||
* @private
|
||||
@@ -146,7 +147,7 @@ class Lexer {
|
||||
|
||||
/**
|
||||
* Fetch and return the next token.
|
||||
* @return {!Token} Next string token.
|
||||
* @return {Token} Next string token.
|
||||
*/
|
||||
nextToken() {
|
||||
const c = this.nextChar_();
|
||||
@@ -238,7 +239,10 @@ class Parser {
|
||||
* @type {Token}
|
||||
* @private
|
||||
*/
|
||||
this.token_;
|
||||
this.token_ = {
|
||||
position: 0,
|
||||
type: TokenType.START,
|
||||
};
|
||||
|
||||
/**
|
||||
* @type {import("../geom/GeometryLayout.js").default}
|
||||
@@ -261,8 +265,7 @@ class Parser {
|
||||
* @return {boolean} Whether the token matches the given type.
|
||||
*/
|
||||
isTokenType(type) {
|
||||
const isMatch = this.token_.type == type;
|
||||
return isMatch;
|
||||
return this.token_.type == type;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -284,8 +287,7 @@ class Parser {
|
||||
*/
|
||||
parse() {
|
||||
this.consume_();
|
||||
const geometry = this.parseGeometry_();
|
||||
return geometry;
|
||||
return this.parseGeometry_();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -313,7 +315,7 @@ class Parser {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {!Array<import("../geom/Geometry.js").default>} A collection of geometries.
|
||||
* @return {Array<import("../geom/Geometry.js").default>} A collection of geometries.
|
||||
* @private
|
||||
*/
|
||||
parseGeometryCollectionText_() {
|
||||
@@ -325,8 +327,6 @@ class Parser {
|
||||
if (this.match(TokenType.RIGHT_PAREN)) {
|
||||
return geometries;
|
||||
}
|
||||
} else if (this.isEmptyGeometry_()) {
|
||||
return [];
|
||||
}
|
||||
throw new Error(this.formatErrorMessage_());
|
||||
}
|
||||
@@ -341,14 +341,12 @@ class Parser {
|
||||
if (this.match(TokenType.RIGHT_PAREN)) {
|
||||
return coordinates;
|
||||
}
|
||||
} else if (this.isEmptyGeometry_()) {
|
||||
return null;
|
||||
}
|
||||
throw new Error(this.formatErrorMessage_());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {!Array<!Array<number>>} All points in a linestring.
|
||||
* @return {Array<Array<number>>} All points in a linestring.
|
||||
* @private
|
||||
*/
|
||||
parseLineStringText_() {
|
||||
@@ -357,14 +355,12 @@ class Parser {
|
||||
if (this.match(TokenType.RIGHT_PAREN)) {
|
||||
return coordinates;
|
||||
}
|
||||
} else if (this.isEmptyGeometry_()) {
|
||||
return [];
|
||||
}
|
||||
throw new Error(this.formatErrorMessage_());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {!Array<!Array<!Array<number>>>} All points in a polygon.
|
||||
* @return {Array<Array<Array<number>>>} All points in a polygon.
|
||||
* @private
|
||||
*/
|
||||
parsePolygonText_() {
|
||||
@@ -373,14 +369,12 @@ class Parser {
|
||||
if (this.match(TokenType.RIGHT_PAREN)) {
|
||||
return coordinates;
|
||||
}
|
||||
} else if (this.isEmptyGeometry_()) {
|
||||
return [];
|
||||
}
|
||||
throw new Error(this.formatErrorMessage_());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {!Array<!Array<number>>} All points in a multipoint.
|
||||
* @return {Array<Array<number>>} All points in a multipoint.
|
||||
* @private
|
||||
*/
|
||||
parseMultiPointText_() {
|
||||
@@ -394,14 +388,12 @@ class Parser {
|
||||
if (this.match(TokenType.RIGHT_PAREN)) {
|
||||
return coordinates;
|
||||
}
|
||||
} else if (this.isEmptyGeometry_()) {
|
||||
return [];
|
||||
}
|
||||
throw new Error(this.formatErrorMessage_());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {!Array<!Array<!Array<number>>>} All linestring points
|
||||
* @return {Array<Array<Array<number>>>} All linestring points
|
||||
* in a multilinestring.
|
||||
* @private
|
||||
*/
|
||||
@@ -411,14 +403,12 @@ class Parser {
|
||||
if (this.match(TokenType.RIGHT_PAREN)) {
|
||||
return coordinates;
|
||||
}
|
||||
} else if (this.isEmptyGeometry_()) {
|
||||
return [];
|
||||
}
|
||||
throw new Error(this.formatErrorMessage_());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {!Array<!Array<!Array<!Array<number>>>>} All polygon points in a multipolygon.
|
||||
* @return {Array<Array<Array<Array<number>>>>} All polygon points in a multipolygon.
|
||||
* @private
|
||||
*/
|
||||
parseMultiPolygonText_() {
|
||||
@@ -427,14 +417,12 @@ class Parser {
|
||||
if (this.match(TokenType.RIGHT_PAREN)) {
|
||||
return coordinates;
|
||||
}
|
||||
} else if (this.isEmptyGeometry_()) {
|
||||
return [];
|
||||
}
|
||||
throw new Error(this.formatErrorMessage_());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {!Array<number>} A point.
|
||||
* @return {Array<number>} A point.
|
||||
* @private
|
||||
*/
|
||||
parsePoint_() {
|
||||
@@ -455,7 +443,7 @@ class Parser {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {!Array<!Array<number>>} An array of points.
|
||||
* @return {Array<Array<number>>} An array of points.
|
||||
* @private
|
||||
*/
|
||||
parsePointList_() {
|
||||
@@ -467,7 +455,7 @@ class Parser {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {!Array<!Array<number>>} An array of points.
|
||||
* @return {Array<Array<number>>} An array of points.
|
||||
* @private
|
||||
*/
|
||||
parsePointTextList_() {
|
||||
@@ -479,7 +467,7 @@ class Parser {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {!Array<!Array<!Array<number>>>} An array of points.
|
||||
* @return {Array<Array<Array<number>>>} An array of points.
|
||||
* @private
|
||||
*/
|
||||
parseLineStringTextList_() {
|
||||
@@ -491,7 +479,7 @@ class Parser {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {!Array<!Array<!Array<!Array<number>>>>} An array of points.
|
||||
* @return {Array<Array<Array<Array<number>>>>} An array of points.
|
||||
* @private
|
||||
*/
|
||||
parsePolygonTextList_() {
|
||||
@@ -533,15 +521,19 @@ class Parser {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {!import("../geom/Geometry.js").default} The geometry.
|
||||
* @return {import("../geom/Geometry.js").default} The geometry.
|
||||
* @private
|
||||
*/
|
||||
parseGeometry_() {
|
||||
const token = this.token_;
|
||||
if (this.match(TokenType.TEXT)) {
|
||||
const geomType = token.value;
|
||||
const geomType = /** @type {string} */ (token.value);
|
||||
this.layout_ = this.parseGeometryLayout_();
|
||||
const isEmpty = this.isEmptyGeometry_();
|
||||
if (geomType == 'GEOMETRYCOLLECTION') {
|
||||
if (isEmpty) {
|
||||
return new GeometryCollection([]);
|
||||
}
|
||||
const geometries = this.parseGeometryCollectionText_();
|
||||
return new GeometryCollection(geometries);
|
||||
} else {
|
||||
@@ -551,43 +543,44 @@ class Parser {
|
||||
}
|
||||
|
||||
let coordinates;
|
||||
switch (geomType) {
|
||||
case 'POINT': {
|
||||
coordinates = this.parsePointText_();
|
||||
break;
|
||||
}
|
||||
case 'LINESTRING': {
|
||||
coordinates = this.parseLineStringText_();
|
||||
break;
|
||||
}
|
||||
case 'POLYGON': {
|
||||
coordinates = this.parsePolygonText_();
|
||||
break;
|
||||
}
|
||||
case 'MULTIPOINT': {
|
||||
coordinates = this.parseMultiPointText_();
|
||||
break;
|
||||
}
|
||||
case 'MULTILINESTRING': {
|
||||
coordinates = this.parseMultiLineStringText_();
|
||||
break;
|
||||
}
|
||||
case 'MULTIPOLYGON': {
|
||||
coordinates = this.parseMultiPolygonText_();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
throw new Error('Invalid geometry type: ' + geomType);
|
||||
}
|
||||
}
|
||||
|
||||
if (!coordinates) {
|
||||
if (ctor === GeometryConstructor['POINT']) {
|
||||
if (isEmpty) {
|
||||
if (geomType == 'POINT') {
|
||||
coordinates = [NaN, NaN];
|
||||
} else {
|
||||
coordinates = [];
|
||||
}
|
||||
} else {
|
||||
switch (geomType) {
|
||||
case 'POINT': {
|
||||
coordinates = this.parsePointText_();
|
||||
break;
|
||||
}
|
||||
case 'LINESTRING': {
|
||||
coordinates = this.parseLineStringText_();
|
||||
break;
|
||||
}
|
||||
case 'POLYGON': {
|
||||
coordinates = this.parsePolygonText_();
|
||||
break;
|
||||
}
|
||||
case 'MULTIPOINT': {
|
||||
coordinates = this.parseMultiPointText_();
|
||||
break;
|
||||
}
|
||||
case 'MULTILINESTRING': {
|
||||
coordinates = this.parseMultiLineStringText_();
|
||||
break;
|
||||
}
|
||||
case 'MULTIPOLYGON': {
|
||||
coordinates = this.parseMultiPolygonText_();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return new ctor(coordinates, this.layout_);
|
||||
}
|
||||
}
|
||||
@@ -604,7 +597,7 @@ class Parser {
|
||||
*/
|
||||
class WKT extends TextFeature {
|
||||
/**
|
||||
* @param {Options=} opt_options Options.
|
||||
* @param {Options} [opt_options] Options.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
super();
|
||||
@@ -623,7 +616,7 @@ class WKT extends TextFeature {
|
||||
/**
|
||||
* Parse a WKT string.
|
||||
* @param {string} wkt WKT string.
|
||||
* @return {import("../geom/Geometry.js").default|undefined}
|
||||
* @return {import("../geom/Geometry.js").default}
|
||||
* The geometry created.
|
||||
* @private
|
||||
*/
|
||||
@@ -636,22 +629,19 @@ class WKT extends TextFeature {
|
||||
/**
|
||||
* @protected
|
||||
* @param {string} text Text.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options.
|
||||
* @return {import("../Feature.js").default} Feature.
|
||||
*/
|
||||
readFeatureFromText(text, opt_options) {
|
||||
const geom = this.readGeometryFromText(text, opt_options);
|
||||
if (geom) {
|
||||
const feature = new Feature();
|
||||
feature.setGeometry(geom);
|
||||
return feature;
|
||||
}
|
||||
return null;
|
||||
const feature = new Feature();
|
||||
feature.setGeometry(geom);
|
||||
return feature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} text Text.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options.
|
||||
* @protected
|
||||
* @return {Array<Feature>} Features.
|
||||
*/
|
||||
@@ -677,22 +667,18 @@ class WKT extends TextFeature {
|
||||
|
||||
/**
|
||||
* @param {string} text Text.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options.
|
||||
* @protected
|
||||
* @return {import("../geom/Geometry.js").default} Geometry.
|
||||
*/
|
||||
readGeometryFromText(text, opt_options) {
|
||||
const geometry = this.parse_(text);
|
||||
if (geometry) {
|
||||
return transformGeometryWithOptions(geometry, false, opt_options);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return transformGeometryWithOptions(geometry, false, opt_options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import("../Feature.js").default} feature Features.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options.
|
||||
* @protected
|
||||
* @return {string} Text.
|
||||
*/
|
||||
@@ -706,7 +692,7 @@ class WKT extends TextFeature {
|
||||
|
||||
/**
|
||||
* @param {Array<import("../Feature.js").default>} features Features.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options.
|
||||
* @protected
|
||||
* @return {string} Text.
|
||||
*/
|
||||
@@ -724,7 +710,7 @@ class WKT extends TextFeature {
|
||||
|
||||
/**
|
||||
* @param {import("../geom/Geometry.js").default} geometry Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options.
|
||||
* @protected
|
||||
* @return {string} Text.
|
||||
*/
|
||||
@@ -855,7 +841,7 @@ const GeometryEncoder = {
|
||||
|
||||
/**
|
||||
* Encode a geometry as WKT.
|
||||
* @param {!import("../geom/Geometry.js").default} geom The geometry to encode.
|
||||
* @param {import("../geom/Geometry.js").default} geom The geometry to encode.
|
||||
* @return {string} WKT string for the geometry.
|
||||
*/
|
||||
function encode(geom) {
|
||||
|
||||
@@ -407,7 +407,13 @@ function readException(node, objectStack) {
|
||||
* @return {Object|undefined} Layer object.
|
||||
*/
|
||||
function readCapabilityLayer(node, objectStack) {
|
||||
return pushParseAndPop({}, LAYER_PARSERS, node, objectStack);
|
||||
const layerObject = pushParseAndPop({}, LAYER_PARSERS, node, objectStack);
|
||||
|
||||
if (layerObject['Layer'] === undefined) {
|
||||
return Object.assign(layerObject, readLayer(node, objectStack));
|
||||
}
|
||||
|
||||
return layerObject;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,7 +33,7 @@ const layerIdentifier = '_layer';
|
||||
*/
|
||||
class WMSGetFeatureInfo extends XMLFeature {
|
||||
/**
|
||||
* @param {Options=} opt_options Options.
|
||||
* @param {Options} [opt_options] Options.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
super();
|
||||
@@ -151,7 +151,7 @@ class WMSGetFeatureInfo extends XMLFeature {
|
||||
/**
|
||||
* @protected
|
||||
* @param {Element} node Node.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Options.
|
||||
* @return {Array<import("../Feature.js").default>} Features.
|
||||
*/
|
||||
readFeaturesFromNode(node, opt_options) {
|
||||
|
||||
@@ -37,7 +37,7 @@ class XMLFeature extends FeatureFormat {
|
||||
* Read a single feature.
|
||||
*
|
||||
* @param {Document|Element|Object|string} source Source.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options.
|
||||
* @return {import("../Feature.js").default} Feature.
|
||||
* @api
|
||||
*/
|
||||
@@ -62,7 +62,7 @@ class XMLFeature extends FeatureFormat {
|
||||
|
||||
/**
|
||||
* @param {Document} doc Document.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Options.
|
||||
* @return {import("../Feature.js").default} Feature.
|
||||
*/
|
||||
readFeatureFromDocument(doc, opt_options) {
|
||||
@@ -76,7 +76,7 @@ class XMLFeature extends FeatureFormat {
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Options.
|
||||
* @return {import("../Feature.js").default} Feature.
|
||||
*/
|
||||
readFeatureFromNode(node, opt_options) {
|
||||
@@ -87,7 +87,7 @@ class XMLFeature extends FeatureFormat {
|
||||
* Read all features from a feature collection.
|
||||
*
|
||||
* @param {Document|Element|Object|string} source Source.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Options.
|
||||
* @return {Array<import("../Feature.js").default>} Features.
|
||||
* @api
|
||||
*/
|
||||
@@ -112,7 +112,7 @@ class XMLFeature extends FeatureFormat {
|
||||
|
||||
/**
|
||||
* @param {Document} doc Document.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Options.
|
||||
* @protected
|
||||
* @return {Array<import("../Feature.js").default>} Features.
|
||||
*/
|
||||
@@ -133,7 +133,7 @@ class XMLFeature extends FeatureFormat {
|
||||
/**
|
||||
* @abstract
|
||||
* @param {Element} node Node.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Options.
|
||||
* @protected
|
||||
* @return {Array<import("../Feature.js").default>} Features.
|
||||
*/
|
||||
@@ -145,7 +145,7 @@ class XMLFeature extends FeatureFormat {
|
||||
* Read a single geometry from a source.
|
||||
*
|
||||
* @param {Document|Element|Object|string} source Source.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Read options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options.
|
||||
* @return {import("../geom/Geometry.js").default} Geometry.
|
||||
*/
|
||||
readGeometry(source, opt_options) {
|
||||
@@ -169,7 +169,7 @@ class XMLFeature extends FeatureFormat {
|
||||
|
||||
/**
|
||||
* @param {Document} doc Document.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Options.
|
||||
* @protected
|
||||
* @return {import("../geom/Geometry.js").default} Geometry.
|
||||
*/
|
||||
@@ -179,7 +179,7 @@ class XMLFeature extends FeatureFormat {
|
||||
|
||||
/**
|
||||
* @param {Element} node Node.
|
||||
* @param {import("./Feature.js").ReadOptions=} opt_options Options.
|
||||
* @param {import("./Feature.js").ReadOptions} [opt_options] Options.
|
||||
* @protected
|
||||
* @return {import("../geom/Geometry.js").default} Geometry.
|
||||
*/
|
||||
@@ -229,7 +229,7 @@ class XMLFeature extends FeatureFormat {
|
||||
* Encode a feature as string.
|
||||
*
|
||||
* @param {import("../Feature.js").default} feature Feature.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options.
|
||||
* @return {string} Encoded feature.
|
||||
*/
|
||||
writeFeature(feature, opt_options) {
|
||||
@@ -239,7 +239,7 @@ class XMLFeature extends FeatureFormat {
|
||||
|
||||
/**
|
||||
* @param {import("../Feature.js").default} feature Feature.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Options.
|
||||
* @protected
|
||||
* @return {Node} Node.
|
||||
*/
|
||||
@@ -251,7 +251,7 @@ class XMLFeature extends FeatureFormat {
|
||||
* Encode an array of features as string.
|
||||
*
|
||||
* @param {Array<import("../Feature.js").default>} features Features.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options.
|
||||
* @return {string} Result.
|
||||
* @api
|
||||
*/
|
||||
@@ -262,7 +262,7 @@ class XMLFeature extends FeatureFormat {
|
||||
|
||||
/**
|
||||
* @param {Array<import("../Feature.js").default>} features Features.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Options.
|
||||
* @return {Node} Node.
|
||||
*/
|
||||
writeFeaturesNode(features, opt_options) {
|
||||
@@ -273,7 +273,7 @@ class XMLFeature extends FeatureFormat {
|
||||
* Encode a geometry as string.
|
||||
*
|
||||
* @param {import("../geom/Geometry.js").default} geometry Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Write options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options.
|
||||
* @return {string} Encoded geometry.
|
||||
*/
|
||||
writeGeometry(geometry, opt_options) {
|
||||
@@ -283,7 +283,7 @@ class XMLFeature extends FeatureFormat {
|
||||
|
||||
/**
|
||||
* @param {import("../geom/Geometry.js").default} geometry Geometry.
|
||||
* @param {import("./Feature.js").WriteOptions=} opt_options Options.
|
||||
* @param {import("./Feature.js").WriteOptions} [opt_options] Options.
|
||||
* @return {Node} Node.
|
||||
*/
|
||||
writeGeometryNode(geometry, opt_options) {
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
import And from './filter/And.js';
|
||||
import Bbox from './filter/Bbox.js';
|
||||
import Contains from './filter/Contains.js';
|
||||
import DWithin from './filter/DWithin.js';
|
||||
import Disjoint from './filter/Disjoint.js';
|
||||
import During from './filter/During.js';
|
||||
import EqualTo from './filter/EqualTo.js';
|
||||
import GreaterThan from './filter/GreaterThan.js';
|
||||
@@ -17,13 +19,14 @@ import LessThanOrEqualTo from './filter/LessThanOrEqualTo.js';
|
||||
import Not from './filter/Not.js';
|
||||
import NotEqualTo from './filter/NotEqualTo.js';
|
||||
import Or from './filter/Or.js';
|
||||
import ResourceId from './filter/ResourceId.js';
|
||||
import Within from './filter/Within.js';
|
||||
|
||||
/**
|
||||
* Create a logical `<And>` operator between two or more filter conditions.
|
||||
*
|
||||
* @param {...import("./filter/Filter.js").default} conditions Filter conditions.
|
||||
* @returns {!And} `<And>` operator.
|
||||
* @return {!And} `<And>` operator.
|
||||
* @api
|
||||
*/
|
||||
export function and(conditions) {
|
||||
@@ -35,7 +38,7 @@ export function and(conditions) {
|
||||
* Create a logical `<Or>` operator between two or more filter conditions.
|
||||
*
|
||||
* @param {...import("./filter/Filter.js").default} conditions Filter conditions.
|
||||
* @returns {!Or} `<Or>` operator.
|
||||
* @return {!Or} `<Or>` operator.
|
||||
* @api
|
||||
*/
|
||||
export function or(conditions) {
|
||||
@@ -47,7 +50,7 @@ export function or(conditions) {
|
||||
* Represents a logical `<Not>` operator for a filter condition.
|
||||
*
|
||||
* @param {!import("./filter/Filter.js").default} condition Filter condition.
|
||||
* @returns {!Not} `<Not>` operator.
|
||||
* @return {!Not} `<Not>` operator.
|
||||
* @api
|
||||
*/
|
||||
export function not(condition) {
|
||||
@@ -60,9 +63,9 @@ export function not(condition) {
|
||||
*
|
||||
* @param {!string} geometryName Geometry name to use.
|
||||
* @param {!import("../extent.js").Extent} extent Extent.
|
||||
* @param {string=} opt_srsName SRS name. No srsName attribute will be
|
||||
* @param {string} [opt_srsName] SRS name. No srsName attribute will be
|
||||
* set on geometries when this is not provided.
|
||||
* @returns {!Bbox} `<BBOX>` operator.
|
||||
* @return {!Bbox} `<BBOX>` operator.
|
||||
* @api
|
||||
*/
|
||||
export function bbox(geometryName, extent, opt_srsName) {
|
||||
@@ -75,9 +78,9 @@ export function bbox(geometryName, extent, opt_srsName) {
|
||||
*
|
||||
* @param {!string} geometryName Geometry name to use.
|
||||
* @param {!import("../geom/Geometry.js").default} geometry Geometry.
|
||||
* @param {string=} opt_srsName SRS name. No srsName attribute will be
|
||||
* @param {string} [opt_srsName] SRS name. No srsName attribute will be
|
||||
* set on geometries when this is not provided.
|
||||
* @returns {!Contains} `<Contains>` operator.
|
||||
* @return {!Contains} `<Contains>` operator.
|
||||
* @api
|
||||
*/
|
||||
export function contains(geometryName, geometry, opt_srsName) {
|
||||
@@ -90,37 +93,69 @@ export function contains(geometryName, geometry, opt_srsName) {
|
||||
*
|
||||
* @param {!string} geometryName Geometry name to use.
|
||||
* @param {!import("../geom/Geometry.js").default} geometry Geometry.
|
||||
* @param {string=} opt_srsName SRS name. No srsName attribute will be
|
||||
* @param {string} [opt_srsName] SRS name. No srsName attribute will be
|
||||
* set on geometries when this is not provided.
|
||||
* @returns {!Intersects} `<Intersects>` operator.
|
||||
* @return {!Intersects} `<Intersects>` operator.
|
||||
* @api
|
||||
*/
|
||||
export function intersects(geometryName, geometry, opt_srsName) {
|
||||
return new Intersects(geometryName, geometry, opt_srsName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a `<Disjoint>` operator to test whether a geometry-valued property
|
||||
* is disjoint to a given geometry.
|
||||
*
|
||||
* @param {!string} geometryName Geometry name to use.
|
||||
* @param {!import("../geom/Geometry.js").default} geometry Geometry.
|
||||
* @param {string} [opt_srsName] SRS name. No srsName attribute will be
|
||||
* set on geometries when this is not provided.
|
||||
* @return {!Disjoint} `<Disjoint>` operator.
|
||||
* @api
|
||||
*/
|
||||
export function disjoint(geometryName, geometry, opt_srsName) {
|
||||
return new Disjoint(geometryName, geometry, opt_srsName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a `<Within>` operator to test whether a geometry-valued property
|
||||
* is within a given geometry.
|
||||
*
|
||||
* @param {!string} geometryName Geometry name to use.
|
||||
* @param {!import("../geom/Geometry.js").default} geometry Geometry.
|
||||
* @param {string=} opt_srsName SRS name. No srsName attribute will be
|
||||
* @param {string} [opt_srsName] SRS name. No srsName attribute will be
|
||||
* set on geometries when this is not provided.
|
||||
* @returns {!Within} `<Within>` operator.
|
||||
* @return {!Within} `<Within>` operator.
|
||||
* @api
|
||||
*/
|
||||
export function within(geometryName, geometry, opt_srsName) {
|
||||
return new Within(geometryName, geometry, opt_srsName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a `<DWithin>` operator to test whether a geometry-valued property
|
||||
* is within a distance to a given geometry.
|
||||
*
|
||||
* @param {!string} geometryName Geometry name to use.
|
||||
* @param {!import("../geom/Geometry.js").default} geometry Geometry.
|
||||
* @param {!number} distance Distance.
|
||||
* @param {!string} unit Unit.
|
||||
* @param {string} [opt_srsName] SRS name. No srsName attribute will be
|
||||
* set on geometries when this is not provided.
|
||||
* @return {!DWithin} `<DWithin>` operator.
|
||||
* @api
|
||||
*/
|
||||
export function dwithin(geometryName, geometry, distance, unit, opt_srsName) {
|
||||
return new DWithin(geometryName, geometry, distance, unit, opt_srsName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a `<PropertyIsEqualTo>` comparison operator.
|
||||
*
|
||||
* @param {!string} propertyName Name of the context property to compare.
|
||||
* @param {!(string|number)} expression The value to compare.
|
||||
* @param {boolean=} opt_matchCase Case-sensitive?
|
||||
* @returns {!EqualTo} `<PropertyIsEqualTo>` operator.
|
||||
* @param {boolean} [opt_matchCase] Case-sensitive?
|
||||
* @return {!EqualTo} `<PropertyIsEqualTo>` operator.
|
||||
* @api
|
||||
*/
|
||||
export function equalTo(propertyName, expression, opt_matchCase) {
|
||||
@@ -132,8 +167,8 @@ export function equalTo(propertyName, expression, opt_matchCase) {
|
||||
*
|
||||
* @param {!string} propertyName Name of the context property to compare.
|
||||
* @param {!(string|number)} expression The value to compare.
|
||||
* @param {boolean=} opt_matchCase Case-sensitive?
|
||||
* @returns {!NotEqualTo} `<PropertyIsNotEqualTo>` operator.
|
||||
* @param {boolean} [opt_matchCase] Case-sensitive?
|
||||
* @return {!NotEqualTo} `<PropertyIsNotEqualTo>` operator.
|
||||
* @api
|
||||
*/
|
||||
export function notEqualTo(propertyName, expression, opt_matchCase) {
|
||||
@@ -145,7 +180,7 @@ export function notEqualTo(propertyName, expression, opt_matchCase) {
|
||||
*
|
||||
* @param {!string} propertyName Name of the context property to compare.
|
||||
* @param {!number} expression The value to compare.
|
||||
* @returns {!LessThan} `<PropertyIsLessThan>` operator.
|
||||
* @return {!LessThan} `<PropertyIsLessThan>` operator.
|
||||
* @api
|
||||
*/
|
||||
export function lessThan(propertyName, expression) {
|
||||
@@ -157,7 +192,7 @@ export function lessThan(propertyName, expression) {
|
||||
*
|
||||
* @param {!string} propertyName Name of the context property to compare.
|
||||
* @param {!number} expression The value to compare.
|
||||
* @returns {!LessThanOrEqualTo} `<PropertyIsLessThanOrEqualTo>` operator.
|
||||
* @return {!LessThanOrEqualTo} `<PropertyIsLessThanOrEqualTo>` operator.
|
||||
* @api
|
||||
*/
|
||||
export function lessThanOrEqualTo(propertyName, expression) {
|
||||
@@ -169,7 +204,7 @@ export function lessThanOrEqualTo(propertyName, expression) {
|
||||
*
|
||||
* @param {!string} propertyName Name of the context property to compare.
|
||||
* @param {!number} expression The value to compare.
|
||||
* @returns {!GreaterThan} `<PropertyIsGreaterThan>` operator.
|
||||
* @return {!GreaterThan} `<PropertyIsGreaterThan>` operator.
|
||||
* @api
|
||||
*/
|
||||
export function greaterThan(propertyName, expression) {
|
||||
@@ -181,7 +216,7 @@ export function greaterThan(propertyName, expression) {
|
||||
*
|
||||
* @param {!string} propertyName Name of the context property to compare.
|
||||
* @param {!number} expression The value to compare.
|
||||
* @returns {!GreaterThanOrEqualTo} `<PropertyIsGreaterThanOrEqualTo>` operator.
|
||||
* @return {!GreaterThanOrEqualTo} `<PropertyIsGreaterThanOrEqualTo>` operator.
|
||||
* @api
|
||||
*/
|
||||
export function greaterThanOrEqualTo(propertyName, expression) {
|
||||
@@ -193,7 +228,7 @@ export function greaterThanOrEqualTo(propertyName, expression) {
|
||||
* is null.
|
||||
*
|
||||
* @param {!string} propertyName Name of the context property to compare.
|
||||
* @returns {!IsNull} `<PropertyIsNull>` operator.
|
||||
* @return {!IsNull} `<PropertyIsNull>` operator.
|
||||
* @api
|
||||
*/
|
||||
export function isNull(propertyName) {
|
||||
@@ -207,7 +242,7 @@ export function isNull(propertyName) {
|
||||
* @param {!string} propertyName Name of the context property to compare.
|
||||
* @param {!number} lowerBoundary The lower bound of the range.
|
||||
* @param {!number} upperBoundary The upper bound of the range.
|
||||
* @returns {!IsBetween} `<PropertyIsBetween>` operator.
|
||||
* @return {!IsBetween} `<PropertyIsBetween>` operator.
|
||||
* @api
|
||||
*/
|
||||
export function between(propertyName, lowerBoundary, upperBoundary) {
|
||||
@@ -220,14 +255,14 @@ export function between(propertyName, lowerBoundary, upperBoundary) {
|
||||
*
|
||||
* @param {!string} propertyName Name of the context property to compare.
|
||||
* @param {!string} pattern Text pattern.
|
||||
* @param {string=} opt_wildCard Pattern character which matches any sequence of
|
||||
* @param {string} [opt_wildCard] Pattern character which matches any sequence of
|
||||
* zero or more string characters. Default is '*'.
|
||||
* @param {string=} opt_singleChar pattern character which matches any single
|
||||
* @param {string} [opt_singleChar] pattern character which matches any single
|
||||
* string character. Default is '.'.
|
||||
* @param {string=} opt_escapeChar Escape character which can be used to escape
|
||||
* @param {string} [opt_escapeChar] Escape character which can be used to escape
|
||||
* the pattern characters. Default is '!'.
|
||||
* @param {boolean=} opt_matchCase Case-sensitive?
|
||||
* @returns {!IsLike} `<PropertyIsLike>` operator.
|
||||
* @param {boolean} [opt_matchCase] Case-sensitive?
|
||||
* @return {!IsLike} `<PropertyIsLike>` operator.
|
||||
* @api
|
||||
*/
|
||||
export function like(
|
||||
@@ -254,9 +289,13 @@ export function like(
|
||||
* @param {!string} propertyName Name of the context property to compare.
|
||||
* @param {!string} begin The begin date in ISO-8601 format.
|
||||
* @param {!string} end The end date in ISO-8601 format.
|
||||
* @returns {!During} `<During>` operator.
|
||||
* @return {!During} `<During>` operator.
|
||||
* @api
|
||||
*/
|
||||
export function during(propertyName, begin, end) {
|
||||
return new During(propertyName, begin, end);
|
||||
}
|
||||
|
||||
export function resourceId(rid) {
|
||||
return new ResourceId(rid);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ class Bbox extends Filter {
|
||||
/**
|
||||
* @param {!string} geometryName Geometry name to use.
|
||||
* @param {!import("../../extent.js").Extent} extent Extent.
|
||||
* @param {string=} opt_srsName SRS name. No srsName attribute will be set
|
||||
* @param {string} [opt_srsName] SRS name. No srsName attribute will be set
|
||||
* on geometries when this is not provided.
|
||||
*/
|
||||
constructor(geometryName, extent, opt_srsName) {
|
||||
|
||||
@@ -15,7 +15,7 @@ class ComparisonBinary extends Comparison {
|
||||
* @param {!string} tagName The XML tag name for this filter.
|
||||
* @param {!string} propertyName Name of the context property to compare.
|
||||
* @param {!(string|number)} expression The value to compare.
|
||||
* @param {boolean=} opt_matchCase Case-sensitive?
|
||||
* @param {boolean} [opt_matchCase] Case-sensitive?
|
||||
*/
|
||||
constructor(tagName, propertyName, expression, opt_matchCase) {
|
||||
super(tagName, propertyName);
|
||||
|
||||
@@ -13,7 +13,7 @@ class Contains extends Spatial {
|
||||
/**
|
||||
* @param {!string} geometryName Geometry name to use.
|
||||
* @param {!import("../../geom/Geometry.js").default} geometry Geometry.
|
||||
* @param {string=} opt_srsName SRS name. No srsName attribute will be
|
||||
* @param {string} [opt_srsName] SRS name. No srsName attribute will be
|
||||
* set on geometries when this is not provided.
|
||||
*/
|
||||
constructor(geometryName, geometry, opt_srsName) {
|
||||
|
||||
38
src/ol/format/filter/DWithin.js
Normal file
38
src/ol/format/filter/DWithin.js
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* @module ol/format/filter/DWithin
|
||||
*/
|
||||
import Spatial from './Spatial.js';
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Represents a `<DWithin>` operator to test whether a geometry-valued property
|
||||
* is within a distance to a given geometry.
|
||||
* @api
|
||||
*/
|
||||
class DWithin extends Spatial {
|
||||
/**
|
||||
* @param {!string} geometryName Geometry name to use.
|
||||
* @param {!import("../../geom/Geometry.js").default} geometry Geometry.
|
||||
* @param {!number} distance Distance.
|
||||
* @param {!string} unit Unit.
|
||||
* @param {string} [opt_srsName] SRS name. No srsName attribute will be
|
||||
* set on geometries when this is not provided.
|
||||
*/
|
||||
constructor(geometryName, geometry, distance, unit, opt_srsName) {
|
||||
super('DWithin', geometryName, geometry, opt_srsName);
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @type {!number}
|
||||
*/
|
||||
this.distance = distance;
|
||||
|
||||
/**
|
||||
* @public
|
||||
* @type {!string}
|
||||
*/
|
||||
this.unit = unit;
|
||||
}
|
||||
}
|
||||
|
||||
export default DWithin;
|
||||
24
src/ol/format/filter/Disjoint.js
Normal file
24
src/ol/format/filter/Disjoint.js
Normal file
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
* @module ol/format/filter/Disjoint
|
||||
*/
|
||||
import Spatial from './Spatial.js';
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Represents a `<Disjoint>` operator to test whether a geometry-valued property
|
||||
* is disjoint to a given geometry.
|
||||
* @api
|
||||
*/
|
||||
class Disjoint extends Spatial {
|
||||
/**
|
||||
* @param {!string} geometryName Geometry name to use.
|
||||
* @param {!import("../../geom/Geometry.js").default} geometry Geometry.
|
||||
* @param {string} [opt_srsName] SRS name. No srsName attribute will be
|
||||
* set on geometries when this is not provided.
|
||||
*/
|
||||
constructor(geometryName, geometry, opt_srsName) {
|
||||
super('Disjoint', geometryName, geometry, opt_srsName);
|
||||
}
|
||||
}
|
||||
|
||||
export default Disjoint;
|
||||
@@ -12,7 +12,7 @@ class EqualTo extends ComparisonBinary {
|
||||
/**
|
||||
* @param {!string} propertyName Name of the context property to compare.
|
||||
* @param {!(string|number)} expression The value to compare.
|
||||
* @param {boolean=} opt_matchCase Case-sensitive?
|
||||
* @param {boolean} [opt_matchCase] Case-sensitive?
|
||||
*/
|
||||
constructor(propertyName, expression, opt_matchCase) {
|
||||
super('PropertyIsEqualTo', propertyName, expression, opt_matchCase);
|
||||
|
||||
@@ -23,7 +23,7 @@ class Filter {
|
||||
|
||||
/**
|
||||
* The XML tag name for a filter.
|
||||
* @returns {!string} Name.
|
||||
* @return {!string} Name.
|
||||
*/
|
||||
getTagName() {
|
||||
return this.tagName_;
|
||||
|
||||
@@ -13,7 +13,7 @@ class Intersects extends Spatial {
|
||||
/**
|
||||
* @param {!string} geometryName Geometry name to use.
|
||||
* @param {!import("../../geom/Geometry.js").default} geometry Geometry.
|
||||
* @param {string=} opt_srsName SRS name. No srsName attribute will be
|
||||
* @param {string} [opt_srsName] SRS name. No srsName attribute will be
|
||||
* set on geometries when this is not provided.
|
||||
*/
|
||||
constructor(geometryName, geometry, opt_srsName) {
|
||||
|
||||
@@ -13,13 +13,13 @@ class IsLike extends Comparison {
|
||||
* [constructor description]
|
||||
* @param {!string} propertyName Name of the context property to compare.
|
||||
* @param {!string} pattern Text pattern.
|
||||
* @param {string=} opt_wildCard Pattern character which matches any sequence of
|
||||
* @param {string} [opt_wildCard] Pattern character which matches any sequence of
|
||||
* zero or more string characters. Default is '*'.
|
||||
* @param {string=} opt_singleChar pattern character which matches any single
|
||||
* @param {string} [opt_singleChar] pattern character which matches any single
|
||||
* string character. Default is '.'.
|
||||
* @param {string=} opt_escapeChar Escape character which can be used to escape
|
||||
* @param {string} [opt_escapeChar] Escape character which can be used to escape
|
||||
* the pattern characters. Default is '!'.
|
||||
* @param {boolean=} opt_matchCase Case-sensitive?
|
||||
* @param {boolean} [opt_matchCase] Case-sensitive?
|
||||
*/
|
||||
constructor(
|
||||
propertyName,
|
||||
|
||||
@@ -12,7 +12,7 @@ class NotEqualTo extends ComparisonBinary {
|
||||
/**
|
||||
* @param {!string} propertyName Name of the context property to compare.
|
||||
* @param {!(string|number)} expression The value to compare.
|
||||
* @param {boolean=} opt_matchCase Case-sensitive?
|
||||
* @param {boolean} [opt_matchCase] Case-sensitive?
|
||||
*/
|
||||
constructor(propertyName, expression, opt_matchCase) {
|
||||
super('PropertyIsNotEqualTo', propertyName, expression, opt_matchCase);
|
||||
|
||||
25
src/ol/format/filter/ResourceId.js
Normal file
25
src/ol/format/filter/ResourceId.js
Normal file
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
* @module ol/format/filter/ResourceId
|
||||
*/
|
||||
import Filter from './Filter.js';
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
*
|
||||
* @abstract
|
||||
*/
|
||||
class ResourceId extends Filter {
|
||||
/**
|
||||
* @param {!string} rid Resource ID.
|
||||
*/
|
||||
constructor(rid) {
|
||||
super('ResourceId');
|
||||
|
||||
/**
|
||||
* @type {!string}
|
||||
*/
|
||||
this.rid = rid;
|
||||
}
|
||||
}
|
||||
|
||||
export default ResourceId;
|
||||
@@ -16,7 +16,7 @@ class Spatial extends Filter {
|
||||
* @param {!string} tagName The XML tag name for this filter.
|
||||
* @param {!string} geometryName Geometry name to use.
|
||||
* @param {!import("../../geom/Geometry.js").default} geometry Geometry.
|
||||
* @param {string=} opt_srsName SRS name. No srsName attribute will be
|
||||
* @param {string} [opt_srsName] SRS name. No srsName attribute will be
|
||||
* set on geometries when this is not provided.
|
||||
*/
|
||||
constructor(tagName, geometryName, geometry, opt_srsName) {
|
||||
|
||||
@@ -13,7 +13,7 @@ class Within extends Spatial {
|
||||
/**
|
||||
* @param {!string} geometryName Geometry name to use.
|
||||
* @param {!import("../../geom/Geometry.js").default} geometry Geometry.
|
||||
* @param {string=} opt_srsName SRS name. No srsName attribute will be
|
||||
* @param {string} [opt_srsName] SRS name. No srsName attribute will be
|
||||
* set on geometries when this is not provided.
|
||||
*/
|
||||
constructor(geometryName, geometry, opt_srsName) {
|
||||
|
||||
@@ -124,7 +124,7 @@ In the above there are many common operations, like setting the property of the
|
||||
|
||||
### Putting it all together
|
||||
|
||||
With the above, you should be able to read through the [source code to `ol/format/GPX`](https://github.com/openlayers/openlayers/blob/main/src/ol/format/gpxformat.js) and get a feel for how it works. Start from the bottom of the file and work upwards. It's also useful to have [an example GPX file](http://www.topografix.com/fells_loop.gpx) and [the GPX specification](http://www.topografix.com/GPX/1/1/) to hand.
|
||||
With the above, you should be able to read through the [source code to `ol/format/GPX`](https://github.com/openlayers/openlayers/blob/main/src/ol/format/GPX.js) and get a feel for how it works. Start from the bottom of the file and work upwards. It's also useful to have [an example GPX file](https://openlayers.org/en/latest/examples/data/fells_loop.gpx) and [the GPX specification](https://www.topografix.com/GPX/1/1/) to hand.
|
||||
|
||||
### Handling errors
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import {equals as arrayEquals} from './array.js';
|
||||
|
||||
/**
|
||||
* Always returns true.
|
||||
* @returns {boolean} true.
|
||||
* @return {boolean} true.
|
||||
*/
|
||||
export function TRUE() {
|
||||
return true;
|
||||
@@ -14,7 +14,7 @@ export function TRUE() {
|
||||
|
||||
/**
|
||||
* Always returns false.
|
||||
* @returns {boolean} false.
|
||||
* @return {boolean} false.
|
||||
*/
|
||||
export function FALSE() {
|
||||
return false;
|
||||
|
||||
@@ -18,8 +18,8 @@ class Circle extends SimpleGeometry {
|
||||
* @param {!import("../coordinate.js").Coordinate} center Center.
|
||||
* For internal use, flat coordinates in combination with `opt_layout` and no
|
||||
* `opt_radius` are also accepted.
|
||||
* @param {number=} opt_radius Radius.
|
||||
* @param {import("./GeometryLayout.js").default=} opt_layout Layout.
|
||||
* @param {number} [opt_radius] Radius.
|
||||
* @param {import("./GeometryLayout.js").default} [opt_layout] Layout.
|
||||
*/
|
||||
constructor(center, opt_radius, opt_layout) {
|
||||
super();
|
||||
@@ -37,7 +37,13 @@ class Circle extends SimpleGeometry {
|
||||
* @api
|
||||
*/
|
||||
clone() {
|
||||
return new Circle(this.flatCoordinates.slice(), undefined, this.layout);
|
||||
const circle = new Circle(
|
||||
this.flatCoordinates.slice(),
|
||||
undefined,
|
||||
this.layout
|
||||
);
|
||||
circle.applyProperties(this);
|
||||
return circle;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -183,7 +189,7 @@ class Circle extends SimpleGeometry {
|
||||
* number) of the circle.
|
||||
* @param {!import("../coordinate.js").Coordinate} center Center.
|
||||
* @param {number} radius Radius.
|
||||
* @param {import("./GeometryLayout.js").default=} opt_layout Layout.
|
||||
* @param {import("./GeometryLayout.js").default} [opt_layout] Layout.
|
||||
* @api
|
||||
*/
|
||||
setCenterAndRadius(center, radius, opt_layout) {
|
||||
@@ -221,7 +227,7 @@ class Circle extends SimpleGeometry {
|
||||
/**
|
||||
* Rotate the geometry around a given coordinate. This modifies the geometry
|
||||
* coordinates in place.
|
||||
* @param {number} angle Rotation angle in radians.
|
||||
* @param {number} angle Rotation angle in counter-clockwise radians.
|
||||
* @param {import("../coordinate.js").Coordinate} anchor The rotation center.
|
||||
* @api
|
||||
*/
|
||||
|
||||
@@ -135,7 +135,7 @@ class Geometry extends BaseObject {
|
||||
* Return the closest point of the geometry to the passed point as
|
||||
* {@link module:ol/coordinate~Coordinate coordinate}.
|
||||
* @param {import("../coordinate.js").Coordinate} point Point.
|
||||
* @param {import("../coordinate.js").Coordinate=} opt_closestPoint Closest point.
|
||||
* @param {import("../coordinate.js").Coordinate} [opt_closestPoint] Closest point.
|
||||
* @return {import("../coordinate.js").Coordinate} Closest point.
|
||||
* @api
|
||||
*/
|
||||
@@ -168,7 +168,7 @@ class Geometry extends BaseObject {
|
||||
|
||||
/**
|
||||
* Get the extent of the geometry.
|
||||
* @param {import("../extent.js").Extent=} opt_extent Extent.
|
||||
* @param {import("../extent.js").Extent} [opt_extent] Extent.
|
||||
* @return {import("../extent.js").Extent} extent Extent.
|
||||
* @api
|
||||
*/
|
||||
@@ -200,8 +200,8 @@ class Geometry extends BaseObject {
|
||||
* coordinates in place.
|
||||
* @abstract
|
||||
* @param {number} sx The scaling factor in the x-direction.
|
||||
* @param {number=} opt_sy The scaling factor in the y-direction (defaults to sx).
|
||||
* @param {import("../coordinate.js").Coordinate=} opt_anchor The scale origin (defaults to the center
|
||||
* @param {number} [opt_sy] The scaling factor in the y-direction (defaults to sx).
|
||||
* @param {import("../coordinate.js").Coordinate} [opt_anchor] The scale origin (defaults to the center
|
||||
* of the geometry extent).
|
||||
* @api
|
||||
*/
|
||||
|
||||
@@ -20,7 +20,7 @@ import {listen, unlistenByKey} from '../events.js';
|
||||
*/
|
||||
class GeometryCollection extends Geometry {
|
||||
/**
|
||||
* @param {Array<Geometry>=} opt_geometries Geometries.
|
||||
* @param {Array<Geometry>} [opt_geometries] Geometries.
|
||||
*/
|
||||
constructor(opt_geometries) {
|
||||
super();
|
||||
@@ -69,6 +69,7 @@ class GeometryCollection extends Geometry {
|
||||
clone() {
|
||||
const geometryCollection = new GeometryCollection(null);
|
||||
geometryCollection.setGeometries(this.geometries_);
|
||||
geometryCollection.applyProperties(this);
|
||||
return geometryCollection;
|
||||
}
|
||||
|
||||
@@ -254,8 +255,8 @@ class GeometryCollection extends Geometry {
|
||||
* coordinates in place.
|
||||
* @abstract
|
||||
* @param {number} sx The scaling factor in the x-direction.
|
||||
* @param {number=} opt_sy The scaling factor in the y-direction (defaults to sx).
|
||||
* @param {import("../coordinate.js").Coordinate=} opt_anchor The scale origin (defaults to the center
|
||||
* @param {number} [opt_sy] The scaling factor in the y-direction (defaults to sx).
|
||||
* @param {import("../coordinate.js").Coordinate} [opt_anchor] The scale origin (defaults to the center
|
||||
* of the geometry extent).
|
||||
* @api
|
||||
*/
|
||||
|
||||
@@ -25,7 +25,7 @@ class LineString extends SimpleGeometry {
|
||||
/**
|
||||
* @param {Array<import("../coordinate.js").Coordinate>|Array<number>} coordinates Coordinates.
|
||||
* For internal use, flat coordinates in combination with `opt_layout` are also accepted.
|
||||
* @param {import("./GeometryLayout.js").default=} opt_layout Layout.
|
||||
* @param {import("./GeometryLayout.js").default} [opt_layout] Layout.
|
||||
*/
|
||||
constructor(coordinates, opt_layout) {
|
||||
super();
|
||||
@@ -87,7 +87,12 @@ class LineString extends SimpleGeometry {
|
||||
* @api
|
||||
*/
|
||||
clone() {
|
||||
return new LineString(this.flatCoordinates.slice(), this.layout);
|
||||
const lineString = new LineString(
|
||||
this.flatCoordinates.slice(),
|
||||
this.layout
|
||||
);
|
||||
lineString.applyProperties(this);
|
||||
return lineString;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -158,7 +163,7 @@ class LineString extends SimpleGeometry {
|
||||
* return the last coordinate.
|
||||
*
|
||||
* @param {number} m M.
|
||||
* @param {boolean=} opt_extrapolate Extrapolate. Default is `false`.
|
||||
* @param {boolean} [opt_extrapolate] Extrapolate. Default is `false`.
|
||||
* @return {import("../coordinate.js").Coordinate} Coordinate.
|
||||
* @api
|
||||
*/
|
||||
@@ -199,7 +204,7 @@ class LineString extends SimpleGeometry {
|
||||
* The `fraction` is a number between 0 and 1, where 0 is the start of the
|
||||
* linestring and 1 is the end.
|
||||
* @param {number} fraction Fraction.
|
||||
* @param {import("../coordinate.js").Coordinate=} opt_dest Optional coordinate whose values will
|
||||
* @param {import("../coordinate.js").Coordinate} [opt_dest] Optional coordinate whose values will
|
||||
* be modified. If not provided, a new coordinate will be returned.
|
||||
* @return {import("../coordinate.js").Coordinate} Coordinate of the interpolated point.
|
||||
* @api
|
||||
@@ -288,7 +293,7 @@ class LineString extends SimpleGeometry {
|
||||
/**
|
||||
* Set the coordinates of the linestring.
|
||||
* @param {!Array<import("../coordinate.js").Coordinate>} coordinates Coordinates.
|
||||
* @param {import("./GeometryLayout.js").default=} opt_layout Layout.
|
||||
* @param {import("./GeometryLayout.js").default} [opt_layout] Layout.
|
||||
* @api
|
||||
*/
|
||||
setCoordinates(coordinates, opt_layout) {
|
||||
|
||||
@@ -22,7 +22,7 @@ class LinearRing extends SimpleGeometry {
|
||||
/**
|
||||
* @param {Array<import("../coordinate.js").Coordinate>|Array<number>} coordinates Coordinates.
|
||||
* For internal use, flat coordinates in combination with `opt_layout` are also accepted.
|
||||
* @param {import("./GeometryLayout.js").default=} opt_layout Layout.
|
||||
* @param {import("./GeometryLayout.js").default} [opt_layout] Layout.
|
||||
*/
|
||||
constructor(coordinates, opt_layout) {
|
||||
super();
|
||||
@@ -167,7 +167,7 @@ class LinearRing extends SimpleGeometry {
|
||||
/**
|
||||
* Set the coordinates of the linear ring.
|
||||
* @param {!Array<import("../coordinate.js").Coordinate>} coordinates Coordinates.
|
||||
* @param {import("./GeometryLayout.js").default=} opt_layout Layout.
|
||||
* @param {import("./GeometryLayout.js").default} [opt_layout] Layout.
|
||||
* @api
|
||||
*/
|
||||
setCoordinates(coordinates, opt_layout) {
|
||||
|
||||
@@ -28,8 +28,8 @@ class MultiLineString extends SimpleGeometry {
|
||||
* @param {Array<Array<import("../coordinate.js").Coordinate>|LineString>|Array<number>} coordinates
|
||||
* Coordinates or LineString geometries. (For internal use, flat coordinates in
|
||||
* combination with `opt_layout` and `opt_ends` are also accepted.)
|
||||
* @param {import("./GeometryLayout.js").default=} opt_layout Layout.
|
||||
* @param {Array<number>=} opt_ends Flat coordinate ends for internal use.
|
||||
* @param {import("./GeometryLayout.js").default} [opt_layout] Layout.
|
||||
* @param {Array<number>} [opt_ends] Flat coordinate ends for internal use.
|
||||
*/
|
||||
constructor(coordinates, opt_layout, opt_ends) {
|
||||
super();
|
||||
@@ -102,11 +102,13 @@ class MultiLineString extends SimpleGeometry {
|
||||
* @api
|
||||
*/
|
||||
clone() {
|
||||
return new MultiLineString(
|
||||
const multiLineString = new MultiLineString(
|
||||
this.flatCoordinates.slice(),
|
||||
this.layout,
|
||||
this.ends_.slice()
|
||||
);
|
||||
multiLineString.applyProperties(this);
|
||||
return multiLineString;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -163,8 +165,8 @@ class MultiLineString extends SimpleGeometry {
|
||||
* LineStrings.
|
||||
*
|
||||
* @param {number} m M.
|
||||
* @param {boolean=} opt_extrapolate Extrapolate. Default is `false`.
|
||||
* @param {boolean=} opt_interpolate Interpolate. Default is `false`.
|
||||
* @param {boolean} [opt_extrapolate] Extrapolate. Default is `false`.
|
||||
* @param {boolean} [opt_interpolate] Interpolate. Default is `false`.
|
||||
* @return {import("../coordinate.js").Coordinate} Coordinate.
|
||||
* @api
|
||||
*/
|
||||
@@ -330,7 +332,7 @@ class MultiLineString extends SimpleGeometry {
|
||||
/**
|
||||
* Set the coordinates of the multilinestring.
|
||||
* @param {!Array<Array<import("../coordinate.js").Coordinate>>} coordinates Coordinates.
|
||||
* @param {GeometryLayout=} opt_layout Layout.
|
||||
* @param {GeometryLayout} [opt_layout] Layout.
|
||||
* @api
|
||||
*/
|
||||
setCoordinates(coordinates, opt_layout) {
|
||||
|
||||
@@ -20,7 +20,7 @@ class MultiPoint extends SimpleGeometry {
|
||||
/**
|
||||
* @param {Array<import("../coordinate.js").Coordinate>|Array<number>} coordinates Coordinates.
|
||||
* For internal use, flat coordinates in combination with `opt_layout` are also accepted.
|
||||
* @param {import("./GeometryLayout.js").default=} opt_layout Layout.
|
||||
* @param {import("./GeometryLayout.js").default} [opt_layout] Layout.
|
||||
*/
|
||||
constructor(coordinates, opt_layout) {
|
||||
super();
|
||||
@@ -61,6 +61,7 @@ class MultiPoint extends SimpleGeometry {
|
||||
this.flatCoordinates.slice(),
|
||||
this.layout
|
||||
);
|
||||
multiPoint.applyProperties(this);
|
||||
return multiPoint;
|
||||
}
|
||||
|
||||
@@ -180,7 +181,7 @@ class MultiPoint extends SimpleGeometry {
|
||||
/**
|
||||
* Set the coordinates of the multipoint.
|
||||
* @param {!Array<import("../coordinate.js").Coordinate>} coordinates Coordinates.
|
||||
* @param {import("./GeometryLayout.js").default=} opt_layout Layout.
|
||||
* @param {import("./GeometryLayout.js").default} [opt_layout] Layout.
|
||||
* @api
|
||||
*/
|
||||
setCoordinates(coordinates, opt_layout) {
|
||||
|
||||
@@ -35,8 +35,8 @@ class MultiPolygon extends SimpleGeometry {
|
||||
/**
|
||||
* @param {Array<Array<Array<import("../coordinate.js").Coordinate>>|Polygon>|Array<number>} coordinates Coordinates.
|
||||
* For internal use, flat coordinates in combination with `opt_layout` and `opt_endss` are also accepted.
|
||||
* @param {import("./GeometryLayout.js").default=} opt_layout Layout.
|
||||
* @param {Array<Array<number>>=} opt_endss Array of ends for internal use with flat coordinates.
|
||||
* @param {import("./GeometryLayout.js").default} [opt_layout] Layout.
|
||||
* @param {Array<Array<number>>} [opt_endss] Array of ends for internal use with flat coordinates.
|
||||
*/
|
||||
constructor(coordinates, opt_layout, opt_endss) {
|
||||
super();
|
||||
@@ -155,11 +155,14 @@ class MultiPolygon extends SimpleGeometry {
|
||||
newEndss[i] = this.endss_[i].slice();
|
||||
}
|
||||
|
||||
return new MultiPolygon(
|
||||
const multiPolygon = new MultiPolygon(
|
||||
this.flatCoordinates.slice(),
|
||||
this.layout,
|
||||
newEndss
|
||||
);
|
||||
multiPolygon.applyProperties(this);
|
||||
|
||||
return multiPolygon;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -233,7 +236,7 @@ class MultiPolygon extends SimpleGeometry {
|
||||
* Get the coordinate array for this geometry. This array has the structure
|
||||
* of a GeoJSON coordinate array for multi-polygons.
|
||||
*
|
||||
* @param {boolean=} opt_right Orient coordinates according to the right-hand
|
||||
* @param {boolean} [opt_right] Orient coordinates according to the right-hand
|
||||
* rule (counter-clockwise for exterior and clockwise for interior rings).
|
||||
* If `false`, coordinates will be oriented according to the left-hand rule
|
||||
* (clockwise for exterior and counter-clockwise for interior rings).
|
||||
@@ -446,7 +449,7 @@ class MultiPolygon extends SimpleGeometry {
|
||||
/**
|
||||
* Set the coordinates of the multipolygon.
|
||||
* @param {!Array<Array<Array<import("../coordinate.js").Coordinate>>>} coordinates Coordinates.
|
||||
* @param {import("./GeometryLayout.js").default=} opt_layout Layout.
|
||||
* @param {import("./GeometryLayout.js").default} [opt_layout] Layout.
|
||||
* @api
|
||||
*/
|
||||
setCoordinates(coordinates, opt_layout) {
|
||||
|
||||
@@ -16,7 +16,7 @@ import {squaredDistance as squaredDx} from '../math.js';
|
||||
class Point extends SimpleGeometry {
|
||||
/**
|
||||
* @param {import("../coordinate.js").Coordinate} coordinates Coordinates.
|
||||
* @param {import("./GeometryLayout.js").default=} opt_layout Layout.
|
||||
* @param {import("./GeometryLayout.js").default} [opt_layout] Layout.
|
||||
*/
|
||||
constructor(coordinates, opt_layout) {
|
||||
super();
|
||||
@@ -30,6 +30,7 @@ class Point extends SimpleGeometry {
|
||||
*/
|
||||
clone() {
|
||||
const point = new Point(this.flatCoordinates.slice(), this.layout);
|
||||
point.applyProperties(this);
|
||||
return point;
|
||||
}
|
||||
|
||||
@@ -99,7 +100,7 @@ class Point extends SimpleGeometry {
|
||||
|
||||
/**
|
||||
* @param {!Array<*>} coordinates Coordinates.
|
||||
* @param {import("./GeometryLayout.js").default=} opt_layout Layout.
|
||||
* @param {import("./GeometryLayout.js").default} [opt_layout] Layout.
|
||||
* @api
|
||||
*/
|
||||
setCoordinates(coordinates, opt_layout) {
|
||||
|
||||
@@ -35,8 +35,8 @@ class Polygon extends SimpleGeometry {
|
||||
* an array of vertices' coordinates where the first coordinate and the last are
|
||||
* equivalent. (For internal use, flat coordinates in combination with
|
||||
* `opt_layout` and `opt_ends` are also accepted.)
|
||||
* @param {import("./GeometryLayout.js").default=} opt_layout Layout.
|
||||
* @param {Array<number>=} opt_ends Ends (for internal use with flat coordinates).
|
||||
* @param {import("./GeometryLayout.js").default} [opt_layout] Layout.
|
||||
* @param {Array<number>} [opt_ends] Ends (for internal use with flat coordinates).
|
||||
*/
|
||||
constructor(coordinates, opt_layout, opt_ends) {
|
||||
super();
|
||||
@@ -118,11 +118,13 @@ class Polygon extends SimpleGeometry {
|
||||
* @api
|
||||
*/
|
||||
clone() {
|
||||
return new Polygon(
|
||||
const polygon = new Polygon(
|
||||
this.flatCoordinates.slice(),
|
||||
this.layout,
|
||||
this.ends_.slice()
|
||||
);
|
||||
polygon.applyProperties(this);
|
||||
return polygon;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -196,7 +198,7 @@ class Polygon extends SimpleGeometry {
|
||||
* Get the coordinate array for this geometry. This array has the structure
|
||||
* of a GeoJSON coordinate array for polygons.
|
||||
*
|
||||
* @param {boolean=} opt_right Orient coordinates according to the right-hand
|
||||
* @param {boolean} [opt_right] Orient coordinates according to the right-hand
|
||||
* rule (counter-clockwise for exterior and clockwise for interior rings).
|
||||
* If `false`, coordinates will be oriented according to the left-hand rule
|
||||
* (clockwise for exterior and counter-clockwise for interior rings).
|
||||
@@ -385,7 +387,7 @@ class Polygon extends SimpleGeometry {
|
||||
/**
|
||||
* Set the coordinates of the polygon.
|
||||
* @param {!Array<Array<import("../coordinate.js").Coordinate>>} coordinates Coordinates.
|
||||
* @param {import("./GeometryLayout.js").default=} opt_layout Layout.
|
||||
* @param {import("./GeometryLayout.js").default} [opt_layout] Layout.
|
||||
* @api
|
||||
*/
|
||||
setCoordinates(coordinates, opt_layout) {
|
||||
@@ -411,10 +413,10 @@ export default Polygon;
|
||||
* Create an approximation of a circle on the surface of a sphere.
|
||||
* @param {import("../coordinate.js").Coordinate} center Center (`[lon, lat]` in degrees).
|
||||
* @param {number} radius The great-circle distance from the center to
|
||||
* the polygon vertices.
|
||||
* @param {number=} opt_n Optional number of vertices for the resulting
|
||||
* the polygon vertices in meters.
|
||||
* @param {number} [opt_n] Optional number of vertices for the resulting
|
||||
* polygon. Default is `32`.
|
||||
* @param {number=} opt_sphereRadius Optional radius for the sphere (defaults to
|
||||
* @param {number} [opt_sphereRadius] Optional radius for the sphere (defaults to
|
||||
* the Earth's mean radius using the WGS84 ellipsoid).
|
||||
* @return {Polygon} The "circular" polygon.
|
||||
* @api
|
||||
@@ -466,9 +468,9 @@ export function fromExtent(extent) {
|
||||
/**
|
||||
* Create a regular polygon from a circle.
|
||||
* @param {import("./Circle.js").default} circle Circle geometry.
|
||||
* @param {number=} opt_sides Number of sides of the polygon. Default is 32.
|
||||
* @param {number=} opt_angle Start angle for the first vertex of the polygon in
|
||||
* radians. Default is 0.
|
||||
* @param {number} [opt_sides] Number of sides of the polygon. Default is 32.
|
||||
* @param {number} [opt_angle] Start angle for the first vertex of the polygon in
|
||||
* counter-clockwise radians. 0 means East. Default is 0.
|
||||
* @return {Polygon} Polygon geometry.
|
||||
* @api
|
||||
*/
|
||||
@@ -497,8 +499,8 @@ export function fromCircle(circle, opt_sides, opt_angle) {
|
||||
* @param {Polygon} polygon Polygon geometry.
|
||||
* @param {import("../coordinate.js").Coordinate} center Center of the regular polygon.
|
||||
* @param {number} radius Radius of the regular polygon.
|
||||
* @param {number=} opt_angle Start angle for the first vertex of the polygon in
|
||||
* radians. Default is 0.
|
||||
* @param {number} [opt_angle] Start angle for the first vertex of the polygon in
|
||||
* counter-clockwise radians. 0 means East. Default is 0.
|
||||
*/
|
||||
export function makeRegular(polygon, center, radius, opt_angle) {
|
||||
const flatCoordinates = polygon.getFlatCoordinates();
|
||||
|
||||
@@ -164,7 +164,7 @@ class SimpleGeometry extends Geometry {
|
||||
/**
|
||||
* @abstract
|
||||
* @param {!Array<*>} coordinates Coordinates.
|
||||
* @param {import("./GeometryLayout.js").default=} opt_layout Layout.
|
||||
* @param {import("./GeometryLayout.js").default} [opt_layout] Layout.
|
||||
*/
|
||||
setCoordinates(coordinates, opt_layout) {
|
||||
abstract();
|
||||
@@ -217,7 +217,7 @@ class SimpleGeometry extends Geometry {
|
||||
/**
|
||||
* Rotate the geometry around a given coordinate. This modifies the geometry
|
||||
* coordinates in place.
|
||||
* @param {number} angle Rotation angle in radians.
|
||||
* @param {number} angle Rotation angle in counter-clockwise radians.
|
||||
* @param {import("../coordinate.js").Coordinate} anchor The rotation center.
|
||||
* @api
|
||||
*/
|
||||
@@ -242,8 +242,8 @@ class SimpleGeometry extends Geometry {
|
||||
* Scale the geometry (with an optional origin). This modifies the geometry
|
||||
* coordinates in place.
|
||||
* @param {number} sx The scaling factor in the x-direction.
|
||||
* @param {number=} opt_sy The scaling factor in the y-direction (defaults to sx).
|
||||
* @param {import("../coordinate.js").Coordinate=} opt_anchor The scale origin (defaults to the center
|
||||
* @param {number} [opt_sy] The scaling factor in the y-direction (defaults to sx).
|
||||
* @param {import("../coordinate.js").Coordinate} [opt_anchor] The scale origin (defaults to the center
|
||||
* of the geometry extent).
|
||||
* @api
|
||||
*/
|
||||
@@ -333,7 +333,7 @@ export function getStrideForLayout(layout) {
|
||||
/**
|
||||
* @param {SimpleGeometry} simpleGeometry Simple geometry.
|
||||
* @param {import("../transform.js").Transform} transform Transform.
|
||||
* @param {Array<number>=} opt_dest Destination.
|
||||
* @param {Array<number>} [opt_dest] Destination.
|
||||
* @return {Array<number>} Transformed flat coordinates.
|
||||
*/
|
||||
export function transformGeom2D(simpleGeometry, transform, opt_dest) {
|
||||
|
||||
@@ -138,7 +138,7 @@ export function multiArrayMaxSquaredDelta(
|
||||
* @param {number} y Y.
|
||||
* @param {Array<number>} closestPoint Closest point.
|
||||
* @param {number} minSquaredDistance Minimum squared distance.
|
||||
* @param {Array<number>=} opt_tmpPoint Temporary point object.
|
||||
* @param {Array<number>} [opt_tmpPoint] Temporary point object.
|
||||
* @return {number} Minimum squared distance.
|
||||
*/
|
||||
export function assignClosestPoint(
|
||||
@@ -251,7 +251,7 @@ export function assignClosestPoint(
|
||||
* @param {number} y Y.
|
||||
* @param {Array<number>} closestPoint Closest point.
|
||||
* @param {number} minSquaredDistance Minimum squared distance.
|
||||
* @param {Array<number>=} opt_tmpPoint Temporary point object.
|
||||
* @param {Array<number>} [opt_tmpPoint] Temporary point object.
|
||||
* @return {number} Minimum squared distance.
|
||||
*/
|
||||
export function assignClosestArrayPoint(
|
||||
@@ -299,7 +299,7 @@ export function assignClosestArrayPoint(
|
||||
* @param {number} y Y.
|
||||
* @param {Array<number>} closestPoint Closest point.
|
||||
* @param {number} minSquaredDistance Minimum squared distance.
|
||||
* @param {Array<number>=} opt_tmpPoint Temporary point object.
|
||||
* @param {Array<number>} [opt_tmpPoint] Temporary point object.
|
||||
* @return {number} Minimum squared distance.
|
||||
*/
|
||||
export function assignClosestMultiArrayPoint(
|
||||
|
||||
@@ -55,7 +55,7 @@ export function linearRingContainsXY(
|
||||
x,
|
||||
y
|
||||
) {
|
||||
// http://geomalgorithms.com/a03-_inclusion.html
|
||||
// https://geomalgorithms.com/a03-_inclusion.html
|
||||
// Copyright 2000 softSurfer, 2012 Dan Sunday
|
||||
// This code may be freely used and modified for any purpose
|
||||
// providing that this copyright notice is included with it.
|
||||
|
||||
@@ -43,7 +43,7 @@ export function deflateCoordinates(
|
||||
* @param {number} offset Offset.
|
||||
* @param {Array<Array<import("../../coordinate.js").Coordinate>>} coordinatess Coordinatess.
|
||||
* @param {number} stride Stride.
|
||||
* @param {Array<number>=} opt_ends Ends.
|
||||
* @param {Array<number>} [opt_ends] Ends.
|
||||
* @return {Array<number>} Ends.
|
||||
*/
|
||||
export function deflateCoordinatesArray(
|
||||
@@ -74,7 +74,7 @@ export function deflateCoordinatesArray(
|
||||
* @param {number} offset Offset.
|
||||
* @param {Array<Array<Array<import("../../coordinate.js").Coordinate>>>} coordinatesss Coordinatesss.
|
||||
* @param {number} stride Stride.
|
||||
* @param {Array<Array<number>>=} opt_endss Endss.
|
||||
* @param {Array<Array<number>>} [opt_endss] Endss.
|
||||
* @return {Array<Array<number>>} Endss.
|
||||
*/
|
||||
export function deflateMultiCoordinatesArray(
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
* @param {number} offset Offset.
|
||||
* @param {number} end End.
|
||||
* @param {number} stride Stride.
|
||||
* @param {Array<number>=} opt_dest Destination.
|
||||
* @param {number=} opt_destOffset Destination offset.
|
||||
* @param {Array<number>} [opt_dest] Destination.
|
||||
* @param {number} [opt_destOffset] Destination offset.
|
||||
* @return {Array<number>} Flat coordinates.
|
||||
*/
|
||||
export function flipXY(
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* @param {number} offset Offset.
|
||||
* @param {number} end End.
|
||||
* @param {number} stride Stride.
|
||||
* @param {Array<import("../../coordinate.js").Coordinate>=} opt_coordinates Coordinates.
|
||||
* @param {Array<import("../../coordinate.js").Coordinate>} [opt_coordinates] Coordinates.
|
||||
* @return {Array<import("../../coordinate.js").Coordinate>} Coordinates.
|
||||
*/
|
||||
export function inflateCoordinates(
|
||||
@@ -31,7 +31,7 @@ export function inflateCoordinates(
|
||||
* @param {number} offset Offset.
|
||||
* @param {Array<number>} ends Ends.
|
||||
* @param {number} stride Stride.
|
||||
* @param {Array<Array<import("../../coordinate.js").Coordinate>>=} opt_coordinatess Coordinatess.
|
||||
* @param {Array<Array<import("../../coordinate.js").Coordinate>>} [opt_coordinatess] Coordinatess.
|
||||
* @return {Array<Array<import("../../coordinate.js").Coordinate>>} Coordinatess.
|
||||
*/
|
||||
export function inflateCoordinatesArray(
|
||||
@@ -63,7 +63,7 @@ export function inflateCoordinatesArray(
|
||||
* @param {number} offset Offset.
|
||||
* @param {Array<Array<number>>} endss Endss.
|
||||
* @param {number} stride Stride.
|
||||
* @param {Array<Array<Array<import("../../coordinate.js").Coordinate>>>=} opt_coordinatesss
|
||||
* @param {Array<Array<Array<import("../../coordinate.js").Coordinate>>>} [opt_coordinatesss]
|
||||
* Coordinatesss.
|
||||
* @return {Array<Array<Array<import("../../coordinate.js").Coordinate>>>} Coordinatesss.
|
||||
*/
|
||||
|
||||
@@ -13,7 +13,7 @@ import {numberSafeCompareFunction} from '../../array.js';
|
||||
* @param {number} stride Stride.
|
||||
* @param {Array<number>} flatCenters Flat centers.
|
||||
* @param {number} flatCentersOffset Flat center offset.
|
||||
* @param {Array<number>=} opt_dest Destination.
|
||||
* @param {Array<number>} [opt_dest] Destination.
|
||||
* @return {Array<number>} Destination point as XYM coordinate, where M is the
|
||||
* length of the horizontal intersection that the point belongs to.
|
||||
*/
|
||||
|
||||
@@ -10,8 +10,8 @@ import {lerp} from '../../math.js';
|
||||
* @param {number} end End.
|
||||
* @param {number} stride Stride.
|
||||
* @param {number} fraction Fraction.
|
||||
* @param {Array<number>=} opt_dest Destination.
|
||||
* @param {number=} opt_dimension Destination dimension (default is `2`)
|
||||
* @param {Array<number>} [opt_dest] Destination.
|
||||
* @param {number} [opt_dimension] Destination dimension (default is `2`)
|
||||
* @return {Array<number>} Destination.
|
||||
*/
|
||||
export function interpolatePoint(
|
||||
|
||||
@@ -14,69 +14,19 @@ import {coordinates as reverseCoordinates} from './reverse.js';
|
||||
* @return {boolean} Is clockwise.
|
||||
*/
|
||||
export function linearRingIsClockwise(flatCoordinates, offset, end, stride) {
|
||||
// https://stackoverflow.com/a/1180256/2389327
|
||||
// https://en.wikipedia.org/wiki/Curve_orientation#Orientation_of_a_simple_polygon
|
||||
|
||||
let firstVertexRepeated = true;
|
||||
for (let i = 0; i < stride; ++i) {
|
||||
if (flatCoordinates[offset + i] !== flatCoordinates[end - stride + i]) {
|
||||
firstVertexRepeated = false;
|
||||
break;
|
||||
}
|
||||
// https://stackoverflow.com/q/1165647/clockwise-method#1165943
|
||||
// https://github.com/OSGeo/gdal/blob/master/gdal/ogr/ogrlinearring.cpp
|
||||
let edge = 0;
|
||||
let x1 = flatCoordinates[end - stride];
|
||||
let y1 = flatCoordinates[end - stride + 1];
|
||||
for (; offset < end; offset += stride) {
|
||||
const x2 = flatCoordinates[offset];
|
||||
const y2 = flatCoordinates[offset + 1];
|
||||
edge += (x2 - x1) * (y2 + y1);
|
||||
x1 = x2;
|
||||
y1 = y2;
|
||||
}
|
||||
if (firstVertexRepeated) {
|
||||
end -= stride;
|
||||
}
|
||||
const iMinVertex = findCornerVertex(flatCoordinates, offset, end, stride);
|
||||
// Orientation matrix:
|
||||
// [ 1 xa ya ]
|
||||
// O = | 1 xb yb |
|
||||
// [ 1 xc yc ]
|
||||
let iPreviousVertex = iMinVertex - stride;
|
||||
if (iPreviousVertex < offset) {
|
||||
iPreviousVertex = end - stride;
|
||||
}
|
||||
let iNextVertex = iMinVertex + stride;
|
||||
if (iNextVertex >= end) {
|
||||
iNextVertex = offset;
|
||||
}
|
||||
const aX = flatCoordinates[iPreviousVertex];
|
||||
const aY = flatCoordinates[iPreviousVertex + 1];
|
||||
const bX = flatCoordinates[iMinVertex];
|
||||
const bY = flatCoordinates[iMinVertex + 1];
|
||||
const cX = flatCoordinates[iNextVertex];
|
||||
const cY = flatCoordinates[iNextVertex + 1];
|
||||
const determinant =
|
||||
bX * cY + aX * bY + aY * cX - (aY * bX + bY * cX + aX * cY);
|
||||
|
||||
return determinant < 0;
|
||||
}
|
||||
|
||||
// Find vertex along one edge of bounding box.
|
||||
// In this case, we find smallest y; in case of tie also smallest x.
|
||||
function findCornerVertex(flatCoordinates, offset, end, stride) {
|
||||
let iMinVertex = -1;
|
||||
let minY = Infinity;
|
||||
let minXAtMinY = Infinity;
|
||||
for (let i = offset; i < end; i += stride) {
|
||||
const x = flatCoordinates[i];
|
||||
const y = flatCoordinates[i + 1];
|
||||
if (y > minY) {
|
||||
continue;
|
||||
}
|
||||
if (y == minY) {
|
||||
if (x >= minXAtMinY) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Minimum so far.
|
||||
iMinVertex = i;
|
||||
minY = y;
|
||||
minXAtMinY = x;
|
||||
}
|
||||
|
||||
return iMinVertex;
|
||||
return edge === 0 ? undefined : edge > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -88,7 +38,7 @@ function findCornerVertex(flatCoordinates, offset, end, stride) {
|
||||
* @param {number} offset Offset.
|
||||
* @param {Array<number>} ends Array of end indexes.
|
||||
* @param {number} stride Stride.
|
||||
* @param {boolean=} opt_right Test for right-hand orientation
|
||||
* @param {boolean} [opt_right] Test for right-hand orientation
|
||||
* (counter-clockwise exterior ring and clockwise interior rings).
|
||||
* @return {boolean} Rings are correctly oriented.
|
||||
*/
|
||||
@@ -131,7 +81,7 @@ export function linearRingsAreOriented(
|
||||
* @param {number} offset Offset.
|
||||
* @param {Array<Array<number>>} endss Array of array of end indexes.
|
||||
* @param {number} stride Stride.
|
||||
* @param {boolean=} opt_right Test for right-hand orientation
|
||||
* @param {boolean} [opt_right] Test for right-hand orientation
|
||||
* (counter-clockwise exterior ring and clockwise interior rings).
|
||||
* @return {boolean} Rings are correctly oriented.
|
||||
*/
|
||||
@@ -166,7 +116,7 @@ export function linearRingssAreOriented(
|
||||
* @param {number} offset Offset.
|
||||
* @param {Array<number>} ends Ends.
|
||||
* @param {number} stride Stride.
|
||||
* @param {boolean=} opt_right Follow the right-hand rule for orientation.
|
||||
* @param {boolean} [opt_right] Follow the right-hand rule for orientation.
|
||||
* @return {number} End.
|
||||
*/
|
||||
export function orientLinearRings(
|
||||
@@ -207,7 +157,7 @@ export function orientLinearRings(
|
||||
* @param {number} offset Offset.
|
||||
* @param {Array<Array<number>>} endss Array of array of end indexes.
|
||||
* @param {number} stride Stride.
|
||||
* @param {boolean=} opt_right Follow the right-hand rule for orientation.
|
||||
* @param {boolean} [opt_right] Follow the right-hand rule for orientation.
|
||||
* @return {number} End.
|
||||
*/
|
||||
export function orientLinearRingsArray(
|
||||
|
||||
@@ -36,7 +36,7 @@ import {squaredDistance, squaredSegmentDistance} from '../../math.js';
|
||||
* @param {number} stride Stride.
|
||||
* @param {number} squaredTolerance Squared tolerance.
|
||||
* @param {boolean} highQuality Highest quality.
|
||||
* @param {Array<number>=} opt_simplifiedFlatCoordinates Simplified flat
|
||||
* @param {Array<number>} [opt_simplifiedFlatCoordinates] Simplified flat
|
||||
* coordinates.
|
||||
* @return {Array<number>} Simplified line string.
|
||||
*/
|
||||
|
||||
@@ -34,74 +34,114 @@ export function drawTextOnPath(
|
||||
cache,
|
||||
rotation
|
||||
) {
|
||||
const result = [];
|
||||
let x2 = flatCoordinates[offset];
|
||||
let y2 = flatCoordinates[offset + 1];
|
||||
let x1 = 0;
|
||||
let y1 = 0;
|
||||
let segmentLength = 0;
|
||||
let segmentM = 0;
|
||||
|
||||
function advance() {
|
||||
x1 = x2;
|
||||
y1 = y2;
|
||||
offset += stride;
|
||||
x2 = flatCoordinates[offset];
|
||||
y2 = flatCoordinates[offset + 1];
|
||||
segmentM += segmentLength;
|
||||
segmentLength = Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
|
||||
}
|
||||
do {
|
||||
advance();
|
||||
} while (offset < end - stride && segmentM + segmentLength < startM);
|
||||
|
||||
let interpolate = (startM - segmentM) / segmentLength;
|
||||
const beginX = lerp(x1, x2, interpolate);
|
||||
const beginY = lerp(y1, y2, interpolate);
|
||||
|
||||
const startOffset = offset - stride;
|
||||
const startLength = segmentM;
|
||||
const endM = startM + scale * measureAndCacheTextWidth(font, text, cache);
|
||||
while (offset < end - stride && segmentM + segmentLength < endM) {
|
||||
advance();
|
||||
}
|
||||
interpolate = (endM - segmentM) / segmentLength;
|
||||
const endX = lerp(x1, x2, interpolate);
|
||||
const endY = lerp(y1, y2, interpolate);
|
||||
|
||||
// Keep text upright
|
||||
let reverse;
|
||||
if (rotation) {
|
||||
const rotatedCoordinates = rotate(
|
||||
flatCoordinates,
|
||||
offset,
|
||||
end,
|
||||
stride,
|
||||
rotation,
|
||||
[flatCoordinates[offset], flatCoordinates[offset + 1]]
|
||||
);
|
||||
reverse =
|
||||
rotatedCoordinates[0] >
|
||||
rotatedCoordinates[rotatedCoordinates.length - stride];
|
||||
const flat = [beginX, beginY, endX, endY];
|
||||
rotate(flat, 0, 4, 2, rotation, flat, flat);
|
||||
reverse = flat[0] > flat[2];
|
||||
} else {
|
||||
reverse = flatCoordinates[offset] > flatCoordinates[end - stride];
|
||||
reverse = beginX > endX;
|
||||
}
|
||||
|
||||
const numChars = text.length;
|
||||
const PI = Math.PI;
|
||||
const result = [];
|
||||
const singleSegment = startOffset + stride === offset;
|
||||
|
||||
let x1 = flatCoordinates[offset];
|
||||
let y1 = flatCoordinates[offset + 1];
|
||||
offset += stride;
|
||||
let x2 = flatCoordinates[offset];
|
||||
let y2 = flatCoordinates[offset + 1];
|
||||
let segmentM = 0;
|
||||
let segmentLength = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
|
||||
let angleChanged = false;
|
||||
offset = startOffset;
|
||||
segmentLength = 0;
|
||||
segmentM = startLength;
|
||||
x2 = flatCoordinates[offset];
|
||||
y2 = flatCoordinates[offset + 1];
|
||||
|
||||
let index, previousAngle;
|
||||
for (let i = 0; i < numChars; ++i) {
|
||||
index = reverse ? numChars - i - 1 : i;
|
||||
const char = text[index];
|
||||
const charLength = scale * measureAndCacheTextWidth(font, char, cache);
|
||||
const charM = startM + charLength / 2;
|
||||
while (offset < end - stride && segmentM + segmentLength < charM) {
|
||||
x1 = x2;
|
||||
y1 = y2;
|
||||
offset += stride;
|
||||
x2 = flatCoordinates[offset];
|
||||
y2 = flatCoordinates[offset + 1];
|
||||
segmentM += segmentLength;
|
||||
segmentLength = Math.sqrt(Math.pow(x2 - x1, 2) + Math.pow(y2 - y1, 2));
|
||||
// All on the same segment
|
||||
if (singleSegment) {
|
||||
advance();
|
||||
|
||||
let previousAngle = Math.atan2(y2 - y1, x2 - x1);
|
||||
if (reverse) {
|
||||
previousAngle += previousAngle > 0 ? -PI : PI;
|
||||
}
|
||||
const segmentPos = charM - segmentM;
|
||||
const x = (endX + beginX) / 2;
|
||||
const y = (endY + beginY) / 2;
|
||||
result[0] = [x, y, (endM - startM) / 2, previousAngle, text];
|
||||
return result;
|
||||
}
|
||||
|
||||
let previousAngle;
|
||||
for (let i = 0, ii = text.length; i < ii; ) {
|
||||
advance();
|
||||
let angle = Math.atan2(y2 - y1, x2 - x1);
|
||||
if (reverse) {
|
||||
angle += angle > 0 ? -Math.PI : Math.PI;
|
||||
angle += angle > 0 ? -PI : PI;
|
||||
}
|
||||
if (previousAngle !== undefined) {
|
||||
let delta = angle - previousAngle;
|
||||
angleChanged = angleChanged || delta !== 0;
|
||||
delta +=
|
||||
delta > Math.PI ? -2 * Math.PI : delta < -Math.PI ? 2 * Math.PI : 0;
|
||||
delta += delta > PI ? -2 * PI : delta < -PI ? 2 * PI : 0;
|
||||
if (Math.abs(delta) > maxAngle) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
previousAngle = angle;
|
||||
const interpolate = segmentPos / segmentLength;
|
||||
|
||||
const iStart = i;
|
||||
let charLength = 0;
|
||||
for (; i < ii; ++i) {
|
||||
const index = reverse ? ii - i - 1 : i;
|
||||
const len = scale * measureAndCacheTextWidth(font, text[index], cache);
|
||||
if (
|
||||
offset + stride < end &&
|
||||
segmentM + segmentLength < startM + charLength + len / 2
|
||||
) {
|
||||
break;
|
||||
}
|
||||
charLength += len;
|
||||
}
|
||||
if (i === iStart) {
|
||||
continue;
|
||||
}
|
||||
const chars = reverse
|
||||
? text.substring(ii - iStart, ii - i)
|
||||
: text.substring(iStart, i);
|
||||
interpolate = (startM + charLength / 2 - segmentM) / segmentLength;
|
||||
const x = lerp(x1, x2, interpolate);
|
||||
const y = lerp(y1, y2, interpolate);
|
||||
result[index] = [x, y, charLength / 2, angle, char];
|
||||
result.push([x, y, charLength / 2, angle, chars]);
|
||||
startM += charLength;
|
||||
}
|
||||
return angleChanged
|
||||
? result
|
||||
: [[result[0][0], result[0][1], result[0][2], result[0][3], text]];
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
* @param {number} end End.
|
||||
* @param {number} stride Stride.
|
||||
* @param {import("../../transform.js").Transform} transform Transform.
|
||||
* @param {Array<number>=} opt_dest Destination.
|
||||
* @param {Array<number>} [opt_dest] Destination.
|
||||
* @return {Array<number>} Transformed coordinates.
|
||||
*/
|
||||
export function transform2D(
|
||||
@@ -40,7 +40,7 @@ export function transform2D(
|
||||
* @param {number} stride Stride.
|
||||
* @param {number} angle Angle.
|
||||
* @param {Array<number>} anchor Rotation anchor point.
|
||||
* @param {Array<number>=} opt_dest Destination.
|
||||
* @param {Array<number>} [opt_dest] Destination.
|
||||
* @return {Array<number>} Transformed coordinates.
|
||||
*/
|
||||
export function rotate(
|
||||
@@ -82,7 +82,7 @@ export function rotate(
|
||||
* @param {number} sx Scale factor in the x-direction.
|
||||
* @param {number} sy Scale factor in the y-direction.
|
||||
* @param {Array<number>} anchor Scale anchor point.
|
||||
* @param {Array<number>=} opt_dest Destination.
|
||||
* @param {Array<number>} [opt_dest] Destination.
|
||||
* @return {Array<number>} Transformed coordinates.
|
||||
*/
|
||||
export function scale(
|
||||
@@ -121,7 +121,7 @@ export function scale(
|
||||
* @param {number} stride Stride.
|
||||
* @param {number} deltaX Delta X.
|
||||
* @param {number} deltaY Delta Y.
|
||||
* @param {Array<number>=} opt_dest Destination.
|
||||
* @param {Array<number>} [opt_dest] Destination.
|
||||
* @return {Array<number>} Transformed coordinates.
|
||||
*/
|
||||
export function translate(
|
||||
|
||||
@@ -75,7 +75,7 @@ export {default as Translate} from './interaction/Translate.js';
|
||||
* * {@link module:ol/interaction/MouseWheelZoom~MouseWheelZoom}
|
||||
* * {@link module:ol/interaction/DragZoom~DragZoom}
|
||||
*
|
||||
* @param {DefaultsOptions=} opt_options Defaults options.
|
||||
* @param {DefaultsOptions} [opt_options] Defaults options.
|
||||
* @return {import("./Collection.js").default<import("./interaction/Interaction.js").default>}
|
||||
* A collection of interactions to be used with the {@link module:ol/Map~Map}
|
||||
* constructor's `interactions` option.
|
||||
|
||||
@@ -17,7 +17,7 @@ import MapBrowserEventType from '../MapBrowserEventType.js';
|
||||
*/
|
||||
class DoubleClickZoom extends Interaction {
|
||||
/**
|
||||
* @param {Options=} opt_options Options.
|
||||
* @param {Options} [opt_options] Options.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
super();
|
||||
@@ -52,7 +52,7 @@ class DoubleClickZoom extends Interaction {
|
||||
const delta = browserEvent.shiftKey ? -this.delta_ : this.delta_;
|
||||
const view = map.getView();
|
||||
zoomByDelta(view, delta, anchor, this.duration_);
|
||||
mapBrowserEvent.preventDefault();
|
||||
browserEvent.preventDefault();
|
||||
stopEvent = true;
|
||||
}
|
||||
return !stopEvent;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
import Event from '../events/Event.js';
|
||||
import EventType from '../events/EventType.js';
|
||||
import FormatType from '../format/FormatType.js';
|
||||
import Interaction from './Interaction.js';
|
||||
import {TRUE} from '../functions.js';
|
||||
import {get as getProjection} from '../proj.js';
|
||||
@@ -12,7 +13,8 @@ import {listen, unlistenByKey} from '../events.js';
|
||||
|
||||
/**
|
||||
* @typedef {Object} Options
|
||||
* @property {Array<typeof import("../format/Feature.js").default>} [formatConstructors] Format constructors.
|
||||
* @property {Array<typeof import("../format/Feature.js").default|import("../format/Feature.js").default>} [formatConstructors] Format constructors
|
||||
* (and/or formats pre-constructed with options).
|
||||
* @property {import("../source/Vector.js").default} [source] Optional vector source where features will be added. If a source is provided
|
||||
* all existing features will be removed and new features will be added when
|
||||
* they are dropped on the target. If you want to add features to a vector
|
||||
@@ -39,12 +41,12 @@ const DragAndDropEventType = {
|
||||
* Events emitted by {@link module:ol/interaction/DragAndDrop~DragAndDrop} instances are instances
|
||||
* of this type.
|
||||
*/
|
||||
class DragAndDropEvent extends Event {
|
||||
export class DragAndDropEvent extends Event {
|
||||
/**
|
||||
* @param {DragAndDropEventType} type Type.
|
||||
* @param {File} file File.
|
||||
* @param {Array<import("../Feature.js").default>=} opt_features Features.
|
||||
* @param {import("../proj/Projection.js").default=} opt_projection Projection.
|
||||
* @param {Array<import("../Feature.js").default>} [opt_features] Features.
|
||||
* @param {import("../proj/Projection.js").default} [opt_projection] Projection.
|
||||
*/
|
||||
constructor(type, file, opt_features, opt_projection) {
|
||||
super(type);
|
||||
@@ -75,13 +77,18 @@ class DragAndDropEvent extends Event {
|
||||
/**
|
||||
* @classdesc
|
||||
* Handles input of vector data by drag and drop.
|
||||
*
|
||||
* Note that the DragAndDrop interaction uses the TextDecoder() constructor if the supplied
|
||||
* combinnation of formats read both text string and ArrayBuffer sources. Older browsers such
|
||||
* as IE which do not support this will need a TextDecoder polyfill to be loaded before use.
|
||||
*
|
||||
* @api
|
||||
*
|
||||
* @fires DragAndDropEvent
|
||||
*/
|
||||
class DragAndDrop extends Interaction {
|
||||
/**
|
||||
* @param {Options=} opt_options Options.
|
||||
* @param {Options} [opt_options] Options.
|
||||
*/
|
||||
constructor(opt_options) {
|
||||
const options = opt_options ? opt_options : {};
|
||||
@@ -92,11 +99,27 @@ class DragAndDrop extends Interaction {
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array<typeof import("../format/Feature.js").default>}
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.formatConstructors_ = options.formatConstructors
|
||||
this.readAsBuffer_ = false;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {Array<import("../format/Feature.js").default>}
|
||||
*/
|
||||
this.formats_ = [];
|
||||
const formatConstructors = options.formatConstructors
|
||||
? options.formatConstructors
|
||||
: [];
|
||||
for (let i = 0, ii = formatConstructors.length; i < ii; ++i) {
|
||||
let format = formatConstructors[i];
|
||||
if (typeof format === 'function') {
|
||||
format = new format();
|
||||
}
|
||||
this.formats_.push(format);
|
||||
this.readAsBuffer_ =
|
||||
this.readAsBuffer_ || format.getType() === FormatType.ARRAY_BUFFER;
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
@@ -139,10 +162,18 @@ class DragAndDrop extends Interaction {
|
||||
projection = view.getProjection();
|
||||
}
|
||||
|
||||
const formatConstructors = this.formatConstructors_;
|
||||
for (let i = 0, ii = formatConstructors.length; i < ii; ++i) {
|
||||
const format = new formatConstructors[i]();
|
||||
const features = this.tryReadFeatures_(format, result, {
|
||||
let text;
|
||||
const formats = this.formats_;
|
||||
for (let i = 0, ii = formats.length; i < ii; ++i) {
|
||||
const format = formats[i];
|
||||
let input = result;
|
||||
if (this.readAsBuffer_ && format.getType() !== FormatType.ARRAY_BUFFER) {
|
||||
if (text === undefined) {
|
||||
text = new TextDecoder().decode(result);
|
||||
}
|
||||
input = text;
|
||||
}
|
||||
const features = this.tryReadFeatures_(format, input, {
|
||||
featureProjection: projection,
|
||||
});
|
||||
if (features && features.length > 0) {
|
||||
@@ -249,7 +280,11 @@ class DragAndDrop extends Interaction {
|
||||
EventType.LOAD,
|
||||
this.handleResult_.bind(this, file)
|
||||
);
|
||||
reader.readAsText(file);
|
||||
if (this.readAsBuffer_) {
|
||||
reader.readAsArrayBuffer(file);
|
||||
} else {
|
||||
reader.readAsText(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user