Merge pull request #13972 from tschaub/un_opt

Remove opt_ prefix
This commit is contained in:
Tim Schaub
2022-08-12 06:16:27 -06:00
committed by GitHub
183 changed files with 1918 additions and 2079 deletions

View File

@@ -76,10 +76,10 @@ export class CollectionEvent extends Event {
*/ */
class Collection extends BaseObject { class Collection extends BaseObject {
/** /**
* @param {Array<T>} [opt_array] Array. * @param {Array<T>} [array] Array.
* @param {Options} [opt_options] Collection options. * @param {Options} [options] Collection options.
*/ */
constructor(opt_array, opt_options) { constructor(array, options) {
super(); super();
/*** /***
@@ -97,7 +97,7 @@ class Collection extends BaseObject {
*/ */
this.un; this.un;
const options = opt_options || {}; options = options || {};
/** /**
* @private * @private
@@ -109,7 +109,7 @@ class Collection extends BaseObject {
* @private * @private
* @type {!Array<T>} * @type {!Array<T>}
*/ */
this.array_ = opt_array ? opt_array : []; this.array_ = array ? array : [];
if (this.unique_) { if (this.unique_) {
for (let i = 0, ii = this.array_.length; i < ii; ++i) { for (let i = 0, ii = this.array_.length; i < ii; ++i) {
@@ -315,11 +315,11 @@ class Collection extends BaseObject {
/** /**
* @private * @private
* @param {T} elem Element. * @param {T} elem Element.
* @param {number} [opt_except] Optional index to ignore. * @param {number} [except] Optional index to ignore.
*/ */
assertUnique_(elem, opt_except) { assertUnique_(elem, except) {
for (let i = 0, ii = this.array_.length; i < ii; ++i) { for (let i = 0, ii = this.array_.length; i < ii; ++i) {
if (this.array_[i] === elem && i !== opt_except) { if (this.array_[i] === elem && i !== except) {
throw new AssertionError(58); throw new AssertionError(58);
} }
} }

View File

@@ -74,12 +74,12 @@ import {listen, unlistenByKey} from './events.js';
*/ */
class Feature extends BaseObject { class Feature extends BaseObject {
/** /**
* @param {Geometry|ObjectWithGeometry<Geometry>} [opt_geometryOrProperties] * @param {Geometry|ObjectWithGeometry<Geometry>} [geometryOrProperties]
* You may pass a Geometry object directly, or an object literal containing * You may pass a Geometry object directly, or an object literal containing
* properties. If you pass an object literal, you may include a Geometry * properties. If you pass an object literal, you may include a Geometry
* associated with a `geometry` key. * associated with a `geometry` key.
*/ */
constructor(opt_geometryOrProperties) { constructor(geometryOrProperties) {
super(); super();
/*** /***
@@ -130,17 +130,17 @@ class Feature extends BaseObject {
this.addChangeListener(this.geometryName_, this.handleGeometryChanged_); this.addChangeListener(this.geometryName_, this.handleGeometryChanged_);
if (opt_geometryOrProperties) { if (geometryOrProperties) {
if ( if (
typeof ( typeof (
/** @type {?} */ (opt_geometryOrProperties).getSimplifiedGeometry /** @type {?} */ (geometryOrProperties).getSimplifiedGeometry
) === 'function' ) === 'function'
) { ) {
const geometry = /** @type {Geometry} */ (opt_geometryOrProperties); const geometry = /** @type {Geometry} */ (geometryOrProperties);
this.setGeometry(geometry); this.setGeometry(geometry);
} else { } else {
/** @type {Object<string, *>} */ /** @type {Object<string, *>} */
const properties = opt_geometryOrProperties; const properties = geometryOrProperties;
this.setProperties(properties); this.setProperties(properties);
} }
} }
@@ -265,15 +265,13 @@ class Feature extends BaseObject {
* single style object, an array of styles, or a function that takes a * 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 * resolution and returns an array of styles. To unset the feature style, call
* `setStyle()` without arguments or a falsey value. * `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} [style] Style for this feature.
* @api * @api
* @fires module:ol/events/Event~BaseEvent#event:change * @fires module:ol/events/Event~BaseEvent#event:change
*/ */
setStyle(opt_style) { setStyle(style) {
this.style_ = opt_style; this.style_ = style;
this.styleFunction_ = !opt_style this.styleFunction_ = !style ? undefined : createStyleFunction(style);
? undefined
: createStyleFunction(opt_style);
this.changed(); this.changed();
} }

View File

@@ -101,9 +101,9 @@ class GeolocationError extends BaseEvent {
*/ */
class Geolocation extends BaseObject { class Geolocation extends BaseObject {
/** /**
* @param {Options} [opt_options] Options. * @param {Options} [options] Options.
*/ */
constructor(opt_options) { constructor(options) {
super(); super();
/*** /***
@@ -121,7 +121,7 @@ class Geolocation extends BaseObject {
*/ */
this.un; this.un;
const options = opt_options || {}; options = options || {};
/** /**
* The unprojected (EPSG:4326) device position. * The unprojected (EPSG:4326) device position.

View File

@@ -19,12 +19,11 @@ class ImageCanvas extends ImageBase {
* @param {number} resolution Resolution. * @param {number} resolution Resolution.
* @param {number} pixelRatio Pixel ratio. * @param {number} pixelRatio Pixel ratio.
* @param {HTMLCanvasElement} canvas Canvas. * @param {HTMLCanvasElement} canvas Canvas.
* @param {Loader} [opt_loader] Optional loader function to * @param {Loader} [loader] Optional loader function to
* support asynchronous canvas drawing. * support asynchronous canvas drawing.
*/ */
constructor(extent, resolution, pixelRatio, canvas, opt_loader) { constructor(extent, resolution, pixelRatio, canvas, loader) {
const state = const state = loader !== undefined ? ImageState.IDLE : ImageState.LOADED;
opt_loader !== undefined ? ImageState.IDLE : ImageState.LOADED;
super(extent, resolution, pixelRatio, state); super(extent, resolution, pixelRatio, state);
@@ -33,7 +32,7 @@ class ImageCanvas extends ImageBase {
* @type {?Loader} * @type {?Loader}
* @private * @private
*/ */
this.loader_ = opt_loader !== undefined ? opt_loader : null; this.loader_ = loader !== undefined ? loader : null;
/** /**
* @private * @private

View File

@@ -13,17 +13,10 @@ class ImageTile extends Tile {
* @param {string} src Image source URI. * @param {string} src Image source URI.
* @param {?string} crossOrigin Cross origin. * @param {?string} crossOrigin Cross origin.
* @param {import("./Tile.js").LoadFunction} tileLoadFunction Tile load function. * @param {import("./Tile.js").LoadFunction} tileLoadFunction Tile load function.
* @param {import("./Tile.js").Options} [opt_options] Tile options. * @param {import("./Tile.js").Options} [options] Tile options.
*/ */
constructor( constructor(tileCoord, state, src, crossOrigin, tileLoadFunction, options) {
tileCoord, super(tileCoord, state, options);
state,
src,
crossOrigin,
tileLoadFunction,
opt_options
) {
super(tileCoord, state, opt_options);
/** /**
* @private * @private

View File

@@ -234,12 +234,12 @@ function setLayerMapProperty(layer, map) {
*/ */
class Map extends BaseObject { class Map extends BaseObject {
/** /**
* @param {MapOptions} [opt_options] Map options. * @param {MapOptions} [options] Map options.
*/ */
constructor(opt_options) { constructor(options) {
super(); super();
const options = opt_options || {}; options = options || {};
/*** /***
* @type {MapEventHandler<import("./events").EventsKey>} * @type {MapEventHandler<import("./events").EventsKey>}
@@ -652,7 +652,7 @@ class Map extends BaseObject {
/** /**
* Detect features that intersect a pixel on the viewport, and execute a * Detect features that intersect a pixel on the viewport, and execute a
* callback with each intersecting feature. Layers included in the detection can * callback with each intersecting feature. Layers included in the detection can
* be configured through the `layerFilter` option in `opt_options`. * be configured through the `layerFilter` option in `options`.
* @param {import("./pixel.js").Pixel} pixel Pixel. * @param {import("./pixel.js").Pixel} pixel Pixel.
* @param {function(import("./Feature.js").FeatureLike, import("./layer/Layer.js").default<import("./source/Source").default>, import("./geom/SimpleGeometry.js").default): T} callback Feature callback. The callback will be * @param {function(import("./Feature.js").FeatureLike, import("./layer/Layer.js").default<import("./source/Source").default>, import("./geom/SimpleGeometry.js").default): T} callback Feature callback. The callback will be
* called with two arguments. The first argument is one * called with two arguments. The first argument is one
@@ -661,23 +661,23 @@ class Map extends BaseObject {
* the {@link module:ol/layer/Layer~Layer layer} of the feature and will be null for * the {@link module:ol/layer/Layer~Layer layer} of the feature and will be null for
* unmanaged layers. To stop detection, callback functions can return a * unmanaged layers. To stop detection, callback functions can return a
* truthy value. * truthy value.
* @param {AtPixelOptions} [opt_options] Optional options. * @param {AtPixelOptions} [options] Optional options.
* @return {T|undefined} Callback result, i.e. the return value of last * @return {T|undefined} Callback result, i.e. the return value of last
* callback execution, or the first truthy callback return value. * callback execution, or the first truthy callback return value.
* @template T * @template T
* @api * @api
*/ */
forEachFeatureAtPixel(pixel, callback, opt_options) { forEachFeatureAtPixel(pixel, callback, options) {
if (!this.frameState_ || !this.renderer_) { if (!this.frameState_ || !this.renderer_) {
return; return;
} }
const coordinate = this.getCoordinateFromPixelInternal(pixel); const coordinate = this.getCoordinateFromPixelInternal(pixel);
opt_options = opt_options !== undefined ? opt_options : {}; options = options !== undefined ? options : {};
const hitTolerance = const hitTolerance =
opt_options.hitTolerance !== undefined ? opt_options.hitTolerance : 0; options.hitTolerance !== undefined ? options.hitTolerance : 0;
const layerFilter = const layerFilter =
opt_options.layerFilter !== undefined ? opt_options.layerFilter : TRUE; options.layerFilter !== undefined ? options.layerFilter : TRUE;
const checkWrapped = opt_options.checkWrapped !== false; const checkWrapped = options.checkWrapped !== false;
return this.renderer_.forEachFeatureAtCoordinate( return this.renderer_.forEachFeatureAtCoordinate(
coordinate, coordinate,
this.frameState_, this.frameState_,
@@ -693,19 +693,19 @@ class Map extends BaseObject {
/** /**
* Get all features that intersect a pixel on the viewport. * Get all features that intersect a pixel on the viewport.
* @param {import("./pixel.js").Pixel} pixel Pixel. * @param {import("./pixel.js").Pixel} pixel Pixel.
* @param {AtPixelOptions} [opt_options] Optional options. * @param {AtPixelOptions} [options] Optional options.
* @return {Array<import("./Feature.js").FeatureLike>} The detected features or * @return {Array<import("./Feature.js").FeatureLike>} The detected features or
* an empty array if none were found. * an empty array if none were found.
* @api * @api
*/ */
getFeaturesAtPixel(pixel, opt_options) { getFeaturesAtPixel(pixel, options) {
const features = []; const features = [];
this.forEachFeatureAtPixel( this.forEachFeatureAtPixel(
pixel, pixel,
function (feature) { function (feature) {
features.push(feature); features.push(feature);
}, },
opt_options options
); );
return features; return features;
} }
@@ -732,23 +732,23 @@ class Map extends BaseObject {
/** /**
* Detect if features intersect a pixel on the viewport. Layers included in the * Detect if features intersect a pixel on the viewport. Layers included in the
* detection can be configured through `opt_layerFilter`. * detection can be configured through the `layerFilter` option.
* @param {import("./pixel.js").Pixel} pixel Pixel. * @param {import("./pixel.js").Pixel} pixel Pixel.
* @param {AtPixelOptions} [opt_options] Optional options. * @param {AtPixelOptions} [options] Optional options.
* @return {boolean} Is there a feature at the given pixel? * @return {boolean} Is there a feature at the given pixel?
* @api * @api
*/ */
hasFeatureAtPixel(pixel, opt_options) { hasFeatureAtPixel(pixel, options) {
if (!this.frameState_ || !this.renderer_) { if (!this.frameState_ || !this.renderer_) {
return false; return false;
} }
const coordinate = this.getCoordinateFromPixelInternal(pixel); const coordinate = this.getCoordinateFromPixelInternal(pixel);
opt_options = opt_options !== undefined ? opt_options : {}; options = options !== undefined ? options : {};
const layerFilter = const layerFilter =
opt_options.layerFilter !== undefined ? opt_options.layerFilter : TRUE; options.layerFilter !== undefined ? options.layerFilter : TRUE;
const hitTolerance = const hitTolerance =
opt_options.hitTolerance !== undefined ? opt_options.hitTolerance : 0; options.hitTolerance !== undefined ? options.hitTolerance : 0;
const checkWrapped = opt_options.checkWrapped !== false; const checkWrapped = options.checkWrapped !== false;
return this.renderer_.hasFeatureAtCoordinate( return this.renderer_.hasFeatureAtCoordinate(
coordinate, coordinate,
this.frameState_, this.frameState_,
@@ -1089,10 +1089,10 @@ class Map extends BaseObject {
/** /**
* @param {UIEvent} browserEvent Browser event. * @param {UIEvent} browserEvent Browser event.
* @param {string} [opt_type] Type. * @param {string} [type] Type.
*/ */
handleBrowserEvent(browserEvent, opt_type) { handleBrowserEvent(browserEvent, type) {
const type = opt_type || browserEvent.type; type = type || browserEvent.type;
const mapBrowserEvent = new MapBrowserEvent(type, this, browserEvent); const mapBrowserEvent = new MapBrowserEvent(type, this, browserEvent);
this.handleMapBrowserEvent(mapBrowserEvent); this.handleMapBrowserEvent(mapBrowserEvent);
} }

View File

@@ -14,19 +14,12 @@ class MapBrowserEvent extends MapEvent {
* @param {string} type Event type. * @param {string} type Event type.
* @param {import("./Map.js").default} map Map. * @param {import("./Map.js").default} map Map.
* @param {EVENT} originalEvent Original event. * @param {EVENT} originalEvent Original event.
* @param {boolean} [opt_dragging] Is the map currently being dragged? * @param {boolean} [dragging] Is the map currently being dragged?
* @param {import("./Map.js").FrameState} [opt_frameState] Frame state. * @param {import("./Map.js").FrameState} [frameState] Frame state.
* @param {Array<PointerEvent>} [opt_activePointers] Active pointers. * @param {Array<PointerEvent>} [activePointers] Active pointers.
*/ */
constructor( constructor(type, map, originalEvent, dragging, frameState, activePointers) {
type, super(type, map, frameState);
map,
originalEvent,
opt_dragging,
opt_frameState,
opt_activePointers
) {
super(type, map, opt_frameState);
/** /**
* The original browser event. * The original browser event.
@@ -55,12 +48,12 @@ class MapBrowserEvent extends MapEvent {
* @type {boolean} * @type {boolean}
* @api * @api
*/ */
this.dragging = opt_dragging !== undefined ? opt_dragging : false; this.dragging = dragging !== undefined ? dragging : false;
/** /**
* @type {Array<PointerEvent>|undefined} * @type {Array<PointerEvent>|undefined}
*/ */
this.activePointers = opt_activePointers; this.activePointers = activePointers;
} }
/** /**

View File

@@ -12,9 +12,9 @@ class MapEvent extends Event {
/** /**
* @param {string} type Event type. * @param {string} type Event type.
* @param {import("./Map.js").default} map Map. * @param {import("./Map.js").default} map Map.
* @param {?import("./Map.js").FrameState} [opt_frameState] Frame state. * @param {?import("./Map.js").FrameState} [frameState] Frame state.
*/ */
constructor(type, map, opt_frameState) { constructor(type, map, frameState) {
super(type); super(type);
/** /**
@@ -29,7 +29,7 @@ class MapEvent extends Event {
* @type {?import("./Map.js").FrameState} * @type {?import("./Map.js").FrameState}
* @api * @api
*/ */
this.frameState = opt_frameState !== undefined ? opt_frameState : null; this.frameState = frameState !== undefined ? frameState : null;
} }
} }

View File

@@ -89,9 +89,9 @@ export class ObjectEvent extends Event {
*/ */
class BaseObject extends Observable { class BaseObject extends Observable {
/** /**
* @param {Object<string, *>} [opt_values] An object with key-value pairs. * @param {Object<string, *>} [values] An object with key-value pairs.
*/ */
constructor(opt_values) { constructor(values) {
super(); super();
/*** /***
@@ -121,8 +121,8 @@ class BaseObject extends Observable {
*/ */
this.values_ = null; this.values_ = null;
if (opt_values !== undefined) { if (values !== undefined) {
this.setProperties(opt_values); this.setProperties(values);
} }
} }
@@ -201,12 +201,12 @@ class BaseObject extends Observable {
* Sets a value. * Sets a value.
* @param {string} key Key name. * @param {string} key Key name.
* @param {*} value Value. * @param {*} value Value.
* @param {boolean} [opt_silent] Update without triggering an event. * @param {boolean} [silent] Update without triggering an event.
* @api * @api
*/ */
set(key, value, opt_silent) { set(key, value, silent) {
const values = this.values_ || (this.values_ = {}); const values = this.values_ || (this.values_ = {});
if (opt_silent) { if (silent) {
values[key] = value; values[key] = value;
} else { } else {
const oldValue = values[key]; const oldValue = values[key];
@@ -221,12 +221,12 @@ class BaseObject extends Observable {
* Sets a collection of key-value pairs. Note that this changes any existing * 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). * properties and adds new ones (it does not remove any existing properties).
* @param {Object<string, *>} values Values. * @param {Object<string, *>} values Values.
* @param {boolean} [opt_silent] Update without triggering an event. * @param {boolean} [silent] Update without triggering an event.
* @api * @api
*/ */
setProperties(values, opt_silent) { setProperties(values, silent) {
for (const key in values) { for (const key in values) {
this.set(key, values[key], opt_silent); this.set(key, values[key], silent);
} }
} }
@@ -245,17 +245,17 @@ class BaseObject extends Observable {
/** /**
* Unsets a property. * Unsets a property.
* @param {string} key Key name. * @param {string} key Key name.
* @param {boolean} [opt_silent] Unset without triggering an event. * @param {boolean} [silent] Unset without triggering an event.
* @api * @api
*/ */
unset(key, opt_silent) { unset(key, silent) {
if (this.values_ && key in this.values_) { if (this.values_ && key in this.values_) {
const oldValue = this.values_[key]; const oldValue = this.values_[key];
delete this.values_[key]; delete this.values_[key];
if (isEmpty(this.values_)) { if (isEmpty(this.values_)) {
this.values_ = null; this.values_ = null;
} }
if (!opt_silent) { if (!silent) {
this.notify(key, oldValue); this.notify(key, oldValue);
} }
} }

View File

@@ -402,10 +402,10 @@ class Overlay extends BaseObject {
/** /**
* Pan the map so that the overlay is entirely visible in the current viewport * Pan the map so that the overlay is entirely visible in the current viewport
* (if necessary). * (if necessary).
* @param {PanIntoViewOptions} [opt_panIntoViewOptions] Options for the pan action * @param {PanIntoViewOptions} [panIntoViewOptions] Options for the pan action
* @api * @api
*/ */
panIntoView(opt_panIntoViewOptions) { panIntoView(panIntoViewOptions) {
const map = this.getMap(); const map = this.getMap();
if (!map || !map.getTargetElement() || !this.get(Property.POSITION)) { if (!map || !map.getTargetElement() || !this.get(Property.POSITION)) {
@@ -419,7 +419,7 @@ class Overlay extends BaseObject {
outerHeight(element), outerHeight(element),
]); ]);
const panIntoViewOptions = opt_panIntoViewOptions || {}; panIntoViewOptions = panIntoViewOptions || {};
const myMargin = const myMargin =
panIntoViewOptions.margin === undefined ? 20 : panIntoViewOptions.margin; panIntoViewOptions.margin === undefined ? 20 : panIntoViewOptions.margin;

View File

@@ -78,12 +78,12 @@ class Tile extends EventTarget {
/** /**
* @param {import("./tilecoord.js").TileCoord} tileCoord Tile coordinate. * @param {import("./tilecoord.js").TileCoord} tileCoord Tile coordinate.
* @param {import("./TileState.js").default} state State. * @param {import("./TileState.js").default} state State.
* @param {Options} [opt_options] Tile options. * @param {Options} [options] Tile options.
*/ */
constructor(tileCoord, state, opt_options) { constructor(tileCoord, state, options) {
super(); super();
const options = opt_options ? opt_options : {}; options = options ? options : {};
/** /**
* @type {import("./tilecoord.js").TileCoord} * @type {import("./tilecoord.js").TileCoord}

View File

@@ -11,10 +11,10 @@ class VectorTile extends Tile {
* @param {string} src Data source url. * @param {string} src Data source url.
* @param {import("./format/Feature.js").default} format Feature format. * @param {import("./format/Feature.js").default} format Feature format.
* @param {import("./Tile.js").LoadFunction} tileLoadFunction Tile load function. * @param {import("./Tile.js").LoadFunction} tileLoadFunction Tile load function.
* @param {import("./Tile.js").Options} [opt_options] Tile options. * @param {import("./Tile.js").Options} [options] Tile options.
*/ */
constructor(tileCoord, state, src, format, tileLoadFunction, opt_options) { constructor(tileCoord, state, src, format, tileLoadFunction, options) {
super(tileCoord, state, opt_options); super(tileCoord, state, options);
/** /**
* Extent of this tile; set by the source. * Extent of this tile; set by the source.

View File

@@ -288,7 +288,7 @@ const DEFAULT_MIN_ZOOM = 0;
* A consequence of this is that, when applying a delta on the view state, one * A consequence of this is that, when applying a delta on the view state, one
* should use `adjustCenter`, `adjustRotation`, `adjustZoom` and `adjustResolution` * should use `adjustCenter`, `adjustRotation`, `adjustZoom` and `adjustResolution`
* rather than the corresponding setters. This will let view do its internal * rather than the corresponding setters. This will let view do its internal
* computations. Besides, the `adjust*` methods also take an `opt_anchor` * computations. Besides, the `adjust*` methods also take an `anchor`
* argument which allows specifying an origin for the transformation. * argument which allows specifying an origin for the transformation.
* *
* ### Interacting with the view * ### Interacting with the view
@@ -303,9 +303,9 @@ const DEFAULT_MIN_ZOOM = 0;
*/ */
class View extends BaseObject { class View extends BaseObject {
/** /**
* @param {ViewOptions} [opt_options] View options. * @param {ViewOptions} [options] View options.
*/ */
constructor(opt_options) { constructor(options) {
super(); super();
/*** /***
@@ -323,7 +323,7 @@ class View extends BaseObject {
*/ */
this.un; this.un;
const options = Object.assign({}, opt_options); options = Object.assign({}, options);
/** /**
* @private * @private
@@ -896,19 +896,17 @@ class View extends BaseObject {
/** /**
* Returns the current viewport size. * Returns the current viewport size.
* @private * @private
* @param {number} [opt_rotation] Take into account the rotation of the viewport when giving the size * @param {number} [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. * @return {import("./size.js").Size} Viewport size or `[100, 100]` when no viewport is found.
*/ */
getViewportSize_(opt_rotation) { getViewportSize_(rotation) {
const size = this.viewportSize_; const size = this.viewportSize_;
if (opt_rotation) { if (rotation) {
const w = size[0]; const w = size[0];
const h = size[1]; const h = size[1];
return [ return [
Math.abs(w * Math.cos(opt_rotation)) + Math.abs(w * Math.cos(rotation)) + Math.abs(h * Math.sin(rotation)),
Math.abs(h * Math.sin(opt_rotation)), Math.abs(w * Math.sin(rotation)) + Math.abs(h * Math.cos(rotation)),
Math.abs(w * Math.sin(opt_rotation)) +
Math.abs(h * Math.cos(opt_rotation)),
]; ];
} else { } else {
return size; return size;
@@ -920,12 +918,10 @@ class View extends BaseObject {
* to avoid performance hit and layout reflow. * to avoid performance hit and layout reflow.
* This should be done on map size change. * This should be done on map size change.
* Note: the constraints are not resolved during an animation to avoid stopping it * 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} [size] Viewport size; if undefined, [100, 100] is assumed
*/ */
setViewportSize(opt_size) { setViewportSize(size) {
this.viewportSize_ = Array.isArray(opt_size) this.viewportSize_ = Array.isArray(size) ? size.slice() : [100, 100];
? opt_size.slice()
: [100, 100];
if (!this.getAnimating()) { if (!this.getAnimating()) {
this.resolveConstraints(0); this.resolveConstraints(0);
} }
@@ -970,14 +966,14 @@ class View extends BaseObject {
} }
/** /**
* @param {Array<number>} [opt_hints] Destination array. * @param {Array<number>} [hints] Destination array.
* @return {Array<number>} Hint. * @return {Array<number>} Hint.
*/ */
getHints(opt_hints) { getHints(hints) {
if (opt_hints !== undefined) { if (hints !== undefined) {
opt_hints[0] = this.hints_[0]; hints[0] = this.hints_[0];
opt_hints[1] = this.hints_[1]; hints[1] = this.hints_[1];
return opt_hints; return hints;
} else { } else {
return this.hints_.slice(); return this.hints_.slice();
} }
@@ -988,23 +984,23 @@ class View extends BaseObject {
* The size is the pixel dimensions of the box into which the calculated extent * 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, * should fit. In most cases you want to get the extent of the entire map,
* that is `map.getSize()`. * that is `map.getSize()`.
* @param {import("./size.js").Size} [opt_size] Box pixel size. If not provided, the size * @param {import("./size.js").Size} [size] Box pixel size. If not provided, the size
* of the map that uses this view will be used. * of the map that uses this view will be used.
* @return {import("./extent.js").Extent} Extent. * @return {import("./extent.js").Extent} Extent.
* @api * @api
*/ */
calculateExtent(opt_size) { calculateExtent(size) {
const extent = this.calculateExtentInternal(opt_size); const extent = this.calculateExtentInternal(size);
return toUserExtent(extent, this.getProjection()); return toUserExtent(extent, this.getProjection());
} }
/** /**
* @param {import("./size.js").Size} [opt_size] Box pixel size. If not provided, * @param {import("./size.js").Size} [size] Box pixel size. If not provided,
* the map's last known viewport size will be used. * the map's last known viewport size will be used.
* @return {import("./extent.js").Extent} Extent. * @return {import("./extent.js").Extent} Extent.
*/ */
calculateExtentInternal(opt_size) { calculateExtentInternal(size) {
const size = opt_size || this.getViewportSizeMinusPadding_(); size = size || this.getViewportSizeMinusPadding_();
const center = /** @type {!import("./coordinate.js").Coordinate} */ ( const center = /** @type {!import("./coordinate.js").Coordinate} */ (
this.getCenterInternal() this.getCenterInternal()
); );
@@ -1116,27 +1112,27 @@ class View extends BaseObject {
/** /**
* Get the resolution for a provided extent (in map units) and size (in pixels). * Get the resolution for a provided extent (in map units) and size (in pixels).
* @param {import("./extent.js").Extent} extent Extent. * @param {import("./extent.js").Extent} extent Extent.
* @param {import("./size.js").Size} [opt_size] Box pixel size. * @param {import("./size.js").Size} [size] Box pixel size.
* @return {number} The resolution at which the provided extent will render at * @return {number} The resolution at which the provided extent will render at
* the given size. * the given size.
* @api * @api
*/ */
getResolutionForExtent(extent, opt_size) { getResolutionForExtent(extent, size) {
return this.getResolutionForExtentInternal( return this.getResolutionForExtentInternal(
fromUserExtent(extent, this.getProjection()), fromUserExtent(extent, this.getProjection()),
opt_size size
); );
} }
/** /**
* Get the resolution for a provided extent (in map units) and size (in pixels). * Get the resolution for a provided extent (in map units) and size (in pixels).
* @param {import("./extent.js").Extent} extent Extent. * @param {import("./extent.js").Extent} extent Extent.
* @param {import("./size.js").Size} [opt_size] Box pixel size. * @param {import("./size.js").Size} [size] Box pixel size.
* @return {number} The resolution at which the provided extent will render at * @return {number} The resolution at which the provided extent will render at
* the given size. * the given size.
*/ */
getResolutionForExtentInternal(extent, opt_size) { getResolutionForExtentInternal(extent, size) {
const size = opt_size || this.getViewportSizeMinusPadding_(); size = size || this.getViewportSizeMinusPadding_();
const xResolution = getWidth(extent) / size[0]; const xResolution = getWidth(extent) / size[0];
const yResolution = getHeight(extent) / size[1]; const yResolution = getHeight(extent) / size[1];
return Math.max(xResolution, yResolution); return Math.max(xResolution, yResolution);
@@ -1145,11 +1141,11 @@ class View extends BaseObject {
/** /**
* Return a function that returns a value between 0 and 1 for a * Return a function that returns a value between 0 and 1 for a
* resolution. Exponential scaling is assumed. * resolution. Exponential scaling is assumed.
* @param {number} [opt_power] Power. * @param {number} [power] Power.
* @return {function(number): number} Resolution for value function. * @return {function(number): number} Resolution for value function.
*/ */
getResolutionForValueFunction(opt_power) { getResolutionForValueFunction(power) {
const power = opt_power || 2; power = power || 2;
const maxResolution = this.getConstrainedResolution(this.maxResolution_); const maxResolution = this.getConstrainedResolution(this.maxResolution_);
const minResolution = this.minResolution_; const minResolution = this.minResolution_;
const max = Math.log(maxResolution / minResolution) / Math.log(power); const max = Math.log(maxResolution / minResolution) / Math.log(power);
@@ -1178,11 +1174,11 @@ class View extends BaseObject {
/** /**
* Return a function that returns a resolution for a value between * Return a function that returns a resolution for a value between
* 0 and 1. Exponential scaling is assumed. * 0 and 1. Exponential scaling is assumed.
* @param {number} [opt_power] Power. * @param {number} [power] Power.
* @return {function(number): number} Value for resolution function. * @return {function(number): number} Value for resolution function.
*/ */
getValueForResolutionFunction(opt_power) { getValueForResolutionFunction(power) {
const logPower = Math.log(opt_power || 2); const logPower = Math.log(power || 2);
const maxResolution = this.getConstrainedResolution(this.maxResolution_); const maxResolution = this.getConstrainedResolution(this.maxResolution_);
const minResolution = this.minResolution_; const minResolution = this.minResolution_;
const max = Math.log(maxResolution / minResolution) / logPower; const max = Math.log(maxResolution / minResolution) / logPower;
@@ -1201,11 +1197,11 @@ class View extends BaseObject {
/** /**
* Returns the size of the viewport minus padding. * Returns the size of the viewport minus padding.
* @private * @private
* @param {number} [opt_rotation] Take into account the rotation of the viewport when giving the size * @param {number} [rotation] Take into account the rotation of the viewport when giving the size
* @return {import("./size.js").Size} Viewport size reduced by the padding. * @return {import("./size.js").Size} Viewport size reduced by the padding.
*/ */
getViewportSizeMinusPadding_(opt_rotation) { getViewportSizeMinusPadding_(rotation) {
let size = this.getViewportSize_(opt_rotation); let size = this.getViewportSize_(rotation);
const padding = this.padding_; const padding = this.padding_;
if (padding) { if (padding) {
size = [ size = [
@@ -1326,10 +1322,10 @@ class View extends BaseObject {
* Takes care of the map angle. * Takes care of the map angle.
* @param {import("./geom/SimpleGeometry.js").default|import("./extent.js").Extent} geometryOrExtent The geometry or * @param {import("./geom/SimpleGeometry.js").default|import("./extent.js").Extent} geometryOrExtent The geometry or
* extent to fit the view to. * extent to fit the view to.
* @param {FitOptions} [opt_options] Options. * @param {FitOptions} [options] Options.
* @api * @api
*/ */
fit(geometryOrExtent, opt_options) { fit(geometryOrExtent, options) {
/** @type {import("./geom/SimpleGeometry.js").default} */ /** @type {import("./geom/SimpleGeometry.js").default} */
let geometry; let geometry;
assert( assert(
@@ -1362,7 +1358,7 @@ class View extends BaseObject {
} }
} }
this.fitInternal(geometry, opt_options); this.fitInternal(geometry, options);
} }
/** /**
@@ -1393,10 +1389,10 @@ class View extends BaseObject {
/** /**
* @param {import("./geom/SimpleGeometry.js").default} geometry The geometry. * @param {import("./geom/SimpleGeometry.js").default} geometry The geometry.
* @param {FitOptions} [opt_options] Options. * @param {FitOptions} [options] Options.
*/ */
fitInternal(geometry, opt_options) { fitInternal(geometry, options) {
const options = opt_options || {}; options = options || {};
let size = options.size; let size = options.size;
if (!size) { if (!size) {
size = this.getViewportSizeMinusPadding_(); size = this.getViewportSizeMinusPadding_();
@@ -1551,12 +1547,11 @@ class View extends BaseObject {
* Multiply the view resolution by a ratio, optionally using an anchor. Any resolution * Multiply the view resolution by a ratio, optionally using an anchor. Any resolution
* constraint will apply. * constraint will apply.
* @param {number} ratio The ratio to apply on the view resolution. * @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} [anchor] The origin of the transformation.
* @api * @api
*/ */
adjustResolution(ratio, opt_anchor) { adjustResolution(ratio, anchor) {
const anchor = anchor = anchor && fromUserCoordinate(anchor, this.getProjection());
opt_anchor && fromUserCoordinate(opt_anchor, this.getProjection());
this.adjustResolutionInternal(ratio, anchor); this.adjustResolutionInternal(ratio, anchor);
} }
@@ -1564,9 +1559,9 @@ class View extends BaseObject {
* Multiply the view resolution by a ratio, optionally using an anchor. Any resolution * Multiply the view resolution by a ratio, optionally using an anchor. Any resolution
* constraint will apply. * constraint will apply.
* @param {number} ratio The ratio to apply on the view resolution. * @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} [anchor] The origin of the transformation.
*/ */
adjustResolutionInternal(ratio, opt_anchor) { adjustResolutionInternal(ratio, anchor) {
const isMoving = this.getAnimating() || this.getInteracting(); const isMoving = this.getAnimating() || this.getInteracting();
const size = this.getViewportSize_(this.getRotation()); const size = this.getViewportSize_(this.getRotation());
const newResolution = this.constraints_.resolution( const newResolution = this.constraints_.resolution(
@@ -1576,8 +1571,8 @@ class View extends BaseObject {
isMoving isMoving
); );
if (opt_anchor) { if (anchor) {
this.targetCenter_ = this.calculateCenterZoom(newResolution, opt_anchor); this.targetCenter_ = this.calculateCenterZoom(newResolution, anchor);
} }
this.targetResolution_ *= ratio; this.targetResolution_ *= ratio;
@@ -1588,39 +1583,39 @@ class View extends BaseObject {
* Adds a value to the view zoom level, optionally using an anchor. Any resolution * Adds a value to the view zoom level, optionally using an anchor. Any resolution
* constraint will apply. * constraint will apply.
* @param {number} delta Relative value to add to the zoom level. * @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} [anchor] The origin of the transformation.
* @api * @api
*/ */
adjustZoom(delta, opt_anchor) { adjustZoom(delta, anchor) {
this.adjustResolution(Math.pow(this.zoomFactor_, -delta), opt_anchor); this.adjustResolution(Math.pow(this.zoomFactor_, -delta), anchor);
} }
/** /**
* Adds a value to the view rotation, optionally using an anchor. Any rotation * Adds a value to the view rotation, optionally using an anchor. Any rotation
* constraint will apply. * constraint will apply.
* @param {number} delta Relative value to add to the zoom rotation, in radians. * @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} [anchor] The rotation center.
* @api * @api
*/ */
adjustRotation(delta, opt_anchor) { adjustRotation(delta, anchor) {
if (opt_anchor) { if (anchor) {
opt_anchor = fromUserCoordinate(opt_anchor, this.getProjection()); anchor = fromUserCoordinate(anchor, this.getProjection());
} }
this.adjustRotationInternal(delta, opt_anchor); this.adjustRotationInternal(delta, anchor);
} }
/** /**
* @param {number} delta Relative value to add to the zoom rotation, in radians. * @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} [anchor] The rotation center.
*/ */
adjustRotationInternal(delta, opt_anchor) { adjustRotationInternal(delta, anchor) {
const isMoving = this.getAnimating() || this.getInteracting(); const isMoving = this.getAnimating() || this.getInteracting();
const newRotation = this.constraints_.rotation( const newRotation = this.constraints_.rotation(
this.targetRotation_ + delta, this.targetRotation_ + delta,
isMoving isMoving
); );
if (opt_anchor) { if (anchor) {
this.targetCenter_ = this.calculateCenterRotate(newRotation, opt_anchor); this.targetCenter_ = this.calculateCenterRotate(newRotation, anchor);
} }
this.targetRotation_ += delta; this.targetRotation_ += delta;
this.applyTargetState_(); this.applyTargetState_();
@@ -1693,13 +1688,13 @@ class View extends BaseObject {
* Recompute rotation/resolution/center based on target values. * Recompute rotation/resolution/center based on target values.
* Note: we have to compute rotation first, then resolution and center considering that * 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. * parameters can influence one another in case a view extent constraint is present.
* @param {boolean} [opt_doNotCancelAnims] Do not cancel animations. * @param {boolean} [doNotCancelAnims] Do not cancel animations.
* @param {boolean} [opt_forceMoving] Apply constraints as if the view is moving. * @param {boolean} [forceMoving] Apply constraints as if the view is moving.
* @private * @private
*/ */
applyTargetState_(opt_doNotCancelAnims, opt_forceMoving) { applyTargetState_(doNotCancelAnims, forceMoving) {
const isMoving = const isMoving =
this.getAnimating() || this.getInteracting() || opt_forceMoving; this.getAnimating() || this.getInteracting() || forceMoving;
// compute rotation // compute rotation
const newRotation = this.constraints_.rotation( const newRotation = this.constraints_.rotation(
@@ -1741,7 +1736,7 @@ class View extends BaseObject {
this.set(ViewProperty.CENTER, newCenter); this.set(ViewProperty.CENTER, newCenter);
} }
if (this.getAnimating() && !opt_doNotCancelAnims) { if (this.getAnimating() && !doNotCancelAnims) {
this.cancelAnimations(); this.cancelAnimations();
} }
this.cancelAnchor_ = undefined; this.cancelAnchor_ = undefined;
@@ -1752,13 +1747,13 @@ class View extends BaseObject {
* This is typically done on interaction end. * This is typically done on interaction end.
* Note: calling this with a duration of 0 will apply the constrained values straight away, * Note: calling this with a duration of 0 will apply the constrained values straight away,
* without animation. * without animation.
* @param {number} [opt_duration] The animation duration in ms. * @param {number} [duration] The animation duration in ms.
* @param {number} [opt_resolutionDirection] Which direction to zoom. * @param {number} [resolutionDirection] Which direction to zoom.
* @param {import("./coordinate.js").Coordinate} [opt_anchor] The origin of the transformation. * @param {import("./coordinate.js").Coordinate} [anchor] The origin of the transformation.
*/ */
resolveConstraints(opt_duration, opt_resolutionDirection, opt_anchor) { resolveConstraints(duration, resolutionDirection, anchor) {
const duration = opt_duration !== undefined ? opt_duration : 200; duration = duration !== undefined ? duration : 200;
const direction = opt_resolutionDirection || 0; const direction = resolutionDirection || 0;
const newRotation = this.constraints_.rotation(this.targetRotation_); const newRotation = this.constraints_.rotation(this.targetRotation_);
const size = this.getViewportSize_(newRotation); const size = this.getViewportSize_(newRotation);
@@ -1788,8 +1783,7 @@ class View extends BaseObject {
return; return;
} }
const anchor = anchor = anchor || (duration === 0 ? this.cancelAnchor_ : undefined);
opt_anchor || (duration === 0 ? this.cancelAnchor_ : undefined);
this.cancelAnchor_ = undefined; this.cancelAnchor_ = undefined;
if ( if (
@@ -1828,42 +1822,41 @@ class View extends BaseObject {
/** /**
* Notify the View that an interaction has ended. The view state will be resolved * Notify the View that an interaction has ended. The view state will be resolved
* to a stable one if needed (depending on its constraints). * to a stable one if needed (depending on its constraints).
* @param {number} [opt_duration] Animation duration in ms. * @param {number} [duration] Animation duration in ms.
* @param {number} [opt_resolutionDirection] Which direction to zoom. * @param {number} [resolutionDirection] Which direction to zoom.
* @param {import("./coordinate.js").Coordinate} [opt_anchor] The origin of the transformation. * @param {import("./coordinate.js").Coordinate} [anchor] The origin of the transformation.
* @api * @api
*/ */
endInteraction(opt_duration, opt_resolutionDirection, opt_anchor) { endInteraction(duration, resolutionDirection, anchor) {
const anchor = anchor = anchor && fromUserCoordinate(anchor, this.getProjection());
opt_anchor && fromUserCoordinate(opt_anchor, this.getProjection()); this.endInteractionInternal(duration, resolutionDirection, anchor);
this.endInteractionInternal(opt_duration, opt_resolutionDirection, anchor);
} }
/** /**
* Notify the View that an interaction has ended. The view state will be resolved * Notify the View that an interaction has ended. The view state will be resolved
* to a stable one if needed (depending on its constraints). * to a stable one if needed (depending on its constraints).
* @param {number} [opt_duration] Animation duration in ms. * @param {number} [duration] Animation duration in ms.
* @param {number} [opt_resolutionDirection] Which direction to zoom. * @param {number} [resolutionDirection] Which direction to zoom.
* @param {import("./coordinate.js").Coordinate} [opt_anchor] The origin of the transformation. * @param {import("./coordinate.js").Coordinate} [anchor] The origin of the transformation.
*/ */
endInteractionInternal(opt_duration, opt_resolutionDirection, opt_anchor) { endInteractionInternal(duration, resolutionDirection, anchor) {
this.setHint(ViewHint.INTERACTING, -1); this.setHint(ViewHint.INTERACTING, -1);
this.resolveConstraints(opt_duration, opt_resolutionDirection, opt_anchor); this.resolveConstraints(duration, resolutionDirection, anchor);
} }
/** /**
* Get a valid position for the view center according to the current constraints. * Get a valid position for the view center according to the current constraints.
* @param {import("./coordinate.js").Coordinate|undefined} targetCenter Target center position. * @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} [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. * This is useful to guess a valid center position at a different zoom level.
* @return {import("./coordinate.js").Coordinate|undefined} Valid center position. * @return {import("./coordinate.js").Coordinate|undefined} Valid center position.
*/ */
getConstrainedCenter(targetCenter, opt_targetResolution) { getConstrainedCenter(targetCenter, targetResolution) {
const size = this.getViewportSize_(this.getRotation()); const size = this.getViewportSize_(this.getRotation());
return this.constraints_.center( return this.constraints_.center(
targetCenter, targetCenter,
opt_targetResolution || this.getResolution(), targetResolution || this.getResolution(),
size size
); );
} }
@@ -1871,30 +1864,30 @@ class View extends BaseObject {
/** /**
* Get a valid zoom level according to the current view constraints. * Get a valid zoom level according to the current view constraints.
* @param {number|undefined} targetZoom Target zoom. * @param {number|undefined} targetZoom Target zoom.
* @param {number} [opt_direction=0] Indicate which resolution should be used * @param {number} [direction=0] Indicate which resolution should be used
* by a renderer if the view resolution does not match any resolution of the tile source. * 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 * 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. * will be used. If -1, the nearest higher resolution will be used.
* @return {number|undefined} Valid zoom level. * @return {number|undefined} Valid zoom level.
*/ */
getConstrainedZoom(targetZoom, opt_direction) { getConstrainedZoom(targetZoom, direction) {
const targetRes = this.getResolutionForZoom(targetZoom); const targetRes = this.getResolutionForZoom(targetZoom);
return this.getZoomForResolution( return this.getZoomForResolution(
this.getConstrainedResolution(targetRes, opt_direction) this.getConstrainedResolution(targetRes, direction)
); );
} }
/** /**
* Get a valid resolution according to the current view constraints. * Get a valid resolution according to the current view constraints.
* @param {number|undefined} targetResolution Target resolution. * @param {number|undefined} targetResolution Target resolution.
* @param {number} [opt_direction=0] Indicate which resolution should be used * @param {number} [direction=0] Indicate which resolution should be used
* by a renderer if the view resolution does not match any resolution of the tile source. * 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 * 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. * will be used. If -1, the nearest higher resolution will be used.
* @return {number|undefined} Valid resolution. * @return {number|undefined} Valid resolution.
*/ */
getConstrainedResolution(targetResolution, opt_direction) { getConstrainedResolution(targetResolution, direction) {
const direction = opt_direction || 0; direction = direction || 0;
const size = this.getViewportSize_(this.getRotation()); const size = this.getViewportSize_(this.getRotation());
return this.constraints_.resolution(targetResolution, direction, size); return this.constraints_.resolution(targetResolution, direction, size);

View File

@@ -8,12 +8,12 @@
* *
* @param {Array<*>} haystack Items to search through. * @param {Array<*>} haystack Items to search through.
* @param {*} needle The item to look for. * @param {*} needle The item to look for.
* @param {Function} [opt_comparator] Comparator function. * @param {Function} [comparator] Comparator function.
* @return {number} The index of the item if found, -1 if not. * @return {number} The index of the item if found, -1 if not.
*/ */
export function binarySearch(haystack, needle, opt_comparator) { export function binarySearch(haystack, needle, comparator) {
let mid, cmp; let mid, cmp;
const comparator = opt_comparator || numberSafeCompareFunction; comparator = comparator || numberSafeCompareFunction;
let low = 0; let low = 0;
let high = haystack.length; let high = haystack.length;
let found = false; let found = false;
@@ -200,17 +200,17 @@ export function stableSort(arr, compareFnc) {
/** /**
* @param {Array<*>} arr The array to test. * @param {Array<*>} arr The array to test.
* @param {Function} [opt_func] Comparison function. * @param {Function} [func] Comparison function.
* @param {boolean} [opt_strict] Strictly sorted (default false). * @param {boolean} [strict] Strictly sorted (default false).
* @return {boolean} Return index. * @return {boolean} Return index.
*/ */
export function isSorted(arr, opt_func, opt_strict) { export function isSorted(arr, func, strict) {
const compare = opt_func || numberSafeCompareFunction; const compare = func || numberSafeCompareFunction;
return arr.every(function (currentVal, index) { return arr.every(function (currentVal, index) {
if (index === 0) { if (index === 0) {
return true; return true;
} }
const res = compare(arr[index - 1], currentVal); const res = compare(arr[index - 1], currentVal);
return !(res > 0 || (opt_strict && res === 0)); return !(res > 0 || (strict && res === 0));
}); });
} }

View File

@@ -20,11 +20,11 @@ export function createExtent(extent, onlyCenter, smooth) {
* @param {import("./coordinate.js").Coordinate|undefined} center Center. * @param {import("./coordinate.js").Coordinate|undefined} center Center.
* @param {number|undefined} resolution Resolution. * @param {number|undefined} resolution Resolution.
* @param {import("./size.js").Size} size Viewport size; unused if `onlyCenter` was specified. * @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} [isMoving] True if an interaction or animation is in progress.
* @param {Array<number>} [opt_centerShift] Shift between map center and viewport center. * @param {Array<number>} [centerShift] Shift between map center and viewport center.
* @return {import("./coordinate.js").Coordinate|undefined} Center. * @return {import("./coordinate.js").Coordinate|undefined} Center.
*/ */
function (center, resolution, size, opt_isMoving, opt_centerShift) { function (center, resolution, size, isMoving, centerShift) {
if (!center) { if (!center) {
return undefined; return undefined;
} }
@@ -33,8 +33,8 @@ export function createExtent(extent, onlyCenter, smooth) {
} }
const viewWidth = onlyCenter ? 0 : size[0] * resolution; const viewWidth = onlyCenter ? 0 : size[0] * resolution;
const viewHeight = onlyCenter ? 0 : size[1] * resolution; const viewHeight = onlyCenter ? 0 : size[1] * resolution;
const shiftX = opt_centerShift ? opt_centerShift[0] : 0; const shiftX = centerShift ? centerShift[0] : 0;
const shiftY = opt_centerShift ? opt_centerShift[1] : 0; const shiftY = centerShift ? centerShift[1] : 0;
let minX = extent[0] + viewWidth / 2 + shiftX; let minX = extent[0] + viewWidth / 2 + shiftX;
let maxX = extent[2] - viewWidth / 2 + shiftX; let maxX = extent[2] - viewWidth / 2 + shiftX;
let minY = extent[1] + viewHeight / 2 + shiftY; let minY = extent[1] + viewHeight / 2 + shiftY;
@@ -55,7 +55,7 @@ export function createExtent(extent, onlyCenter, smooth) {
let y = clamp(center[1], minY, maxY); let y = clamp(center[1], minY, maxY);
// during an interaction, allow some overscroll // during an interaction, allow some overscroll
if (opt_isMoving && smooth && resolution) { if (isMoving && smooth && resolution) {
const ratio = 30 * resolution; const ratio = 30 * resolution;
x += x +=
-ratio * Math.log(1 + Math.max(0, minX - center[0]) / ratio) + -ratio * Math.log(1 + Math.max(0, minX - center[0]) / ratio) +

View File

@@ -46,10 +46,10 @@ import {removeChildren, replaceNode} from '../dom.js';
*/ */
class Attribution extends Control { class Attribution extends Control {
/** /**
* @param {Options} [opt_options] Attribution options. * @param {Options} [options] Attribution options.
*/ */
constructor(opt_options) { constructor(options) {
const options = opt_options ? opt_options : {}; options = options ? options : {};
super({ super({
element: document.createElement('div'), element: document.createElement('div'),

View File

@@ -80,10 +80,10 @@ const FullScreenEventType = {
*/ */
class FullScreen extends Control { class FullScreen extends Control {
/** /**
* @param {Options} [opt_options] Options. * @param {Options} [options] Options.
*/ */
constructor(opt_options) { constructor(options) {
const options = opt_options ? opt_options : {}; options = options ? options : {};
super({ super({
element: document.createElement('div'), element: document.createElement('div'),

View File

@@ -62,10 +62,10 @@ const COORDINATE_FORMAT = 'coordinateFormat';
*/ */
class MousePosition extends Control { class MousePosition extends Control {
/** /**
* @param {Options} [opt_options] Mouse position options. * @param {Options} [options] Mouse position options.
*/ */
constructor(opt_options) { constructor(options) {
const options = opt_options ? opt_options : {}; options = options ? options : {};
const element = document.createElement('div'); const element = document.createElement('div');
element.className = element.className =

View File

@@ -66,10 +66,10 @@ const MIN_RATIO = 0.1;
*/ */
class OverviewMap extends Control { class OverviewMap extends Control {
/** /**
* @param {Options} [opt_options] OverviewMap options. * @param {Options} [options] OverviewMap options.
*/ */
constructor(opt_options) { constructor(options) {
const options = opt_options ? opt_options : {}; options = options ? options : {};
super({ super({
element: document.createElement('div'), element: document.createElement('div'),

View File

@@ -33,10 +33,10 @@ import {easeOut} from '../easing.js';
*/ */
class Rotate extends Control { class Rotate extends Control {
/** /**
* @param {Options} [opt_options] Rotate options. * @param {Options} [options] Rotate options.
*/ */
constructor(opt_options) { constructor(options) {
const options = opt_options ? opt_options : {}; options = options ? options : {};
super({ super({
element: document.createElement('div'), element: document.createElement('div'),

View File

@@ -75,10 +75,10 @@ const DEFAULT_DPI = 25.4 / 0.28;
*/ */
class ScaleLine extends Control { class ScaleLine extends Control {
/** /**
* @param {Options} [opt_options] Scale line options. * @param {Options} [options] Scale line options.
*/ */
constructor(opt_options) { constructor(options) {
const options = opt_options ? opt_options : {}; options = options ? options : {};
const element = document.createElement('div'); const element = document.createElement('div');
element.style.pointerEvents = 'none'; element.style.pointerEvents = 'none';

View File

@@ -33,10 +33,10 @@ import {easeOut} from '../easing.js';
*/ */
class Zoom extends Control { class Zoom extends Control {
/** /**
* @param {Options} [opt_options] Zoom options. * @param {Options} [options] Zoom options.
*/ */
constructor(opt_options) { constructor(options) {
const options = opt_options ? opt_options : {}; options = options ? options : {};
super({ super({
element: document.createElement('div'), element: document.createElement('div'),

View File

@@ -41,10 +41,10 @@ const Direction = {
*/ */
class ZoomSlider extends Control { class ZoomSlider extends Control {
/** /**
* @param {Options} [opt_options] Zoom slider options. * @param {Options} [options] Zoom slider options.
*/ */
constructor(opt_options) { constructor(options) {
const options = opt_options ? opt_options : {}; options = options ? options : {};
super({ super({
element: document.createElement('div'), element: document.createElement('div'),

View File

@@ -27,10 +27,10 @@ import {fromExtent as polygonFromExtent} from '../geom/Polygon.js';
*/ */
class ZoomToExtent extends Control { class ZoomToExtent extends Control {
/** /**
* @param {Options} [opt_options] Options. * @param {Options} [options] Options.
*/ */
constructor(opt_options) { constructor(options) {
const options = opt_options ? opt_options : {}; options = options ? options : {};
super({ super({
element: document.createElement('div'), element: document.createElement('div'),

View File

@@ -29,13 +29,13 @@ import Zoom from './Zoom.js';
* * {@link module:ol/control/Rotate~Rotate} * * {@link module:ol/control/Rotate~Rotate}
* * {@link module:ol/control/Attribution~Attribution} * * {@link module:ol/control/Attribution~Attribution}
* *
* @param {DefaultsOptions} [opt_options] Options for the default controls. * @param {DefaultsOptions} [options] Options for the default controls.
* @return {Collection<import("./Control.js").default>} A collection of controls * @return {Collection<import("./Control.js").default>} A collection of controls
* to be used with the {@link module:ol/Map~Map} constructor's `controls` option. * to be used with the {@link module:ol/Map~Map} constructor's `controls` option.
* @api * @api
*/ */
export function defaults(opt_options) { export function defaults(options) {
const options = opt_options ? opt_options : {}; options = options ? options : {};
/** @type {Collection<import("./Control.js").default>} */ /** @type {Collection<import("./Control.js").default>} */
const controls = new Collection(); const controls = new Collection();

View File

@@ -135,19 +135,19 @@ export function closestOnSegment(coordinate, segment) {
* const out = stringifyFunc(coord); * const out = stringifyFunc(coord);
* // out is now '7.85, 47.98' * // out is now '7.85, 47.98'
* *
* @param {number} [opt_fractionDigits] The number of digits to include * @param {number} [fractionDigits] The number of digits to include
* after the decimal point. Default is `0`. * after the decimal point. Default is `0`.
* @return {CoordinateFormat} Coordinate format. * @return {CoordinateFormat} Coordinate format.
* @api * @api
*/ */
export function createStringXY(opt_fractionDigits) { export function createStringXY(fractionDigits) {
return ( return (
/** /**
* @param {Coordinate} coordinate Coordinate. * @param {Coordinate} coordinate Coordinate.
* @return {string} String XY. * @return {string} String XY.
*/ */
function (coordinate) { function (coordinate) {
return toStringXY(coordinate, opt_fractionDigits); return toStringXY(coordinate, fractionDigits);
} }
); );
} }
@@ -155,14 +155,14 @@ export function createStringXY(opt_fractionDigits) {
/** /**
* @param {string} hemispheres Hemispheres. * @param {string} hemispheres Hemispheres.
* @param {number} degrees Degrees. * @param {number} degrees Degrees.
* @param {number} [opt_fractionDigits] The number of digits to include * @param {number} [fractionDigits] The number of digits to include
* after the decimal point. Default is `0`. * after the decimal point. Default is `0`.
* @return {string} String. * @return {string} String.
*/ */
export function degreesToStringHDMS(hemispheres, degrees, opt_fractionDigits) { export function degreesToStringHDMS(hemispheres, degrees, fractionDigits) {
const normalizedDegrees = modulo(degrees + 180, 360) - 180; const normalizedDegrees = modulo(degrees + 180, 360) - 180;
const x = Math.abs(3600 * normalizedDegrees); const x = Math.abs(3600 * normalizedDegrees);
const decimals = opt_fractionDigits || 0; const decimals = fractionDigits || 0;
let deg = Math.floor(x / 3600); let deg = Math.floor(x / 3600);
let min = Math.floor((x - deg * 3600) / 60); let min = Math.floor((x - deg * 3600) / 60);
@@ -218,16 +218,16 @@ export function degreesToStringHDMS(hemispheres, degrees, opt_fractionDigits) {
* @param {Coordinate} coordinate Coordinate. * @param {Coordinate} coordinate Coordinate.
* @param {string} template A template string with `{x}` and `{y}` placeholders * @param {string} template A template string with `{x}` and `{y}` placeholders
* that will be replaced by first and second coordinate values. * that will be replaced by first and second coordinate values.
* @param {number} [opt_fractionDigits] The number of digits to include * @param {number} [fractionDigits] The number of digits to include
* after the decimal point. Default is `0`. * after the decimal point. Default is `0`.
* @return {string} Formatted coordinate. * @return {string} Formatted coordinate.
* @api * @api
*/ */
export function format(coordinate, template, opt_fractionDigits) { export function format(coordinate, template, fractionDigits) {
if (coordinate) { if (coordinate) {
return template return template
.replace('{x}', coordinate[0].toFixed(opt_fractionDigits)) .replace('{x}', coordinate[0].toFixed(fractionDigits))
.replace('{y}', coordinate[1].toFixed(opt_fractionDigits)); .replace('{y}', coordinate[1].toFixed(fractionDigits));
} else { } else {
return ''; return '';
} }
@@ -353,17 +353,17 @@ export function squaredDistanceToSegment(coordinate, segment) {
* // out is now '47° 58 60.0″ N 7° 50 60.0″ E' * // out is now '47° 58 60.0″ N 7° 50 60.0″ E'
* *
* @param {Coordinate} coordinate Coordinate. * @param {Coordinate} coordinate Coordinate.
* @param {number} [opt_fractionDigits] The number of digits to include * @param {number} [fractionDigits] The number of digits to include
* after the decimal point. Default is `0`. * after the decimal point. Default is `0`.
* @return {string} Hemisphere, degrees, minutes and seconds. * @return {string} Hemisphere, degrees, minutes and seconds.
* @api * @api
*/ */
export function toStringHDMS(coordinate, opt_fractionDigits) { export function toStringHDMS(coordinate, fractionDigits) {
if (coordinate) { if (coordinate) {
return ( return (
degreesToStringHDMS('NS', coordinate[1], opt_fractionDigits) + degreesToStringHDMS('NS', coordinate[1], fractionDigits) +
' ' + ' ' +
degreesToStringHDMS('EW', coordinate[0], opt_fractionDigits) degreesToStringHDMS('EW', coordinate[0], fractionDigits)
); );
} else { } else {
return ''; return '';
@@ -390,13 +390,13 @@ export function toStringHDMS(coordinate, opt_fractionDigits) {
* // out is now '7.8, 48.0' * // out is now '7.8, 48.0'
* *
* @param {Coordinate} coordinate Coordinate. * @param {Coordinate} coordinate Coordinate.
* @param {number} [opt_fractionDigits] The number of digits to include * @param {number} [fractionDigits] The number of digits to include
* after the decimal point. Default is `0`. * after the decimal point. Default is `0`.
* @return {string} XY. * @return {string} XY.
* @api * @api
*/ */
export function toStringXY(coordinate, opt_fractionDigits) { export function toStringXY(coordinate, fractionDigits) {
return format(coordinate, '{x}, {y}', opt_fractionDigits); return format(coordinate, '{x}, {y}', fractionDigits);
} }
/** /**
@@ -421,18 +421,17 @@ export function wrapX(coordinate, projection) {
/** /**
* @param {Coordinate} coordinate Coordinate. * @param {Coordinate} coordinate Coordinate.
* @param {import("./proj/Projection.js").default} projection Projection. * @param {import("./proj/Projection.js").default} projection Projection.
* @param {number} [opt_sourceExtentWidth] Width of the source extent. * @param {number} [sourceExtentWidth] Width of the source extent.
* @return {number} Offset in world widths. * @return {number} Offset in world widths.
*/ */
export function getWorldsAway(coordinate, projection, opt_sourceExtentWidth) { export function getWorldsAway(coordinate, projection, sourceExtentWidth) {
const projectionExtent = projection.getExtent(); const projectionExtent = projection.getExtent();
let worldsAway = 0; let worldsAway = 0;
if ( if (
projection.canWrapX() && projection.canWrapX() &&
(coordinate[0] < projectionExtent[0] || coordinate[0] > projectionExtent[2]) (coordinate[0] < projectionExtent[0] || coordinate[0] > projectionExtent[2])
) { ) {
const sourceExtentWidth = sourceExtentWidth = sourceExtentWidth || getWidth(projectionExtent);
opt_sourceExtentWidth || getWidth(projectionExtent);
worldsAway = Math.floor( worldsAway = Math.floor(
(coordinate[0] - projectionExtent[0]) / sourceExtentWidth (coordinate[0] - projectionExtent[0]) / sourceExtentWidth
); );

View File

@@ -7,36 +7,31 @@ import {WORKER_OFFSCREEN_CANVAS} from './has.js';
//FIXME Move this function to the canvas module //FIXME Move this function to the canvas module
/** /**
* Create an html canvas element and returns its 2d context. * Create an html canvas element and returns its 2d context.
* @param {number} [opt_width] Canvas width. * @param {number} [width] Canvas width.
* @param {number} [opt_height] Canvas height. * @param {number} [height] Canvas height.
* @param {Array<HTMLCanvasElement>} [opt_canvasPool] Canvas pool to take existing canvas from. * @param {Array<HTMLCanvasElement>} [canvasPool] Canvas pool to take existing canvas from.
* @param {CanvasRenderingContext2DSettings} [opt_Context2DSettings] CanvasRenderingContext2DSettings * @param {CanvasRenderingContext2DSettings} [settings] CanvasRenderingContext2DSettings
* @return {CanvasRenderingContext2D} The context. * @return {CanvasRenderingContext2D} The context.
*/ */
export function createCanvasContext2D( export function createCanvasContext2D(width, height, canvasPool, settings) {
opt_width,
opt_height,
opt_canvasPool,
opt_Context2DSettings
) {
/** @type {HTMLCanvasElement|OffscreenCanvas} */ /** @type {HTMLCanvasElement|OffscreenCanvas} */
let canvas; let canvas;
if (opt_canvasPool && opt_canvasPool.length) { if (canvasPool && canvasPool.length) {
canvas = opt_canvasPool.shift(); canvas = canvasPool.shift();
} else if (WORKER_OFFSCREEN_CANVAS) { } else if (WORKER_OFFSCREEN_CANVAS) {
canvas = new OffscreenCanvas(opt_width || 300, opt_height || 300); canvas = new OffscreenCanvas(width || 300, height || 300);
} else { } else {
canvas = document.createElement('canvas'); canvas = document.createElement('canvas');
} }
if (opt_width) { if (width) {
canvas.width = opt_width; canvas.width = width;
} }
if (opt_height) { if (height) {
canvas.height = opt_height; canvas.height = height;
} }
//FIXME Allow OffscreenCanvasRenderingContext2D as return type //FIXME Allow OffscreenCanvasRenderingContext2D as return type
return /** @type {CanvasRenderingContext2D} */ ( return /** @type {CanvasRenderingContext2D} */ (
canvas.getContext('2d', opt_Context2DSettings) canvas.getContext('2d', settings)
); );
} }

View File

@@ -39,16 +39,16 @@ import {clear} from './obj.js';
* @param {import("./events/Target.js").EventTargetLike} target Event target. * @param {import("./events/Target.js").EventTargetLike} target Event target.
* @param {string} type Event type. * @param {string} type Event type.
* @param {ListenerFunction} listener Listener. * @param {ListenerFunction} listener Listener.
* @param {Object} [opt_this] Object referenced by the `this` keyword in the * @param {Object} [thisArg] Object referenced by the `this` keyword in the
* listener. Default is the `target`. * listener. Default is the `target`.
* @param {boolean} [opt_once] If true, add the listener as one-off listener. * @param {boolean} [once] If true, add the listener as one-off listener.
* @return {EventsKey} Unique key for the listener. * @return {EventsKey} Unique key for the listener.
*/ */
export function listen(target, type, listener, opt_this, opt_once) { export function listen(target, type, listener, thisArg, once) {
if (opt_this && opt_this !== target) { if (thisArg && thisArg !== target) {
listener = listener.bind(opt_this); listener = listener.bind(thisArg);
} }
if (opt_once) { if (once) {
const originalListener = listener; const originalListener = listener;
listener = function () { listener = function () {
target.removeEventListener(type, listener); target.removeEventListener(type, listener);
@@ -80,12 +80,12 @@ export function listen(target, type, listener, opt_this, opt_once) {
* @param {import("./events/Target.js").EventTargetLike} target Event target. * @param {import("./events/Target.js").EventTargetLike} target Event target.
* @param {string} type Event type. * @param {string} type Event type.
* @param {ListenerFunction} listener Listener. * @param {ListenerFunction} listener Listener.
* @param {Object} [opt_this] Object referenced by the `this` keyword in the * @param {Object} [thisArg] Object referenced by the `this` keyword in the
* listener. Default is the `target`. * listener. Default is the `target`.
* @return {EventsKey} Key for unlistenByKey. * @return {EventsKey} Key for unlistenByKey.
*/ */
export function listenOnce(target, type, listener, opt_this) { export function listenOnce(target, type, listener, thisArg) {
return listen(target, type, listener, opt_this, true); return listen(target, type, listener, thisArg, true);
} }
/** /**

View File

@@ -27,16 +27,16 @@ import {clear} from '../obj.js';
*/ */
class Target extends Disposable { class Target extends Disposable {
/** /**
* @param {*} [opt_target] Default event target for dispatched events. * @param {*} [target] Default event target for dispatched events.
*/ */
constructor(opt_target) { constructor(target) {
super(); super();
/** /**
* @private * @private
* @type {*} * @type {*}
*/ */
this.eventTarget_ = opt_target; this.eventTarget_ = target;
/** /**
* @private * @private
@@ -148,16 +148,16 @@ class Target extends Disposable {
} }
/** /**
* @param {string} [opt_type] Type. If not provided, * @param {string} [type] Type. If not provided,
* `true` will be returned if this event target has any listeners. * `true` will be returned if this event target has any listeners.
* @return {boolean} Has listeners. * @return {boolean} Has listeners.
*/ */
hasListener(opt_type) { hasListener(type) {
if (!this.listeners_) { if (!this.listeners_) {
return false; return false;
} }
return opt_type return type
? opt_type in this.listeners_ ? type in this.listeners_
: Object.keys(this.listeners_).length > 0; : Object.keys(this.listeners_).length > 0;
} }

View File

@@ -33,33 +33,33 @@ export function boundingExtent(coordinates) {
/** /**
* @param {Array<number>} xs Xs. * @param {Array<number>} xs Xs.
* @param {Array<number>} ys Ys. * @param {Array<number>} ys Ys.
* @param {Extent} [opt_extent] Destination extent. * @param {Extent} [dest] Destination extent.
* @private * @private
* @return {Extent} Extent. * @return {Extent} Extent.
*/ */
function _boundingExtentXYs(xs, ys, opt_extent) { function _boundingExtentXYs(xs, ys, dest) {
const minX = Math.min.apply(null, xs); const minX = Math.min.apply(null, xs);
const minY = Math.min.apply(null, ys); const minY = Math.min.apply(null, ys);
const maxX = Math.max.apply(null, xs); const maxX = Math.max.apply(null, xs);
const maxY = Math.max.apply(null, ys); const maxY = Math.max.apply(null, ys);
return createOrUpdate(minX, minY, maxX, maxY, opt_extent); return createOrUpdate(minX, minY, maxX, maxY, dest);
} }
/** /**
* Return extent increased by the provided value. * Return extent increased by the provided value.
* @param {Extent} extent Extent. * @param {Extent} extent Extent.
* @param {number} value The amount by which the extent should be buffered. * @param {number} value The amount by which the extent should be buffered.
* @param {Extent} [opt_extent] Extent. * @param {Extent} [dest] Extent.
* @return {Extent} Extent. * @return {Extent} Extent.
* @api * @api
*/ */
export function buffer(extent, value, opt_extent) { export function buffer(extent, value, dest) {
if (opt_extent) { if (dest) {
opt_extent[0] = extent[0] - value; dest[0] = extent[0] - value;
opt_extent[1] = extent[1] - value; dest[1] = extent[1] - value;
opt_extent[2] = extent[2] + value; dest[2] = extent[2] + value;
opt_extent[3] = extent[3] + value; dest[3] = extent[3] + value;
return opt_extent; return dest;
} else { } else {
return [ return [
extent[0] - value, extent[0] - value,
@@ -74,16 +74,16 @@ export function buffer(extent, value, opt_extent) {
* Creates a clone of an extent. * Creates a clone of an extent.
* *
* @param {Extent} extent Extent to clone. * @param {Extent} extent Extent to clone.
* @param {Extent} [opt_extent] Extent. * @param {Extent} [dest] Extent.
* @return {Extent} The clone. * @return {Extent} The clone.
*/ */
export function clone(extent, opt_extent) { export function clone(extent, dest) {
if (opt_extent) { if (dest) {
opt_extent[0] = extent[0]; dest[0] = extent[0];
opt_extent[1] = extent[1]; dest[1] = extent[1];
opt_extent[2] = extent[2]; dest[2] = extent[2];
opt_extent[3] = extent[3]; dest[3] = extent[3];
return opt_extent; return dest;
} else { } else {
return extent.slice(); return extent.slice();
} }
@@ -206,16 +206,16 @@ export function createEmpty() {
* @param {number} minY Minimum Y. * @param {number} minY Minimum Y.
* @param {number} maxX Maximum X. * @param {number} maxX Maximum X.
* @param {number} maxY Maximum Y. * @param {number} maxY Maximum Y.
* @param {Extent} [opt_extent] Destination extent. * @param {Extent} [dest] Destination extent.
* @return {Extent} Extent. * @return {Extent} Extent.
*/ */
export function createOrUpdate(minX, minY, maxX, maxY, opt_extent) { export function createOrUpdate(minX, minY, maxX, maxY, dest) {
if (opt_extent) { if (dest) {
opt_extent[0] = minX; dest[0] = minX;
opt_extent[1] = minY; dest[1] = minY;
opt_extent[2] = maxX; dest[2] = maxX;
opt_extent[3] = maxY; dest[3] = maxY;
return opt_extent; return dest;
} else { } else {
return [minX, minY, maxX, maxY]; return [minX, minY, maxX, maxY];
} }
@@ -223,31 +223,31 @@ export function createOrUpdate(minX, minY, maxX, maxY, opt_extent) {
/** /**
* Create a new empty extent or make the provided one empty. * Create a new empty extent or make the provided one empty.
* @param {Extent} [opt_extent] Extent. * @param {Extent} [dest] Extent.
* @return {Extent} Extent. * @return {Extent} Extent.
*/ */
export function createOrUpdateEmpty(opt_extent) { export function createOrUpdateEmpty(dest) {
return createOrUpdate(Infinity, Infinity, -Infinity, -Infinity, opt_extent); return createOrUpdate(Infinity, Infinity, -Infinity, -Infinity, dest);
} }
/** /**
* @param {import("./coordinate.js").Coordinate} coordinate Coordinate. * @param {import("./coordinate.js").Coordinate} coordinate Coordinate.
* @param {Extent} [opt_extent] Extent. * @param {Extent} [dest] Extent.
* @return {Extent} Extent. * @return {Extent} Extent.
*/ */
export function createOrUpdateFromCoordinate(coordinate, opt_extent) { export function createOrUpdateFromCoordinate(coordinate, dest) {
const x = coordinate[0]; const x = coordinate[0];
const y = coordinate[1]; const y = coordinate[1];
return createOrUpdate(x, y, x, y, opt_extent); return createOrUpdate(x, y, x, y, dest);
} }
/** /**
* @param {Array<import("./coordinate.js").Coordinate>} coordinates Coordinates. * @param {Array<import("./coordinate.js").Coordinate>} coordinates Coordinates.
* @param {Extent} [opt_extent] Extent. * @param {Extent} [dest] Extent.
* @return {Extent} Extent. * @return {Extent} Extent.
*/ */
export function createOrUpdateFromCoordinates(coordinates, opt_extent) { export function createOrUpdateFromCoordinates(coordinates, dest) {
const extent = createOrUpdateEmpty(opt_extent); const extent = createOrUpdateEmpty(dest);
return extendCoordinates(extent, coordinates); return extendCoordinates(extent, coordinates);
} }
@@ -256,7 +256,7 @@ export function createOrUpdateFromCoordinates(coordinates, opt_extent) {
* @param {number} offset Offset. * @param {number} offset Offset.
* @param {number} end End. * @param {number} end End.
* @param {number} stride Stride. * @param {number} stride Stride.
* @param {Extent} [opt_extent] Extent. * @param {Extent} [dest] Extent.
* @return {Extent} Extent. * @return {Extent} Extent.
*/ */
export function createOrUpdateFromFlatCoordinates( export function createOrUpdateFromFlatCoordinates(
@@ -264,19 +264,19 @@ export function createOrUpdateFromFlatCoordinates(
offset, offset,
end, end,
stride, stride,
opt_extent dest
) { ) {
const extent = createOrUpdateEmpty(opt_extent); const extent = createOrUpdateEmpty(dest);
return extendFlatCoordinates(extent, flatCoordinates, offset, end, stride); return extendFlatCoordinates(extent, flatCoordinates, offset, end, stride);
} }
/** /**
* @param {Array<Array<import("./coordinate.js").Coordinate>>} rings Rings. * @param {Array<Array<import("./coordinate.js").Coordinate>>} rings Rings.
* @param {Extent} [opt_extent] Extent. * @param {Extent} [dest] Extent.
* @return {Extent} Extent. * @return {Extent} Extent.
*/ */
export function createOrUpdateFromRings(rings, opt_extent) { export function createOrUpdateFromRings(rings, dest) {
const extent = createOrUpdateEmpty(opt_extent); const extent = createOrUpdateEmpty(dest);
return extendRings(extent, rings); return extendRings(extent, rings);
} }
@@ -525,16 +525,10 @@ export function getEnlargedArea(extent1, extent2) {
* @param {number} resolution Resolution. * @param {number} resolution Resolution.
* @param {number} rotation Rotation. * @param {number} rotation Rotation.
* @param {import("./size.js").Size} size Size. * @param {import("./size.js").Size} size Size.
* @param {Extent} [opt_extent] Destination extent. * @param {Extent} [dest] Destination extent.
* @return {Extent} Extent. * @return {Extent} Extent.
*/ */
export function getForViewAndSize( export function getForViewAndSize(center, resolution, rotation, size, dest) {
center,
resolution,
rotation,
size,
opt_extent
) {
const [x0, y0, x1, y1, x2, y2, x3, y3] = getRotatedViewport( const [x0, y0, x1, y1, x2, y2, x3, y3] = getRotatedViewport(
center, center,
resolution, resolution,
@@ -546,7 +540,7 @@ export function getForViewAndSize(
Math.min(y0, y1, y2, y3), Math.min(y0, y1, y2, y3),
Math.max(x0, x1, x2, x3), Math.max(x0, x1, x2, x3),
Math.max(y0, y1, y2, y3), Math.max(y0, y1, y2, y3),
opt_extent dest
); );
} }
@@ -606,12 +600,12 @@ export function getIntersectionArea(extent1, extent2) {
* Get the intersection of two extents. * Get the intersection of two extents.
* @param {Extent} extent1 Extent 1. * @param {Extent} extent1 Extent 1.
* @param {Extent} extent2 Extent 2. * @param {Extent} extent2 Extent 2.
* @param {Extent} [opt_extent] Optional extent to populate with intersection. * @param {Extent} [dest] Optional extent to populate with intersection.
* @return {Extent} Intersecting extent. * @return {Extent} Intersecting extent.
* @api * @api
*/ */
export function getIntersection(extent1, extent2, opt_extent) { export function getIntersection(extent1, extent2, dest) {
const intersection = opt_extent ? opt_extent : createEmpty(); const intersection = dest ? dest : createEmpty();
if (intersects(extent1, extent2)) { if (intersects(extent1, extent2)) {
if (extent1[0] > extent2[0]) { if (extent1[0] > extent2[0]) {
intersection[0] = extent1[0]; intersection[0] = extent1[0];
@@ -715,16 +709,16 @@ export function isEmpty(extent) {
/** /**
* @param {Extent} extent Extent. * @param {Extent} extent Extent.
* @param {Extent} [opt_extent] Extent. * @param {Extent} [dest] Extent.
* @return {Extent} Extent. * @return {Extent} Extent.
*/ */
export function returnOrUpdate(extent, opt_extent) { export function returnOrUpdate(extent, dest) {
if (opt_extent) { if (dest) {
opt_extent[0] = extent[0]; dest[0] = extent[0];
opt_extent[1] = extent[1]; dest[1] = extent[1];
opt_extent[2] = extent[2]; dest[2] = extent[2];
opt_extent[3] = extent[3]; dest[3] = extent[3];
return opt_extent; return dest;
} else { } else {
return extent; return extent;
} }
@@ -812,27 +806,27 @@ export function intersectsSegment(extent, start, end) {
* @param {Extent} extent Extent. * @param {Extent} extent Extent.
* @param {import("./proj.js").TransformFunction} transformFn Transform function. * @param {import("./proj.js").TransformFunction} transformFn Transform function.
* Called with `[minX, minY, maxX, maxY]` extent coordinates. * Called with `[minX, minY, maxX, maxY]` extent coordinates.
* @param {Extent} [opt_extent] Destination extent. * @param {Extent} [dest] Destination extent.
* @param {number} [opt_stops] Number of stops per side used for the transform. * @param {number} [stops] Number of stops per side used for the transform.
* By default only the corners are used. * By default only the corners are used.
* @return {Extent} Extent. * @return {Extent} Extent.
* @api * @api
*/ */
export function applyTransform(extent, transformFn, opt_extent, opt_stops) { export function applyTransform(extent, transformFn, dest, stops) {
let coordinates = []; let coordinates = [];
if (opt_stops > 1) { if (stops > 1) {
const width = extent[2] - extent[0]; const width = extent[2] - extent[0];
const height = extent[3] - extent[1]; const height = extent[3] - extent[1];
for (let i = 0; i < opt_stops; ++i) { for (let i = 0; i < stops; ++i) {
coordinates.push( coordinates.push(
extent[0] + (width * i) / opt_stops, extent[0] + (width * i) / stops,
extent[1], extent[1],
extent[2], extent[2],
extent[1] + (height * i) / opt_stops, extent[1] + (height * i) / stops,
extent[2] - (width * i) / opt_stops, extent[2] - (width * i) / stops,
extent[3], extent[3],
extent[0], extent[0],
extent[3] - (height * i) / opt_stops extent[3] - (height * i) / stops
); );
} }
} else { } else {
@@ -854,7 +848,7 @@ export function applyTransform(extent, transformFn, opt_extent, opt_stops) {
xs.push(coordinates[i]); xs.push(coordinates[i]);
ys.push(coordinates[i + 1]); ys.push(coordinates[i + 1]);
} }
return _boundingExtentXYs(xs, ys, opt_extent); return _boundingExtentXYs(xs, ys, dest);
} }
/** /**

View File

@@ -78,10 +78,10 @@ const GEOMETRY_WRITERS = {
*/ */
class EsriJSON extends JSONFeature { class EsriJSON extends JSONFeature {
/** /**
* @param {Options} [opt_options] Options. * @param {Options} [options] Options.
*/ */
constructor(opt_options) { constructor(options) {
const options = opt_options ? opt_options : {}; options = options ? options : {};
super(); super();
@@ -95,14 +95,14 @@ class EsriJSON extends JSONFeature {
/** /**
* @param {Object} object Object. * @param {Object} object Object.
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options. * @param {import("./Feature.js").ReadOptions} [options] Read options.
* @param {string} [opt_idField] Name of the field where to get the id from. * @param {string} [idField] Name of the field where to get the id from.
* @protected * @protected
* @return {import("../Feature.js").default} Feature. * @return {import("../Feature.js").default} Feature.
*/ */
readFeatureFromObject(object, opt_options, opt_idField) { readFeatureFromObject(object, options, idField) {
const esriJSONFeature = /** @type {EsriJSONFeature} */ (object); const esriJSONFeature = /** @type {EsriJSONFeature} */ (object);
const geometry = readGeometry(esriJSONFeature.geometry, opt_options); const geometry = readGeometry(esriJSONFeature.geometry, options);
const feature = new Feature(); const feature = new Feature();
if (this.geometryName_) { if (this.geometryName_) {
feature.setGeometryName(this.geometryName_); feature.setGeometryName(this.geometryName_);
@@ -110,7 +110,7 @@ class EsriJSON extends JSONFeature {
feature.setGeometry(geometry); feature.setGeometry(geometry);
if (esriJSONFeature.attributes) { if (esriJSONFeature.attributes) {
feature.setProperties(esriJSONFeature.attributes, true); feature.setProperties(esriJSONFeature.attributes, true);
const id = esriJSONFeature.attributes[opt_idField]; const id = esriJSONFeature.attributes[idField];
if (id !== undefined) { if (id !== undefined) {
feature.setId(/** @type {number} */ (id)); feature.setId(/** @type {number} */ (id));
} }
@@ -120,12 +120,12 @@ class EsriJSON extends JSONFeature {
/** /**
* @param {Object} object Object. * @param {Object} object Object.
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options. * @param {import("./Feature.js").ReadOptions} [options] Read options.
* @protected * @protected
* @return {Array<Feature>} Features. * @return {Array<Feature>} Features.
*/ */
readFeaturesFromObject(object, opt_options) { readFeaturesFromObject(object, options) {
const options = opt_options ? opt_options : {}; options = options ? options : {};
if (object['features']) { if (object['features']) {
const esriJSONFeatureSet = /** @type {EsriJSONFeatureSet} */ (object); const esriJSONFeatureSet = /** @type {EsriJSONFeatureSet} */ (object);
/** @type {Array<import("../Feature.js").default>} */ /** @type {Array<import("../Feature.js").default>} */
@@ -148,12 +148,12 @@ class EsriJSON extends JSONFeature {
/** /**
* @param {EsriJSONGeometry} object Object. * @param {EsriJSONGeometry} object Object.
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options. * @param {import("./Feature.js").ReadOptions} [options] Read options.
* @protected * @protected
* @return {import("../geom/Geometry.js").default} Geometry. * @return {import("../geom/Geometry.js").default} Geometry.
*/ */
readGeometryFromObject(object, opt_options) { readGeometryFromObject(object, options) {
return readGeometry(object, opt_options); return readGeometry(object, options);
} }
/** /**
@@ -180,24 +180,24 @@ class EsriJSON extends JSONFeature {
* Encode a geometry as a EsriJSON object. * Encode a geometry as a EsriJSON object.
* *
* @param {import("../geom/Geometry.js").default} geometry Geometry. * @param {import("../geom/Geometry.js").default} geometry Geometry.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @return {EsriJSONGeometry} Object. * @return {EsriJSONGeometry} Object.
* @api * @api
*/ */
writeGeometryObject(geometry, opt_options) { writeGeometryObject(geometry, options) {
return writeGeometry(geometry, this.adaptOptions(opt_options)); return writeGeometry(geometry, this.adaptOptions(options));
} }
/** /**
* Encode a feature as a esriJSON Feature object. * Encode a feature as a esriJSON Feature object.
* *
* @param {import("../Feature.js").default} feature Feature. * @param {import("../Feature.js").default} feature Feature.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @return {Object} Object. * @return {Object} Object.
* @api * @api
*/ */
writeFeatureObject(feature, opt_options) { writeFeatureObject(feature, options) {
opt_options = this.adaptOptions(opt_options); options = this.adaptOptions(options);
const object = {}; const object = {};
if (!feature.hasProperties()) { if (!feature.hasProperties()) {
object['attributes'] = {}; object['attributes'] = {};
@@ -206,10 +206,9 @@ class EsriJSON extends JSONFeature {
const properties = feature.getProperties(); const properties = feature.getProperties();
const geometry = feature.getGeometry(); const geometry = feature.getGeometry();
if (geometry) { if (geometry) {
object['geometry'] = writeGeometry(geometry, opt_options); object['geometry'] = writeGeometry(geometry, options);
const projection = const projection =
opt_options && options && (options.dataProjection || options.featureProjection);
(opt_options.dataProjection || opt_options.featureProjection);
if (projection) { if (projection) {
object['geometry']['spatialReference'] = object['geometry']['spatialReference'] =
/** @type {EsriJSONSpatialReferenceWkid} */ ({ /** @type {EsriJSONSpatialReferenceWkid} */ ({
@@ -230,15 +229,15 @@ class EsriJSON extends JSONFeature {
* Encode an array of features as a EsriJSON object. * Encode an array of features as a EsriJSON object.
* *
* @param {Array<import("../Feature.js").default>} features Features. * @param {Array<import("../Feature.js").default>} features Features.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @return {EsriJSONFeatureSet} EsriJSON Object. * @return {EsriJSONFeatureSet} EsriJSON Object.
* @api * @api
*/ */
writeFeaturesObject(features, opt_options) { writeFeaturesObject(features, options) {
opt_options = this.adaptOptions(opt_options); options = this.adaptOptions(options);
const objects = []; const objects = [];
for (let i = 0, ii = features.length; i < ii; ++i) { for (let i = 0, ii = features.length; i < ii; ++i) {
objects.push(this.writeFeatureObject(features[i], opt_options)); objects.push(this.writeFeatureObject(features[i], options));
} }
return { return {
'features': objects, 'features': objects,
@@ -248,10 +247,10 @@ class EsriJSON extends JSONFeature {
/** /**
* @param {EsriJSONGeometry} object Object. * @param {EsriJSONGeometry} object Object.
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options. * @param {import("./Feature.js").ReadOptions} [options] Read options.
* @return {import("../geom/Geometry.js").default} Geometry. * @return {import("../geom/Geometry.js").default} Geometry.
*/ */
function readGeometry(object, opt_options) { function readGeometry(object, options) {
if (!object) { if (!object) {
return null; return null;
} }
@@ -281,11 +280,7 @@ function readGeometry(object, opt_options) {
} }
} }
const geometryReader = GEOMETRY_READERS[type]; const geometryReader = GEOMETRY_READERS[type];
return transformGeometryWithOptions( return transformGeometryWithOptions(geometryReader(object), false, options);
geometryReader(object),
false,
opt_options
);
} }
/** /**
@@ -426,10 +421,10 @@ function readPolygonGeometry(object) {
/** /**
* @param {import("../geom/Point.js").default} geometry Geometry. * @param {import("../geom/Point.js").default} geometry Geometry.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @return {EsriJSONPoint} EsriJSON geometry. * @return {EsriJSONPoint} EsriJSON geometry.
*/ */
function writePointGeometry(geometry, opt_options) { function writePointGeometry(geometry, options) {
const coordinates = geometry.getCoordinates(); const coordinates = geometry.getCoordinates();
/** @type {EsriJSONPoint} */ /** @type {EsriJSONPoint} */
let esriJSON; let esriJSON;
@@ -478,10 +473,10 @@ function getHasZM(geometry) {
/** /**
* @param {import("../geom/LineString.js").default} lineString Geometry. * @param {import("../geom/LineString.js").default} lineString Geometry.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @return {EsriJSONPolyline} EsriJSON geometry. * @return {EsriJSONPolyline} EsriJSON geometry.
*/ */
function writeLineStringGeometry(lineString, opt_options) { function writeLineStringGeometry(lineString, options) {
const hasZM = getHasZM(lineString); const hasZM = getHasZM(lineString);
return { return {
hasZ: hasZM.hasZ, hasZ: hasZM.hasZ,
@@ -494,10 +489,10 @@ function writeLineStringGeometry(lineString, opt_options) {
/** /**
* @param {import("../geom/Polygon.js").default} polygon Geometry. * @param {import("../geom/Polygon.js").default} polygon Geometry.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @return {EsriJSONPolygon} EsriJSON geometry. * @return {EsriJSONPolygon} EsriJSON geometry.
*/ */
function writePolygonGeometry(polygon, opt_options) { function writePolygonGeometry(polygon, options) {
// Esri geometries use the left-hand rule // Esri geometries use the left-hand rule
const hasZM = getHasZM(polygon); const hasZM = getHasZM(polygon);
return { return {
@@ -511,10 +506,10 @@ function writePolygonGeometry(polygon, opt_options) {
/** /**
* @param {import("../geom/MultiLineString.js").default} multiLineString Geometry. * @param {import("../geom/MultiLineString.js").default} multiLineString Geometry.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @return {EsriJSONPolyline} EsriJSON geometry. * @return {EsriJSONPolyline} EsriJSON geometry.
*/ */
function writeMultiLineStringGeometry(multiLineString, opt_options) { function writeMultiLineStringGeometry(multiLineString, options) {
const hasZM = getHasZM(multiLineString); const hasZM = getHasZM(multiLineString);
return { return {
hasZ: hasZM.hasZ, hasZ: hasZM.hasZ,
@@ -527,10 +522,10 @@ function writeMultiLineStringGeometry(multiLineString, opt_options) {
/** /**
* @param {import("../geom/MultiPoint.js").default} multiPoint Geometry. * @param {import("../geom/MultiPoint.js").default} multiPoint Geometry.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @return {EsriJSONMultipoint} EsriJSON geometry. * @return {EsriJSONMultipoint} EsriJSON geometry.
*/ */
function writeMultiPointGeometry(multiPoint, opt_options) { function writeMultiPointGeometry(multiPoint, options) {
const hasZM = getHasZM(multiPoint); const hasZM = getHasZM(multiPoint);
return { return {
hasZ: hasZM.hasZ, hasZ: hasZM.hasZ,
@@ -543,10 +538,10 @@ function writeMultiPointGeometry(multiPoint, opt_options) {
/** /**
* @param {import("../geom/MultiPolygon.js").default} geometry Geometry. * @param {import("../geom/MultiPolygon.js").default} geometry Geometry.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @return {EsriJSONPolygon} EsriJSON geometry. * @return {EsriJSONPolygon} EsriJSON geometry.
*/ */
function writeMultiPolygonGeometry(geometry, opt_options) { function writeMultiPolygonGeometry(geometry, options) {
const hasZM = getHasZM(geometry); const hasZM = getHasZM(geometry);
const coordinates = geometry.getCoordinates(false); const coordinates = geometry.getCoordinates(false);
const output = []; const output = [];
@@ -564,14 +559,14 @@ function writeMultiPolygonGeometry(geometry, opt_options) {
/** /**
* @param {import("../geom/Geometry.js").default} geometry Geometry. * @param {import("../geom/Geometry.js").default} geometry Geometry.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @return {EsriJSONGeometry} EsriJSON geometry. * @return {EsriJSONGeometry} EsriJSON geometry.
*/ */
function writeGeometry(geometry, opt_options) { function writeGeometry(geometry, options) {
const geometryWriter = GEOMETRY_WRITERS[geometry.getType()]; const geometryWriter = GEOMETRY_WRITERS[geometry.getType()];
return geometryWriter( return geometryWriter(
transformGeometryWithOptions(geometry, true, opt_options), transformGeometryWithOptions(geometry, true, options),
opt_options options
); );
} }

View File

@@ -89,27 +89,26 @@ class FeatureFormat {
/** /**
* Adds the data projection to the read options. * Adds the data projection to the read options.
* @param {Document|Element|Object|string} source Source. * @param {Document|Element|Object|string} source Source.
* @param {ReadOptions} [opt_options] Options. * @param {ReadOptions} [options] Options.
* @return {ReadOptions|undefined} Options. * @return {ReadOptions|undefined} Options.
* @protected * @protected
*/ */
getReadOptions(source, opt_options) { getReadOptions(source, options) {
let options; if (options) {
if (opt_options) { let dataProjection = options.dataProjection
let dataProjection = opt_options.dataProjection ? getProjection(options.dataProjection)
? getProjection(opt_options.dataProjection)
: this.readProjection(source); : this.readProjection(source);
if ( if (
opt_options.extent && options.extent &&
dataProjection && dataProjection &&
dataProjection.getUnits() === 'tile-pixels' dataProjection.getUnits() === 'tile-pixels'
) { ) {
dataProjection = getProjection(dataProjection); dataProjection = getProjection(dataProjection);
dataProjection.setWorldExtent(opt_options.extent); dataProjection.setWorldExtent(options.extent);
} }
options = { options = {
dataProjection: dataProjection, dataProjection: dataProjection,
featureProjection: opt_options.featureProjection, featureProjection: options.featureProjection,
}; };
} }
return this.adaptOptions(options); return this.adaptOptions(options);
@@ -147,10 +146,10 @@ class FeatureFormat {
* *
* @abstract * @abstract
* @param {Document|Element|Object|string} source Source. * @param {Document|Element|Object|string} source Source.
* @param {ReadOptions} [opt_options] Read options. * @param {ReadOptions} [options] Read options.
* @return {import("../Feature.js").FeatureLike} Feature. * @return {import("../Feature.js").FeatureLike} Feature.
*/ */
readFeature(source, opt_options) { readFeature(source, options) {
return abstract(); return abstract();
} }
@@ -159,10 +158,10 @@ class FeatureFormat {
* *
* @abstract * @abstract
* @param {Document|Element|ArrayBuffer|Object|string} source Source. * @param {Document|Element|ArrayBuffer|Object|string} source Source.
* @param {ReadOptions} [opt_options] Read options. * @param {ReadOptions} [options] Read options.
* @return {Array<import("../Feature.js").FeatureLike>} Features. * @return {Array<import("../Feature.js").FeatureLike>} Features.
*/ */
readFeatures(source, opt_options) { readFeatures(source, options) {
return abstract(); return abstract();
} }
@@ -171,10 +170,10 @@ class FeatureFormat {
* *
* @abstract * @abstract
* @param {Document|Element|Object|string} source Source. * @param {Document|Element|Object|string} source Source.
* @param {ReadOptions} [opt_options] Read options. * @param {ReadOptions} [options] Read options.
* @return {import("../geom/Geometry.js").default} Geometry. * @return {import("../geom/Geometry.js").default} Geometry.
*/ */
readGeometry(source, opt_options) { readGeometry(source, options) {
return abstract(); return abstract();
} }
@@ -194,10 +193,10 @@ class FeatureFormat {
* *
* @abstract * @abstract
* @param {import("../Feature.js").default} feature Feature. * @param {import("../Feature.js").default} feature Feature.
* @param {WriteOptions} [opt_options] Write options. * @param {WriteOptions} [options] Write options.
* @return {string|ArrayBuffer} Result. * @return {string|ArrayBuffer} Result.
*/ */
writeFeature(feature, opt_options) { writeFeature(feature, options) {
return abstract(); return abstract();
} }
@@ -206,10 +205,10 @@ class FeatureFormat {
* *
* @abstract * @abstract
* @param {Array<import("../Feature.js").default>} features Features. * @param {Array<import("../Feature.js").default>} features Features.
* @param {WriteOptions} [opt_options] Write options. * @param {WriteOptions} [options] Write options.
* @return {string|ArrayBuffer} Result. * @return {string|ArrayBuffer} Result.
*/ */
writeFeatures(features, opt_options) { writeFeatures(features, options) {
return abstract(); return abstract();
} }
@@ -218,10 +217,10 @@ class FeatureFormat {
* *
* @abstract * @abstract
* @param {import("../geom/Geometry.js").default} geometry Geometry. * @param {import("../geom/Geometry.js").default} geometry Geometry.
* @param {WriteOptions} [opt_options] Write options. * @param {WriteOptions} [options] Write options.
* @return {string|ArrayBuffer} Result. * @return {string|ArrayBuffer} Result.
*/ */
writeGeometry(geometry, opt_options) { writeGeometry(geometry, options) {
return abstract(); return abstract();
} }
} }
@@ -231,16 +230,14 @@ export default FeatureFormat;
/** /**
* @param {import("../geom/Geometry.js").default} geometry Geometry. * @param {import("../geom/Geometry.js").default} geometry Geometry.
* @param {boolean} write Set to true for writing, false for reading. * @param {boolean} write Set to true for writing, false for reading.
* @param {WriteOptions|ReadOptions} [opt_options] Options. * @param {WriteOptions|ReadOptions} [options] Options.
* @return {import("../geom/Geometry.js").default} Transformed geometry. * @return {import("../geom/Geometry.js").default} Transformed geometry.
*/ */
export function transformGeometryWithOptions(geometry, write, opt_options) { export function transformGeometryWithOptions(geometry, write, options) {
const featureProjection = opt_options const featureProjection = options
? getProjection(opt_options.featureProjection) ? getProjection(options.featureProjection)
: null;
const dataProjection = opt_options
? getProjection(opt_options.dataProjection)
: null; : null;
const dataProjection = options ? getProjection(options.dataProjection) : null;
let transformed; let transformed;
if ( if (
@@ -257,13 +254,10 @@ export function transformGeometryWithOptions(geometry, write, opt_options) {
} }
if ( if (
write && write &&
opt_options && options &&
/** @type {WriteOptions} */ (opt_options).decimals !== undefined /** @type {WriteOptions} */ (options).decimals !== undefined
) { ) {
const power = Math.pow( const power = Math.pow(10, /** @type {WriteOptions} */ (options).decimals);
10,
/** @type {WriteOptions} */ (opt_options).decimals
);
// if decimals option on write, round each coordinate appropriately // if decimals option on write, round each coordinate appropriately
/** /**
* @param {Array<number>} coordinates Coordinates. * @param {Array<number>} coordinates Coordinates.
@@ -285,16 +279,14 @@ export function transformGeometryWithOptions(geometry, write, opt_options) {
/** /**
* @param {import("../extent.js").Extent} extent Extent. * @param {import("../extent.js").Extent} extent Extent.
* @param {ReadOptions} [opt_options] Read options. * @param {ReadOptions} [options] Read options.
* @return {import("../extent.js").Extent} Transformed extent. * @return {import("../extent.js").Extent} Transformed extent.
*/ */
export function transformExtentWithOptions(extent, opt_options) { export function transformExtentWithOptions(extent, options) {
const featureProjection = opt_options const featureProjection = options
? getProjection(opt_options.featureProjection) ? getProjection(options.featureProjection)
: null;
const dataProjection = opt_options
? getProjection(opt_options.dataProjection)
: null; : null;
const dataProjection = options ? getProjection(options.dataProjection) : null;
if ( if (
featureProjection && featureProjection &&

View File

@@ -9,7 +9,7 @@ import GML3 from './GML3.js';
* Currently only supports GML 3.1.1 Simple Features profile. * Currently only supports GML 3.1.1 Simple Features profile.
* *
* @class * @class
* @param {import("./GMLBase.js").Options} [opt_options] * @param {import("./GMLBase.js").Options} [options]
* Optional configuration object. * Optional configuration object.
* @api * @api
*/ */
@@ -20,7 +20,7 @@ const GML = GML3;
* *
* @function * @function
* @param {Array<import("../Feature.js").default>} features Features. * @param {Array<import("../Feature.js").default>} features Features.
* @param {import("./Feature.js").WriteOptions} [opt_options] Options. * @param {import("./Feature.js").WriteOptions} [options] Options.
* @return {string} Result. * @return {string} Result.
* @api * @api
*/ */
@@ -31,7 +31,7 @@ GML.prototype.writeFeatures;
* *
* @function * @function
* @param {Array<import("../Feature.js").default>} features Features. * @param {Array<import("../Feature.js").default>} features Features.
* @param {import("./Feature.js").WriteOptions} [opt_options] Options. * @param {import("./Feature.js").WriteOptions} [options] Options.
* @return {Node} Node. * @return {Node} Node.
* @api * @api
*/ */

View File

@@ -48,12 +48,10 @@ const MULTIGEOMETRY_TO_MEMBER_NODENAME = {
*/ */
class GML2 extends GMLBase { class GML2 extends GMLBase {
/** /**
* @param {import("./GMLBase.js").Options} [opt_options] Optional configuration object. * @param {import("./GMLBase.js").Options} [options] Optional configuration object.
*/ */
constructor(opt_options) { constructor(options) {
const options = options = options ? options : {};
/** @type {import("./GMLBase.js").Options} */
(opt_options ? opt_options : {});
super(options); super(options);
@@ -171,16 +169,15 @@ class GML2 extends GMLBase {
* @const * @const
* @param {*} value Value. * @param {*} value Value.
* @param {Array<*>} objectStack Object stack. * @param {Array<*>} objectStack Object stack.
* @param {string} [opt_nodeName] Node name. * @param {string} [nodeName] Node name.
* @return {Element|undefined} Node. * @return {Element|undefined} Node.
* @private * @private
*/ */
GEOMETRY_NODE_FACTORY_(value, objectStack, opt_nodeName) { GEOMETRY_NODE_FACTORY_(value, objectStack, nodeName) {
const context = objectStack[objectStack.length - 1]; const context = objectStack[objectStack.length - 1];
const multiSurface = context['multiSurface']; const multiSurface = context['multiSurface'];
const surface = context['surface']; const surface = context['surface'];
const multiCurve = context['multiCurve']; const multiCurve = context['multiCurve'];
let nodeName;
if (!Array.isArray(value)) { if (!Array.isArray(value)) {
nodeName = /** @type {import("../geom/Geometry.js").default} */ ( nodeName = /** @type {import("../geom/Geometry.js").default} */ (
value value
@@ -436,11 +433,11 @@ class GML2 extends GMLBase {
/** /**
* @param {*} value Value. * @param {*} value Value.
* @param {Array<*>} objectStack Object stack. * @param {Array<*>} objectStack Object stack.
* @param {string} [opt_nodeName] Node name. * @param {string} [nodeName] Node name.
* @return {Node} Node. * @return {Node} Node.
* @private * @private
*/ */
RING_NODE_FACTORY_(value, objectStack, opt_nodeName) { RING_NODE_FACTORY_(value, objectStack, nodeName) {
const context = objectStack[objectStack.length - 1]; const context = objectStack[objectStack.length - 1];
const parentNode = context.node; const parentNode = context.node;
const exteriorWritten = context['exteriorWritten']; const exteriorWritten = context['exteriorWritten'];
@@ -478,21 +475,21 @@ class GML2 extends GMLBase {
/** /**
* @param {Array<number>} point Point geometry. * @param {Array<number>} point Point geometry.
* @param {string} [opt_srsName] Optional srsName * @param {string} [srsName] Optional srsName
* @param {boolean} [opt_hasZ] whether the geometry has a Z coordinate (is 3D) or not. * @param {boolean} [hasZ] whether the geometry has a Z coordinate (is 3D) or not.
* @return {string} The coords string. * @return {string} The coords string.
* @private * @private
*/ */
getCoords_(point, opt_srsName, opt_hasZ) { getCoords_(point, srsName, hasZ) {
let axisOrientation = 'enu'; let axisOrientation = 'enu';
if (opt_srsName) { if (srsName) {
axisOrientation = getProjection(opt_srsName).getAxisOrientation(); axisOrientation = getProjection(srsName).getAxisOrientation();
} }
let coords = let coords =
axisOrientation.substr(0, 2) === 'en' axisOrientation.substr(0, 2) === 'en'
? point[0] + ',' + point[1] ? point[0] + ',' + point[1]
: point[1] + ',' + point[0]; : point[1] + ',' + point[0];
if (opt_hasZ) { if (hasZ) {
// For newly created points, Z can be undefined. // For newly created points, Z can be undefined.
const z = point[2] || 0; const z = point[2] || 0;
coords += ',' + z; coords += ',' + z;
@@ -638,11 +635,11 @@ class GML2 extends GMLBase {
* @const * @const
* @param {*} value Value. * @param {*} value Value.
* @param {Array<*>} objectStack Object stack. * @param {Array<*>} objectStack Object stack.
* @param {string} [opt_nodeName] Node name. * @param {string} [nodeName] Node name.
* @return {Node|undefined} Node. * @return {Node|undefined} Node.
* @private * @private
*/ */
MULTIGEOMETRY_MEMBER_NODE_FACTORY_(value, objectStack, opt_nodeName) { MULTIGEOMETRY_MEMBER_NODE_FACTORY_(value, objectStack, nodeName) {
const parentNode = objectStack[objectStack.length - 1].node; const parentNode = objectStack[objectStack.length - 1].node;
return createElementNS( return createElementNS(
'http://www.opengis.net/gml', 'http://www.opengis.net/gml',

View File

@@ -61,12 +61,10 @@ const MULTIGEOMETRY_TO_MEMBER_NODENAME = {
*/ */
class GML3 extends GMLBase { class GML3 extends GMLBase {
/** /**
* @param {import("./GMLBase.js").Options} [opt_options] Optional configuration object. * @param {import("./GMLBase.js").Options} [options] Optional configuration object.
*/ */
constructor(opt_options) { constructor(options) {
const options = options = options ? options : {};
/** @type {import("./GMLBase.js").Options} */
(opt_options ? opt_options : {});
super(options); super(options);
@@ -480,21 +478,21 @@ class GML3 extends GMLBase {
/** /**
* @param {Array<number>} point Point geometry. * @param {Array<number>} point Point geometry.
* @param {string} [opt_srsName] Optional srsName * @param {string} [srsName] Optional srsName
* @param {boolean} [opt_hasZ] whether the geometry has a Z coordinate (is 3D) or not. * @param {boolean} [hasZ] whether the geometry has a Z coordinate (is 3D) or not.
* @return {string} The coords string. * @return {string} The coords string.
* @private * @private
*/ */
getCoords_(point, opt_srsName, opt_hasZ) { getCoords_(point, srsName, hasZ) {
let axisOrientation = 'enu'; let axisOrientation = 'enu';
if (opt_srsName) { if (srsName) {
axisOrientation = getProjection(opt_srsName).getAxisOrientation(); axisOrientation = getProjection(srsName).getAxisOrientation();
} }
let coords = let coords =
axisOrientation.substr(0, 2) === 'en' axisOrientation.substr(0, 2) === 'en'
? point[0] + ' ' + point[1] ? point[0] + ' ' + point[1]
: point[1] + ' ' + point[0]; : point[1] + ' ' + point[0];
if (opt_hasZ) { if (hasZ) {
// For newly created points, Z can be undefined. // For newly created points, Z can be undefined.
const z = point[2] || 0; const z = point[2] || 0;
coords += ' ' + z; coords += ' ' + z;
@@ -587,11 +585,11 @@ class GML3 extends GMLBase {
/** /**
* @param {*} value Value. * @param {*} value Value.
* @param {Array<*>} objectStack Object stack. * @param {Array<*>} objectStack Object stack.
* @param {string} [opt_nodeName] Node name. * @param {string} [nodeName] Node name.
* @return {Node} Node. * @return {Node} Node.
* @private * @private
*/ */
RING_NODE_FACTORY_(value, objectStack, opt_nodeName) { RING_NODE_FACTORY_(value, objectStack, nodeName) {
const context = objectStack[objectStack.length - 1]; const context = objectStack[objectStack.length - 1];
const parentNode = context.node; const parentNode = context.node;
const exteriorWritten = context['exteriorWritten']; const exteriorWritten = context['exteriorWritten'];
@@ -933,11 +931,11 @@ class GML3 extends GMLBase {
* @const * @const
* @param {*} value Value. * @param {*} value Value.
* @param {Array<*>} objectStack Object stack. * @param {Array<*>} objectStack Object stack.
* @param {string} [opt_nodeName] Node name. * @param {string} [nodeName] Node name.
* @return {Node|undefined} Node. * @return {Node|undefined} Node.
* @private * @private
*/ */
MULTIGEOMETRY_MEMBER_NODE_FACTORY_(value, objectStack, opt_nodeName) { MULTIGEOMETRY_MEMBER_NODE_FACTORY_(value, objectStack, nodeName) {
const parentNode = objectStack[objectStack.length - 1].node; const parentNode = objectStack[objectStack.length - 1].node;
return createElementNS( return createElementNS(
this.namespace, this.namespace,
@@ -949,17 +947,16 @@ class GML3 extends GMLBase {
* @const * @const
* @param {*} value Value. * @param {*} value Value.
* @param {Array<*>} objectStack Object stack. * @param {Array<*>} objectStack Object stack.
* @param {string} [opt_nodeName] Node name. * @param {string} [nodeName] Node name.
* @return {Element|undefined} Node. * @return {Element|undefined} Node.
* @private * @private
*/ */
GEOMETRY_NODE_FACTORY_(value, objectStack, opt_nodeName) { GEOMETRY_NODE_FACTORY_(value, objectStack, nodeName) {
const context = objectStack[objectStack.length - 1]; const context = objectStack[objectStack.length - 1];
const multiSurface = context['multiSurface']; const multiSurface = context['multiSurface'];
const surface = context['surface']; const surface = context['surface'];
const curve = context['curve']; const curve = context['curve'];
const multiCurve = context['multiCurve']; const multiCurve = context['multiCurve'];
let nodeName;
if (!Array.isArray(value)) { if (!Array.isArray(value)) {
nodeName = /** @type {import("../geom/Geometry.js").default} */ ( nodeName = /** @type {import("../geom/Geometry.js").default} */ (
value value
@@ -983,12 +980,12 @@ class GML3 extends GMLBase {
* Encode a geometry in GML 3.1.1 Simple Features. * Encode a geometry in GML 3.1.1 Simple Features.
* *
* @param {import("../geom/Geometry.js").default} geometry Geometry. * @param {import("../geom/Geometry.js").default} geometry Geometry.
* @param {import("./Feature.js").WriteOptions} [opt_options] Options. * @param {import("./Feature.js").WriteOptions} [options] Options.
* @return {Node} Node. * @return {Node} Node.
* @api * @api
*/ */
writeGeometryNode(geometry, opt_options) { writeGeometryNode(geometry, options) {
opt_options = this.adaptOptions(opt_options); options = this.adaptOptions(options);
const geom = createElementNS(this.namespace, 'geom'); const geom = createElementNS(this.namespace, 'geom');
const context = { const context = {
node: geom, node: geom,
@@ -999,8 +996,8 @@ class GML3 extends GMLBase {
multiSurface: this.multiSurface_, multiSurface: this.multiSurface_,
multiCurve: this.multiCurve_, multiCurve: this.multiCurve_,
}; };
if (opt_options) { if (options) {
Object.assign(context, opt_options); Object.assign(context, options);
} }
this.writeGeometryElement(geom, geometry, [context]); this.writeGeometryElement(geom, geometry, [context]);
return geom; return geom;
@@ -1010,12 +1007,12 @@ class GML3 extends GMLBase {
* Encode an array of features in the GML 3.1.1 format as an XML node. * 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 {Array<import("../Feature.js").default>} features Features.
* @param {import("./Feature.js").WriteOptions} [opt_options] Options. * @param {import("./Feature.js").WriteOptions} [options] Options.
* @return {Element} Node. * @return {Element} Node.
* @api * @api
*/ */
writeFeaturesNode(features, opt_options) { writeFeaturesNode(features, options) {
opt_options = this.adaptOptions(opt_options); options = this.adaptOptions(options);
const node = createElementNS(this.namespace, 'featureMembers'); const node = createElementNS(this.namespace, 'featureMembers');
node.setAttributeNS( node.setAttributeNS(
XML_SCHEMA_INSTANCE_URI, XML_SCHEMA_INSTANCE_URI,
@@ -1032,8 +1029,8 @@ class GML3 extends GMLBase {
featureNS: this.featureNS, featureNS: this.featureNS,
featureType: this.featureType, featureType: this.featureType,
}; };
if (opt_options) { if (options) {
Object.assign(context, opt_options); Object.assign(context, options);
} }
this.writeFeatureMembers_(node, features, [context]); this.writeFeatureMembers_(node, features, [context]);
return node; return node;
@@ -1197,7 +1194,7 @@ GMLBase.prototype.RING_PARSERS = {
* *
* @function * @function
* @param {Array<import("../Feature.js").default>} features Features. * @param {Array<import("../Feature.js").default>} features Features.
* @param {import("./Feature.js").WriteOptions} [opt_options] Options. * @param {import("./Feature.js").WriteOptions} [options] Options.
* @return {string} Result. * @return {string} Result.
* @api * @api
*/ */

View File

@@ -19,12 +19,10 @@ import {writeStringTextNode} from '../format/xsd.js';
*/ */
class GML32 extends GML3 { class GML32 extends GML3 {
/** /**
* @param {import("./GMLBase.js").Options} [opt_options] Optional configuration object. * @param {import("./GMLBase.js").Options} [options] Optional configuration object.
*/ */
constructor(opt_options) { constructor(options) {
const options = /** @type {import("./GMLBase.js").Options} */ ( options = options ? options : {};
opt_options ? opt_options : {}
);
super(options); super(options);

View File

@@ -61,7 +61,7 @@ const ONLY_WHITESPACE_RE = /^\s*$/;
* So for instance there might be a featureType item `topp:states` and then * So for instance there might be a featureType item `topp:states` and then
* there will be a key named `topp` in the featureNS object with value * there will be a key named `topp` in the featureNS object with value
* `http://www.openplans.org/topp`. * `http://www.openplans.org/topp`.
* @property {string} srsName srsName to use when writing geometries. * @property {string} [srsName] srsName to use when writing geometries.
* @property {boolean} [surface=false] Write gml:Surface instead of gml:Polygon * @property {boolean} [surface=false] Write gml:Surface instead of gml:Polygon
* elements. This also affects the elements in multi-part geometries. * elements. This also affects the elements in multi-part geometries.
* @property {boolean} [curve=false] Write gml:Curve instead of gml:LineString * @property {boolean} [curve=false] Write gml:Curve instead of gml:LineString
@@ -88,12 +88,12 @@ const ONLY_WHITESPACE_RE = /^\s*$/;
*/ */
class GMLBase extends XMLFeature { class GMLBase extends XMLFeature {
/** /**
* @param {Options} [opt_options] Optional configuration object. * @param {Options} [options] Optional configuration object.
*/ */
constructor(opt_options) { constructor(options) {
super(); super();
const options = /** @type {Options} */ (opt_options ? opt_options : {}); options = options ? options : {};
/** /**
* @protected * @protected
@@ -109,7 +109,7 @@ class GMLBase extends XMLFeature {
/** /**
* @protected * @protected
* @type {string} * @type {string|undefined}
*/ */
this.srsName = options.srsName; this.srsName = options.srsName;
@@ -542,31 +542,31 @@ class GMLBase extends XMLFeature {
/** /**
* @param {Element} node Node. * @param {Element} node Node.
* @param {import("./Feature.js").ReadOptions} [opt_options] Options. * @param {import("./Feature.js").ReadOptions} [options] Options.
* @protected * @protected
* @return {import("../geom/Geometry.js").default} Geometry. * @return {import("../geom/Geometry.js").default} Geometry.
*/ */
readGeometryFromNode(node, opt_options) { readGeometryFromNode(node, options) {
const geometry = this.readGeometryElement(node, [ const geometry = this.readGeometryElement(node, [
this.getReadOptions(node, opt_options ? opt_options : {}), this.getReadOptions(node, options ? options : {}),
]); ]);
return geometry ? geometry : null; return geometry ? geometry : null;
} }
/** /**
* @param {Element} node Node. * @param {Element} node Node.
* @param {import("./Feature.js").ReadOptions} [opt_options] Options. * @param {import("./Feature.js").ReadOptions} [options] Options.
* @return {Array<import("../Feature.js").default>} Features. * @return {Array<import("../Feature.js").default>} Features.
*/ */
readFeaturesFromNode(node, opt_options) { readFeaturesFromNode(node, options) {
const options = { const internalOptions = {
featureType: this.featureType, featureType: this.featureType,
featureNS: this.featureNS, featureNS: this.featureNS,
}; };
if (opt_options) { if (internalOptions) {
Object.assign(options, this.getReadOptions(node, opt_options)); Object.assign(internalOptions, this.getReadOptions(node, options));
} }
const features = this.readFeaturesInternal(node, [options]); const features = this.readFeaturesInternal(node, [internalOptions]);
return features || []; return features || [];
} }

View File

@@ -128,12 +128,12 @@ const GPX_SERIALIZERS = makeStructureNS(NAMESPACE_URIS, {
*/ */
class GPX extends XMLFeature { class GPX extends XMLFeature {
/** /**
* @param {Options} [opt_options] Options. * @param {Options} [options] Options.
*/ */
constructor(opt_options) { constructor(options) {
super(); super();
const options = opt_options ? opt_options : {}; options = options ? options : {};
/** /**
* @type {import("../proj/Projection.js").default} * @type {import("../proj/Projection.js").default}
@@ -167,10 +167,10 @@ class GPX extends XMLFeature {
/** /**
* @param {Element} node Node. * @param {Element} node Node.
* @param {import("./Feature.js").ReadOptions} [opt_options] Options. * @param {import("./Feature.js").ReadOptions} [options] Options.
* @return {import("../Feature.js").default} Feature. * @return {import("../Feature.js").default} Feature.
*/ */
readFeatureFromNode(node, opt_options) { readFeatureFromNode(node, options) {
if (!NAMESPACE_URIS.includes(node.namespaceURI)) { if (!NAMESPACE_URIS.includes(node.namespaceURI)) {
return null; return null;
} }
@@ -178,9 +178,7 @@ class GPX extends XMLFeature {
if (!featureReader) { if (!featureReader) {
return null; return null;
} }
const feature = featureReader(node, [ const feature = featureReader(node, [this.getReadOptions(node, options)]);
this.getReadOptions(node, opt_options),
]);
if (!feature) { if (!feature) {
return null; return null;
} }
@@ -190,17 +188,17 @@ class GPX extends XMLFeature {
/** /**
* @param {Element} node Node. * @param {Element} node Node.
* @param {import("./Feature.js").ReadOptions} [opt_options] Options. * @param {import("./Feature.js").ReadOptions} [options] Options.
* @return {Array<import("../Feature.js").default>} Features. * @return {Array<import("../Feature.js").default>} Features.
*/ */
readFeaturesFromNode(node, opt_options) { readFeaturesFromNode(node, options) {
if (!NAMESPACE_URIS.includes(node.namespaceURI)) { if (!NAMESPACE_URIS.includes(node.namespaceURI)) {
return []; return [];
} }
if (node.localName == 'gpx') { if (node.localName == 'gpx') {
/** @type {Array<Feature>} */ /** @type {Array<Feature>} */
const features = pushParseAndPop([], GPX_PARSERS, node, [ const features = pushParseAndPop([], GPX_PARSERS, node, [
this.getReadOptions(node, opt_options), this.getReadOptions(node, options),
]); ]);
if (features) { if (features) {
this.handleReadExtensions_(features); this.handleReadExtensions_(features);
@@ -218,12 +216,12 @@ class GPX extends XMLFeature {
* as tracks (`<trk>`). * as tracks (`<trk>`).
* *
* @param {Array<Feature>} features Features. * @param {Array<Feature>} features Features.
* @param {import("./Feature.js").WriteOptions} [opt_options] Options. * @param {import("./Feature.js").WriteOptions} [options] Options.
* @return {Node} Node. * @return {Node} Node.
* @api * @api
*/ */
writeFeaturesNode(features, opt_options) { writeFeaturesNode(features, options) {
opt_options = this.adaptOptions(opt_options); options = this.adaptOptions(options);
//FIXME Serialize metadata //FIXME Serialize metadata
const gpx = createElementNS('http://www.topografix.com/GPX/1/1', 'gpx'); const gpx = createElementNS('http://www.topografix.com/GPX/1/1', 'gpx');
const xmlnsUri = 'http://www.w3.org/2000/xmlns/'; const xmlnsUri = 'http://www.w3.org/2000/xmlns/';
@@ -242,7 +240,7 @@ class GPX extends XMLFeature {
GPX_SERIALIZERS, GPX_SERIALIZERS,
GPX_NODE_FACTORY, GPX_NODE_FACTORY,
features, features,
[opt_options] [options]
); );
return gpx; return gpx;
} }
@@ -505,10 +503,10 @@ const GEOMETRY_TYPE_TO_NODENAME = {
/** /**
* @param {*} value Value. * @param {*} value Value.
* @param {Array<*>} objectStack Object stack. * @param {Array<*>} objectStack Object stack.
* @param {string} [opt_nodeName] Node name. * @param {string} [nodeName] Node name.
* @return {Node|undefined} Node. * @return {Node|undefined} Node.
*/ */
function GPX_NODE_FACTORY(value, objectStack, opt_nodeName) { function GPX_NODE_FACTORY(value, objectStack, nodeName) {
const geometry = /** @type {Feature} */ (value).getGeometry(); const geometry = /** @type {Feature} */ (value).getGeometry();
if (geometry) { if (geometry) {
const nodeName = GEOMETRY_TYPE_TO_NODENAME[geometry.getType()]; const nodeName = GEOMETRY_TYPE_TO_NODENAME[geometry.getType()];

View File

@@ -50,10 +50,10 @@ import {transformGeometryWithOptions} from './Feature.js';
*/ */
class GeoJSON extends JSONFeature { class GeoJSON extends JSONFeature {
/** /**
* @param {Options} [opt_options] Options. * @param {Options} [options] Options.
*/ */
constructor(opt_options) { constructor(options) {
const options = opt_options ? opt_options : {}; options = options ? options : {};
super(); super();
@@ -93,11 +93,11 @@ class GeoJSON extends JSONFeature {
/** /**
* @param {Object} object Object. * @param {Object} object Object.
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options. * @param {import("./Feature.js").ReadOptions} [options] Read options.
* @protected * @protected
* @return {import("../Feature.js").default} Feature. * @return {import("../Feature.js").default} Feature.
*/ */
readFeatureFromObject(object, opt_options) { readFeatureFromObject(object, options) {
/** /**
* @type {GeoJSONFeature} * @type {GeoJSONFeature}
*/ */
@@ -112,7 +112,7 @@ class GeoJSON extends JSONFeature {
}; };
} }
const geometry = readGeometry(geoJSONFeature['geometry'], opt_options); const geometry = readGeometry(geoJSONFeature['geometry'], options);
const feature = new Feature(); const feature = new Feature();
if (this.geometryName_) { if (this.geometryName_) {
feature.setGeometryName(this.geometryName_); feature.setGeometryName(this.geometryName_);
@@ -136,11 +136,11 @@ class GeoJSON extends JSONFeature {
/** /**
* @param {Object} object Object. * @param {Object} object Object.
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options. * @param {import("./Feature.js").ReadOptions} [options] Read options.
* @protected * @protected
* @return {Array<Feature>} Features. * @return {Array<Feature>} Features.
*/ */
readFeaturesFromObject(object, opt_options) { readFeaturesFromObject(object, options) {
const geoJSONObject = /** @type {GeoJSONObject} */ (object); const geoJSONObject = /** @type {GeoJSONObject} */ (object);
/** @type {Array<import("../Feature.js").default>} */ /** @type {Array<import("../Feature.js").default>} */
let features = null; let features = null;
@@ -151,24 +151,22 @@ class GeoJSON extends JSONFeature {
features = []; features = [];
const geoJSONFeatures = geoJSONFeatureCollection['features']; const geoJSONFeatures = geoJSONFeatureCollection['features'];
for (let i = 0, ii = geoJSONFeatures.length; i < ii; ++i) { for (let i = 0, ii = geoJSONFeatures.length; i < ii; ++i) {
features.push( features.push(this.readFeatureFromObject(geoJSONFeatures[i], options));
this.readFeatureFromObject(geoJSONFeatures[i], opt_options)
);
} }
} else { } else {
features = [this.readFeatureFromObject(object, opt_options)]; features = [this.readFeatureFromObject(object, options)];
} }
return features; return features;
} }
/** /**
* @param {GeoJSONGeometry} object Object. * @param {GeoJSONGeometry} object Object.
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options. * @param {import("./Feature.js").ReadOptions} [options] Read options.
* @protected * @protected
* @return {import("../geom/Geometry.js").default} Geometry. * @return {import("../geom/Geometry.js").default} Geometry.
*/ */
readGeometryFromObject(object, opt_options) { readGeometryFromObject(object, options) {
return readGeometry(object, opt_options); return readGeometry(object, options);
} }
/** /**
@@ -197,12 +195,12 @@ class GeoJSON extends JSONFeature {
* Encode a feature as a GeoJSON Feature object. * Encode a feature as a GeoJSON Feature object.
* *
* @param {import("../Feature.js").default} feature Feature. * @param {import("../Feature.js").default} feature Feature.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @return {GeoJSONFeature} Object. * @return {GeoJSONFeature} Object.
* @api * @api
*/ */
writeFeatureObject(feature, opt_options) { writeFeatureObject(feature, options) {
opt_options = this.adaptOptions(opt_options); options = this.adaptOptions(options);
/** @type {GeoJSONFeature} */ /** @type {GeoJSONFeature} */
const object = { const object = {
@@ -223,7 +221,7 @@ class GeoJSON extends JSONFeature {
const properties = feature.getProperties(); const properties = feature.getProperties();
const geometry = feature.getGeometry(); const geometry = feature.getGeometry();
if (geometry) { if (geometry) {
object.geometry = writeGeometry(geometry, opt_options); object.geometry = writeGeometry(geometry, options);
delete properties[feature.getGeometryName()]; delete properties[feature.getGeometryName()];
} }
@@ -239,15 +237,15 @@ class GeoJSON extends JSONFeature {
* Encode an array of features as a GeoJSON object. * Encode an array of features as a GeoJSON object.
* *
* @param {Array<import("../Feature.js").default>} features Features. * @param {Array<import("../Feature.js").default>} features Features.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @return {GeoJSONFeatureCollection} GeoJSON Object. * @return {GeoJSONFeatureCollection} GeoJSON Object.
* @api * @api
*/ */
writeFeaturesObject(features, opt_options) { writeFeaturesObject(features, options) {
opt_options = this.adaptOptions(opt_options); options = this.adaptOptions(options);
const objects = []; const objects = [];
for (let i = 0, ii = features.length; i < ii; ++i) { for (let i = 0, ii = features.length; i < ii; ++i) {
objects.push(this.writeFeatureObject(features[i], opt_options)); objects.push(this.writeFeatureObject(features[i], options));
} }
return { return {
type: 'FeatureCollection', type: 'FeatureCollection',
@@ -259,21 +257,21 @@ class GeoJSON extends JSONFeature {
* Encode a geometry as a GeoJSON object. * Encode a geometry as a GeoJSON object.
* *
* @param {import("../geom/Geometry.js").default} geometry Geometry. * @param {import("../geom/Geometry.js").default} geometry Geometry.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @return {GeoJSONGeometry|GeoJSONGeometryCollection} Object. * @return {GeoJSONGeometry|GeoJSONGeometryCollection} Object.
* @api * @api
*/ */
writeGeometryObject(geometry, opt_options) { writeGeometryObject(geometry, options) {
return writeGeometry(geometry, this.adaptOptions(opt_options)); return writeGeometry(geometry, this.adaptOptions(options));
} }
} }
/** /**
* @param {GeoJSONGeometry|GeoJSONGeometryCollection} object Object. * @param {GeoJSONGeometry|GeoJSONGeometryCollection} object Object.
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options. * @param {import("./Feature.js").ReadOptions} [options] Read options.
* @return {import("../geom/Geometry.js").default} Geometry. * @return {import("../geom/Geometry.js").default} Geometry.
*/ */
function readGeometry(object, opt_options) { function readGeometry(object, options) {
if (!object) { if (!object) {
return null; return null;
} }
@@ -325,22 +323,22 @@ function readGeometry(object, opt_options) {
throw new Error('Unsupported GeoJSON type: ' + object['type']); throw new Error('Unsupported GeoJSON type: ' + object['type']);
} }
} }
return transformGeometryWithOptions(geometry, false, opt_options); return transformGeometryWithOptions(geometry, false, options);
} }
/** /**
* @param {GeoJSONGeometryCollection} object Object. * @param {GeoJSONGeometryCollection} object Object.
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options. * @param {import("./Feature.js").ReadOptions} [options] Read options.
* @return {GeometryCollection} Geometry collection. * @return {GeometryCollection} Geometry collection.
*/ */
function readGeometryCollectionGeometry(object, opt_options) { function readGeometryCollectionGeometry(object, options) {
const geometries = object['geometries'].map( const geometries = object['geometries'].map(
/** /**
* @param {GeoJSONGeometry} geometry Geometry. * @param {GeoJSONGeometry} geometry Geometry.
* @return {import("../geom/Geometry.js").default} geometry Geometry. * @return {import("../geom/Geometry.js").default} geometry Geometry.
*/ */
function (geometry) { function (geometry) {
return readGeometry(geometry, opt_options); return readGeometry(geometry, options);
} }
); );
return new GeometryCollection(geometries); return new GeometryCollection(geometries);
@@ -396,62 +394,59 @@ function readPolygonGeometry(object) {
/** /**
* @param {import("../geom/Geometry.js").default} geometry Geometry. * @param {import("../geom/Geometry.js").default} geometry Geometry.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @return {GeoJSONGeometry} GeoJSON geometry. * @return {GeoJSONGeometry} GeoJSON geometry.
*/ */
function writeGeometry(geometry, opt_options) { function writeGeometry(geometry, options) {
geometry = transformGeometryWithOptions(geometry, true, opt_options); geometry = transformGeometryWithOptions(geometry, true, options);
const type = geometry.getType(); const type = geometry.getType();
/** @type {GeoJSONGeometry} */ /** @type {GeoJSONGeometry} */
let geoJSON; let geoJSON;
switch (type) { switch (type) {
case 'Point': { case 'Point': {
geoJSON = writePointGeometry( geoJSON = writePointGeometry(/** @type {Point} */ (geometry), options);
/** @type {Point} */ (geometry),
opt_options
);
break; break;
} }
case 'LineString': { case 'LineString': {
geoJSON = writeLineStringGeometry( geoJSON = writeLineStringGeometry(
/** @type {LineString} */ (geometry), /** @type {LineString} */ (geometry),
opt_options options
); );
break; break;
} }
case 'Polygon': { case 'Polygon': {
geoJSON = writePolygonGeometry( geoJSON = writePolygonGeometry(
/** @type {Polygon} */ (geometry), /** @type {Polygon} */ (geometry),
opt_options options
); );
break; break;
} }
case 'MultiPoint': { case 'MultiPoint': {
geoJSON = writeMultiPointGeometry( geoJSON = writeMultiPointGeometry(
/** @type {MultiPoint} */ (geometry), /** @type {MultiPoint} */ (geometry),
opt_options options
); );
break; break;
} }
case 'MultiLineString': { case 'MultiLineString': {
geoJSON = writeMultiLineStringGeometry( geoJSON = writeMultiLineStringGeometry(
/** @type {MultiLineString} */ (geometry), /** @type {MultiLineString} */ (geometry),
opt_options options
); );
break; break;
} }
case 'MultiPolygon': { case 'MultiPolygon': {
geoJSON = writeMultiPolygonGeometry( geoJSON = writeMultiPolygonGeometry(
/** @type {MultiPolygon} */ (geometry), /** @type {MultiPolygon} */ (geometry),
opt_options options
); );
break; break;
} }
case 'GeometryCollection': { case 'GeometryCollection': {
geoJSON = writeGeometryCollectionGeometry( geoJSON = writeGeometryCollectionGeometry(
/** @type {GeometryCollection} */ (geometry), /** @type {GeometryCollection} */ (geometry),
opt_options options
); );
break; break;
} }
@@ -471,13 +466,13 @@ function writeGeometry(geometry, opt_options) {
/** /**
* @param {GeometryCollection} geometry Geometry. * @param {GeometryCollection} geometry Geometry.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @return {GeoJSONGeometryCollection} GeoJSON geometry collection. * @return {GeoJSONGeometryCollection} GeoJSON geometry collection.
*/ */
function writeGeometryCollectionGeometry(geometry, opt_options) { function writeGeometryCollectionGeometry(geometry, options) {
const geometries = geometry.getGeometriesArray().map(function (geometry) { options = Object.assign({}, options);
const options = Object.assign({}, opt_options);
delete options.featureProjection; delete options.featureProjection;
const geometries = geometry.getGeometriesArray().map(function (geometry) {
return writeGeometry(geometry, options); return writeGeometry(geometry, options);
}); });
return { return {
@@ -488,10 +483,10 @@ function writeGeometryCollectionGeometry(geometry, opt_options) {
/** /**
* @param {LineString} geometry Geometry. * @param {LineString} geometry Geometry.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @return {GeoJSONGeometry} GeoJSON geometry. * @return {GeoJSONGeometry} GeoJSON geometry.
*/ */
function writeLineStringGeometry(geometry, opt_options) { function writeLineStringGeometry(geometry, options) {
return { return {
type: 'LineString', type: 'LineString',
coordinates: geometry.getCoordinates(), coordinates: geometry.getCoordinates(),
@@ -500,10 +495,10 @@ function writeLineStringGeometry(geometry, opt_options) {
/** /**
* @param {MultiLineString} geometry Geometry. * @param {MultiLineString} geometry Geometry.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @return {GeoJSONGeometry} GeoJSON geometry. * @return {GeoJSONGeometry} GeoJSON geometry.
*/ */
function writeMultiLineStringGeometry(geometry, opt_options) { function writeMultiLineStringGeometry(geometry, options) {
return { return {
type: 'MultiLineString', type: 'MultiLineString',
coordinates: geometry.getCoordinates(), coordinates: geometry.getCoordinates(),
@@ -512,10 +507,10 @@ function writeMultiLineStringGeometry(geometry, opt_options) {
/** /**
* @param {MultiPoint} geometry Geometry. * @param {MultiPoint} geometry Geometry.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @return {GeoJSONGeometry} GeoJSON geometry. * @return {GeoJSONGeometry} GeoJSON geometry.
*/ */
function writeMultiPointGeometry(geometry, opt_options) { function writeMultiPointGeometry(geometry, options) {
return { return {
type: 'MultiPoint', type: 'MultiPoint',
coordinates: geometry.getCoordinates(), coordinates: geometry.getCoordinates(),
@@ -524,13 +519,13 @@ function writeMultiPointGeometry(geometry, opt_options) {
/** /**
* @param {MultiPolygon} geometry Geometry. * @param {MultiPolygon} geometry Geometry.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @return {GeoJSONGeometry} GeoJSON geometry. * @return {GeoJSONGeometry} GeoJSON geometry.
*/ */
function writeMultiPolygonGeometry(geometry, opt_options) { function writeMultiPolygonGeometry(geometry, options) {
let right; let right;
if (opt_options) { if (options) {
right = opt_options.rightHanded; right = options.rightHanded;
} }
return { return {
type: 'MultiPolygon', type: 'MultiPolygon',
@@ -540,10 +535,10 @@ function writeMultiPolygonGeometry(geometry, opt_options) {
/** /**
* @param {Point} geometry Geometry. * @param {Point} geometry Geometry.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @return {GeoJSONGeometry} GeoJSON geometry. * @return {GeoJSONGeometry} GeoJSON geometry.
*/ */
function writePointGeometry(geometry, opt_options) { function writePointGeometry(geometry, options) {
return { return {
type: 'Point', type: 'Point',
coordinates: geometry.getCoordinates(), coordinates: geometry.getCoordinates(),
@@ -552,13 +547,13 @@ function writePointGeometry(geometry, opt_options) {
/** /**
* @param {Polygon} geometry Geometry. * @param {Polygon} geometry Geometry.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @return {GeoJSONGeometry} GeoJSON geometry. * @return {GeoJSONGeometry} GeoJSON geometry.
*/ */
function writePolygonGeometry(geometry, opt_options) { function writePolygonGeometry(geometry, options) {
let right; let right;
if (opt_options) { if (options) {
right = opt_options.rightHanded; right = options.rightHanded;
} }
return { return {
type: 'Polygon', type: 'Polygon',

View File

@@ -57,12 +57,12 @@ const NEWLINE_RE = /\r\n|\r|\n/;
*/ */
class IGC extends TextFeature { class IGC extends TextFeature {
/** /**
* @param {Options} [opt_options] Options. * @param {Options} [options] Options.
*/ */
constructor(opt_options) { constructor(options) {
super(); super();
const options = opt_options ? opt_options : {}; options = options ? options : {};
/** /**
* @type {import("../proj/Projection.js").default} * @type {import("../proj/Projection.js").default}
@@ -79,10 +79,10 @@ class IGC extends TextFeature {
/** /**
* @protected * @protected
* @param {string} text Text. * @param {string} text Text.
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options. * @param {import("./Feature.js").ReadOptions} [options] Read options.
* @return {import("../Feature.js").default} Feature. * @return {import("../Feature.js").default} Feature.
*/ */
readFeatureFromText(text, opt_options) { readFeatureFromText(text, options) {
const altitudeMode = this.altitudeMode_; const altitudeMode = this.altitudeMode_;
const lines = text.split(NEWLINE_RE); const lines = text.split(NEWLINE_RE);
/** @type {Object<string, string>} */ /** @type {Object<string, string>} */
@@ -150,7 +150,7 @@ class IGC extends TextFeature {
const layout = altitudeMode == 'none' ? 'XYM' : 'XYZM'; const layout = altitudeMode == 'none' ? 'XYM' : 'XYZM';
const lineString = new LineString(flatCoordinates, layout); const lineString = new LineString(flatCoordinates, layout);
const feature = new Feature( const feature = new Feature(
transformGeometryWithOptions(lineString, false, opt_options) transformGeometryWithOptions(lineString, false, options)
); );
feature.setProperties(properties, true); feature.setProperties(properties, true);
return feature; return feature;
@@ -158,12 +158,12 @@ class IGC extends TextFeature {
/** /**
* @param {string} text Text. * @param {string} text Text.
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options. * @param {import("./Feature.js").ReadOptions} [options] Read options.
* @protected * @protected
* @return {Array<Feature>} Features. * @return {Array<Feature>} Features.
*/ */
readFeaturesFromText(text, opt_options) { readFeaturesFromText(text, options) {
const feature = this.readFeatureFromText(text, opt_options); const feature = this.readFeatureFromText(text, options);
if (feature) { if (feature) {
return [feature]; return [feature];
} else { } else {

View File

@@ -437,12 +437,12 @@ class IIIFInfo {
} }
/** /**
* @param {PreferredOptions} [opt_preferredOptions] Optional options for preferred format and quality. * @param {PreferredOptions} [preferredOptions] Optional options for preferred format and quality.
* @return {import("../source/IIIF.js").Options} IIIF tile source ready constructor options. * @return {import("../source/IIIF.js").Options} IIIF tile source ready constructor options.
* @api * @api
*/ */
getTileSourceOptions(opt_preferredOptions) { getTileSourceOptions(preferredOptions) {
const options = opt_preferredOptions || {}, const options = preferredOptions || {},
version = this.getImageApiVersion(); version = this.getImageApiVersion();
if (version === undefined) { if (version === undefined) {
return; return;

View File

@@ -29,14 +29,14 @@ class JSONFeature extends FeatureFormat {
* read a feature collection. * read a feature collection.
* *
* @param {ArrayBuffer|Document|Element|Object|string} source Source. * @param {ArrayBuffer|Document|Element|Object|string} source Source.
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options. * @param {import("./Feature.js").ReadOptions} [options] Read options.
* @return {import("../Feature.js").default} Feature. * @return {import("../Feature.js").default} Feature.
* @api * @api
*/ */
readFeature(source, opt_options) { readFeature(source, options) {
return this.readFeatureFromObject( return this.readFeatureFromObject(
getObject(source), getObject(source),
this.getReadOptions(source, opt_options) this.getReadOptions(source, options)
); );
} }
@@ -45,36 +45,36 @@ class JSONFeature extends FeatureFormat {
* collection. * collection.
* *
* @param {ArrayBuffer|Document|Element|Object|string} source Source. * @param {ArrayBuffer|Document|Element|Object|string} source Source.
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options. * @param {import("./Feature.js").ReadOptions} [options] Read options.
* @return {Array<import("../Feature.js").default>} Features. * @return {Array<import("../Feature.js").default>} Features.
* @api * @api
*/ */
readFeatures(source, opt_options) { readFeatures(source, options) {
return this.readFeaturesFromObject( return this.readFeaturesFromObject(
getObject(source), getObject(source),
this.getReadOptions(source, opt_options) this.getReadOptions(source, options)
); );
} }
/** /**
* @abstract * @abstract
* @param {Object} object Object. * @param {Object} object Object.
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options. * @param {import("./Feature.js").ReadOptions} [options] Read options.
* @protected * @protected
* @return {import("../Feature.js").default} Feature. * @return {import("../Feature.js").default} Feature.
*/ */
readFeatureFromObject(object, opt_options) { readFeatureFromObject(object, options) {
return abstract(); return abstract();
} }
/** /**
* @abstract * @abstract
* @param {Object} object Object. * @param {Object} object Object.
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options. * @param {import("./Feature.js").ReadOptions} [options] Read options.
* @protected * @protected
* @return {Array<import("../Feature.js").default>} Features. * @return {Array<import("../Feature.js").default>} Features.
*/ */
readFeaturesFromObject(object, opt_options) { readFeaturesFromObject(object, options) {
return abstract(); return abstract();
} }
@@ -82,25 +82,25 @@ class JSONFeature extends FeatureFormat {
* Read a geometry. * Read a geometry.
* *
* @param {ArrayBuffer|Document|Element|Object|string} source Source. * @param {ArrayBuffer|Document|Element|Object|string} source Source.
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options. * @param {import("./Feature.js").ReadOptions} [options] Read options.
* @return {import("../geom/Geometry.js").default} Geometry. * @return {import("../geom/Geometry.js").default} Geometry.
* @api * @api
*/ */
readGeometry(source, opt_options) { readGeometry(source, options) {
return this.readGeometryFromObject( return this.readGeometryFromObject(
getObject(source), getObject(source),
this.getReadOptions(source, opt_options) this.getReadOptions(source, options)
); );
} }
/** /**
* @abstract * @abstract
* @param {Object} object Object. * @param {Object} object Object.
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options. * @param {import("./Feature.js").ReadOptions} [options] Read options.
* @protected * @protected
* @return {import("../geom/Geometry.js").default} Geometry. * @return {import("../geom/Geometry.js").default} Geometry.
*/ */
readGeometryFromObject(object, opt_options) { readGeometryFromObject(object, options) {
return abstract(); return abstract();
} }
@@ -129,21 +129,21 @@ class JSONFeature extends FeatureFormat {
* Encode a feature as string. * Encode a feature as string.
* *
* @param {import("../Feature.js").default} feature Feature. * @param {import("../Feature.js").default} feature Feature.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @return {string} Encoded feature. * @return {string} Encoded feature.
* @api * @api
*/ */
writeFeature(feature, opt_options) { writeFeature(feature, options) {
return JSON.stringify(this.writeFeatureObject(feature, opt_options)); return JSON.stringify(this.writeFeatureObject(feature, options));
} }
/** /**
* @abstract * @abstract
* @param {import("../Feature.js").default} feature Feature. * @param {import("../Feature.js").default} feature Feature.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @return {Object} Object. * @return {Object} Object.
*/ */
writeFeatureObject(feature, opt_options) { writeFeatureObject(feature, options) {
return abstract(); return abstract();
} }
@@ -151,21 +151,21 @@ class JSONFeature extends FeatureFormat {
* Encode an array of features as string. * Encode an array of features as string.
* *
* @param {Array<import("../Feature.js").default>} features Features. * @param {Array<import("../Feature.js").default>} features Features.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @return {string} Encoded features. * @return {string} Encoded features.
* @api * @api
*/ */
writeFeatures(features, opt_options) { writeFeatures(features, options) {
return JSON.stringify(this.writeFeaturesObject(features, opt_options)); return JSON.stringify(this.writeFeaturesObject(features, options));
} }
/** /**
* @abstract * @abstract
* @param {Array<import("../Feature.js").default>} features Features. * @param {Array<import("../Feature.js").default>} features Features.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @return {Object} Object. * @return {Object} Object.
*/ */
writeFeaturesObject(features, opt_options) { writeFeaturesObject(features, options) {
return abstract(); return abstract();
} }
@@ -173,21 +173,21 @@ class JSONFeature extends FeatureFormat {
* Encode a geometry as string. * Encode a geometry as string.
* *
* @param {import("../geom/Geometry.js").default} geometry Geometry. * @param {import("../geom/Geometry.js").default} geometry Geometry.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @return {string} Encoded geometry. * @return {string} Encoded geometry.
* @api * @api
*/ */
writeGeometry(geometry, opt_options) { writeGeometry(geometry, options) {
return JSON.stringify(this.writeGeometryObject(geometry, opt_options)); return JSON.stringify(this.writeGeometryObject(geometry, options));
} }
/** /**
* @abstract * @abstract
* @param {import("../geom/Geometry.js").default} geometry Geometry. * @param {import("../geom/Geometry.js").default} geometry Geometry.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @return {Object} Object. * @return {Object} Object.
*/ */
writeGeometryObject(geometry, opt_options) { writeGeometryObject(geometry, options) {
return abstract(); return abstract();
} }
} }

View File

@@ -423,12 +423,12 @@ function defaultIconUrlFunction(href) {
*/ */
class KML extends XMLFeature { class KML extends XMLFeature {
/** /**
* @param {Options} [opt_options] Options. * @param {Options} [options] Options.
*/ */
constructor(opt_options) { constructor(options) {
super(); super();
const options = opt_options ? opt_options : {}; options = options ? options : {};
if (!DEFAULT_STYLE_ARRAY) { if (!DEFAULT_STYLE_ARRAY) {
createStyleDefaults(); createStyleDefaults();
@@ -624,15 +624,15 @@ class KML extends XMLFeature {
/** /**
* @param {Element} node Node. * @param {Element} node Node.
* @param {import("./Feature.js").ReadOptions} [opt_options] Options. * @param {import("./Feature.js").ReadOptions} [options] Options.
* @return {import("../Feature.js").default} Feature. * @return {import("../Feature.js").default} Feature.
*/ */
readFeatureFromNode(node, opt_options) { readFeatureFromNode(node, options) {
if (!NAMESPACE_URIS.includes(node.namespaceURI)) { if (!NAMESPACE_URIS.includes(node.namespaceURI)) {
return null; return null;
} }
const feature = this.readPlacemark_(node, [ const feature = this.readPlacemark_(node, [
this.getReadOptions(node, opt_options), this.getReadOptions(node, options),
]); ]);
if (feature) { if (feature) {
return feature; return feature;
@@ -644,10 +644,10 @@ class KML extends XMLFeature {
/** /**
* @protected * @protected
* @param {Element} node Node. * @param {Element} node Node.
* @param {import("./Feature.js").ReadOptions} [opt_options] Options. * @param {import("./Feature.js").ReadOptions} [options] Options.
* @return {Array<import("../Feature.js").default>} Features. * @return {Array<import("../Feature.js").default>} Features.
*/ */
readFeaturesFromNode(node, opt_options) { readFeaturesFromNode(node, options) {
if (!NAMESPACE_URIS.includes(node.namespaceURI)) { if (!NAMESPACE_URIS.includes(node.namespaceURI)) {
return []; return [];
} }
@@ -655,7 +655,7 @@ class KML extends XMLFeature {
const localName = node.localName; const localName = node.localName;
if (localName == 'Document' || localName == 'Folder') { if (localName == 'Document' || localName == 'Folder') {
features = this.readDocumentOrFolder_(node, [ features = this.readDocumentOrFolder_(node, [
this.getReadOptions(node, opt_options), this.getReadOptions(node, options),
]); ]);
if (features) { if (features) {
return features; return features;
@@ -664,7 +664,7 @@ class KML extends XMLFeature {
} }
} else if (localName == 'Placemark') { } else if (localName == 'Placemark') {
const feature = this.readPlacemark_(node, [ const feature = this.readPlacemark_(node, [
this.getReadOptions(node, opt_options), this.getReadOptions(node, options),
]); ]);
if (feature) { if (feature) {
return [feature]; return [feature];
@@ -674,7 +674,7 @@ class KML extends XMLFeature {
} else if (localName == 'kml') { } else if (localName == 'kml') {
features = []; features = [];
for (let n = node.firstElementChild; n; n = n.nextElementSibling) { for (let n = node.firstElementChild; n; n = n.nextElementSibling) {
const fs = this.readFeaturesFromNode(n, opt_options); const fs = this.readFeaturesFromNode(n, options);
if (fs) { if (fs) {
extend(features, fs); extend(features, fs);
} }
@@ -886,12 +886,12 @@ class KML extends XMLFeature {
* MultiPoints, MultiLineStrings, and MultiPolygons are output as MultiGeometries. * MultiPoints, MultiLineStrings, and MultiPolygons are output as MultiGeometries.
* *
* @param {Array<Feature>} features Features. * @param {Array<Feature>} features Features.
* @param {import("./Feature.js").WriteOptions} [opt_options] Options. * @param {import("./Feature.js").WriteOptions} [options] Options.
* @return {Node} Node. * @return {Node} Node.
* @api * @api
*/ */
writeFeaturesNode(features, opt_options) { writeFeaturesNode(features, options) {
opt_options = this.adaptOptions(opt_options); options = this.adaptOptions(options);
const kml = createElementNS(NAMESPACE_URIS[4], 'kml'); const kml = createElementNS(NAMESPACE_URIS[4], 'kml');
const xmlnsUri = 'http://www.w3.org/2000/xmlns/'; const xmlnsUri = 'http://www.w3.org/2000/xmlns/';
kml.setAttributeNS(xmlnsUri, 'xmlns:gx', GX_NAMESPACE_URIS[0]); kml.setAttributeNS(xmlnsUri, 'xmlns:gx', GX_NAMESPACE_URIS[0]);
@@ -919,7 +919,7 @@ class KML extends XMLFeature {
KML_SERIALIZERS, KML_SERIALIZERS,
OBJECT_PROPERTY_NODE_FACTORY, OBJECT_PROPERTY_NODE_FACTORY,
values, values,
[opt_options], [options],
orderedKeys, orderedKeys,
this this
); );
@@ -2444,10 +2444,10 @@ const DOCUMENT_SERIALIZERS = makeStructureNS(NAMESPACE_URIS, {
* @const * @const
* @param {*} value Value. * @param {*} value Value.
* @param {Array<*>} objectStack Object stack. * @param {Array<*>} objectStack Object stack.
* @param {string} [opt_nodeName] Node name. * @param {string} [nodeName] Node name.
* @return {Node|undefined} Node. * @return {Node|undefined} Node.
*/ */
const DOCUMENT_NODE_FACTORY = function (value, objectStack, opt_nodeName) { const DOCUMENT_NODE_FACTORY = function (value, objectStack, nodeName) {
const parentNode = objectStack[objectStack.length - 1].node; const parentNode = objectStack[objectStack.length - 1].node;
return createElementNS(parentNode.namespaceURI, 'Placemark'); return createElementNS(parentNode.namespaceURI, 'Placemark');
}; };
@@ -2533,11 +2533,11 @@ const ICON_SERIALIZERS = makeStructureNS(
* @const * @const
* @param {*} value Value. * @param {*} value Value.
* @param {Array<*>} objectStack Object stack. * @param {Array<*>} objectStack Object stack.
* @param {string} [opt_nodeName] Node name. * @param {string} [nodeName] Node name.
* @return {Node|undefined} Node. * @return {Node|undefined} Node.
*/ */
const GX_NODE_FACTORY = function (value, objectStack, opt_nodeName) { const GX_NODE_FACTORY = function (value, objectStack, nodeName) {
return createElementNS(GX_NAMESPACE_URIS[0], 'gx:' + opt_nodeName); return createElementNS(GX_NAMESPACE_URIS[0], 'gx:' + nodeName);
}; };
/** /**
@@ -2780,10 +2780,10 @@ const GEOMETRY_TYPE_TO_NODENAME = {
* @const * @const
* @param {*} value Value. * @param {*} value Value.
* @param {Array<*>} objectStack Object stack. * @param {Array<*>} objectStack Object stack.
* @param {string} [opt_nodeName] Node name. * @param {string} [nodeName] Node name.
* @return {Node|undefined} Node. * @return {Node|undefined} Node.
*/ */
const GEOMETRY_NODE_FACTORY = function (value, objectStack, opt_nodeName) { const GEOMETRY_NODE_FACTORY = function (value, objectStack, nodeName) {
if (value) { if (value) {
const parentNode = objectStack[objectStack.length - 1].node; const parentNode = objectStack[objectStack.length - 1].node;
return createElementNS( return createElementNS(

View File

@@ -34,17 +34,17 @@ import {inflateEnds} from '../geom/flat/orient.js';
* @classdesc * @classdesc
* Feature format for reading data in the Mapbox MVT format. * Feature format for reading data in the Mapbox MVT format.
* *
* @param {Options} [opt_options] Options. * @param {Options} [options] Options.
* @api * @api
*/ */
class MVT extends FeatureFormat { class MVT extends FeatureFormat {
/** /**
* @param {Options} [opt_options] Options. * @param {Options} [options] Options.
*/ */
constructor(opt_options) { constructor(options) {
super(); super();
const options = opt_options ? opt_options : {}; options = options ? options : {};
/** /**
* @type {Projection} * @type {Projection}
@@ -245,15 +245,13 @@ class MVT extends FeatureFormat {
* Read all features. * Read all features.
* *
* @param {ArrayBuffer} source Source. * @param {ArrayBuffer} source Source.
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options. * @param {import("./Feature.js").ReadOptions} [options] Read options.
* @return {Array<import("../Feature.js").FeatureLike>} Features. * @return {Array<import("../Feature.js").FeatureLike>} Features.
* @api * @api
*/ */
readFeatures(source, opt_options) { readFeatures(source, options) {
const layers = this.layers_; const layers = this.layers_;
const options = /** @type {import("./Feature.js").ReadOptions} */ ( options = this.adaptOptions(options);
this.adaptOptions(opt_options)
);
const dataProjection = get(options.dataProjection); const dataProjection = get(options.dataProjection);
dataProjection.setWorldExtent(options.extent); dataProjection.setWorldExtent(options.extent);
options.dataProjection = dataProjection; options.dataProjection = dataProjection;

View File

@@ -59,11 +59,11 @@ class OSMXML extends XMLFeature {
/** /**
* @protected * @protected
* @param {Element} node Node. * @param {Element} node Node.
* @param {import("./Feature.js").ReadOptions} [opt_options] Options. * @param {import("./Feature.js").ReadOptions} [options] Options.
* @return {Array<import("../Feature.js").default>} Features. * @return {Array<import("../Feature.js").default>} Features.
*/ */
readFeaturesFromNode(node, opt_options) { readFeaturesFromNode(node, options) {
const options = this.getReadOptions(node, opt_options); options = this.getReadOptions(node, options);
if (node.localName == 'osm') { if (node.localName == 'osm') {
const state = pushParseAndPop( const state = pushParseAndPop(
{ {

View File

@@ -34,12 +34,12 @@ import {transformGeometryWithOptions} from './Feature.js';
*/ */
class Polyline extends TextFeature { class Polyline extends TextFeature {
/** /**
* @param {Options} [opt_options] Optional configuration object. * @param {Options} [options] Optional configuration object.
*/ */
constructor(opt_options) { constructor(options) {
super(); super();
const options = opt_options ? opt_options : {}; options = options ? options : {};
/** /**
* @type {import("../proj/Projection.js").default} * @type {import("../proj/Projection.js").default}
@@ -64,32 +64,32 @@ class Polyline extends TextFeature {
/** /**
* @protected * @protected
* @param {string} text Text. * @param {string} text Text.
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options. * @param {import("./Feature.js").ReadOptions} [options] Read options.
* @return {import("../Feature.js").default} Feature. * @return {import("../Feature.js").default} Feature.
*/ */
readFeatureFromText(text, opt_options) { readFeatureFromText(text, options) {
const geometry = this.readGeometryFromText(text, opt_options); const geometry = this.readGeometryFromText(text, options);
return new Feature(geometry); return new Feature(geometry);
} }
/** /**
* @param {string} text Text. * @param {string} text Text.
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options. * @param {import("./Feature.js").ReadOptions} [options] Read options.
* @protected * @protected
* @return {Array<Feature>} Features. * @return {Array<Feature>} Features.
*/ */
readFeaturesFromText(text, opt_options) { readFeaturesFromText(text, options) {
const feature = this.readFeatureFromText(text, opt_options); const feature = this.readFeatureFromText(text, options);
return [feature]; return [feature];
} }
/** /**
* @param {string} text Text. * @param {string} text Text.
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options. * @param {import("./Feature.js").ReadOptions} [options] Read options.
* @protected * @protected
* @return {import("../geom/Geometry.js").default} Geometry. * @return {import("../geom/Geometry.js").default} Geometry.
*/ */
readGeometryFromText(text, opt_options) { readGeometryFromText(text, options) {
const stride = getStrideForLayout(this.geometryLayout_); const stride = getStrideForLayout(this.geometryLayout_);
const flatCoordinates = decodeDeltas(text, stride, this.factor_); const flatCoordinates = decodeDeltas(text, stride, this.factor_);
flipXY(flatCoordinates, 0, flatCoordinates.length, stride, flatCoordinates); flipXY(flatCoordinates, 0, flatCoordinates.length, stride, flatCoordinates);
@@ -104,20 +104,20 @@ class Polyline extends TextFeature {
return transformGeometryWithOptions( return transformGeometryWithOptions(
lineString, lineString,
false, false,
this.adaptOptions(opt_options) this.adaptOptions(options)
); );
} }
/** /**
* @param {import("../Feature.js").default<LineString>} feature Features. * @param {import("../Feature.js").default<LineString>} feature Features.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @protected * @protected
* @return {string} Text. * @return {string} Text.
*/ */
writeFeatureText(feature, opt_options) { writeFeatureText(feature, options) {
const geometry = feature.getGeometry(); const geometry = feature.getGeometry();
if (geometry) { if (geometry) {
return this.writeGeometryText(geometry, opt_options); return this.writeGeometryText(geometry, options);
} else { } else {
assert(false, 40); // Expected `feature` to have a geometry assert(false, 40); // Expected `feature` to have a geometry
return ''; return '';
@@ -126,29 +126,25 @@ class Polyline extends TextFeature {
/** /**
* @param {Array<import("../Feature.js").default<LineString>>} features Features. * @param {Array<import("../Feature.js").default<LineString>>} features Features.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @protected * @protected
* @return {string} Text. * @return {string} Text.
*/ */
writeFeaturesText(features, opt_options) { writeFeaturesText(features, options) {
return this.writeFeatureText(features[0], opt_options); return this.writeFeatureText(features[0], options);
} }
/** /**
* @param {LineString} geometry Geometry. * @param {LineString} geometry Geometry.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @protected * @protected
* @return {string} Text. * @return {string} Text.
*/ */
writeGeometryText(geometry, opt_options) { writeGeometryText(geometry, options) {
geometry = geometry =
/** @type {LineString} */ /** @type {LineString} */
( (
transformGeometryWithOptions( transformGeometryWithOptions(geometry, true, this.adaptOptions(options))
geometry,
true,
this.adaptOptions(opt_options)
)
); );
const flatCoordinates = geometry.getFlatCoordinates(); const flatCoordinates = geometry.getFlatCoordinates();
const stride = geometry.getStride(); const stride = geometry.getStride();
@@ -164,14 +160,14 @@ class Polyline extends TextFeature {
* *
* @param {Array<number>} numbers A list of n-dimensional points. * @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} 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} [factor] The factor by which the numbers will be
* multiplied. The remaining decimal places will get rounded away. * multiplied. The remaining decimal places will get rounded away.
* Default is `1e5`. * Default is `1e5`.
* @return {string} The encoded string. * @return {string} The encoded string.
* @api * @api
*/ */
export function encodeDeltas(numbers, stride, opt_factor) { export function encodeDeltas(numbers, stride, factor) {
const factor = opt_factor ? opt_factor : 1e5; factor = factor ? factor : 1e5;
let d; let d;
const lastNumbers = new Array(stride); const lastNumbers = new Array(stride);
@@ -198,13 +194,13 @@ export function encodeDeltas(numbers, stride, opt_factor) {
* @param {string} encoded An encoded string. * @param {string} encoded An encoded string.
* @param {number} stride The number of dimension of the points in the * @param {number} stride The number of dimension of the points in the
* encoded string. * encoded string.
* @param {number} [opt_factor] The factor by which the resulting numbers will * @param {number} [factor] The factor by which the resulting numbers will
* be divided. Default is `1e5`. * be divided. Default is `1e5`.
* @return {Array<number>} A list of n-dimensional points. * @return {Array<number>} A list of n-dimensional points.
* @api * @api
*/ */
export function decodeDeltas(encoded, stride, opt_factor) { export function decodeDeltas(encoded, stride, factor) {
const factor = opt_factor ? opt_factor : 1e5; factor = factor ? factor : 1e5;
let d; let d;
/** @type {Array<number>} */ /** @type {Array<number>} */
@@ -232,14 +228,14 @@ export function decodeDeltas(encoded, stride, opt_factor) {
* Attention: This function will modify the passed array! * Attention: This function will modify the passed array!
* *
* @param {Array<number>} numbers A list of floating point numbers. * @param {Array<number>} numbers A list of floating point numbers.
* @param {number} [opt_factor] The factor by which the numbers will be * @param {number} [factor] The factor by which the numbers will be
* multiplied. The remaining decimal places will get rounded away. * multiplied. The remaining decimal places will get rounded away.
* Default is `1e5`. * Default is `1e5`.
* @return {string} The encoded string. * @return {string} The encoded string.
* @api * @api
*/ */
export function encodeFloats(numbers, opt_factor) { export function encodeFloats(numbers, factor) {
const factor = opt_factor ? opt_factor : 1e5; factor = factor ? factor : 1e5;
for (let i = 0, ii = numbers.length; i < ii; ++i) { for (let i = 0, ii = numbers.length; i < ii; ++i) {
numbers[i] = Math.round(numbers[i] * factor); numbers[i] = Math.round(numbers[i] * factor);
} }
@@ -251,13 +247,13 @@ export function encodeFloats(numbers, opt_factor) {
* Decode a list of floating point numbers from an encoded string * Decode a list of floating point numbers from an encoded string
* *
* @param {string} encoded An encoded string. * @param {string} encoded An encoded string.
* @param {number} [opt_factor] The factor by which the result will be divided. * @param {number} [factor] The factor by which the result will be divided.
* Default is `1e5`. * Default is `1e5`.
* @return {Array<number>} A list of floating point numbers. * @return {Array<number>} A list of floating point numbers.
* @api * @api
*/ */
export function decodeFloats(encoded, opt_factor) { export function decodeFloats(encoded, factor) {
const factor = opt_factor ? opt_factor : 1e5; factor = factor ? factor : 1e5;
const numbers = decodeSignedIntegers(encoded); const numbers = decodeSignedIntegers(encoded);
for (let i = 0, ii = numbers.length; i < ii; ++i) { for (let i = 0, ii = numbers.length; i < ii; ++i) {
numbers[i] /= factor; numbers[i] /= factor;

View File

@@ -28,25 +28,25 @@ class TextFeature extends FeatureFormat {
* Read the feature from the source. * Read the feature from the source.
* *
* @param {Document|Element|Object|string} source Source. * @param {Document|Element|Object|string} source Source.
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options. * @param {import("./Feature.js").ReadOptions} [options] Read options.
* @return {import("../Feature.js").default} Feature. * @return {import("../Feature.js").default} Feature.
* @api * @api
*/ */
readFeature(source, opt_options) { readFeature(source, options) {
return this.readFeatureFromText( return this.readFeatureFromText(
getText(source), getText(source),
this.adaptOptions(opt_options) this.adaptOptions(options)
); );
} }
/** /**
* @abstract * @abstract
* @param {string} text Text. * @param {string} text Text.
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options. * @param {import("./Feature.js").ReadOptions} [options] Read options.
* @protected * @protected
* @return {import("../Feature.js").default} Feature. * @return {import("../Feature.js").default} Feature.
*/ */
readFeatureFromText(text, opt_options) { readFeatureFromText(text, options) {
return abstract(); return abstract();
} }
@@ -54,25 +54,25 @@ class TextFeature extends FeatureFormat {
* Read the features from the source. * Read the features from the source.
* *
* @param {Document|Element|Object|string} source Source. * @param {Document|Element|Object|string} source Source.
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options. * @param {import("./Feature.js").ReadOptions} [options] Read options.
* @return {Array<import("../Feature.js").default>} Features. * @return {Array<import("../Feature.js").default>} Features.
* @api * @api
*/ */
readFeatures(source, opt_options) { readFeatures(source, options) {
return this.readFeaturesFromText( return this.readFeaturesFromText(
getText(source), getText(source),
this.adaptOptions(opt_options) this.adaptOptions(options)
); );
} }
/** /**
* @abstract * @abstract
* @param {string} text Text. * @param {string} text Text.
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options. * @param {import("./Feature.js").ReadOptions} [options] Read options.
* @protected * @protected
* @return {Array<import("../Feature.js").default>} Features. * @return {Array<import("../Feature.js").default>} Features.
*/ */
readFeaturesFromText(text, opt_options) { readFeaturesFromText(text, options) {
return abstract(); return abstract();
} }
@@ -80,25 +80,25 @@ class TextFeature extends FeatureFormat {
* Read the geometry from the source. * Read the geometry from the source.
* *
* @param {Document|Element|Object|string} source Source. * @param {Document|Element|Object|string} source Source.
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options. * @param {import("./Feature.js").ReadOptions} [options] Read options.
* @return {import("../geom/Geometry.js").default} Geometry. * @return {import("../geom/Geometry.js").default} Geometry.
* @api * @api
*/ */
readGeometry(source, opt_options) { readGeometry(source, options) {
return this.readGeometryFromText( return this.readGeometryFromText(
getText(source), getText(source),
this.adaptOptions(opt_options) this.adaptOptions(options)
); );
} }
/** /**
* @abstract * @abstract
* @param {string} text Text. * @param {string} text Text.
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options. * @param {import("./Feature.js").ReadOptions} [options] Read options.
* @protected * @protected
* @return {import("../geom/Geometry.js").default} Geometry. * @return {import("../geom/Geometry.js").default} Geometry.
*/ */
readGeometryFromText(text, opt_options) { readGeometryFromText(text, options) {
return abstract(); return abstract();
} }
@@ -126,22 +126,22 @@ class TextFeature extends FeatureFormat {
* Encode a feature as a string. * Encode a feature as a string.
* *
* @param {import("../Feature.js").default} feature Feature. * @param {import("../Feature.js").default} feature Feature.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @return {string} Encoded feature. * @return {string} Encoded feature.
* @api * @api
*/ */
writeFeature(feature, opt_options) { writeFeature(feature, options) {
return this.writeFeatureText(feature, this.adaptOptions(opt_options)); return this.writeFeatureText(feature, this.adaptOptions(options));
} }
/** /**
* @abstract * @abstract
* @param {import("../Feature.js").default} feature Features. * @param {import("../Feature.js").default} feature Features.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @protected * @protected
* @return {string} Text. * @return {string} Text.
*/ */
writeFeatureText(feature, opt_options) { writeFeatureText(feature, options) {
return abstract(); return abstract();
} }
@@ -149,22 +149,22 @@ class TextFeature extends FeatureFormat {
* Encode an array of features as string. * Encode an array of features as string.
* *
* @param {Array<import("../Feature.js").default>} features Features. * @param {Array<import("../Feature.js").default>} features Features.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @return {string} Encoded features. * @return {string} Encoded features.
* @api * @api
*/ */
writeFeatures(features, opt_options) { writeFeatures(features, options) {
return this.writeFeaturesText(features, this.adaptOptions(opt_options)); return this.writeFeaturesText(features, this.adaptOptions(options));
} }
/** /**
* @abstract * @abstract
* @param {Array<import("../Feature.js").default>} features Features. * @param {Array<import("../Feature.js").default>} features Features.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @protected * @protected
* @return {string} Text. * @return {string} Text.
*/ */
writeFeaturesText(features, opt_options) { writeFeaturesText(features, options) {
return abstract(); return abstract();
} }
@@ -172,22 +172,22 @@ class TextFeature extends FeatureFormat {
* Write a single geometry. * Write a single geometry.
* *
* @param {import("../geom/Geometry.js").default} geometry Geometry. * @param {import("../geom/Geometry.js").default} geometry Geometry.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @return {string} Geometry. * @return {string} Geometry.
* @api * @api
*/ */
writeGeometry(geometry, opt_options) { writeGeometry(geometry, options) {
return this.writeGeometryText(geometry, this.adaptOptions(opt_options)); return this.writeGeometryText(geometry, this.adaptOptions(options));
} }
/** /**
* @abstract * @abstract
* @param {import("../geom/Geometry.js").default} geometry Geometry. * @param {import("../geom/Geometry.js").default} geometry Geometry.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @protected * @protected
* @return {string} Text. * @return {string} Text.
*/ */
writeGeometryText(geometry, opt_options) { writeGeometryText(geometry, options) {
return abstract(); return abstract();
} }
} }

View File

@@ -56,12 +56,12 @@ import {transformGeometryWithOptions} from './Feature.js';
*/ */
class TopoJSON extends JSONFeature { class TopoJSON extends JSONFeature {
/** /**
* @param {Options} [opt_options] Options. * @param {Options} [options] Options.
*/ */
constructor(opt_options) { constructor(options) {
super(); super();
const options = opt_options ? opt_options : {}; options = options ? options : {};
/** /**
* @private * @private
@@ -85,11 +85,11 @@ class TopoJSON extends JSONFeature {
/** /**
* @param {Object} object Object. * @param {Object} object Object.
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options. * @param {import("./Feature.js").ReadOptions} [options] Read options.
* @protected * @protected
* @return {Array<Feature>} Features. * @return {Array<Feature>} Features.
*/ */
readFeaturesFromObject(object, opt_options) { readFeaturesFromObject(object, options) {
if (object.type == 'Topology') { if (object.type == 'Topology') {
const topoJSONTopology = /** @type {TopoJSONTopology} */ (object); const topoJSONTopology = /** @type {TopoJSONTopology} */ (object);
let transform, let transform,
@@ -126,7 +126,7 @@ class TopoJSON extends JSONFeature {
translate, translate,
property, property,
objectName, objectName,
opt_options options
) )
); );
} else { } else {
@@ -141,7 +141,7 @@ class TopoJSON extends JSONFeature {
translate, translate,
property, property,
objectName, objectName,
opt_options options
) )
); );
} }
@@ -319,7 +319,7 @@ function readMultiPolygonGeometry(object, arcs) {
* @param {string|undefined} property Property to set the `GeometryCollection`'s parent * @param {string|undefined} property Property to set the `GeometryCollection`'s parent
* object to. * object to.
* @param {string} name Name of the `Topology`'s child object. * @param {string} name Name of the `Topology`'s child object.
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options. * @param {import("./Feature.js").ReadOptions} [options] Read options.
* @return {Array<Feature>} Array of features. * @return {Array<Feature>} Array of features.
*/ */
function readFeaturesFromGeometryCollection( function readFeaturesFromGeometryCollection(
@@ -329,7 +329,7 @@ function readFeaturesFromGeometryCollection(
translate, translate,
property, property,
name, name,
opt_options options
) { ) {
const geometries = collection['geometries']; const geometries = collection['geometries'];
const features = []; const features = [];
@@ -341,7 +341,7 @@ function readFeaturesFromGeometryCollection(
translate, translate,
property, property,
name, name,
opt_options options
); );
} }
return features; return features;
@@ -357,7 +357,7 @@ function readFeaturesFromGeometryCollection(
* @param {string|undefined} property Property to set the `GeometryCollection`'s parent * @param {string|undefined} property Property to set the `GeometryCollection`'s parent
* object to. * object to.
* @param {string} name Name of the `Topology`'s child object. * @param {string} name Name of the `Topology`'s child object.
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options. * @param {import("./Feature.js").ReadOptions} [options] Read options.
* @return {Feature} Feature. * @return {Feature} Feature.
*/ */
function readFeatureFromGeometry( function readFeatureFromGeometry(
@@ -367,7 +367,7 @@ function readFeatureFromGeometry(
translate, translate,
property, property,
name, name,
opt_options options
) { ) {
let geometry = null; let geometry = null;
const type = object.type; const type = object.type;
@@ -378,7 +378,7 @@ function readFeatureFromGeometry(
} else { } else {
geometry = geometryReader(object, arcs); geometry = geometryReader(object, arcs);
} }
geometry = transformGeometryWithOptions(geometry, false, opt_options); geometry = transformGeometryWithOptions(geometry, false, options);
} }
const feature = new Feature({geometry: geometry}); const feature = new Feature({geometry: geometry});
if (object.id !== undefined) { if (object.id !== undefined) {

View File

@@ -265,12 +265,12 @@ const DEFAULT_VERSION = '1.1.0';
*/ */
class WFS extends XMLFeature { class WFS extends XMLFeature {
/** /**
* @param {Options} [opt_options] Optional configuration object. * @param {Options} [options] Optional configuration object.
*/ */
constructor(opt_options) { constructor(options) {
super(); super();
const options = opt_options ? opt_options : {}; options = options ? options : {};
/** /**
* @private * @private
@@ -324,10 +324,10 @@ class WFS extends XMLFeature {
/** /**
* @protected * @protected
* @param {Element} node Node. * @param {Element} node Node.
* @param {import("./Feature.js").ReadOptions} [opt_options] Options. * @param {import("./Feature.js").ReadOptions} [options] Options.
* @return {Array<import("../Feature.js").default>} Features. * @return {Array<import("../Feature.js").default>} Features.
*/ */
readFeaturesFromNode(node, opt_options) { readFeaturesFromNode(node, options) {
/** @type {import("../xml.js").NodeStackItem} */ /** @type {import("../xml.js").NodeStackItem} */
const context = { const context = {
node, node,
@@ -337,10 +337,7 @@ class WFS extends XMLFeature {
'featureNS': this.featureNS_, 'featureNS': this.featureNS_,
}); });
Object.assign( Object.assign(context, this.getReadOptions(node, options ? options : {}));
context,
this.getReadOptions(node, opt_options ? opt_options : {})
);
const objectStack = [context]; const objectStack = [context];
let featuresNS; let featuresNS;
if (this.version_ === '2.0.0') { if (this.version_ === '2.0.0') {
@@ -565,16 +562,16 @@ class WFS extends XMLFeature {
* *
* @param {!string} geometryName Geometry name to use. * @param {!string} geometryName Geometry name to use.
* @param {!import("../extent.js").Extent} extent Extent. * @param {!import("../extent.js").Extent} extent Extent.
* @param {string} [opt_srsName] SRS name. No srsName attribute will be * @param {string} [srsName] SRS name. No srsName attribute will be
* set on geometries when this is not provided. * set on geometries when this is not provided.
* @param {import("./filter/Filter.js").default} [opt_filter] Filter condition. * @param {import("./filter/Filter.js").default} [filter] Filter condition.
* @return {import("./filter/Filter.js").default} The filter. * @return {import("./filter/Filter.js").default} The filter.
*/ */
combineBboxAndFilter(geometryName, extent, opt_srsName, opt_filter) { combineBboxAndFilter(geometryName, extent, srsName, filter) {
const bboxFilter = bboxFilterFn(geometryName, extent, opt_srsName); const bboxFilter = bboxFilterFn(geometryName, extent, srsName);
if (opt_filter) { if (filter) {
// if bbox and filter are both set, combine the two into a single filter // if bbox and filter are both set, combine the two into a single filter
return andFilterFn(opt_filter, bboxFilter); return andFilterFn(filter, bboxFilter);
} }
return bboxFilter; return bboxFilter;
} }
@@ -1324,12 +1321,12 @@ function writeTimeInstant(node, time) {
* Encode filter as WFS `Filter` and return the Node. * Encode filter as WFS `Filter` and return the Node.
* *
* @param {import("./filter/Filter.js").default} filter Filter. * @param {import("./filter/Filter.js").default} filter Filter.
* @param {string} opt_version WFS version. If not provided defaults to '1.1.0' * @param {string} version WFS version. If not provided defaults to '1.1.0'
* @return {Node} Result. * @return {Node} Result.
* @api * @api
*/ */
export function writeFilter(filter, opt_version) { export function writeFilter(filter, version) {
const version = opt_version || '1.1.0'; version = version || '1.1.0';
const child = createElementNS(getFilterNS(version), 'Filter'); const child = createElementNS(getFilterNS(version), 'Filter');
const context = { const context = {
node: child, node: child,

View File

@@ -700,12 +700,12 @@ class WkbWriter {
*/ */
class WKB extends FeatureFormat { class WKB extends FeatureFormat {
/** /**
* @param {Options} [opt_options] Optional configuration object. * @param {Options} [options] Optional configuration object.
*/ */
constructor(opt_options) { constructor(options) {
super(); super();
const options = opt_options ? opt_options : {}; options = options ? options : {};
this.splitCollection = Boolean(options.splitCollection); this.splitCollection = Boolean(options.splitCollection);
@@ -733,13 +733,13 @@ class WKB extends FeatureFormat {
* Read a single feature from a source. * Read a single feature from a source.
* *
* @param {string|ArrayBuffer|ArrayBufferView} source Source. * @param {string|ArrayBuffer|ArrayBufferView} source Source.
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options. * @param {import("./Feature.js").ReadOptions} [options] Read options.
* @return {import("../Feature.js").default} Feature. * @return {import("../Feature.js").default} Feature.
* @api * @api
*/ */
readFeature(source, opt_options) { readFeature(source, options) {
return new Feature({ return new Feature({
geometry: this.readGeometry(source, opt_options), geometry: this.readGeometry(source, options),
}); });
} }
@@ -747,13 +747,13 @@ class WKB extends FeatureFormat {
* Read all features from a source. * Read all features from a source.
* *
* @param {string|ArrayBuffer|ArrayBufferView} source Source. * @param {string|ArrayBuffer|ArrayBufferView} source Source.
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options. * @param {import("./Feature.js").ReadOptions} [options] Read options.
* @return {Array<import("../Feature.js").default>} Features. * @return {Array<import("../Feature.js").default>} Features.
* @api * @api
*/ */
readFeatures(source, opt_options) { readFeatures(source, options) {
let geometries = []; let geometries = [];
const geometry = this.readGeometry(source, opt_options); const geometry = this.readGeometry(source, options);
if (this.splitCollection && geometry instanceof GeometryCollection) { if (this.splitCollection && geometry instanceof GeometryCollection) {
geometries = geometry.getGeometriesArray(); geometries = geometry.getGeometriesArray();
} else { } else {
@@ -766,11 +766,11 @@ class WKB extends FeatureFormat {
* Read a single geometry from a source. * Read a single geometry from a source.
* *
* @param {string|ArrayBuffer|ArrayBufferView} source Source. * @param {string|ArrayBuffer|ArrayBufferView} source Source.
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options. * @param {import("./Feature.js").ReadOptions} [options] Read options.
* @return {import("../geom/Geometry.js").default} Geometry. * @return {import("../geom/Geometry.js").default} Geometry.
* @api * @api
*/ */
readGeometry(source, opt_options) { readGeometry(source, options) {
const view = getDataView(source); const view = getDataView(source);
if (!view) { if (!view) {
return null; return null;
@@ -780,7 +780,7 @@ class WKB extends FeatureFormat {
const geometry = reader.readGeometry(); const geometry = reader.readGeometry();
this.viewCache_ = view; // cache for internal subsequent call of readProjection() this.viewCache_ = view; // cache for internal subsequent call of readProjection()
const options = this.getReadOptions(source, opt_options); options = this.getReadOptions(source, options);
this.viewCache_ = null; // release this.viewCache_ = null; // release
return transformGeometryWithOptions(geometry, false, options); return transformGeometryWithOptions(geometry, false, options);
@@ -812,26 +812,26 @@ class WKB extends FeatureFormat {
* Encode a feature in this format. * Encode a feature in this format.
* *
* @param {import("../Feature.js").default} feature Feature. * @param {import("../Feature.js").default} feature Feature.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @return {string|ArrayBuffer} Result. * @return {string|ArrayBuffer} Result.
* @api * @api
*/ */
writeFeature(feature, opt_options) { writeFeature(feature, options) {
return this.writeGeometry(feature.getGeometry(), opt_options); return this.writeGeometry(feature.getGeometry(), options);
} }
/** /**
* Encode an array of features in this format. * Encode an array of features in this format.
* *
* @param {Array<import("../Feature.js").default>} features Features. * @param {Array<import("../Feature.js").default>} features Features.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @return {string|ArrayBuffer} Result. * @return {string|ArrayBuffer} Result.
* @api * @api
*/ */
writeFeatures(features, opt_options) { writeFeatures(features, options) {
return this.writeGeometry( return this.writeGeometry(
new GeometryCollection(features.map((f) => f.getGeometry())), new GeometryCollection(features.map((f) => f.getGeometry())),
opt_options options
); );
} }
@@ -839,12 +839,12 @@ class WKB extends FeatureFormat {
* Write a single geometry in this format. * Write a single geometry in this format.
* *
* @param {import("../geom/Geometry.js").default} geometry Geometry. * @param {import("../geom/Geometry.js").default} geometry Geometry.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @return {string|ArrayBuffer} Result. * @return {string|ArrayBuffer} Result.
* @api * @api
*/ */
writeGeometry(geometry, opt_options) { writeGeometry(geometry, options) {
const options = this.adaptOptions(opt_options); options = this.adaptOptions(options);
const writer = new WkbWriter({ const writer = new WkbWriter({
layout: this.layout_, layout: this.layout_,

View File

@@ -121,13 +121,13 @@ class Lexer {
/** /**
* @param {string} c Character. * @param {string} c Character.
* @param {boolean} [opt_decimal] Whether the string number * @param {boolean} [decimal] Whether the string number
* contains a dot, i.e. is a decimal number. * contains a dot, i.e. is a decimal number.
* @return {boolean} Whether the character is numeric. * @return {boolean} Whether the character is numeric.
* @private * @private
*/ */
isNumeric_(c, opt_decimal) { isNumeric_(c, decimal) {
const decimal = opt_decimal !== undefined ? opt_decimal : false; decimal = decimal !== undefined ? decimal : false;
return (c >= '0' && c <= '9') || (c == '.' && !decimal); return (c >= '0' && c <= '9') || (c == '.' && !decimal);
} }
@@ -601,12 +601,12 @@ class Parser {
*/ */
class WKT extends TextFeature { class WKT extends TextFeature {
/** /**
* @param {Options} [opt_options] Options. * @param {Options} [options] Options.
*/ */
constructor(opt_options) { constructor(options) {
super(); super();
const options = opt_options ? opt_options : {}; options = options ? options : {};
/** /**
* Split GeometryCollection into multiple features. * Split GeometryCollection into multiple features.
@@ -633,11 +633,11 @@ class WKT extends TextFeature {
/** /**
* @protected * @protected
* @param {string} text Text. * @param {string} text Text.
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options. * @param {import("./Feature.js").ReadOptions} [options] Read options.
* @return {import("../Feature.js").default} Feature. * @return {import("../Feature.js").default} Feature.
*/ */
readFeatureFromText(text, opt_options) { readFeatureFromText(text, options) {
const geom = this.readGeometryFromText(text, opt_options); const geom = this.readGeometryFromText(text, options);
const feature = new Feature(); const feature = new Feature();
feature.setGeometry(geom); feature.setGeometry(geom);
return feature; return feature;
@@ -645,13 +645,13 @@ class WKT extends TextFeature {
/** /**
* @param {string} text Text. * @param {string} text Text.
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options. * @param {import("./Feature.js").ReadOptions} [options] Read options.
* @protected * @protected
* @return {Array<Feature>} Features. * @return {Array<Feature>} Features.
*/ */
readFeaturesFromText(text, opt_options) { readFeaturesFromText(text, options) {
let geometries = []; let geometries = [];
const geometry = this.readGeometryFromText(text, opt_options); const geometry = this.readGeometryFromText(text, options);
if (this.splitCollection_ && geometry.getType() == 'GeometryCollection') { if (this.splitCollection_ && geometry.getType() == 'GeometryCollection') {
geometries = /** @type {GeometryCollection} */ ( geometries = /** @type {GeometryCollection} */ (
geometry geometry
@@ -670,55 +670,55 @@ class WKT extends TextFeature {
/** /**
* @param {string} text Text. * @param {string} text Text.
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options. * @param {import("./Feature.js").ReadOptions} [options] Read options.
* @protected * @protected
* @return {import("../geom/Geometry.js").default} Geometry. * @return {import("../geom/Geometry.js").default} Geometry.
*/ */
readGeometryFromText(text, opt_options) { readGeometryFromText(text, options) {
const geometry = this.parse_(text); const geometry = this.parse_(text);
return transformGeometryWithOptions(geometry, false, opt_options); return transformGeometryWithOptions(geometry, false, options);
} }
/** /**
* @param {import("../Feature.js").default} feature Features. * @param {import("../Feature.js").default} feature Features.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @protected * @protected
* @return {string} Text. * @return {string} Text.
*/ */
writeFeatureText(feature, opt_options) { writeFeatureText(feature, options) {
const geometry = feature.getGeometry(); const geometry = feature.getGeometry();
if (geometry) { if (geometry) {
return this.writeGeometryText(geometry, opt_options); return this.writeGeometryText(geometry, options);
} }
return ''; return '';
} }
/** /**
* @param {Array<import("../Feature.js").default>} features Features. * @param {Array<import("../Feature.js").default>} features Features.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @protected * @protected
* @return {string} Text. * @return {string} Text.
*/ */
writeFeaturesText(features, opt_options) { writeFeaturesText(features, options) {
if (features.length == 1) { if (features.length == 1) {
return this.writeFeatureText(features[0], opt_options); return this.writeFeatureText(features[0], options);
} }
const geometries = []; const geometries = [];
for (let i = 0, ii = features.length; i < ii; ++i) { for (let i = 0, ii = features.length; i < ii; ++i) {
geometries.push(features[i].getGeometry()); geometries.push(features[i].getGeometry());
} }
const collection = new GeometryCollection(geometries); const collection = new GeometryCollection(geometries);
return this.writeGeometryText(collection, opt_options); return this.writeGeometryText(collection, options);
} }
/** /**
* @param {import("../geom/Geometry.js").default} geometry Geometry. * @param {import("../geom/Geometry.js").default} geometry Geometry.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @protected * @protected
* @return {string} Text. * @return {string} Text.
*/ */
writeGeometryText(geometry, opt_options) { writeGeometryText(geometry, options) {
return encode(transformGeometryWithOptions(geometry, true, opt_options)); return encode(transformGeometryWithOptions(geometry, true, options));
} }
} }

View File

@@ -32,12 +32,12 @@ const layerIdentifier = '_layer';
*/ */
class WMSGetFeatureInfo extends XMLFeature { class WMSGetFeatureInfo extends XMLFeature {
/** /**
* @param {Options} [opt_options] Options. * @param {Options} [options] Options.
*/ */
constructor(opt_options) { constructor(options) {
super(); super();
const options = opt_options ? opt_options : {}; options = options ? options : {};
/** /**
* @private * @private
@@ -150,15 +150,15 @@ class WMSGetFeatureInfo extends XMLFeature {
/** /**
* @protected * @protected
* @param {Element} node Node. * @param {Element} node Node.
* @param {import("./Feature.js").ReadOptions} [opt_options] Options. * @param {import("./Feature.js").ReadOptions} [options] Options.
* @return {Array<import("../Feature.js").default>} Features. * @return {Array<import("../Feature.js").default>} Features.
*/ */
readFeaturesFromNode(node, opt_options) { readFeaturesFromNode(node, options) {
const options = {}; const internalOptions = {};
if (opt_options) { if (options) {
Object.assign(options, this.getReadOptions(node, opt_options)); Object.assign(internalOptions, this.getReadOptions(node, options));
} }
return this.readFeatures_(node, [options]); return this.readFeatures_(node, [internalOptions]);
} }
} }

View File

@@ -36,36 +36,33 @@ class XMLFeature extends FeatureFormat {
* Read a single feature. * Read a single feature.
* *
* @param {Document|Element|Object|string} source Source. * @param {Document|Element|Object|string} source Source.
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options. * @param {import("./Feature.js").ReadOptions} [options] Read options.
* @return {import("../Feature.js").default} Feature. * @return {import("../Feature.js").default} Feature.
* @api * @api
*/ */
readFeature(source, opt_options) { readFeature(source, options) {
if (!source) { if (!source) {
return null; return null;
} else if (typeof source === 'string') { } else if (typeof source === 'string') {
const doc = parse(source); const doc = parse(source);
return this.readFeatureFromDocument(doc, opt_options); return this.readFeatureFromDocument(doc, options);
} else if (isDocument(source)) { } else if (isDocument(source)) {
return this.readFeatureFromDocument( return this.readFeatureFromDocument(
/** @type {Document} */ (source), /** @type {Document} */ (source),
opt_options options
); );
} else { } else {
return this.readFeatureFromNode( return this.readFeatureFromNode(/** @type {Element} */ (source), options);
/** @type {Element} */ (source),
opt_options
);
} }
} }
/** /**
* @param {Document} doc Document. * @param {Document} doc Document.
* @param {import("./Feature.js").ReadOptions} [opt_options] Options. * @param {import("./Feature.js").ReadOptions} [options] Options.
* @return {import("../Feature.js").default} Feature. * @return {import("../Feature.js").default} Feature.
*/ */
readFeatureFromDocument(doc, opt_options) { readFeatureFromDocument(doc, options) {
const features = this.readFeaturesFromDocument(doc, opt_options); const features = this.readFeaturesFromDocument(doc, options);
if (features.length > 0) { if (features.length > 0) {
return features[0]; return features[0];
} else { } else {
@@ -75,10 +72,10 @@ class XMLFeature extends FeatureFormat {
/** /**
* @param {Element} node Node. * @param {Element} node Node.
* @param {import("./Feature.js").ReadOptions} [opt_options] Options. * @param {import("./Feature.js").ReadOptions} [options] Options.
* @return {import("../Feature.js").default} Feature. * @return {import("../Feature.js").default} Feature.
*/ */
readFeatureFromNode(node, opt_options) { readFeatureFromNode(node, options) {
return null; // not implemented return null; // not implemented
} }
@@ -86,43 +83,43 @@ class XMLFeature extends FeatureFormat {
* Read all features from a feature collection. * Read all features from a feature collection.
* *
* @param {Document|Element|Object|string} source Source. * @param {Document|Element|Object|string} source Source.
* @param {import("./Feature.js").ReadOptions} [opt_options] Options. * @param {import("./Feature.js").ReadOptions} [options] Options.
* @return {Array<import("../Feature.js").default>} Features. * @return {Array<import("../Feature.js").default>} Features.
* @api * @api
*/ */
readFeatures(source, opt_options) { readFeatures(source, options) {
if (!source) { if (!source) {
return []; return [];
} else if (typeof source === 'string') { } else if (typeof source === 'string') {
const doc = parse(source); const doc = parse(source);
return this.readFeaturesFromDocument(doc, opt_options); return this.readFeaturesFromDocument(doc, options);
} else if (isDocument(source)) { } else if (isDocument(source)) {
return this.readFeaturesFromDocument( return this.readFeaturesFromDocument(
/** @type {Document} */ (source), /** @type {Document} */ (source),
opt_options options
); );
} else { } else {
return this.readFeaturesFromNode( return this.readFeaturesFromNode(
/** @type {Element} */ (source), /** @type {Element} */ (source),
opt_options options
); );
} }
} }
/** /**
* @param {Document} doc Document. * @param {Document} doc Document.
* @param {import("./Feature.js").ReadOptions} [opt_options] Options. * @param {import("./Feature.js").ReadOptions} [options] Options.
* @protected * @protected
* @return {Array<import("../Feature.js").default>} Features. * @return {Array<import("../Feature.js").default>} Features.
*/ */
readFeaturesFromDocument(doc, opt_options) { readFeaturesFromDocument(doc, options) {
/** @type {Array<import("../Feature.js").default>} */ /** @type {Array<import("../Feature.js").default>} */
const features = []; const features = [];
for (let n = doc.firstChild; n; n = n.nextSibling) { for (let n = doc.firstChild; n; n = n.nextSibling) {
if (n.nodeType == Node.ELEMENT_NODE) { if (n.nodeType == Node.ELEMENT_NODE) {
extend( extend(
features, features,
this.readFeaturesFromNode(/** @type {Element} */ (n), opt_options) this.readFeaturesFromNode(/** @type {Element} */ (n), options)
); );
} }
} }
@@ -132,11 +129,11 @@ class XMLFeature extends FeatureFormat {
/** /**
* @abstract * @abstract
* @param {Element} node Node. * @param {Element} node Node.
* @param {import("./Feature.js").ReadOptions} [opt_options] Options. * @param {import("./Feature.js").ReadOptions} [options] Options.
* @protected * @protected
* @return {Array<import("../Feature.js").default>} Features. * @return {Array<import("../Feature.js").default>} Features.
*/ */
readFeaturesFromNode(node, opt_options) { readFeaturesFromNode(node, options) {
return abstract(); return abstract();
} }
@@ -144,45 +141,45 @@ class XMLFeature extends FeatureFormat {
* Read a single geometry from a source. * Read a single geometry from a source.
* *
* @param {Document|Element|Object|string} source Source. * @param {Document|Element|Object|string} source Source.
* @param {import("./Feature.js").ReadOptions} [opt_options] Read options. * @param {import("./Feature.js").ReadOptions} [options] Read options.
* @return {import("../geom/Geometry.js").default} Geometry. * @return {import("../geom/Geometry.js").default} Geometry.
*/ */
readGeometry(source, opt_options) { readGeometry(source, options) {
if (!source) { if (!source) {
return null; return null;
} else if (typeof source === 'string') { } else if (typeof source === 'string') {
const doc = parse(source); const doc = parse(source);
return this.readGeometryFromDocument(doc, opt_options); return this.readGeometryFromDocument(doc, options);
} else if (isDocument(source)) { } else if (isDocument(source)) {
return this.readGeometryFromDocument( return this.readGeometryFromDocument(
/** @type {Document} */ (source), /** @type {Document} */ (source),
opt_options options
); );
} else { } else {
return this.readGeometryFromNode( return this.readGeometryFromNode(
/** @type {Element} */ (source), /** @type {Element} */ (source),
opt_options options
); );
} }
} }
/** /**
* @param {Document} doc Document. * @param {Document} doc Document.
* @param {import("./Feature.js").ReadOptions} [opt_options] Options. * @param {import("./Feature.js").ReadOptions} [options] Options.
* @protected * @protected
* @return {import("../geom/Geometry.js").default} Geometry. * @return {import("../geom/Geometry.js").default} Geometry.
*/ */
readGeometryFromDocument(doc, opt_options) { readGeometryFromDocument(doc, options) {
return null; // not implemented return null; // not implemented
} }
/** /**
* @param {Element} node Node. * @param {Element} node Node.
* @param {import("./Feature.js").ReadOptions} [opt_options] Options. * @param {import("./Feature.js").ReadOptions} [options] Options.
* @protected * @protected
* @return {import("../geom/Geometry.js").default} Geometry. * @return {import("../geom/Geometry.js").default} Geometry.
*/ */
readGeometryFromNode(node, opt_options) { readGeometryFromNode(node, options) {
return null; // not implemented return null; // not implemented
} }
@@ -228,21 +225,21 @@ class XMLFeature extends FeatureFormat {
* Encode a feature as string. * Encode a feature as string.
* *
* @param {import("../Feature.js").default} feature Feature. * @param {import("../Feature.js").default} feature Feature.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @return {string} Encoded feature. * @return {string} Encoded feature.
*/ */
writeFeature(feature, opt_options) { writeFeature(feature, options) {
const node = this.writeFeatureNode(feature, opt_options); const node = this.writeFeatureNode(feature, options);
return this.xmlSerializer_.serializeToString(node); return this.xmlSerializer_.serializeToString(node);
} }
/** /**
* @param {import("../Feature.js").default} feature Feature. * @param {import("../Feature.js").default} feature Feature.
* @param {import("./Feature.js").WriteOptions} [opt_options] Options. * @param {import("./Feature.js").WriteOptions} [options] Options.
* @protected * @protected
* @return {Node} Node. * @return {Node} Node.
*/ */
writeFeatureNode(feature, opt_options) { writeFeatureNode(feature, options) {
return null; // not implemented return null; // not implemented
} }
@@ -250,21 +247,21 @@ class XMLFeature extends FeatureFormat {
* Encode an array of features as string. * Encode an array of features as string.
* *
* @param {Array<import("../Feature.js").default>} features Features. * @param {Array<import("../Feature.js").default>} features Features.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @return {string} Result. * @return {string} Result.
* @api * @api
*/ */
writeFeatures(features, opt_options) { writeFeatures(features, options) {
const node = this.writeFeaturesNode(features, opt_options); const node = this.writeFeaturesNode(features, options);
return this.xmlSerializer_.serializeToString(node); return this.xmlSerializer_.serializeToString(node);
} }
/** /**
* @param {Array<import("../Feature.js").default>} features Features. * @param {Array<import("../Feature.js").default>} features Features.
* @param {import("./Feature.js").WriteOptions} [opt_options] Options. * @param {import("./Feature.js").WriteOptions} [options] Options.
* @return {Node} Node. * @return {Node} Node.
*/ */
writeFeaturesNode(features, opt_options) { writeFeaturesNode(features, options) {
return null; // not implemented return null; // not implemented
} }
@@ -272,20 +269,20 @@ class XMLFeature extends FeatureFormat {
* Encode a geometry as string. * Encode a geometry as string.
* *
* @param {import("../geom/Geometry.js").default} geometry Geometry. * @param {import("../geom/Geometry.js").default} geometry Geometry.
* @param {import("./Feature.js").WriteOptions} [opt_options] Write options. * @param {import("./Feature.js").WriteOptions} [options] Write options.
* @return {string} Encoded geometry. * @return {string} Encoded geometry.
*/ */
writeGeometry(geometry, opt_options) { writeGeometry(geometry, options) {
const node = this.writeGeometryNode(geometry, opt_options); const node = this.writeGeometryNode(geometry, options);
return this.xmlSerializer_.serializeToString(node); return this.xmlSerializer_.serializeToString(node);
} }
/** /**
* @param {import("../geom/Geometry.js").default} geometry Geometry. * @param {import("../geom/Geometry.js").default} geometry Geometry.
* @param {import("./Feature.js").WriteOptions} [opt_options] Options. * @param {import("./Feature.js").WriteOptions} [options] Options.
* @return {Node} Node. * @return {Node} Node.
*/ */
writeGeometryNode(geometry, opt_options) { writeGeometryNode(geometry, options) {
return null; // not implemented return null; // not implemented
} }
} }

View File

@@ -63,13 +63,13 @@ export function not(condition) {
* *
* @param {!string} geometryName Geometry name to use. * @param {!string} geometryName Geometry name to use.
* @param {!import("../extent.js").Extent} extent Extent. * @param {!import("../extent.js").Extent} extent Extent.
* @param {string} [opt_srsName] SRS name. No srsName attribute will be * @param {string} [srsName] SRS name. No srsName attribute will be
* set on geometries when this is not provided. * set on geometries when this is not provided.
* @return {!Bbox} `<BBOX>` operator. * @return {!Bbox} `<BBOX>` operator.
* @api * @api
*/ */
export function bbox(geometryName, extent, opt_srsName) { export function bbox(geometryName, extent, srsName) {
return new Bbox(geometryName, extent, opt_srsName); return new Bbox(geometryName, extent, srsName);
} }
/** /**
@@ -78,13 +78,13 @@ export function bbox(geometryName, extent, opt_srsName) {
* *
* @param {!string} geometryName Geometry name to use. * @param {!string} geometryName Geometry name to use.
* @param {!import("../geom/Geometry.js").default} geometry Geometry. * @param {!import("../geom/Geometry.js").default} geometry Geometry.
* @param {string} [opt_srsName] SRS name. No srsName attribute will be * @param {string} [srsName] SRS name. No srsName attribute will be
* set on geometries when this is not provided. * set on geometries when this is not provided.
* @return {!Contains} `<Contains>` operator. * @return {!Contains} `<Contains>` operator.
* @api * @api
*/ */
export function contains(geometryName, geometry, opt_srsName) { export function contains(geometryName, geometry, srsName) {
return new Contains(geometryName, geometry, opt_srsName); return new Contains(geometryName, geometry, srsName);
} }
/** /**
@@ -93,13 +93,13 @@ export function contains(geometryName, geometry, opt_srsName) {
* *
* @param {!string} geometryName Geometry name to use. * @param {!string} geometryName Geometry name to use.
* @param {!import("../geom/Geometry.js").default} geometry Geometry. * @param {!import("../geom/Geometry.js").default} geometry Geometry.
* @param {string} [opt_srsName] SRS name. No srsName attribute will be * @param {string} [srsName] SRS name. No srsName attribute will be
* set on geometries when this is not provided. * set on geometries when this is not provided.
* @return {!Intersects} `<Intersects>` operator. * @return {!Intersects} `<Intersects>` operator.
* @api * @api
*/ */
export function intersects(geometryName, geometry, opt_srsName) { export function intersects(geometryName, geometry, srsName) {
return new Intersects(geometryName, geometry, opt_srsName); return new Intersects(geometryName, geometry, srsName);
} }
/** /**
@@ -108,13 +108,13 @@ export function intersects(geometryName, geometry, opt_srsName) {
* *
* @param {!string} geometryName Geometry name to use. * @param {!string} geometryName Geometry name to use.
* @param {!import("../geom/Geometry.js").default} geometry Geometry. * @param {!import("../geom/Geometry.js").default} geometry Geometry.
* @param {string} [opt_srsName] SRS name. No srsName attribute will be * @param {string} [srsName] SRS name. No srsName attribute will be
* set on geometries when this is not provided. * set on geometries when this is not provided.
* @return {!Disjoint} `<Disjoint>` operator. * @return {!Disjoint} `<Disjoint>` operator.
* @api * @api
*/ */
export function disjoint(geometryName, geometry, opt_srsName) { export function disjoint(geometryName, geometry, srsName) {
return new Disjoint(geometryName, geometry, opt_srsName); return new Disjoint(geometryName, geometry, srsName);
} }
/** /**
@@ -123,13 +123,13 @@ export function disjoint(geometryName, geometry, opt_srsName) {
* *
* @param {!string} geometryName Geometry name to use. * @param {!string} geometryName Geometry name to use.
* @param {!import("../geom/Geometry.js").default} geometry Geometry. * @param {!import("../geom/Geometry.js").default} geometry Geometry.
* @param {string} [opt_srsName] SRS name. No srsName attribute will be * @param {string} [srsName] SRS name. No srsName attribute will be
* set on geometries when this is not provided. * set on geometries when this is not provided.
* @return {!Within} `<Within>` operator. * @return {!Within} `<Within>` operator.
* @api * @api
*/ */
export function within(geometryName, geometry, opt_srsName) { export function within(geometryName, geometry, srsName) {
return new Within(geometryName, geometry, opt_srsName); return new Within(geometryName, geometry, srsName);
} }
/** /**
@@ -140,13 +140,13 @@ export function within(geometryName, geometry, opt_srsName) {
* @param {!import("../geom/Geometry.js").default} geometry Geometry. * @param {!import("../geom/Geometry.js").default} geometry Geometry.
* @param {!number} distance Distance. * @param {!number} distance Distance.
* @param {!string} unit Unit. * @param {!string} unit Unit.
* @param {string} [opt_srsName] SRS name. No srsName attribute will be * @param {string} [srsName] SRS name. No srsName attribute will be
* set on geometries when this is not provided. * set on geometries when this is not provided.
* @return {!DWithin} `<DWithin>` operator. * @return {!DWithin} `<DWithin>` operator.
* @api * @api
*/ */
export function dwithin(geometryName, geometry, distance, unit, opt_srsName) { export function dwithin(geometryName, geometry, distance, unit, srsName) {
return new DWithin(geometryName, geometry, distance, unit, opt_srsName); return new DWithin(geometryName, geometry, distance, unit, srsName);
} }
/** /**
@@ -154,12 +154,12 @@ export function dwithin(geometryName, geometry, distance, unit, opt_srsName) {
* *
* @param {!string} propertyName Name of the context property to compare. * @param {!string} propertyName Name of the context property to compare.
* @param {!(string|number)} expression The value to compare. * @param {!(string|number)} expression The value to compare.
* @param {boolean} [opt_matchCase] Case-sensitive? * @param {boolean} [matchCase] Case-sensitive?
* @return {!EqualTo} `<PropertyIsEqualTo>` operator. * @return {!EqualTo} `<PropertyIsEqualTo>` operator.
* @api * @api
*/ */
export function equalTo(propertyName, expression, opt_matchCase) { export function equalTo(propertyName, expression, matchCase) {
return new EqualTo(propertyName, expression, opt_matchCase); return new EqualTo(propertyName, expression, matchCase);
} }
/** /**
@@ -167,12 +167,12 @@ export function equalTo(propertyName, expression, opt_matchCase) {
* *
* @param {!string} propertyName Name of the context property to compare. * @param {!string} propertyName Name of the context property to compare.
* @param {!(string|number)} expression The value to compare. * @param {!(string|number)} expression The value to compare.
* @param {boolean} [opt_matchCase] Case-sensitive? * @param {boolean} [matchCase] Case-sensitive?
* @return {!NotEqualTo} `<PropertyIsNotEqualTo>` operator. * @return {!NotEqualTo} `<PropertyIsNotEqualTo>` operator.
* @api * @api
*/ */
export function notEqualTo(propertyName, expression, opt_matchCase) { export function notEqualTo(propertyName, expression, matchCase) {
return new NotEqualTo(propertyName, expression, opt_matchCase); return new NotEqualTo(propertyName, expression, matchCase);
} }
/** /**
@@ -255,31 +255,31 @@ export function between(propertyName, lowerBoundary, upperBoundary) {
* *
* @param {!string} propertyName Name of the context property to compare. * @param {!string} propertyName Name of the context property to compare.
* @param {!string} pattern Text pattern. * @param {!string} pattern Text pattern.
* @param {string} [opt_wildCard] Pattern character which matches any sequence of * @param {string} [wildCard] Pattern character which matches any sequence of
* zero or more string characters. Default is '*'. * zero or more string characters. Default is '*'.
* @param {string} [opt_singleChar] pattern character which matches any single * @param {string} [singleChar] pattern character which matches any single
* string character. Default is '.'. * string character. Default is '.'.
* @param {string} [opt_escapeChar] Escape character which can be used to escape * @param {string} [escapeChar] Escape character which can be used to escape
* the pattern characters. Default is '!'. * the pattern characters. Default is '!'.
* @param {boolean} [opt_matchCase] Case-sensitive? * @param {boolean} [matchCase] Case-sensitive?
* @return {!IsLike} `<PropertyIsLike>` operator. * @return {!IsLike} `<PropertyIsLike>` operator.
* @api * @api
*/ */
export function like( export function like(
propertyName, propertyName,
pattern, pattern,
opt_wildCard, wildCard,
opt_singleChar, singleChar,
opt_escapeChar, escapeChar,
opt_matchCase matchCase
) { ) {
return new IsLike( return new IsLike(
propertyName, propertyName,
pattern, pattern,
opt_wildCard, wildCard,
opt_singleChar, singleChar,
opt_escapeChar, escapeChar,
opt_matchCase matchCase
); );
} }

View File

@@ -14,10 +14,10 @@ class Bbox extends Filter {
/** /**
* @param {!string} geometryName Geometry name to use. * @param {!string} geometryName Geometry name to use.
* @param {!import("../../extent.js").Extent} extent Extent. * @param {!import("../../extent.js").Extent} extent Extent.
* @param {string} [opt_srsName] SRS name. No srsName attribute will be set * @param {string} [srsName] SRS name. No srsName attribute will be set
* on geometries when this is not provided. * on geometries when this is not provided.
*/ */
constructor(geometryName, extent, opt_srsName) { constructor(geometryName, extent, srsName) {
super('BBOX'); super('BBOX');
/** /**
@@ -38,7 +38,7 @@ class Bbox extends Filter {
/** /**
* @type {string|undefined} * @type {string|undefined}
*/ */
this.srsName = opt_srsName; this.srsName = srsName;
} }
} }

View File

@@ -15,9 +15,9 @@ class ComparisonBinary extends Comparison {
* @param {!string} tagName The XML tag name for this filter. * @param {!string} tagName The XML tag name for this filter.
* @param {!string} propertyName Name of the context property to compare. * @param {!string} propertyName Name of the context property to compare.
* @param {!(string|number)} expression The value to compare. * @param {!(string|number)} expression The value to compare.
* @param {boolean} [opt_matchCase] Case-sensitive? * @param {boolean} [matchCase] Case-sensitive?
*/ */
constructor(tagName, propertyName, expression, opt_matchCase) { constructor(tagName, propertyName, expression, matchCase) {
super(tagName, propertyName); super(tagName, propertyName);
/** /**
@@ -28,7 +28,7 @@ class ComparisonBinary extends Comparison {
/** /**
* @type {boolean|undefined} * @type {boolean|undefined}
*/ */
this.matchCase = opt_matchCase; this.matchCase = matchCase;
} }
} }

View File

@@ -13,11 +13,11 @@ class Contains extends Spatial {
/** /**
* @param {!string} geometryName Geometry name to use. * @param {!string} geometryName Geometry name to use.
* @param {!import("../../geom/Geometry.js").default} geometry Geometry. * @param {!import("../../geom/Geometry.js").default} geometry Geometry.
* @param {string} [opt_srsName] SRS name. No srsName attribute will be * @param {string} [srsName] SRS name. No srsName attribute will be
* set on geometries when this is not provided. * set on geometries when this is not provided.
*/ */
constructor(geometryName, geometry, opt_srsName) { constructor(geometryName, geometry, srsName) {
super('Contains', geometryName, geometry, opt_srsName); super('Contains', geometryName, geometry, srsName);
} }
} }

View File

@@ -15,11 +15,11 @@ class DWithin extends Spatial {
* @param {!import("../../geom/Geometry.js").default} geometry Geometry. * @param {!import("../../geom/Geometry.js").default} geometry Geometry.
* @param {!number} distance Distance. * @param {!number} distance Distance.
* @param {!string} unit Unit. * @param {!string} unit Unit.
* @param {string} [opt_srsName] SRS name. No srsName attribute will be * @param {string} [srsName] SRS name. No srsName attribute will be
* set on geometries when this is not provided. * set on geometries when this is not provided.
*/ */
constructor(geometryName, geometry, distance, unit, opt_srsName) { constructor(geometryName, geometry, distance, unit, srsName) {
super('DWithin', geometryName, geometry, opt_srsName); super('DWithin', geometryName, geometry, srsName);
/** /**
* @public * @public

View File

@@ -13,11 +13,11 @@ class Disjoint extends Spatial {
/** /**
* @param {!string} geometryName Geometry name to use. * @param {!string} geometryName Geometry name to use.
* @param {!import("../../geom/Geometry.js").default} geometry Geometry. * @param {!import("../../geom/Geometry.js").default} geometry Geometry.
* @param {string} [opt_srsName] SRS name. No srsName attribute will be * @param {string} [srsName] SRS name. No srsName attribute will be
* set on geometries when this is not provided. * set on geometries when this is not provided.
*/ */
constructor(geometryName, geometry, opt_srsName) { constructor(geometryName, geometry, srsName) {
super('Disjoint', geometryName, geometry, opt_srsName); super('Disjoint', geometryName, geometry, srsName);
} }
} }

View File

@@ -12,10 +12,10 @@ class EqualTo extends ComparisonBinary {
/** /**
* @param {!string} propertyName Name of the context property to compare. * @param {!string} propertyName Name of the context property to compare.
* @param {!(string|number)} expression The value to compare. * @param {!(string|number)} expression The value to compare.
* @param {boolean} [opt_matchCase] Case-sensitive? * @param {boolean} [matchCase] Case-sensitive?
*/ */
constructor(propertyName, expression, opt_matchCase) { constructor(propertyName, expression, matchCase) {
super('PropertyIsEqualTo', propertyName, expression, opt_matchCase); super('PropertyIsEqualTo', propertyName, expression, matchCase);
} }
} }

View File

@@ -13,11 +13,11 @@ class Intersects extends Spatial {
/** /**
* @param {!string} geometryName Geometry name to use. * @param {!string} geometryName Geometry name to use.
* @param {!import("../../geom/Geometry.js").default} geometry Geometry. * @param {!import("../../geom/Geometry.js").default} geometry Geometry.
* @param {string} [opt_srsName] SRS name. No srsName attribute will be * @param {string} [srsName] SRS name. No srsName attribute will be
* set on geometries when this is not provided. * set on geometries when this is not provided.
*/ */
constructor(geometryName, geometry, opt_srsName) { constructor(geometryName, geometry, srsName) {
super('Intersects', geometryName, geometry, opt_srsName); super('Intersects', geometryName, geometry, srsName);
} }
} }

View File

@@ -13,21 +13,21 @@ class IsLike extends Comparison {
* [constructor description] * [constructor description]
* @param {!string} propertyName Name of the context property to compare. * @param {!string} propertyName Name of the context property to compare.
* @param {!string} pattern Text pattern. * @param {!string} pattern Text pattern.
* @param {string} [opt_wildCard] Pattern character which matches any sequence of * @param {string} [wildCard] Pattern character which matches any sequence of
* zero or more string characters. Default is '*'. * zero or more string characters. Default is '*'.
* @param {string} [opt_singleChar] pattern character which matches any single * @param {string} [singleChar] pattern character which matches any single
* string character. Default is '.'. * string character. Default is '.'.
* @param {string} [opt_escapeChar] Escape character which can be used to escape * @param {string} [escapeChar] Escape character which can be used to escape
* the pattern characters. Default is '!'. * the pattern characters. Default is '!'.
* @param {boolean} [opt_matchCase] Case-sensitive? * @param {boolean} [matchCase] Case-sensitive?
*/ */
constructor( constructor(
propertyName, propertyName,
pattern, pattern,
opt_wildCard, wildCard,
opt_singleChar, singleChar,
opt_escapeChar, escapeChar,
opt_matchCase matchCase
) { ) {
super('PropertyIsLike', propertyName); super('PropertyIsLike', propertyName);
@@ -39,22 +39,22 @@ class IsLike extends Comparison {
/** /**
* @type {!string} * @type {!string}
*/ */
this.wildCard = opt_wildCard !== undefined ? opt_wildCard : '*'; this.wildCard = wildCard !== undefined ? wildCard : '*';
/** /**
* @type {!string} * @type {!string}
*/ */
this.singleChar = opt_singleChar !== undefined ? opt_singleChar : '.'; this.singleChar = singleChar !== undefined ? singleChar : '.';
/** /**
* @type {!string} * @type {!string}
*/ */
this.escapeChar = opt_escapeChar !== undefined ? opt_escapeChar : '!'; this.escapeChar = escapeChar !== undefined ? escapeChar : '!';
/** /**
* @type {boolean|undefined} * @type {boolean|undefined}
*/ */
this.matchCase = opt_matchCase; this.matchCase = matchCase;
} }
} }

View File

@@ -12,10 +12,10 @@ class NotEqualTo extends ComparisonBinary {
/** /**
* @param {!string} propertyName Name of the context property to compare. * @param {!string} propertyName Name of the context property to compare.
* @param {!(string|number)} expression The value to compare. * @param {!(string|number)} expression The value to compare.
* @param {boolean} [opt_matchCase] Case-sensitive? * @param {boolean} [matchCase] Case-sensitive?
*/ */
constructor(propertyName, expression, opt_matchCase) { constructor(propertyName, expression, matchCase) {
super('PropertyIsNotEqualTo', propertyName, expression, opt_matchCase); super('PropertyIsNotEqualTo', propertyName, expression, matchCase);
} }
} }

View File

@@ -16,10 +16,10 @@ class Spatial extends Filter {
* @param {!string} tagName The XML tag name for this filter. * @param {!string} tagName The XML tag name for this filter.
* @param {!string} geometryName Geometry name to use. * @param {!string} geometryName Geometry name to use.
* @param {!import("../../geom/Geometry.js").default} geometry Geometry. * @param {!import("../../geom/Geometry.js").default} geometry Geometry.
* @param {string} [opt_srsName] SRS name. No srsName attribute will be * @param {string} [srsName] SRS name. No srsName attribute will be
* set on geometries when this is not provided. * set on geometries when this is not provided.
*/ */
constructor(tagName, geometryName, geometry, opt_srsName) { constructor(tagName, geometryName, geometry, srsName) {
super(tagName); super(tagName);
/** /**
@@ -35,7 +35,7 @@ class Spatial extends Filter {
/** /**
* @type {string|undefined} * @type {string|undefined}
*/ */
this.srsName = opt_srsName; this.srsName = srsName;
} }
} }

View File

@@ -13,11 +13,11 @@ class Within extends Spatial {
/** /**
* @param {!string} geometryName Geometry name to use. * @param {!string} geometryName Geometry name to use.
* @param {!import("../../geom/Geometry.js").default} geometry Geometry. * @param {!import("../../geom/Geometry.js").default} geometry Geometry.
* @param {string} [opt_srsName] SRS name. No srsName attribute will be * @param {string} [srsName] SRS name. No srsName attribute will be
* set on geometries when this is not provided. * set on geometries when this is not provided.
*/ */
constructor(geometryName, geometry, opt_srsName) { constructor(geometryName, geometry, srsName) {
super('Within', geometryName, geometry, opt_srsName); super('Within', geometryName, geometry, srsName);
} }
} }

View File

@@ -15,18 +15,18 @@ import {rotate, translate} from './flat/transform.js';
class Circle extends SimpleGeometry { class Circle extends SimpleGeometry {
/** /**
* @param {!import("../coordinate.js").Coordinate} center Center. * @param {!import("../coordinate.js").Coordinate} center Center.
* For internal use, flat coordinates in combination with `opt_layout` and no * For internal use, flat coordinates in combination with `layout` and no
* `opt_radius` are also accepted. * `radius` are also accepted.
* @param {number} [opt_radius] Radius. * @param {number} [radius] Radius.
* @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout. * @param {import("./Geometry.js").GeometryLayout} [layout] Layout.
*/ */
constructor(center, opt_radius, opt_layout) { constructor(center, radius, layout) {
super(); super();
if (opt_layout !== undefined && opt_radius === undefined) { if (layout !== undefined && radius === undefined) {
this.setFlatCoordinates(opt_layout, center); this.setFlatCoordinates(layout, center);
} else { } else {
const radius = opt_radius ? opt_radius : 0; radius = radius ? radius : 0;
this.setCenterAndRadius(center, radius, opt_layout); this.setCenterAndRadius(center, radius, layout);
} }
} }
@@ -188,11 +188,11 @@ class Circle extends SimpleGeometry {
* number) of the circle. * number) of the circle.
* @param {!import("../coordinate.js").Coordinate} center Center. * @param {!import("../coordinate.js").Coordinate} center Center.
* @param {number} radius Radius. * @param {number} radius Radius.
* @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout. * @param {import("./Geometry.js").GeometryLayout} [layout] Layout.
* @api * @api
*/ */
setCenterAndRadius(center, radius, opt_layout) { setCenterAndRadius(center, radius, layout) {
this.setLayout(opt_layout, center, 0); this.setLayout(layout, center, 0);
if (!this.flatCoordinates) { if (!this.flatCoordinates) {
this.flatCoordinates = []; this.flatCoordinates = [];
} }
@@ -211,7 +211,7 @@ class Circle extends SimpleGeometry {
return null; return null;
} }
setCoordinates(coordinates, opt_layout) {} setCoordinates(coordinates, layout) {}
/** /**
* Set the radius of the circle. The radius is in the units of the projection. * Set the radius of the circle. The radius is in the units of the projection.

View File

@@ -80,19 +80,19 @@ class Geometry extends BaseObject {
* @abstract * @abstract
* @param {number} revision The geometry revision. * @param {number} revision The geometry revision.
* @param {number} squaredTolerance Squared tolerance. * @param {number} squaredTolerance Squared tolerance.
* @param {import("../proj.js").TransformFunction} [opt_transform] Optional transform function. * @param {import("../proj.js").TransformFunction} [transform] Optional transform function.
* @return {Geometry} Simplified geometry. * @return {Geometry} Simplified geometry.
*/ */
this.simplifyTransformedInternal = memoizeOne(function ( this.simplifyTransformedInternal = memoizeOne(function (
revision, revision,
squaredTolerance, squaredTolerance,
opt_transform transform
) { ) {
if (!opt_transform) { if (!transform) {
return this.getSimplifiedGeometry(squaredTolerance); return this.getSimplifiedGeometry(squaredTolerance);
} }
const clone = this.clone(); const clone = this.clone();
clone.applyTransform(opt_transform); clone.applyTransform(transform);
return clone.getSimplifiedGeometry(squaredTolerance); return clone.getSimplifiedGeometry(squaredTolerance);
}); });
} }
@@ -101,14 +101,14 @@ class Geometry extends BaseObject {
* Get a transformed and simplified version of the geometry. * Get a transformed and simplified version of the geometry.
* @abstract * @abstract
* @param {number} squaredTolerance Squared tolerance. * @param {number} squaredTolerance Squared tolerance.
* @param {import("../proj.js").TransformFunction} [opt_transform] Optional transform function. * @param {import("../proj.js").TransformFunction} [transform] Optional transform function.
* @return {Geometry} Simplified geometry. * @return {Geometry} Simplified geometry.
*/ */
simplifyTransformed(squaredTolerance, opt_transform) { simplifyTransformed(squaredTolerance, transform) {
return this.simplifyTransformedInternal( return this.simplifyTransformedInternal(
this.getRevision(), this.getRevision(),
squaredTolerance, squaredTolerance,
opt_transform transform
); );
} }
@@ -147,12 +147,12 @@ class Geometry extends BaseObject {
* Return the closest point of the geometry to the passed point as * Return the closest point of the geometry to the passed point as
* {@link module:ol/coordinate~Coordinate coordinate}. * {@link module:ol/coordinate~Coordinate coordinate}.
* @param {import("../coordinate.js").Coordinate} point Point. * @param {import("../coordinate.js").Coordinate} point Point.
* @param {import("../coordinate.js").Coordinate} [opt_closestPoint] Closest point. * @param {import("../coordinate.js").Coordinate} [closestPoint] Closest point.
* @return {import("../coordinate.js").Coordinate} Closest point. * @return {import("../coordinate.js").Coordinate} Closest point.
* @api * @api
*/ */
getClosestPoint(point, opt_closestPoint) { getClosestPoint(point, closestPoint) {
const closestPoint = opt_closestPoint ? opt_closestPoint : [NaN, NaN]; closestPoint = closestPoint ? closestPoint : [NaN, NaN];
this.closestPointXY(point[0], point[1], closestPoint, Infinity); this.closestPointXY(point[0], point[1], closestPoint, Infinity);
return closestPoint; return closestPoint;
} }
@@ -180,11 +180,11 @@ class Geometry extends BaseObject {
/** /**
* Get the extent of the geometry. * Get the extent of the geometry.
* @param {import("../extent.js").Extent} [opt_extent] Extent. * @param {import("../extent.js").Extent} [extent] Extent.
* @return {import("../extent.js").Extent} extent Extent. * @return {import("../extent.js").Extent} extent Extent.
* @api * @api
*/ */
getExtent(opt_extent) { getExtent(extent) {
if (this.extentRevision_ != this.getRevision()) { if (this.extentRevision_ != this.getRevision()) {
const extent = this.computeExtent(this.extent_); const extent = this.computeExtent(this.extent_);
if (isNaN(extent[0]) || isNaN(extent[1])) { if (isNaN(extent[0]) || isNaN(extent[1])) {
@@ -192,7 +192,7 @@ class Geometry extends BaseObject {
} }
this.extentRevision_ = this.getRevision(); this.extentRevision_ = this.getRevision();
} }
return returnOrUpdate(this.extent_, opt_extent); return returnOrUpdate(this.extent_, extent);
} }
/** /**
@@ -212,12 +212,12 @@ class Geometry extends BaseObject {
* coordinates in place. * coordinates in place.
* @abstract * @abstract
* @param {number} sx The scaling factor in the x-direction. * @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 {number} [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 {import("../coordinate.js").Coordinate} [anchor] The scale origin (defaults to the center
* of the geometry extent). * of the geometry extent).
* @api * @api
*/ */
scale(sx, opt_sy, opt_anchor) { scale(sx, sy, anchor) {
abstract(); abstract();
} }

View File

@@ -19,16 +19,16 @@ import {listen, unlistenByKey} from '../events.js';
*/ */
class GeometryCollection extends Geometry { class GeometryCollection extends Geometry {
/** /**
* @param {Array<Geometry>} [opt_geometries] Geometries. * @param {Array<Geometry>} [geometries] Geometries.
*/ */
constructor(opt_geometries) { constructor(geometries) {
super(); super();
/** /**
* @private * @private
* @type {Array<Geometry>} * @type {Array<Geometry>}
*/ */
this.geometries_ = opt_geometries ? opt_geometries : null; this.geometries_ = geometries ? geometries : null;
/** /**
* @type {Array<import("../events.js").EventsKey>} * @type {Array<import("../events.js").EventsKey>}
@@ -253,19 +253,18 @@ class GeometryCollection extends Geometry {
* coordinates in place. * coordinates in place.
* @abstract * @abstract
* @param {number} sx The scaling factor in the x-direction. * @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 {number} [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 {import("../coordinate.js").Coordinate} [anchor] The scale origin (defaults to the center
* of the geometry extent). * of the geometry extent).
* @api * @api
*/ */
scale(sx, opt_sy, opt_anchor) { scale(sx, sy, anchor) {
let anchor = opt_anchor;
if (!anchor) { if (!anchor) {
anchor = getCenter(this.getExtent()); anchor = getCenter(this.getExtent());
} }
const geometries = this.geometries_; const geometries = this.geometries_;
for (let i = 0, ii = geometries.length; i < ii; ++i) { for (let i = 0, ii = geometries.length; i < ii; ++i) {
geometries[i].scale(sx, opt_sy, anchor); geometries[i].scale(sx, sy, anchor);
} }
this.changed(); this.changed();
} }

View File

@@ -22,10 +22,10 @@ import {lineStringLength} from './flat/length.js';
class LineString extends SimpleGeometry { class LineString extends SimpleGeometry {
/** /**
* @param {Array<import("../coordinate.js").Coordinate>|Array<number>} coordinates Coordinates. * @param {Array<import("../coordinate.js").Coordinate>|Array<number>} coordinates Coordinates.
* For internal use, flat coordinates in combination with `opt_layout` are also accepted. * For internal use, flat coordinates in combination with `layout` are also accepted.
* @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout. * @param {import("./Geometry.js").GeometryLayout} [layout] Layout.
*/ */
constructor(coordinates, opt_layout) { constructor(coordinates, layout) {
super(); super();
/** /**
@@ -52,9 +52,9 @@ class LineString extends SimpleGeometry {
*/ */
this.maxDeltaRevision_ = -1; this.maxDeltaRevision_ = -1;
if (opt_layout !== undefined && !Array.isArray(coordinates[0])) { if (layout !== undefined && !Array.isArray(coordinates[0])) {
this.setFlatCoordinates( this.setFlatCoordinates(
opt_layout, layout,
/** @type {Array<number>} */ (coordinates) /** @type {Array<number>} */ (coordinates)
); );
} else { } else {
@@ -62,7 +62,7 @@ class LineString extends SimpleGeometry {
/** @type {Array<import("../coordinate.js").Coordinate>} */ ( /** @type {Array<import("../coordinate.js").Coordinate>} */ (
coordinates coordinates
), ),
opt_layout layout
); );
} }
} }
@@ -157,21 +157,21 @@ class LineString extends SimpleGeometry {
* Returns the coordinate at `m` using linear interpolation, or `null` if no * Returns the coordinate at `m` using linear interpolation, or `null` if no
* such coordinate exists. * such coordinate exists.
* *
* `opt_extrapolate` controls extrapolation beyond the range of Ms in the * `extrapolate` controls extrapolation beyond the range of Ms in the
* MultiLineString. If `opt_extrapolate` is `true` then Ms less than the first * MultiLineString. If `extrapolate` is `true` then Ms less than the first
* M will return the first coordinate and Ms greater than the last M will * M will return the first coordinate and Ms greater than the last M will
* return the last coordinate. * return the last coordinate.
* *
* @param {number} m M. * @param {number} m M.
* @param {boolean} [opt_extrapolate] Extrapolate. Default is `false`. * @param {boolean} [extrapolate] Extrapolate. Default is `false`.
* @return {import("../coordinate.js").Coordinate|null} Coordinate. * @return {import("../coordinate.js").Coordinate|null} Coordinate.
* @api * @api
*/ */
getCoordinateAtM(m, opt_extrapolate) { getCoordinateAtM(m, extrapolate) {
if (this.layout != 'XYM' && this.layout != 'XYZM') { if (this.layout != 'XYM' && this.layout != 'XYZM') {
return null; return null;
} }
const extrapolate = opt_extrapolate !== undefined ? opt_extrapolate : false; extrapolate = extrapolate !== undefined ? extrapolate : false;
return lineStringCoordinateAtM( return lineStringCoordinateAtM(
this.flatCoordinates, this.flatCoordinates,
0, 0,
@@ -201,19 +201,19 @@ class LineString extends SimpleGeometry {
* The `fraction` is a number between 0 and 1, where 0 is the start of the * The `fraction` is a number between 0 and 1, where 0 is the start of the
* linestring and 1 is the end. * linestring and 1 is the end.
* @param {number} fraction Fraction. * @param {number} fraction Fraction.
* @param {import("../coordinate.js").Coordinate} [opt_dest] Optional coordinate whose values will * @param {import("../coordinate.js").Coordinate} [dest] Optional coordinate whose values will
* be modified. If not provided, a new coordinate will be returned. * be modified. If not provided, a new coordinate will be returned.
* @return {import("../coordinate.js").Coordinate} Coordinate of the interpolated point. * @return {import("../coordinate.js").Coordinate} Coordinate of the interpolated point.
* @api * @api
*/ */
getCoordinateAt(fraction, opt_dest) { getCoordinateAt(fraction, dest) {
return interpolatePoint( return interpolatePoint(
this.flatCoordinates, this.flatCoordinates,
0, 0,
this.flatCoordinates.length, this.flatCoordinates.length,
this.stride, this.stride,
fraction, fraction,
opt_dest, dest,
this.stride this.stride
); );
} }
@@ -290,11 +290,11 @@ class LineString extends SimpleGeometry {
/** /**
* Set the coordinates of the linestring. * Set the coordinates of the linestring.
* @param {!Array<import("../coordinate.js").Coordinate>} coordinates Coordinates. * @param {!Array<import("../coordinate.js").Coordinate>} coordinates Coordinates.
* @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout. * @param {import("./Geometry.js").GeometryLayout} [layout] Layout.
* @api * @api
*/ */
setCoordinates(coordinates, opt_layout) { setCoordinates(coordinates, layout) {
this.setLayout(opt_layout, coordinates, 1); this.setLayout(layout, coordinates, 1);
if (!this.flatCoordinates) { if (!this.flatCoordinates) {
this.flatCoordinates = []; this.flatCoordinates = [];
} }

View File

@@ -19,10 +19,10 @@ import {linearRing as linearRingArea} from './flat/area.js';
class LinearRing extends SimpleGeometry { class LinearRing extends SimpleGeometry {
/** /**
* @param {Array<import("../coordinate.js").Coordinate>|Array<number>} coordinates Coordinates. * @param {Array<import("../coordinate.js").Coordinate>|Array<number>} coordinates Coordinates.
* For internal use, flat coordinates in combination with `opt_layout` are also accepted. * For internal use, flat coordinates in combination with `layout` are also accepted.
* @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout. * @param {import("./Geometry.js").GeometryLayout} [layout] Layout.
*/ */
constructor(coordinates, opt_layout) { constructor(coordinates, layout) {
super(); super();
/** /**
@@ -37,9 +37,9 @@ class LinearRing extends SimpleGeometry {
*/ */
this.maxDeltaRevision_ = -1; this.maxDeltaRevision_ = -1;
if (opt_layout !== undefined && !Array.isArray(coordinates[0])) { if (layout !== undefined && !Array.isArray(coordinates[0])) {
this.setFlatCoordinates( this.setFlatCoordinates(
opt_layout, layout,
/** @type {Array<number>} */ (coordinates) /** @type {Array<number>} */ (coordinates)
); );
} else { } else {
@@ -47,7 +47,7 @@ class LinearRing extends SimpleGeometry {
/** @type {Array<import("../coordinate.js").Coordinate>} */ ( /** @type {Array<import("../coordinate.js").Coordinate>} */ (
coordinates coordinates
), ),
opt_layout layout
); );
} }
} }
@@ -167,11 +167,11 @@ class LinearRing extends SimpleGeometry {
/** /**
* Set the coordinates of the linear ring. * Set the coordinates of the linear ring.
* @param {!Array<import("../coordinate.js").Coordinate>} coordinates Coordinates. * @param {!Array<import("../coordinate.js").Coordinate>} coordinates Coordinates.
* @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout. * @param {import("./Geometry.js").GeometryLayout} [layout] Layout.
* @api * @api
*/ */
setCoordinates(coordinates, opt_layout) { setCoordinates(coordinates, layout) {
this.setLayout(opt_layout, coordinates, 1); this.setLayout(layout, coordinates, 1);
if (!this.flatCoordinates) { if (!this.flatCoordinates) {
this.flatCoordinates = []; this.flatCoordinates = [];
} }

View File

@@ -25,11 +25,11 @@ class MultiLineString extends SimpleGeometry {
/** /**
* @param {Array<Array<import("../coordinate.js").Coordinate>|LineString>|Array<number>} coordinates * @param {Array<Array<import("../coordinate.js").Coordinate>|LineString>|Array<number>} coordinates
* Coordinates or LineString geometries. (For internal use, flat coordinates in * Coordinates or LineString geometries. (For internal use, flat coordinates in
* combination with `opt_layout` and `opt_ends` are also accepted.) * combination with `layout` and `ends` are also accepted.)
* @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout. * @param {import("./Geometry.js").GeometryLayout} [layout] Layout.
* @param {Array<number>} [opt_ends] Flat coordinate ends for internal use. * @param {Array<number>} [ends] Flat coordinate ends for internal use.
*/ */
constructor(coordinates, opt_layout, opt_ends) { constructor(coordinates, layout, ends) {
super(); super();
/** /**
@@ -55,14 +55,14 @@ class MultiLineString extends SimpleGeometry {
/** @type {Array<Array<import("../coordinate.js").Coordinate>>} */ ( /** @type {Array<Array<import("../coordinate.js").Coordinate>>} */ (
coordinates coordinates
), ),
opt_layout layout
); );
} else if (opt_layout !== undefined && opt_ends) { } else if (layout !== undefined && ends) {
this.setFlatCoordinates( this.setFlatCoordinates(
opt_layout, layout,
/** @type {Array<number>} */ (coordinates) /** @type {Array<number>} */ (coordinates)
); );
this.ends_ = opt_ends; this.ends_ = ends;
} else { } else {
let layout = this.getLayout(); let layout = this.getLayout();
const lineStrings = /** @type {Array<LineString>} */ (coordinates); const lineStrings = /** @type {Array<LineString>} */ (coordinates);
@@ -152,33 +152,33 @@ class MultiLineString extends SimpleGeometry {
* Returns the coordinate at `m` using linear interpolation, or `null` if no * Returns the coordinate at `m` using linear interpolation, or `null` if no
* such coordinate exists. * such coordinate exists.
* *
* `opt_extrapolate` controls extrapolation beyond the range of Ms in the * `extrapolate` controls extrapolation beyond the range of Ms in the
* MultiLineString. If `opt_extrapolate` is `true` then Ms less than the first * MultiLineString. If `extrapolate` is `true` then Ms less than the first
* M will return the first coordinate and Ms greater than the last M will * M will return the first coordinate and Ms greater than the last M will
* return the last coordinate. * return the last coordinate.
* *
* `opt_interpolate` controls interpolation between consecutive LineStrings * `interpolate` controls interpolation between consecutive LineStrings
* within the MultiLineString. If `opt_interpolate` is `true` the coordinates * within the MultiLineString. If `interpolate` is `true` the coordinates
* will be linearly interpolated between the last coordinate of one LineString * will be linearly interpolated between the last coordinate of one LineString
* and the first coordinate of the next LineString. If `opt_interpolate` is * and the first coordinate of the next LineString. If `interpolate` is
* `false` then the function will return `null` for Ms falling between * `false` then the function will return `null` for Ms falling between
* LineStrings. * LineStrings.
* *
* @param {number} m M. * @param {number} m M.
* @param {boolean} [opt_extrapolate] Extrapolate. Default is `false`. * @param {boolean} [extrapolate] Extrapolate. Default is `false`.
* @param {boolean} [opt_interpolate] Interpolate. Default is `false`. * @param {boolean} [interpolate] Interpolate. Default is `false`.
* @return {import("../coordinate.js").Coordinate|null} Coordinate. * @return {import("../coordinate.js").Coordinate|null} Coordinate.
* @api * @api
*/ */
getCoordinateAtM(m, opt_extrapolate, opt_interpolate) { getCoordinateAtM(m, extrapolate, interpolate) {
if ( if (
(this.layout != 'XYM' && this.layout != 'XYZM') || (this.layout != 'XYM' && this.layout != 'XYZM') ||
this.flatCoordinates.length === 0 this.flatCoordinates.length === 0
) { ) {
return null; return null;
} }
const extrapolate = opt_extrapolate !== undefined ? opt_extrapolate : false; extrapolate = extrapolate !== undefined ? extrapolate : false;
const interpolate = opt_interpolate !== undefined ? opt_interpolate : false; interpolate = interpolate !== undefined ? interpolate : false;
return lineStringsCoordinateAtM( return lineStringsCoordinateAtM(
this.flatCoordinates, this.flatCoordinates,
0, 0,
@@ -327,11 +327,11 @@ class MultiLineString extends SimpleGeometry {
/** /**
* Set the coordinates of the multilinestring. * Set the coordinates of the multilinestring.
* @param {!Array<Array<import("../coordinate.js").Coordinate>>} coordinates Coordinates. * @param {!Array<Array<import("../coordinate.js").Coordinate>>} coordinates Coordinates.
* @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout. * @param {import("./Geometry.js").GeometryLayout} [layout] Layout.
* @api * @api
*/ */
setCoordinates(coordinates, opt_layout) { setCoordinates(coordinates, layout) {
this.setLayout(opt_layout, coordinates, 2); this.setLayout(layout, coordinates, 2);
if (!this.flatCoordinates) { if (!this.flatCoordinates) {
this.flatCoordinates = []; this.flatCoordinates = [];
} }

View File

@@ -18,14 +18,14 @@ import {squaredDistance as squaredDx} from '../math.js';
class MultiPoint extends SimpleGeometry { class MultiPoint extends SimpleGeometry {
/** /**
* @param {Array<import("../coordinate.js").Coordinate>|Array<number>} coordinates Coordinates. * @param {Array<import("../coordinate.js").Coordinate>|Array<number>} coordinates Coordinates.
* For internal use, flat coordinates in combination with `opt_layout` are also accepted. * For internal use, flat coordinates in combination with `layout` are also accepted.
* @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout. * @param {import("./Geometry.js").GeometryLayout} [layout] Layout.
*/ */
constructor(coordinates, opt_layout) { constructor(coordinates, layout) {
super(); super();
if (opt_layout && !Array.isArray(coordinates[0])) { if (layout && !Array.isArray(coordinates[0])) {
this.setFlatCoordinates( this.setFlatCoordinates(
opt_layout, layout,
/** @type {Array<number>} */ (coordinates) /** @type {Array<number>} */ (coordinates)
); );
} else { } else {
@@ -33,7 +33,7 @@ class MultiPoint extends SimpleGeometry {
/** @type {Array<import("../coordinate.js").Coordinate>} */ ( /** @type {Array<import("../coordinate.js").Coordinate>} */ (
coordinates coordinates
), ),
opt_layout layout
); );
} }
} }
@@ -182,11 +182,11 @@ class MultiPoint extends SimpleGeometry {
/** /**
* Set the coordinates of the multipoint. * Set the coordinates of the multipoint.
* @param {!Array<import("../coordinate.js").Coordinate>} coordinates Coordinates. * @param {!Array<import("../coordinate.js").Coordinate>} coordinates Coordinates.
* @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout. * @param {import("./Geometry.js").GeometryLayout} [layout] Layout.
* @api * @api
*/ */
setCoordinates(coordinates, opt_layout) { setCoordinates(coordinates, layout) {
this.setLayout(opt_layout, coordinates, 1); this.setLayout(layout, coordinates, 1);
if (!this.flatCoordinates) { if (!this.flatCoordinates) {
this.flatCoordinates = []; this.flatCoordinates = [];
} }

View File

@@ -32,11 +32,11 @@ import {quantizeMultiArray} from './flat/simplify.js';
class MultiPolygon extends SimpleGeometry { class MultiPolygon extends SimpleGeometry {
/** /**
* @param {Array<Array<Array<import("../coordinate.js").Coordinate>>|Polygon>|Array<number>} coordinates Coordinates. * @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. * For internal use, flat coordinates in combination with `layout` and `endss` are also accepted.
* @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout. * @param {import("./Geometry.js").GeometryLayout} [layout] Layout.
* @param {Array<Array<number>>} [opt_endss] Array of ends for internal use with flat coordinates. * @param {Array<Array<number>>} [endss] Array of ends for internal use with flat coordinates.
*/ */
constructor(coordinates, opt_layout, opt_endss) { constructor(coordinates, layout, endss) {
super(); super();
/** /**
@@ -81,15 +81,15 @@ class MultiPolygon extends SimpleGeometry {
*/ */
this.orientedFlatCoordinates_ = null; this.orientedFlatCoordinates_ = null;
if (!opt_endss && !Array.isArray(coordinates[0])) { if (!endss && !Array.isArray(coordinates[0])) {
let layout = this.getLayout(); let thisLayout = this.getLayout();
const polygons = /** @type {Array<Polygon>} */ (coordinates); const polygons = /** @type {Array<Polygon>} */ (coordinates);
const flatCoordinates = []; const flatCoordinates = [];
const endss = []; const thisEndss = [];
for (let i = 0, ii = polygons.length; i < ii; ++i) { for (let i = 0, ii = polygons.length; i < ii; ++i) {
const polygon = polygons[i]; const polygon = polygons[i];
if (i === 0) { if (i === 0) {
layout = polygon.getLayout(); thisLayout = polygon.getLayout();
} }
const offset = flatCoordinates.length; const offset = flatCoordinates.length;
const ends = polygon.getEnds(); const ends = polygon.getEnds();
@@ -97,24 +97,24 @@ class MultiPolygon extends SimpleGeometry {
ends[j] += offset; ends[j] += offset;
} }
extend(flatCoordinates, polygon.getFlatCoordinates()); extend(flatCoordinates, polygon.getFlatCoordinates());
endss.push(ends); thisEndss.push(ends);
} }
opt_layout = layout; layout = thisLayout;
coordinates = flatCoordinates; coordinates = flatCoordinates;
opt_endss = endss; endss = thisEndss;
} }
if (opt_layout !== undefined && opt_endss) { if (layout !== undefined && endss) {
this.setFlatCoordinates( this.setFlatCoordinates(
opt_layout, layout,
/** @type {Array<number>} */ (coordinates) /** @type {Array<number>} */ (coordinates)
); );
this.endss_ = opt_endss; this.endss_ = endss;
} else { } else {
this.setCoordinates( this.setCoordinates(
/** @type {Array<Array<Array<import("../coordinate.js").Coordinate>>>} */ ( /** @type {Array<Array<Array<import("../coordinate.js").Coordinate>>>} */ (
coordinates coordinates
), ),
opt_layout layout
); );
} }
} }
@@ -236,7 +236,7 @@ class MultiPolygon extends SimpleGeometry {
* Get the coordinate array for this geometry. This array has the structure * Get the coordinate array for this geometry. This array has the structure
* of a GeoJSON coordinate array for multi-polygons. * of a GeoJSON coordinate array for multi-polygons.
* *
* @param {boolean} [opt_right] Orient coordinates according to the right-hand * @param {boolean} [right] Orient coordinates according to the right-hand
* rule (counter-clockwise for exterior and clockwise for interior rings). * rule (counter-clockwise for exterior and clockwise for interior rings).
* If `false`, coordinates will be oriented according to the left-hand rule * If `false`, coordinates will be oriented according to the left-hand rule
* (clockwise for exterior and counter-clockwise for interior rings). * (clockwise for exterior and counter-clockwise for interior rings).
@@ -245,16 +245,16 @@ class MultiPolygon extends SimpleGeometry {
* @return {Array<Array<Array<import("../coordinate.js").Coordinate>>>} Coordinates. * @return {Array<Array<Array<import("../coordinate.js").Coordinate>>>} Coordinates.
* @api * @api
*/ */
getCoordinates(opt_right) { getCoordinates(right) {
let flatCoordinates; let flatCoordinates;
if (opt_right !== undefined) { if (right !== undefined) {
flatCoordinates = this.getOrientedFlatCoordinates().slice(); flatCoordinates = this.getOrientedFlatCoordinates().slice();
orientLinearRingsArray( orientLinearRingsArray(
flatCoordinates, flatCoordinates,
0, 0,
this.endss_, this.endss_,
this.stride, this.stride,
opt_right right
); );
} else { } else {
flatCoordinates = this.flatCoordinates; flatCoordinates = this.flatCoordinates;
@@ -442,11 +442,11 @@ class MultiPolygon extends SimpleGeometry {
/** /**
* Set the coordinates of the multipolygon. * Set the coordinates of the multipolygon.
* @param {!Array<Array<Array<import("../coordinate.js").Coordinate>>>} coordinates Coordinates. * @param {!Array<Array<Array<import("../coordinate.js").Coordinate>>>} coordinates Coordinates.
* @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout. * @param {import("./Geometry.js").GeometryLayout} [layout] Layout.
* @api * @api
*/ */
setCoordinates(coordinates, opt_layout) { setCoordinates(coordinates, layout) {
this.setLayout(opt_layout, coordinates, 3); this.setLayout(layout, coordinates, 3);
if (!this.flatCoordinates) { if (!this.flatCoordinates) {
this.flatCoordinates = []; this.flatCoordinates = [];
} }

View File

@@ -15,11 +15,11 @@ import {squaredDistance as squaredDx} from '../math.js';
class Point extends SimpleGeometry { class Point extends SimpleGeometry {
/** /**
* @param {import("../coordinate.js").Coordinate} coordinates Coordinates. * @param {import("../coordinate.js").Coordinate} coordinates Coordinates.
* @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout. * @param {import("./Geometry.js").GeometryLayout} [layout] Layout.
*/ */
constructor(coordinates, opt_layout) { constructor(coordinates, layout) {
super(); super();
this.setCoordinates(coordinates, opt_layout); this.setCoordinates(coordinates, layout);
} }
/** /**
@@ -99,11 +99,11 @@ class Point extends SimpleGeometry {
/** /**
* @param {!Array<*>} coordinates Coordinates. * @param {!Array<*>} coordinates Coordinates.
* @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout. * @param {import("./Geometry.js").GeometryLayout} [layout] Layout.
* @api * @api
*/ */
setCoordinates(coordinates, opt_layout) { setCoordinates(coordinates, layout) {
this.setLayout(opt_layout, coordinates, 0); this.setLayout(layout, coordinates, 0);
if (!this.flatCoordinates) { if (!this.flatCoordinates) {
this.flatCoordinates = []; this.flatCoordinates = [];
} }

View File

@@ -32,11 +32,11 @@ class Polygon extends SimpleGeometry {
* linear ring defines a hole in the surface of the polygon. A linear ring is * linear ring defines a hole in the surface of the polygon. A linear ring is
* an array of vertices' coordinates where the first coordinate and the last are * an array of vertices' coordinates where the first coordinate and the last are
* equivalent. (For internal use, flat coordinates in combination with * equivalent. (For internal use, flat coordinates in combination with
* `opt_layout` and `opt_ends` are also accepted.) * `layout` and `ends` are also accepted.)
* @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout. * @param {import("./Geometry.js").GeometryLayout} [layout] Layout.
* @param {Array<number>} [opt_ends] Ends (for internal use with flat coordinates). * @param {Array<number>} [ends] Ends (for internal use with flat coordinates).
*/ */
constructor(coordinates, opt_layout, opt_ends) { constructor(coordinates, layout, ends) {
super(); super();
/** /**
@@ -81,18 +81,18 @@ class Polygon extends SimpleGeometry {
*/ */
this.orientedFlatCoordinates_ = null; this.orientedFlatCoordinates_ = null;
if (opt_layout !== undefined && opt_ends) { if (layout !== undefined && ends) {
this.setFlatCoordinates( this.setFlatCoordinates(
opt_layout, layout,
/** @type {Array<number>} */ (coordinates) /** @type {Array<number>} */ (coordinates)
); );
this.ends_ = opt_ends; this.ends_ = ends;
} else { } else {
this.setCoordinates( this.setCoordinates(
/** @type {Array<Array<import("../coordinate.js").Coordinate>>} */ ( /** @type {Array<Array<import("../coordinate.js").Coordinate>>} */ (
coordinates coordinates
), ),
opt_layout layout
); );
} }
} }
@@ -198,7 +198,7 @@ class Polygon extends SimpleGeometry {
* Get the coordinate array for this geometry. This array has the structure * Get the coordinate array for this geometry. This array has the structure
* of a GeoJSON coordinate array for polygons. * of a GeoJSON coordinate array for polygons.
* *
* @param {boolean} [opt_right] Orient coordinates according to the right-hand * @param {boolean} [right] Orient coordinates according to the right-hand
* rule (counter-clockwise for exterior and clockwise for interior rings). * rule (counter-clockwise for exterior and clockwise for interior rings).
* If `false`, coordinates will be oriented according to the left-hand rule * If `false`, coordinates will be oriented according to the left-hand rule
* (clockwise for exterior and counter-clockwise for interior rings). * (clockwise for exterior and counter-clockwise for interior rings).
@@ -207,11 +207,11 @@ class Polygon extends SimpleGeometry {
* @return {Array<Array<import("../coordinate.js").Coordinate>>} Coordinates. * @return {Array<Array<import("../coordinate.js").Coordinate>>} Coordinates.
* @api * @api
*/ */
getCoordinates(opt_right) { getCoordinates(right) {
let flatCoordinates; let flatCoordinates;
if (opt_right !== undefined) { if (right !== undefined) {
flatCoordinates = this.getOrientedFlatCoordinates().slice(); flatCoordinates = this.getOrientedFlatCoordinates().slice();
orientLinearRings(flatCoordinates, 0, this.ends_, this.stride, opt_right); orientLinearRings(flatCoordinates, 0, this.ends_, this.stride, right);
} else { } else {
flatCoordinates = this.flatCoordinates; flatCoordinates = this.flatCoordinates;
} }
@@ -383,11 +383,11 @@ class Polygon extends SimpleGeometry {
/** /**
* Set the coordinates of the polygon. * Set the coordinates of the polygon.
* @param {!Array<Array<import("../coordinate.js").Coordinate>>} coordinates Coordinates. * @param {!Array<Array<import("../coordinate.js").Coordinate>>} coordinates Coordinates.
* @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout. * @param {import("./Geometry.js").GeometryLayout} [layout] Layout.
* @api * @api
*/ */
setCoordinates(coordinates, opt_layout) { setCoordinates(coordinates, layout) {
this.setLayout(opt_layout, coordinates, 2); this.setLayout(layout, coordinates, 2);
if (!this.flatCoordinates) { if (!this.flatCoordinates) {
this.flatCoordinates = []; this.flatCoordinates = [];
} }
@@ -410,21 +410,21 @@ export default Polygon;
* @param {import("../coordinate.js").Coordinate} center Center (`[lon, lat]` in degrees). * @param {import("../coordinate.js").Coordinate} center Center (`[lon, lat]` in degrees).
* @param {number} radius The great-circle distance from the center to * @param {number} radius The great-circle distance from the center to
* the polygon vertices in meters. * the polygon vertices in meters.
* @param {number} [opt_n] Optional number of vertices for the resulting * @param {number} [n] Optional number of vertices for the resulting
* polygon. Default is `32`. * polygon. Default is `32`.
* @param {number} [opt_sphereRadius] Optional radius for the sphere (defaults to * @param {number} [sphereRadius] Optional radius for the sphere (defaults to
* the Earth's mean radius using the WGS84 ellipsoid). * the Earth's mean radius using the WGS84 ellipsoid).
* @return {Polygon} The "circular" polygon. * @return {Polygon} The "circular" polygon.
* @api * @api
*/ */
export function circular(center, radius, opt_n, opt_sphereRadius) { export function circular(center, radius, n, sphereRadius) {
const n = opt_n ? opt_n : 32; n = n ? n : 32;
/** @type {Array<number>} */ /** @type {Array<number>} */
const flatCoordinates = []; const flatCoordinates = [];
for (let i = 0; i < n; ++i) { for (let i = 0; i < n; ++i) {
extend( extend(
flatCoordinates, flatCoordinates,
sphereOffset(center, radius, (2 * Math.PI * i) / n, opt_sphereRadius) sphereOffset(center, radius, (2 * Math.PI * i) / n, sphereRadius)
); );
} }
flatCoordinates.push(flatCoordinates[0], flatCoordinates[1]); flatCoordinates.push(flatCoordinates[0], flatCoordinates[1]);
@@ -460,14 +460,14 @@ export function fromExtent(extent) {
/** /**
* Create a regular polygon from a circle. * Create a regular polygon from a circle.
* @param {import("./Circle.js").default} circle Circle geometry. * @param {import("./Circle.js").default} circle Circle geometry.
* @param {number} [opt_sides] Number of sides of the polygon. Default is 32. * @param {number} [sides] Number of sides of the polygon. Default is 32.
* @param {number} [opt_angle] Start angle for the first vertex of the polygon in * @param {number} [angle] Start angle for the first vertex of the polygon in
* counter-clockwise radians. 0 means East. Default is 0. * counter-clockwise radians. 0 means East. Default is 0.
* @return {Polygon} Polygon geometry. * @return {Polygon} Polygon geometry.
* @api * @api
*/ */
export function fromCircle(circle, opt_sides, opt_angle) { export function fromCircle(circle, sides, angle) {
const sides = opt_sides ? opt_sides : 32; sides = sides ? sides : 32;
const stride = circle.getStride(); const stride = circle.getStride();
const layout = circle.getLayout(); const layout = circle.getLayout();
const center = circle.getCenter(); const center = circle.getCenter();
@@ -482,7 +482,7 @@ export function fromCircle(circle, opt_sides, opt_angle) {
} }
const ends = [flatCoordinates.length]; const ends = [flatCoordinates.length];
const polygon = new Polygon(flatCoordinates, layout, ends); const polygon = new Polygon(flatCoordinates, layout, ends);
makeRegular(polygon, center, circle.getRadius(), opt_angle); makeRegular(polygon, center, circle.getRadius(), angle);
return polygon; return polygon;
} }
@@ -491,14 +491,14 @@ export function fromCircle(circle, opt_sides, opt_angle) {
* @param {Polygon} polygon Polygon geometry. * @param {Polygon} polygon Polygon geometry.
* @param {import("../coordinate.js").Coordinate} center Center of the regular polygon. * @param {import("../coordinate.js").Coordinate} center Center of the regular polygon.
* @param {number} radius Radius 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 * @param {number} [angle] Start angle for the first vertex of the polygon in
* counter-clockwise radians. 0 means East. Default is 0. * counter-clockwise radians. 0 means East. Default is 0.
*/ */
export function makeRegular(polygon, center, radius, opt_angle) { export function makeRegular(polygon, center, radius, angle) {
const flatCoordinates = polygon.getFlatCoordinates(); const flatCoordinates = polygon.getFlatCoordinates();
const stride = polygon.getStride(); const stride = polygon.getStride();
const sides = flatCoordinates.length / stride - 1; const sides = flatCoordinates.length / stride - 1;
const startAngle = opt_angle ? opt_angle : 0; const startAngle = angle ? angle : 0;
for (let i = 0; i <= sides; ++i) { for (let i = 0; i <= sides; ++i) {
const offset = i * stride; const offset = i * stride;
const angle = startAngle + (modulo(i, sides) * 2 * Math.PI) / sides; const angle = startAngle + (modulo(i, sides) * 2 * Math.PI) / sides;

View File

@@ -162,9 +162,9 @@ class SimpleGeometry extends Geometry {
/** /**
* @abstract * @abstract
* @param {!Array<*>} coordinates Coordinates. * @param {!Array<*>} coordinates Coordinates.
* @param {import("./Geometry.js").GeometryLayout} [opt_layout] Layout. * @param {import("./Geometry.js").GeometryLayout} [layout] Layout.
*/ */
setCoordinates(coordinates, opt_layout) { setCoordinates(coordinates, layout) {
abstract(); abstract();
} }
@@ -240,17 +240,15 @@ class SimpleGeometry extends Geometry {
* Scale the geometry (with an optional origin). This modifies the geometry * Scale the geometry (with an optional origin). This modifies the geometry
* coordinates in place. * coordinates in place.
* @param {number} sx The scaling factor in the x-direction. * @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 {number} [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 {import("../coordinate.js").Coordinate} [anchor] The scale origin (defaults to the center
* of the geometry extent). * of the geometry extent).
* @api * @api
*/ */
scale(sx, opt_sy, opt_anchor) { scale(sx, sy, anchor) {
let sy = opt_sy;
if (sy === undefined) { if (sy === undefined) {
sy = sx; sy = sx;
} }
let anchor = opt_anchor;
if (!anchor) { if (!anchor) {
anchor = getCenter(this.getExtent()); anchor = getCenter(this.getExtent());
} }
@@ -331,10 +329,10 @@ export function getStrideForLayout(layout) {
/** /**
* @param {SimpleGeometry} simpleGeometry Simple geometry. * @param {SimpleGeometry} simpleGeometry Simple geometry.
* @param {import("../transform.js").Transform} transform Transform. * @param {import("../transform.js").Transform} transform Transform.
* @param {Array<number>} [opt_dest] Destination. * @param {Array<number>} [dest] Destination.
* @return {Array<number>} Transformed flat coordinates. * @return {Array<number>} Transformed flat coordinates.
*/ */
export function transformGeom2D(simpleGeometry, transform, opt_dest) { export function transformGeom2D(simpleGeometry, transform, dest) {
const flatCoordinates = simpleGeometry.getFlatCoordinates(); const flatCoordinates = simpleGeometry.getFlatCoordinates();
if (!flatCoordinates) { if (!flatCoordinates) {
return null; return null;
@@ -346,7 +344,7 @@ export function transformGeom2D(simpleGeometry, transform, opt_dest) {
flatCoordinates.length, flatCoordinates.length,
stride, stride,
transform, transform,
opt_dest dest
); );
} }
} }

View File

@@ -138,7 +138,7 @@ export function multiArrayMaxSquaredDelta(
* @param {number} y Y. * @param {number} y Y.
* @param {Array<number>} closestPoint Closest point. * @param {Array<number>} closestPoint Closest point.
* @param {number} minSquaredDistance Minimum squared distance. * @param {number} minSquaredDistance Minimum squared distance.
* @param {Array<number>} [opt_tmpPoint] Temporary point object. * @param {Array<number>} [tmpPoint] Temporary point object.
* @return {number} Minimum squared distance. * @return {number} Minimum squared distance.
*/ */
export function assignClosestPoint( export function assignClosestPoint(
@@ -152,7 +152,7 @@ export function assignClosestPoint(
y, y,
closestPoint, closestPoint,
minSquaredDistance, minSquaredDistance,
opt_tmpPoint tmpPoint
) { ) {
if (offset == end) { if (offset == end) {
return minSquaredDistance; return minSquaredDistance;
@@ -176,7 +176,7 @@ export function assignClosestPoint(
return minSquaredDistance; return minSquaredDistance;
} }
} }
const tmpPoint = opt_tmpPoint ? opt_tmpPoint : [NaN, NaN]; tmpPoint = tmpPoint ? tmpPoint : [NaN, NaN];
let index = offset + stride; let index = offset + stride;
while (index < end) { while (index < end) {
assignClosest( assignClosest(
@@ -251,7 +251,7 @@ export function assignClosestPoint(
* @param {number} y Y. * @param {number} y Y.
* @param {Array<number>} closestPoint Closest point. * @param {Array<number>} closestPoint Closest point.
* @param {number} minSquaredDistance Minimum squared distance. * @param {number} minSquaredDistance Minimum squared distance.
* @param {Array<number>} [opt_tmpPoint] Temporary point object. * @param {Array<number>} [tmpPoint] Temporary point object.
* @return {number} Minimum squared distance. * @return {number} Minimum squared distance.
*/ */
export function assignClosestArrayPoint( export function assignClosestArrayPoint(
@@ -265,9 +265,9 @@ export function assignClosestArrayPoint(
y, y,
closestPoint, closestPoint,
minSquaredDistance, minSquaredDistance,
opt_tmpPoint tmpPoint
) { ) {
const tmpPoint = opt_tmpPoint ? opt_tmpPoint : [NaN, NaN]; tmpPoint = tmpPoint ? tmpPoint : [NaN, NaN];
for (let i = 0, ii = ends.length; i < ii; ++i) { for (let i = 0, ii = ends.length; i < ii; ++i) {
const end = ends[i]; const end = ends[i];
minSquaredDistance = assignClosestPoint( minSquaredDistance = assignClosestPoint(
@@ -299,7 +299,7 @@ export function assignClosestArrayPoint(
* @param {number} y Y. * @param {number} y Y.
* @param {Array<number>} closestPoint Closest point. * @param {Array<number>} closestPoint Closest point.
* @param {number} minSquaredDistance Minimum squared distance. * @param {number} minSquaredDistance Minimum squared distance.
* @param {Array<number>} [opt_tmpPoint] Temporary point object. * @param {Array<number>} [tmpPoint] Temporary point object.
* @return {number} Minimum squared distance. * @return {number} Minimum squared distance.
*/ */
export function assignClosestMultiArrayPoint( export function assignClosestMultiArrayPoint(
@@ -313,9 +313,9 @@ export function assignClosestMultiArrayPoint(
y, y,
closestPoint, closestPoint,
minSquaredDistance, minSquaredDistance,
opt_tmpPoint tmpPoint
) { ) {
const tmpPoint = opt_tmpPoint ? opt_tmpPoint : [NaN, NaN]; tmpPoint = tmpPoint ? tmpPoint : [NaN, NaN];
for (let i = 0, ii = endss.length; i < ii; ++i) { for (let i = 0, ii = endss.length; i < ii; ++i) {
const ends = endss[i]; const ends = endss[i];
minSquaredDistance = assignClosestArrayPoint( minSquaredDistance = assignClosestArrayPoint(

View File

@@ -43,7 +43,7 @@ export function deflateCoordinates(
* @param {number} offset Offset. * @param {number} offset Offset.
* @param {Array<Array<import("../../coordinate.js").Coordinate>>} coordinatess Coordinatess. * @param {Array<Array<import("../../coordinate.js").Coordinate>>} coordinatess Coordinatess.
* @param {number} stride Stride. * @param {number} stride Stride.
* @param {Array<number>} [opt_ends] Ends. * @param {Array<number>} [ends] Ends.
* @return {Array<number>} Ends. * @return {Array<number>} Ends.
*/ */
export function deflateCoordinatesArray( export function deflateCoordinatesArray(
@@ -51,9 +51,9 @@ export function deflateCoordinatesArray(
offset, offset,
coordinatess, coordinatess,
stride, stride,
opt_ends ends
) { ) {
const ends = opt_ends ? opt_ends : []; ends = ends ? ends : [];
let i = 0; let i = 0;
for (let j = 0, jj = coordinatess.length; j < jj; ++j) { for (let j = 0, jj = coordinatess.length; j < jj; ++j) {
const end = deflateCoordinates( const end = deflateCoordinates(
@@ -74,7 +74,7 @@ export function deflateCoordinatesArray(
* @param {number} offset Offset. * @param {number} offset Offset.
* @param {Array<Array<Array<import("../../coordinate.js").Coordinate>>>} coordinatesss Coordinatesss. * @param {Array<Array<Array<import("../../coordinate.js").Coordinate>>>} coordinatesss Coordinatesss.
* @param {number} stride Stride. * @param {number} stride Stride.
* @param {Array<Array<number>>} [opt_endss] Endss. * @param {Array<Array<number>>} [endss] Endss.
* @return {Array<Array<number>>} Endss. * @return {Array<Array<number>>} Endss.
*/ */
export function deflateMultiCoordinatesArray( export function deflateMultiCoordinatesArray(
@@ -82,9 +82,9 @@ export function deflateMultiCoordinatesArray(
offset, offset,
coordinatesss, coordinatesss,
stride, stride,
opt_endss endss
) { ) {
const endss = opt_endss ? opt_endss : []; endss = endss ? endss : [];
let i = 0; let i = 0;
for (let j = 0, jj = coordinatesss.length; j < jj; ++j) { for (let j = 0, jj = coordinatesss.length; j < jj; ++j) {
const ends = deflateCoordinatesArray( const ends = deflateCoordinatesArray(

View File

@@ -7,22 +7,14 @@
* @param {number} offset Offset. * @param {number} offset Offset.
* @param {number} end End. * @param {number} end End.
* @param {number} stride Stride. * @param {number} stride Stride.
* @param {Array<number>} [opt_dest] Destination. * @param {Array<number>} [dest] Destination.
* @param {number} [opt_destOffset] Destination offset. * @param {number} [destOffset] Destination offset.
* @return {Array<number>} Flat coordinates. * @return {Array<number>} Flat coordinates.
*/ */
export function flipXY( export function flipXY(flatCoordinates, offset, end, stride, dest, destOffset) {
flatCoordinates, if (dest !== undefined) {
offset, dest = dest;
end, destOffset = destOffset !== undefined ? destOffset : 0;
stride,
opt_dest,
opt_destOffset
) {
let dest, destOffset;
if (opt_dest !== undefined) {
dest = opt_dest;
destOffset = opt_destOffset !== undefined ? opt_destOffset : 0;
} else { } else {
dest = []; dest = [];
destOffset = 0; destOffset = 0;

View File

@@ -7,7 +7,7 @@
* @param {number} offset Offset. * @param {number} offset Offset.
* @param {number} end End. * @param {number} end End.
* @param {number} stride Stride. * @param {number} stride Stride.
* @param {Array<import("../../coordinate.js").Coordinate>} [opt_coordinates] Coordinates. * @param {Array<import("../../coordinate.js").Coordinate>} [coordinates] Coordinates.
* @return {Array<import("../../coordinate.js").Coordinate>} Coordinates. * @return {Array<import("../../coordinate.js").Coordinate>} Coordinates.
*/ */
export function inflateCoordinates( export function inflateCoordinates(
@@ -15,9 +15,9 @@ export function inflateCoordinates(
offset, offset,
end, end,
stride, stride,
opt_coordinates coordinates
) { ) {
const coordinates = opt_coordinates !== undefined ? opt_coordinates : []; coordinates = coordinates !== undefined ? coordinates : [];
let i = 0; let i = 0;
for (let j = offset; j < end; j += stride) { for (let j = offset; j < end; j += stride) {
coordinates[i++] = flatCoordinates.slice(j, j + stride); coordinates[i++] = flatCoordinates.slice(j, j + stride);
@@ -31,7 +31,7 @@ export function inflateCoordinates(
* @param {number} offset Offset. * @param {number} offset Offset.
* @param {Array<number>} ends Ends. * @param {Array<number>} ends Ends.
* @param {number} stride Stride. * @param {number} stride Stride.
* @param {Array<Array<import("../../coordinate.js").Coordinate>>} [opt_coordinatess] Coordinatess. * @param {Array<Array<import("../../coordinate.js").Coordinate>>} [coordinatess] Coordinatess.
* @return {Array<Array<import("../../coordinate.js").Coordinate>>} Coordinatess. * @return {Array<Array<import("../../coordinate.js").Coordinate>>} Coordinatess.
*/ */
export function inflateCoordinatesArray( export function inflateCoordinatesArray(
@@ -39,9 +39,9 @@ export function inflateCoordinatesArray(
offset, offset,
ends, ends,
stride, stride,
opt_coordinatess coordinatess
) { ) {
const coordinatess = opt_coordinatess !== undefined ? opt_coordinatess : []; coordinatess = coordinatess !== undefined ? coordinatess : [];
let i = 0; let i = 0;
for (let j = 0, jj = ends.length; j < jj; ++j) { for (let j = 0, jj = ends.length; j < jj; ++j) {
const end = ends[j]; const end = ends[j];
@@ -63,7 +63,7 @@ export function inflateCoordinatesArray(
* @param {number} offset Offset. * @param {number} offset Offset.
* @param {Array<Array<number>>} endss Endss. * @param {Array<Array<number>>} endss Endss.
* @param {number} stride Stride. * @param {number} stride Stride.
* @param {Array<Array<Array<import("../../coordinate.js").Coordinate>>>} [opt_coordinatesss] * @param {Array<Array<Array<import("../../coordinate.js").Coordinate>>>} [coordinatesss]
* Coordinatesss. * Coordinatesss.
* @return {Array<Array<Array<import("../../coordinate.js").Coordinate>>>} Coordinatesss. * @return {Array<Array<Array<import("../../coordinate.js").Coordinate>>>} Coordinatesss.
*/ */
@@ -72,10 +72,9 @@ export function inflateMultiCoordinatesArray(
offset, offset,
endss, endss,
stride, stride,
opt_coordinatesss coordinatesss
) { ) {
const coordinatesss = coordinatesss = coordinatesss !== undefined ? coordinatesss : [];
opt_coordinatesss !== undefined ? opt_coordinatesss : [];
let i = 0; let i = 0;
for (let j = 0, jj = endss.length; j < jj; ++j) { for (let j = 0, jj = endss.length; j < jj; ++j) {
const ends = endss[j]; const ends = endss[j];

View File

@@ -13,7 +13,7 @@ import {numberSafeCompareFunction} from '../../array.js';
* @param {number} stride Stride. * @param {number} stride Stride.
* @param {Array<number>} flatCenters Flat centers. * @param {Array<number>} flatCenters Flat centers.
* @param {number} flatCentersOffset Flat center offset. * @param {number} flatCentersOffset Flat center offset.
* @param {Array<number>} [opt_dest] Destination. * @param {Array<number>} [dest] Destination.
* @return {Array<number>} Destination point as XYM coordinate, where M is the * @return {Array<number>} Destination point as XYM coordinate, where M is the
* length of the horizontal intersection that the point belongs to. * length of the horizontal intersection that the point belongs to.
*/ */
@@ -24,7 +24,7 @@ export function getInteriorPointOfArray(
stride, stride,
flatCenters, flatCenters,
flatCentersOffset, flatCentersOffset,
opt_dest dest
) { ) {
let i, ii, x, x1, x2, y1, y2; let i, ii, x, x1, x2, y1, y2;
const y = flatCenters[flatCentersOffset + 1]; const y = flatCenters[flatCentersOffset + 1];
@@ -69,9 +69,9 @@ export function getInteriorPointOfArray(
// ring. Use the center of the the linear ring's extent. // ring. Use the center of the the linear ring's extent.
pointX = flatCenters[flatCentersOffset]; pointX = flatCenters[flatCentersOffset];
} }
if (opt_dest) { if (dest) {
opt_dest.push(pointX, y, maxSegmentLength); dest.push(pointX, y, maxSegmentLength);
return opt_dest; return dest;
} else { } else {
return [pointX, y, maxSegmentLength]; return [pointX, y, maxSegmentLength];
} }

View File

@@ -10,8 +10,8 @@ import {lerp} from '../../math.js';
* @param {number} end End. * @param {number} end End.
* @param {number} stride Stride. * @param {number} stride Stride.
* @param {number} fraction Fraction. * @param {number} fraction Fraction.
* @param {Array<number>} [opt_dest] Destination. * @param {Array<number>} [dest] Destination.
* @param {number} [opt_dimension] Destination dimension (default is `2`) * @param {number} [dimension] Destination dimension (default is `2`)
* @return {Array<number>} Destination. * @return {Array<number>} Destination.
*/ */
export function interpolatePoint( export function interpolatePoint(
@@ -20,8 +20,8 @@ export function interpolatePoint(
end, end,
stride, stride,
fraction, fraction,
opt_dest, dest,
opt_dimension dimension
) { ) {
let o, t; let o, t;
const n = (end - offset) / stride; const n = (end - offset) / stride;
@@ -54,8 +54,8 @@ export function interpolatePoint(
o = offset + index * stride; o = offset + index * stride;
} }
} }
const dimension = opt_dimension > 1 ? opt_dimension : 2; dimension = dimension > 1 ? dimension : 2;
const dest = opt_dest ? opt_dest : new Array(dimension); dest = dest ? dest : new Array(dimension);
for (let i = 0; i < dimension; ++i) { for (let i = 0; i < dimension; ++i) {
dest[i] = dest[i] =
o === undefined o === undefined

View File

@@ -32,13 +32,13 @@ export function linearRingIsClockwise(flatCoordinates, offset, end, stride) {
/** /**
* Determines if linear rings are oriented. By default, left-hand orientation * Determines if linear rings are oriented. By default, left-hand orientation
* is tested (first ring must be clockwise, remaining rings counter-clockwise). * is tested (first ring must be clockwise, remaining rings counter-clockwise).
* To test for right-hand orientation, use the `opt_right` argument. * To test for right-hand orientation, use the `right` argument.
* *
* @param {Array<number>} flatCoordinates Flat coordinates. * @param {Array<number>} flatCoordinates Flat coordinates.
* @param {number} offset Offset. * @param {number} offset Offset.
* @param {Array<number>} ends Array of end indexes. * @param {Array<number>} ends Array of end indexes.
* @param {number} stride Stride. * @param {number} stride Stride.
* @param {boolean} [opt_right] Test for right-hand orientation * @param {boolean} [right] Test for right-hand orientation
* (counter-clockwise exterior ring and clockwise interior rings). * (counter-clockwise exterior ring and clockwise interior rings).
* @return {boolean} Rings are correctly oriented. * @return {boolean} Rings are correctly oriented.
*/ */
@@ -47,9 +47,9 @@ export function linearRingsAreOriented(
offset, offset,
ends, ends,
stride, stride,
opt_right right
) { ) {
const right = opt_right !== undefined ? opt_right : false; right = right !== undefined ? right : false;
for (let i = 0, ii = ends.length; i < ii; ++i) { for (let i = 0, ii = ends.length; i < ii; ++i) {
const end = ends[i]; const end = ends[i];
const isClockwise = linearRingIsClockwise( const isClockwise = linearRingIsClockwise(
@@ -75,13 +75,13 @@ export function linearRingsAreOriented(
/** /**
* Determines if linear rings are oriented. By default, left-hand orientation * Determines if linear rings are oriented. By default, left-hand orientation
* is tested (first ring must be clockwise, remaining rings counter-clockwise). * is tested (first ring must be clockwise, remaining rings counter-clockwise).
* To test for right-hand orientation, use the `opt_right` argument. * To test for right-hand orientation, use the `right` argument.
* *
* @param {Array<number>} flatCoordinates Flat coordinates. * @param {Array<number>} flatCoordinates Flat coordinates.
* @param {number} offset Offset. * @param {number} offset Offset.
* @param {Array<Array<number>>} endss Array of array of end indexes. * @param {Array<Array<number>>} endss Array of array of end indexes.
* @param {number} stride Stride. * @param {number} stride Stride.
* @param {boolean} [opt_right] Test for right-hand orientation * @param {boolean} [right] Test for right-hand orientation
* (counter-clockwise exterior ring and clockwise interior rings). * (counter-clockwise exterior ring and clockwise interior rings).
* @return {boolean} Rings are correctly oriented. * @return {boolean} Rings are correctly oriented.
*/ */
@@ -90,13 +90,11 @@ export function linearRingssAreOriented(
offset, offset,
endss, endss,
stride, stride,
opt_right right
) { ) {
for (let i = 0, ii = endss.length; i < ii; ++i) { for (let i = 0, ii = endss.length; i < ii; ++i) {
const ends = endss[i]; const ends = endss[i];
if ( if (!linearRingsAreOriented(flatCoordinates, offset, ends, stride, right)) {
!linearRingsAreOriented(flatCoordinates, offset, ends, stride, opt_right)
) {
return false; return false;
} }
if (ends.length) { if (ends.length) {
@@ -110,13 +108,13 @@ export function linearRingssAreOriented(
* Orient coordinates in a flat array of linear rings. By default, rings * Orient coordinates in a flat array of linear rings. By default, rings
* are oriented following the left-hand rule (clockwise for exterior and * are oriented following the left-hand rule (clockwise for exterior and
* counter-clockwise for interior rings). To orient according to the * counter-clockwise for interior rings). To orient according to the
* right-hand rule, use the `opt_right` argument. * right-hand rule, use the `right` argument.
* *
* @param {Array<number>} flatCoordinates Flat coordinates. * @param {Array<number>} flatCoordinates Flat coordinates.
* @param {number} offset Offset. * @param {number} offset Offset.
* @param {Array<number>} ends Ends. * @param {Array<number>} ends Ends.
* @param {number} stride Stride. * @param {number} stride Stride.
* @param {boolean} [opt_right] Follow the right-hand rule for orientation. * @param {boolean} [right] Follow the right-hand rule for orientation.
* @return {number} End. * @return {number} End.
*/ */
export function orientLinearRings( export function orientLinearRings(
@@ -124,9 +122,9 @@ export function orientLinearRings(
offset, offset,
ends, ends,
stride, stride,
opt_right right
) { ) {
const right = opt_right !== undefined ? opt_right : false; right = right !== undefined ? right : false;
for (let i = 0, ii = ends.length; i < ii; ++i) { for (let i = 0, ii = ends.length; i < ii; ++i) {
const end = ends[i]; const end = ends[i];
const isClockwise = linearRingIsClockwise( const isClockwise = linearRingIsClockwise(
@@ -151,13 +149,13 @@ export function orientLinearRings(
* Orient coordinates in a flat array of linear rings. By default, rings * Orient coordinates in a flat array of linear rings. By default, rings
* are oriented following the left-hand rule (clockwise for exterior and * are oriented following the left-hand rule (clockwise for exterior and
* counter-clockwise for interior rings). To orient according to the * counter-clockwise for interior rings). To orient according to the
* right-hand rule, use the `opt_right` argument. * right-hand rule, use the `right` argument.
* *
* @param {Array<number>} flatCoordinates Flat coordinates. * @param {Array<number>} flatCoordinates Flat coordinates.
* @param {number} offset Offset. * @param {number} offset Offset.
* @param {Array<Array<number>>} endss Array of array of end indexes. * @param {Array<Array<number>>} endss Array of array of end indexes.
* @param {number} stride Stride. * @param {number} stride Stride.
* @param {boolean} [opt_right] Follow the right-hand rule for orientation. * @param {boolean} [right] Follow the right-hand rule for orientation.
* @return {number} End. * @return {number} End.
*/ */
export function orientLinearRingsArray( export function orientLinearRingsArray(
@@ -165,7 +163,7 @@ export function orientLinearRingsArray(
offset, offset,
endss, endss,
stride, stride,
opt_right right
) { ) {
for (let i = 0, ii = endss.length; i < ii; ++i) { for (let i = 0, ii = endss.length; i < ii; ++i) {
offset = orientLinearRings( offset = orientLinearRings(
@@ -173,7 +171,7 @@ export function orientLinearRingsArray(
offset, offset,
endss[i], endss[i],
stride, stride,
opt_right right
); );
} }
return offset; return offset;

View File

@@ -36,7 +36,7 @@ import {squaredDistance, squaredSegmentDistance} from '../../math.js';
* @param {number} stride Stride. * @param {number} stride Stride.
* @param {number} squaredTolerance Squared tolerance. * @param {number} squaredTolerance Squared tolerance.
* @param {boolean} highQuality Highest quality. * @param {boolean} highQuality Highest quality.
* @param {Array<number>} [opt_simplifiedFlatCoordinates] Simplified flat * @param {Array<number>} [simplifiedFlatCoordinates] Simplified flat
* coordinates. * coordinates.
* @return {Array<number>} Simplified line string. * @return {Array<number>} Simplified line string.
*/ */
@@ -47,12 +47,10 @@ export function simplifyLineString(
stride, stride,
squaredTolerance, squaredTolerance,
highQuality, highQuality,
opt_simplifiedFlatCoordinates simplifiedFlatCoordinates
) { ) {
const simplifiedFlatCoordinates = simplifiedFlatCoordinates =
opt_simplifiedFlatCoordinates !== undefined simplifiedFlatCoordinates !== undefined ? simplifiedFlatCoordinates : [];
? opt_simplifiedFlatCoordinates
: [];
if (!highQuality) { if (!highQuality) {
end = radialDistance( end = radialDistance(
flatCoordinates, flatCoordinates,

View File

@@ -8,7 +8,7 @@
* @param {number} end End. * @param {number} end End.
* @param {number} stride Stride. * @param {number} stride Stride.
* @param {import("../../transform.js").Transform} transform Transform. * @param {import("../../transform.js").Transform} transform Transform.
* @param {Array<number>} [opt_dest] Destination. * @param {Array<number>} [dest] Destination.
* @return {Array<number>} Transformed coordinates. * @return {Array<number>} Transformed coordinates.
*/ */
export function transform2D( export function transform2D(
@@ -17,9 +17,9 @@ export function transform2D(
end, end,
stride, stride,
transform, transform,
opt_dest dest
) { ) {
const dest = opt_dest ? opt_dest : []; dest = dest ? dest : [];
let i = 0; let i = 0;
for (let j = offset; j < end; j += stride) { for (let j = offset; j < end; j += stride) {
const x = flatCoordinates[j]; const x = flatCoordinates[j];
@@ -27,7 +27,7 @@ export function transform2D(
dest[i++] = transform[0] * x + transform[2] * y + transform[4]; dest[i++] = transform[0] * x + transform[2] * y + transform[4];
dest[i++] = transform[1] * x + transform[3] * y + transform[5]; dest[i++] = transform[1] * x + transform[3] * y + transform[5];
} }
if (opt_dest && dest.length != i) { if (dest && dest.length != i) {
dest.length = i; dest.length = i;
} }
return dest; return dest;
@@ -40,7 +40,7 @@ export function transform2D(
* @param {number} stride Stride. * @param {number} stride Stride.
* @param {number} angle Angle. * @param {number} angle Angle.
* @param {Array<number>} anchor Rotation anchor point. * @param {Array<number>} anchor Rotation anchor point.
* @param {Array<number>} [opt_dest] Destination. * @param {Array<number>} [dest] Destination.
* @return {Array<number>} Transformed coordinates. * @return {Array<number>} Transformed coordinates.
*/ */
export function rotate( export function rotate(
@@ -50,9 +50,9 @@ export function rotate(
stride, stride,
angle, angle,
anchor, anchor,
opt_dest dest
) { ) {
const dest = opt_dest ? opt_dest : []; dest = dest ? dest : [];
const cos = Math.cos(angle); const cos = Math.cos(angle);
const sin = Math.sin(angle); const sin = Math.sin(angle);
const anchorX = anchor[0]; const anchorX = anchor[0];
@@ -67,7 +67,7 @@ export function rotate(
dest[i++] = flatCoordinates[k]; dest[i++] = flatCoordinates[k];
} }
} }
if (opt_dest && dest.length != i) { if (dest && dest.length != i) {
dest.length = i; dest.length = i;
} }
return dest; return dest;
@@ -82,7 +82,7 @@ export function rotate(
* @param {number} sx Scale factor in the x-direction. * @param {number} sx Scale factor in the x-direction.
* @param {number} sy Scale factor in the y-direction. * @param {number} sy Scale factor in the y-direction.
* @param {Array<number>} anchor Scale anchor point. * @param {Array<number>} anchor Scale anchor point.
* @param {Array<number>} [opt_dest] Destination. * @param {Array<number>} [dest] Destination.
* @return {Array<number>} Transformed coordinates. * @return {Array<number>} Transformed coordinates.
*/ */
export function scale( export function scale(
@@ -93,9 +93,9 @@ export function scale(
sx, sx,
sy, sy,
anchor, anchor,
opt_dest dest
) { ) {
const dest = opt_dest ? opt_dest : []; dest = dest ? dest : [];
const anchorX = anchor[0]; const anchorX = anchor[0];
const anchorY = anchor[1]; const anchorY = anchor[1];
let i = 0; let i = 0;
@@ -108,7 +108,7 @@ export function scale(
dest[i++] = flatCoordinates[k]; dest[i++] = flatCoordinates[k];
} }
} }
if (opt_dest && dest.length != i) { if (dest && dest.length != i) {
dest.length = i; dest.length = i;
} }
return dest; return dest;
@@ -121,7 +121,7 @@ export function scale(
* @param {number} stride Stride. * @param {number} stride Stride.
* @param {number} deltaX Delta X. * @param {number} deltaX Delta X.
* @param {number} deltaY Delta Y. * @param {number} deltaY Delta Y.
* @param {Array<number>} [opt_dest] Destination. * @param {Array<number>} [dest] Destination.
* @return {Array<number>} Transformed coordinates. * @return {Array<number>} Transformed coordinates.
*/ */
export function translate( export function translate(
@@ -131,9 +131,9 @@ export function translate(
stride, stride,
deltaX, deltaX,
deltaY, deltaY,
opt_dest dest
) { ) {
const dest = opt_dest ? opt_dest : []; dest = dest ? dest : [];
let i = 0; let i = 0;
for (let j = offset; j < end; j += stride) { for (let j = offset; j < end; j += stride) {
dest[i++] = flatCoordinates[j] + deltaX; dest[i++] = flatCoordinates[j] + deltaX;
@@ -142,7 +142,7 @@ export function translate(
dest[i++] = flatCoordinates[k]; dest[i++] = flatCoordinates[k];
} }
} }
if (opt_dest && dest.length != i) { if (dest && dest.length != i) {
dest.length = i; dest.length = i;
} }
return dest; return dest;

View File

@@ -17,12 +17,12 @@ import MapBrowserEventType from '../MapBrowserEventType.js';
*/ */
class DoubleClickZoom extends Interaction { class DoubleClickZoom extends Interaction {
/** /**
* @param {Options} [opt_options] Options. * @param {Options} [options] Options.
*/ */
constructor(opt_options) { constructor(options) {
super(); super();
const options = opt_options ? opt_options : {}; options = options ? options : {};
/** /**
* @private * @private

View File

@@ -44,10 +44,10 @@ export class DragAndDropEvent extends Event {
/** /**
* @param {DragAndDropEventType} type Type. * @param {DragAndDropEventType} type Type.
* @param {File} file File. * @param {File} file File.
* @param {Array<import("../Feature.js").default>} [opt_features] Features. * @param {Array<import("../Feature.js").default>} [features] Features.
* @param {import("../proj/Projection.js").default} [opt_projection] Projection. * @param {import("../proj/Projection.js").default} [projection] Projection.
*/ */
constructor(type, file, opt_features, opt_projection) { constructor(type, file, features, projection) {
super(type); super(type);
/** /**
@@ -55,7 +55,7 @@ export class DragAndDropEvent extends Event {
* @type {Array<import("../Feature.js").FeatureLike>|undefined} * @type {Array<import("../Feature.js").FeatureLike>|undefined}
* @api * @api
*/ */
this.features = opt_features; this.features = features;
/** /**
* The dropped file. * The dropped file.
@@ -69,7 +69,7 @@ export class DragAndDropEvent extends Event {
* @type {import("../proj/Projection.js").default|undefined} * @type {import("../proj/Projection.js").default|undefined}
* @api * @api
*/ */
this.projection = opt_projection; this.projection = projection;
} }
} }
@@ -93,10 +93,10 @@ export class DragAndDropEvent extends Event {
*/ */
class DragAndDrop extends Interaction { class DragAndDrop extends Interaction {
/** /**
* @param {Options} [opt_options] Options. * @param {Options} [options] Options.
*/ */
constructor(opt_options) { constructor(options) {
const options = opt_options ? opt_options : {}; options = options ? options : {};
super({ super({
handleEvent: TRUE, handleEvent: TRUE,

View File

@@ -117,9 +117,9 @@ export class DragBoxEvent extends Event {
*/ */
class DragBox extends PointerInteraction { class DragBox extends PointerInteraction {
/** /**
* @param {Options} [opt_options] Options. * @param {Options} [options] Options.
*/ */
constructor(opt_options) { constructor(options) {
super(); super();
/*** /***
@@ -137,7 +137,7 @@ class DragBox extends PointerInteraction {
*/ */
this.un; this.un;
const options = opt_options ? opt_options : {}; options = options ? options : {};
/** /**
* @type {import("../render/Box.js").default} * @type {import("../render/Box.js").default}

View File

@@ -34,14 +34,14 @@ import {
*/ */
class DragPan extends PointerInteraction { class DragPan extends PointerInteraction {
/** /**
* @param {Options} [opt_options] Options. * @param {Options} [options] Options.
*/ */
constructor(opt_options) { constructor(options) {
super({ super({
stopDown: FALSE, stopDown: FALSE,
}); });
const options = opt_options ? opt_options : {}; options = options ? options : {};
/** /**
* @private * @private

View File

@@ -30,10 +30,10 @@ import {disable} from '../rotationconstraint.js';
*/ */
class DragRotate extends PointerInteraction { class DragRotate extends PointerInteraction {
/** /**
* @param {Options} [opt_options] Options. * @param {Options} [options] Options.
*/ */
constructor(opt_options) { constructor(options) {
const options = opt_options ? opt_options : {}; options = options ? options : {};
super({ super({
stopDown: FALSE, stopDown: FALSE,

View File

@@ -26,10 +26,10 @@ import {mouseOnly, shiftKeyOnly} from '../events/condition.js';
*/ */
class DragRotateAndZoom extends PointerInteraction { class DragRotateAndZoom extends PointerInteraction {
/** /**
* @param {Options} [opt_options] Options. * @param {Options} [options] Options.
*/ */
constructor(opt_options) { constructor(options) {
const options = opt_options ? opt_options : {}; options = options ? options : {};
super(/** @type {import("./Pointer.js").Options} */ (options)); super(/** @type {import("./Pointer.js").Options} */ (options));

View File

@@ -31,10 +31,10 @@ import {shiftKeyOnly} from '../events/condition.js';
*/ */
class DragZoom extends DragBox { class DragZoom extends DragBox {
/** /**
* @param {Options} [opt_options] Options. * @param {Options} [options] Options.
*/ */
constructor(opt_options) { constructor(options) {
const options = opt_options ? opt_options : {}; options = options ? options : {};
const condition = options.condition ? options.condition : shiftKeyOnly; const condition = options.condition ? options.condition : shiftKeyOnly;

View File

@@ -1179,17 +1179,17 @@ function getDefaultStyleFunction() {
* Create a `geometryFunction` for `type: 'Circle'` that will create a regular * Create a `geometryFunction` for `type: 'Circle'` that will create a regular
* polygon with a user specified number of sides and start angle instead of a * polygon with a user specified number of sides and start angle instead of a
* {@link import("../geom/Circle.js").Circle} geometry. * {@link import("../geom/Circle.js").Circle} geometry.
* @param {number} [opt_sides] Number of sides of the regular polygon. * @param {number} [sides] Number of sides of the regular polygon.
* Default is 32. * Default is 32.
* @param {number} [opt_angle] Angle of the first point in counter-clockwise * @param {number} [angle] Angle of the first point in counter-clockwise
* radians. 0 means East. * radians. 0 means East.
* Default is the angle defined by the heading from the center of the * Default is the angle defined by the heading from the center of the
* regular polygon to the current pointer position. * regular polygon to the current pointer position.
* @return {GeometryFunction} Function that draws a polygon. * @return {GeometryFunction} Function that draws a polygon.
* @api * @api
*/ */
export function createRegularPolygon(opt_sides, opt_angle) { export function createRegularPolygon(sides, angle) {
return function (coordinates, opt_geometry, projection) { return function (coordinates, geometry, projection) {
const center = fromUserCoordinate( const center = fromUserCoordinate(
/** @type {LineCoordType} */ (coordinates)[0], /** @type {LineCoordType} */ (coordinates)[0],
projection projection
@@ -1199,17 +1199,20 @@ export function createRegularPolygon(opt_sides, opt_angle) {
projection projection
); );
const radius = Math.sqrt(squaredCoordinateDistance(center, end)); const radius = Math.sqrt(squaredCoordinateDistance(center, end));
const geometry = opt_geometry geometry = geometry || fromCircle(new Circle(center), sides);
? /** @type {Polygon} */ (opt_geometry)
: fromCircle(new Circle(center), opt_sides);
let angle = opt_angle; let internalAngle = angle;
if (!opt_angle && opt_angle !== 0) { if (!angle && angle !== 0) {
const x = end[0] - center[0]; const x = end[0] - center[0];
const y = end[1] - center[1]; const y = end[1] - center[1];
angle = Math.atan2(y, x); internalAngle = Math.atan2(y, x);
} }
makeRegular(geometry, center, radius, angle); makeRegular(
/** @type {Polygon} */ (geometry),
center,
radius,
internalAngle
);
const userProjection = getUserProjection(); const userProjection = getUserProjection();
if (userProjection) { if (userProjection) {
@@ -1227,7 +1230,7 @@ export function createRegularPolygon(opt_sides, opt_angle) {
* @api * @api
*/ */
export function createBox() { export function createBox() {
return function (coordinates, opt_geometry, projection) { return function (coordinates, geometry, projection) {
const extent = boundingExtent( const extent = boundingExtent(
/** @type {LineCoordType} */ ([ /** @type {LineCoordType} */ ([
coordinates[0], coordinates[0],
@@ -1245,7 +1248,6 @@ export function createBox() {
getBottomLeft(extent), getBottomLeft(extent),
], ],
]; ];
let geometry = opt_geometry;
if (geometry) { if (geometry) {
geometry.setCoordinates(boxCoordinates); geometry.setCoordinates(boxCoordinates);
} else { } else {

View File

@@ -94,10 +94,10 @@ export class ExtentEvent extends Event {
*/ */
class Extent extends PointerInteraction { class Extent extends PointerInteraction {
/** /**
* @param {Options} [opt_options] Options. * @param {Options} [options] Options.
*/ */
constructor(opt_options) { constructor(options) {
const options = opt_options || {}; options = options || {};
super(/** @type {import("./Pointer.js").Options} */ (options)); super(/** @type {import("./Pointer.js").Options} */ (options));
@@ -166,8 +166,8 @@ class Extent extends PointerInteraction {
*/ */
this.vertexFeature_ = null; this.vertexFeature_ = null;
if (!opt_options) { if (!options) {
opt_options = {}; options = {};
} }
/** /**
@@ -178,10 +178,10 @@ class Extent extends PointerInteraction {
this.extentOverlay_ = new VectorLayer({ this.extentOverlay_ = new VectorLayer({
source: new VectorSource({ source: new VectorSource({
useSpatialIndex: false, useSpatialIndex: false,
wrapX: !!opt_options.wrapX, wrapX: !!options.wrapX,
}), }),
style: opt_options.boxStyle style: options.boxStyle
? opt_options.boxStyle ? options.boxStyle
: getDefaultExtentStyleFunction(), : getDefaultExtentStyleFunction(),
updateWhileAnimating: true, updateWhileAnimating: true,
updateWhileInteracting: true, updateWhileInteracting: true,
@@ -195,17 +195,17 @@ class Extent extends PointerInteraction {
this.vertexOverlay_ = new VectorLayer({ this.vertexOverlay_ = new VectorLayer({
source: new VectorSource({ source: new VectorSource({
useSpatialIndex: false, useSpatialIndex: false,
wrapX: !!opt_options.wrapX, wrapX: !!options.wrapX,
}), }),
style: opt_options.pointerStyle style: options.pointerStyle
? opt_options.pointerStyle ? options.pointerStyle
: getDefaultPointerStyleFunction(), : getDefaultPointerStyleFunction(),
updateWhileAnimating: true, updateWhileAnimating: true,
updateWhileInteracting: true, updateWhileInteracting: true,
}); });
if (opt_options.extent) { if (options.extent) {
this.setExtent(opt_options.extent); this.setExtent(options.extent);
} }
} }

View File

@@ -40,9 +40,9 @@ import {easeOut, linear} from '../easing.js';
*/ */
class Interaction extends BaseObject { class Interaction extends BaseObject {
/** /**
* @param {InteractionOptions} [opt_options] Options. * @param {InteractionOptions} [options] Options.
*/ */
constructor(opt_options) { constructor(options) {
super(); super();
/*** /***
@@ -60,8 +60,8 @@ class Interaction extends BaseObject {
*/ */
this.un; this.un;
if (opt_options && opt_options.handleEvent) { if (options && options.handleEvent) {
this.handleEvent = opt_options.handleEvent; this.handleEvent = options.handleEvent;
} }
/** /**
@@ -126,14 +126,14 @@ class Interaction extends BaseObject {
/** /**
* @param {import("../View.js").default} view View. * @param {import("../View.js").default} view View.
* @param {import("../coordinate.js").Coordinate} delta Delta. * @param {import("../coordinate.js").Coordinate} delta Delta.
* @param {number} [opt_duration] Duration. * @param {number} [duration] Duration.
*/ */
export function pan(view, delta, opt_duration) { export function pan(view, delta, duration) {
const currentCenter = view.getCenterInternal(); const currentCenter = view.getCenterInternal();
if (currentCenter) { if (currentCenter) {
const center = [currentCenter[0] + delta[0], currentCenter[1] + delta[1]]; const center = [currentCenter[0] + delta[0], currentCenter[1] + delta[1]];
view.animateInternal({ view.animateInternal({
duration: opt_duration !== undefined ? opt_duration : 250, duration: duration !== undefined ? duration : 250,
easing: linear, easing: linear,
center: view.getConstrainedCenter(center), center: view.getConstrainedCenter(center),
}); });
@@ -143,10 +143,10 @@ export function pan(view, delta, opt_duration) {
/** /**
* @param {import("../View.js").default} view View. * @param {import("../View.js").default} view View.
* @param {number} delta Delta from previous zoom level. * @param {number} delta Delta from previous zoom level.
* @param {import("../coordinate.js").Coordinate} [opt_anchor] Anchor coordinate in the user projection. * @param {import("../coordinate.js").Coordinate} [anchor] Anchor coordinate in the user projection.
* @param {number} [opt_duration] Duration. * @param {number} [duration] Duration.
*/ */
export function zoomByDelta(view, delta, opt_anchor, opt_duration) { export function zoomByDelta(view, delta, anchor, duration) {
const currentZoom = view.getZoom(); const currentZoom = view.getZoom();
if (currentZoom === undefined) { if (currentZoom === undefined) {
@@ -161,8 +161,8 @@ export function zoomByDelta(view, delta, opt_anchor, opt_duration) {
} }
view.animate({ view.animate({
resolution: newResolution, resolution: newResolution,
anchor: opt_anchor, anchor: anchor,
duration: opt_duration !== undefined ? opt_duration : 250, duration: duration !== undefined ? duration : 250,
easing: easeOut, easing: easeOut,
}); });
} }

View File

@@ -34,12 +34,12 @@ import {rotate as rotateCoordinate} from '../coordinate.js';
*/ */
class KeyboardPan extends Interaction { class KeyboardPan extends Interaction {
/** /**
* @param {Options} [opt_options] Options. * @param {Options} [options] Options.
*/ */
constructor(opt_options) { constructor(options) {
super(); super();
const options = opt_options || {}; options = options || {};
/** /**
* @private * @private

View File

@@ -30,12 +30,12 @@ import {targetNotEditable} from '../events/condition.js';
*/ */
class KeyboardZoom extends Interaction { class KeyboardZoom extends Interaction {
/** /**
* @param {Options} [opt_options] Options. * @param {Options} [options] Options.
*/ */
constructor(opt_options) { constructor(options) {
super(); super();
const options = opt_options ? opt_options : {}; options = options ? options : {};
/** /**
* @private * @private

View File

@@ -70,14 +70,14 @@ function differentArray(a, b) {
*/ */
class Link extends Interaction { class Link extends Interaction {
/** /**
* @param {Options} [opt_options] Link options. * @param {Options} [options] Link options.
*/ */
constructor(opt_options) { constructor(options) {
super(); super();
const options = Object.assign( options = Object.assign(
{animate: true, replace: false, prefix: ''}, {animate: true, replace: false, prefix: ''},
opt_options || {} options || {}
); );
let animationOptions; let animationOptions;

View File

@@ -1159,11 +1159,11 @@ class Modify extends PointerInteraction {
/** /**
* @param {import("../pixel.js").Pixel} pixel Pixel * @param {import("../pixel.js").Pixel} pixel Pixel
* @param {import("../Map.js").default} map Map. * @param {import("../Map.js").default} map Map.
* @param {import("../coordinate.js").Coordinate} [opt_coordinate] The pixel Coordinate. * @param {import("../coordinate.js").Coordinate} [coordinate] The pixel Coordinate.
* @private * @private
*/ */
handlePointerAtPixel_(pixel, map, opt_coordinate) { handlePointerAtPixel_(pixel, map, coordinate) {
const pixelCoordinate = opt_coordinate || map.getCoordinateFromPixel(pixel); const pixelCoordinate = coordinate || map.getCoordinateFromPixel(pixel);
const projection = map.getView().getProjection(); const projection = map.getView().getProjection();
const sortByDistance = function (a, b) { const sortByDistance = function (a, b) {
return ( return (

View File

@@ -37,10 +37,10 @@ import {clamp} from '../math.js';
*/ */
class MouseWheelZoom extends Interaction { class MouseWheelZoom extends Interaction {
/** /**
* @param {Options} [opt_options] Options. * @param {Options} [options] Options.
*/ */
constructor(opt_options) { constructor(options) {
const options = opt_options ? opt_options : {}; options = options ? options : {};
super( super(
/** @type {import("./Interaction.js").InteractionOptions} */ (options) /** @type {import("./Interaction.js").InteractionOptions} */ (options)

Some files were not shown because too many files have changed in this diff Show More