Replace instanceof checks with other logic

This commit is contained in:
ahocevar
2018-10-05 16:16:51 +02:00
parent 96e99e481e
commit 9163558511
40 changed files with 232 additions and 268 deletions
+1 -1
View File
@@ -160,7 +160,7 @@ class Collection extends BaseObject {
* @api * @api
*/ */
getLength() { getLength() {
return /** @type {number} */ (this.get(Property.LENGTH)); return this.get(Property.LENGTH);
} }
/** /**
+15 -17
View File
@@ -5,8 +5,6 @@ import {assert} from './asserts.js';
import {listen, unlisten, unlistenByKey} from './events.js'; import {listen, unlisten, unlistenByKey} from './events.js';
import EventType from './events/EventType.js'; import EventType from './events/EventType.js';
import BaseObject, {getChangeEventType} from './Object.js'; import BaseObject, {getChangeEventType} from './Object.js';
import Geometry from './geom/Geometry.js';
import Style from './style/Style.js';
/** /**
* @typedef {typeof Feature|typeof import("./render/Feature.js").default} FeatureClass * @typedef {typeof Feature|typeof import("./render/Feature.js").default} FeatureClass
@@ -62,7 +60,7 @@ import Style from './style/Style.js';
*/ */
class Feature extends BaseObject { class Feature extends BaseObject {
/** /**
* @param {Geometry|Object<string, *>=} opt_geometryOrProperties * @param {import("./geom/Geometry.js").default|Object<string, *>=} opt_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.
@@ -86,7 +84,7 @@ class Feature extends BaseObject {
/** /**
* User provided style. * User provided style.
* @private * @private
* @type {Style|Array<Style>|import("./style/Style.js").StyleFunction} * @type {import("./style/Style.js").StyleLike}
*/ */
this.style_ = null; this.style_ = null;
@@ -106,10 +104,9 @@ class Feature extends BaseObject {
this, getChangeEventType(this.geometryName_), this, getChangeEventType(this.geometryName_),
this.handleGeometryChanged_, this); this.handleGeometryChanged_, this);
if (opt_geometryOrProperties !== undefined) { if (opt_geometryOrProperties) {
if (opt_geometryOrProperties instanceof Geometry) { if (typeof /** @type {?} */ (opt_geometryOrProperties).getSimplifiedGeometry === 'function') {
const geometry = /** @type {import("./geom/Geometry.js").default} */ (opt_geometryOrProperties);
const geometry = /** @type {Geometry} */ (opt_geometryOrProperties);
this.setGeometry(geometry); this.setGeometry(geometry);
} else { } else {
/** @type {Object<string, *>} */ /** @type {Object<string, *>} */
@@ -143,13 +140,13 @@ class Feature extends BaseObject {
* Get the feature's default geometry. A feature may have any number of named * Get the feature's default geometry. A feature may have any number of named
* geometries. The "default" geometry (the one that is rendered by default) is * geometries. The "default" geometry (the one that is rendered by default) is
* set when calling {@link module:ol/Feature~Feature#setGeometry}. * set when calling {@link module:ol/Feature~Feature#setGeometry}.
* @return {Geometry|undefined} The default geometry for the feature. * @return {import("./geom/Geometry.js").default|undefined} The default geometry for the feature.
* @api * @api
* @observable * @observable
*/ */
getGeometry() { getGeometry() {
return ( return (
/** @type {Geometry|undefined} */ (this.get(this.geometryName_)) /** @type {import("./geom/Geometry.js").default|undefined} */ (this.get(this.geometryName_))
); );
} }
@@ -178,7 +175,7 @@ class Feature extends BaseObject {
/** /**
* Get the feature's style. Will return what was provided to the * Get the feature's style. Will return what was provided to the
* {@link module:ol/Feature~Feature#setStyle} method. * {@link module:ol/Feature~Feature#setStyle} method.
* @return {Style|Array<Style>|import("./style/Style.js").StyleFunction} The feature style. * @return {import("./style/Style.js").StyleLike} The feature style.
* @api * @api
*/ */
getStyle() { getStyle() {
@@ -221,7 +218,7 @@ class Feature extends BaseObject {
/** /**
* Set the default geometry for the feature. This will update the property * Set the default geometry for the feature. This will update the property
* with the name returned by {@link module:ol/Feature~Feature#getGeometryName}. * with the name returned by {@link module:ol/Feature~Feature#getGeometryName}.
* @param {Geometry|undefined} geometry The new geometry. * @param {import("./geom/Geometry.js").default|undefined} geometry The new geometry.
* @api * @api
* @observable * @observable
*/ */
@@ -233,7 +230,7 @@ class Feature extends BaseObject {
* Set the style for the feature. This can be a single style object, an array * Set the style for the feature. This can be a single style object, an array
* of styles, or a function that takes a resolution and returns an array of * of styles, or a function that takes a resolution and returns an array of
* styles. If it is `null` the feature has no style (a `null` style). * styles. If it is `null` the feature has no style (a `null` style).
* @param {Style|Array<Style>|import("./style/Style.js").StyleFunction} style Style for this feature. * @param {import("./style/Style.js").StyleLike} style Style for this feature.
* @api * @api
* @fires module:ol/events/Event~Event#event:change * @fires module:ol/events/Event~Event#event:change
*/ */
@@ -281,7 +278,7 @@ class Feature extends BaseObject {
* Convert the provided object into a feature style function. Functions passed * Convert the provided object into a feature style function. Functions passed
* through unchanged. Arrays of Style or single style objects wrapped * through unchanged. Arrays of Style or single style objects wrapped
* in a new feature style function. * in a new feature style function.
* @param {import("./style/Style.js").StyleFunction|!Array<Style>|!Style} obj * @param {!import("./style/Style.js").StyleFunction|!Array<import("./style/Style.js").default>|!import("./style/Style.js").default} obj
* A feature style function, a single style, or an array of styles. * A feature style function, a single style, or an array of styles.
* @return {import("./style/Style.js").StyleFunction} A style function. * @return {import("./style/Style.js").StyleFunction} A style function.
*/ */
@@ -290,15 +287,16 @@ export function createStyleFunction(obj) {
return obj; return obj;
} else { } else {
/** /**
* @type {Array<Style>} * @type {Array<import("./style/Style.js").default>}
*/ */
let styles; let styles;
if (Array.isArray(obj)) { if (Array.isArray(obj)) {
styles = obj; styles = obj;
} else { } else {
assert(obj instanceof Style, assert(typeof /** @type {?} */ (obj).getZIndex === 'function',
41); // Expected an `import("./style/Style.js").Style` or an array of `import("./style/Style.js").Style` 41); // Expected an `import("./style/Style.js").Style` or an array of `import("./style/Style.js").Style`
styles = [obj]; const style = /** @type {import("./style/Style.js").default} */ (obj);
styles = [style];
} }
return function() { return function() {
return styles; return styles;
+2 -2
View File
@@ -109,8 +109,8 @@ class ImageTile extends Tile {
* @private * @private
*/ */
handleImageLoad_() { handleImageLoad_() {
if (this.image_ instanceof HTMLImageElement && const image = /** @type {HTMLImageElement} */ (this.image_);
this.image_.naturalWidth && this.image_.naturalHeight) { if (image.naturalWidth && image.naturalHeight) {
this.state = TileState.LOADED; this.state = TileState.LOADED;
} else { } else {
this.state = TileState.EMPTY; this.state = TileState.EMPTY;
+10 -10
View File
@@ -102,7 +102,7 @@ import {create as createTransform, apply as applyTransform} from './transform.js
* map target (i.e. the user-provided div for the map). If this is not * map target (i.e. the user-provided div for the map). If this is not
* `document`, the target element needs to be focused for key events to be * `document`, the target element needs to be focused for key events to be
* emitted, requiring that the target element has a `tabindex` attribute. * emitted, requiring that the target element has a `tabindex` attribute.
* @property {Array<import("./layer/Base.js").default>|Collection<import("./layer/Base.js").default>} [layers] * @property {Array<import("./layer/Base.js").default>|Collection<import("./layer/Base.js").default>|LayerGroup} [layers]
* Layers. If this is not defined, a map with no layers will be rendered. Note * Layers. If this is not defined, a map with no layers will be rendered. Note
* that layers are rendered in the order supplied, so if you want, for example, * that layers are rendered in the order supplied, so if you want, for example,
* a vector layer to appear on top of a tile layer, it must come after the tile * a vector layer to appear on top of a tile layer, it must come after the tile
@@ -1368,8 +1368,8 @@ function createOptionsInternal(options) {
*/ */
const values = {}; const values = {};
const layerGroup = (options.layers instanceof LayerGroup) ? const layerGroup = options.layers && typeof /** @type {?} */ (options.layers).getLayers === 'function' ?
options.layers : new LayerGroup({layers: options.layers}); /** @type {LayerGroup} */ (options.layers) : new LayerGroup({layers: /** @type {Collection} */ (options.layers)});
values[MapProperty.LAYERGROUP] = layerGroup; values[MapProperty.LAYERGROUP] = layerGroup;
values[MapProperty.TARGET] = options.target; values[MapProperty.TARGET] = options.target;
@@ -1382,9 +1382,9 @@ function createOptionsInternal(options) {
if (Array.isArray(options.controls)) { if (Array.isArray(options.controls)) {
controls = new Collection(options.controls.slice()); controls = new Collection(options.controls.slice());
} else { } else {
assert(options.controls instanceof Collection, assert(typeof /** @type {?} */ (options.controls).getArray === 'function',
47); // Expected `controls` to be an array or an `import("./Collection.js").Collection` 47); // Expected `controls` to be an array or an `import("./Collection.js").Collection`
controls = options.controls; controls = /** @type {Collection} */ (options.controls);
} }
} }
@@ -1393,9 +1393,9 @@ function createOptionsInternal(options) {
if (Array.isArray(options.interactions)) { if (Array.isArray(options.interactions)) {
interactions = new Collection(options.interactions.slice()); interactions = new Collection(options.interactions.slice());
} else { } else {
assert(options.interactions instanceof Collection, assert(typeof /** @type {?} */ (options.interactions).getArray === 'function',
48); // Expected `interactions` to be an array or an `import("./Collection.js").Collection` 48); // Expected `interactions` to be an array or an `import("./Collection.js").Collection`
interactions = options.interactions; interactions = /** @type {Collection} */ (options.interactions);
} }
} }
@@ -1404,7 +1404,7 @@ function createOptionsInternal(options) {
if (Array.isArray(options.overlays)) { if (Array.isArray(options.overlays)) {
overlays = new Collection(options.overlays.slice()); overlays = new Collection(options.overlays.slice());
} else { } else {
assert(options.overlays instanceof Collection, assert(typeof /** @type {?} */ (options.overlays).getArray === 'function',
49); // Expected `overlays` to be an array or an `import("./Collection.js").Collection` 49); // Expected `overlays` to be an array or an `import("./Collection.js").Collection`
overlays = options.overlays; overlays = options.overlays;
} }
@@ -1430,8 +1430,8 @@ export default PluggableMap;
function getLoading(layers) { function getLoading(layers) {
for (let i = 0, ii = layers.length; i < ii; ++i) { for (let i = 0, ii = layers.length; i < ii; ++i) {
const layer = layers[i]; const layer = layers[i];
if (layer instanceof LayerGroup) { if (typeof /** @type {?} */ (layer).getLayers === 'function') {
return getLoading(layer.getLayers().getArray()); return getLoading(/** @type {LayerGroup} */ (layer).getLayers().getArray());
} else { } else {
const source = /** @type {import("./layer/Layer.js").default} */ ( const source = /** @type {import("./layer/Layer.js").default} */ (
layer).getSource(); layer).getSource();
+5 -6
View File
@@ -17,7 +17,6 @@ import {inAndOut} from './easing.js';
import {getForViewAndSize, getCenter, getHeight, getWidth, isEmpty} from './extent.js'; import {getForViewAndSize, getCenter, getHeight, getWidth, isEmpty} from './extent.js';
import GeometryType from './geom/GeometryType.js'; import GeometryType from './geom/GeometryType.js';
import {fromExtent as polygonFromExtent} from './geom/Polygon.js'; import {fromExtent as polygonFromExtent} from './geom/Polygon.js';
import SimpleGeometry from './geom/SimpleGeometry.js';
import {clamp, modulo} from './math.js'; import {clamp, modulo} from './math.js';
import {assign} from './obj.js'; import {assign} from './obj.js';
import {createProjection, METERS_PER_UNIT} from './proj.js'; import {createProjection, METERS_PER_UNIT} from './proj.js';
@@ -974,7 +973,7 @@ class View extends BaseObject {
* The size is pixel dimensions of the box to fit the extent into. * The size is pixel dimensions of the box to fit the extent into.
* In most cases you will want to use the map size, that is `map.getSize()`. * In most cases you will want to use the map size, that is `map.getSize()`.
* Takes care of the map angle. * Takes care of the map angle.
* @param {SimpleGeometry|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=} opt_options Options.
* @api * @api
@@ -985,11 +984,11 @@ class View extends BaseObject {
if (!size) { if (!size) {
size = this.getSizeFromViewport_(); size = this.getSizeFromViewport_();
} }
/** @type {SimpleGeometry} */ /** @type {import("./geom/SimpleGeometry.js").default} */
let geometry; let geometry;
if (!(geometryOrExtent instanceof SimpleGeometry)) { assert(Array.isArray(geometryOrExtent) || typeof /** @type {?} */ (geometryOrExtent).getSimplifiedGeometry === 'function',
assert(Array.isArray(geometryOrExtent), 24); // Invalid extent or geometry provided as `geometry`
24); // Invalid extent or geometry provided as `geometry` if (Array.isArray(geometryOrExtent)) {
assert(!isEmpty(geometryOrExtent), assert(!isEmpty(geometryOrExtent),
25); // Cannot fit empty extent provided as `geometry` 25); // Cannot fit empty extent provided as `geometry`
geometry = polygonFromExtent(geometryOrExtent); geometry = polygonFromExtent(geometryOrExtent);
+2 -4
View File
@@ -133,7 +133,7 @@ export function asArray(color) {
if (Array.isArray(color)) { if (Array.isArray(color)) {
return color; return color;
} else { } else {
return fromString(/** @type {string} */ (color)); return fromString(color);
} }
} }
@@ -185,9 +185,7 @@ function fromStringInternal_(s) {
} else { } else {
assert(false, 14); // Invalid color assert(false, 14); // Invalid color
} }
return ( return color;
/** @type {Color} */ (color)
);
} }
+3 -16
View File
@@ -23,22 +23,9 @@ import {toString} from './color.js';
* @api * @api
*/ */
export function asColorLike(color) { export function asColorLike(color) {
if (isColorLike(color)) { if (Array.isArray(color)) {
return /** @type {string|CanvasPattern|CanvasGradient} */ (color); return toString(color);
} else { } else {
return toString(/** @type {import("./color.js").Color} */ (color)); return color;
} }
} }
/**
* @param {?} color The value that is potentially an {@link ol/colorlike~ColorLike}.
* @return {boolean} The color is an {@link ol/colorlike~ColorLike}.
*/
export function isColorLike(color) {
return (
typeof color === 'string' ||
color instanceof CanvasPattern ||
color instanceof CanvasGradient
);
}
+5 -5
View File
@@ -2,7 +2,6 @@
* @module ol/events/condition * @module ol/events/condition
*/ */
import MapBrowserEventType from '../MapBrowserEventType.js'; import MapBrowserEventType from '../MapBrowserEventType.js';
import MapBrowserPointerEvent from '../MapBrowserPointerEvent.js';
import {assert} from '../asserts.js'; import {assert} from '../asserts.js';
import {TRUE, FALSE} from '../functions.js'; import {TRUE, FALSE} from '../functions.js';
import {WEBKIT, MAC} from '../has.js'; import {WEBKIT, MAC} from '../has.js';
@@ -225,9 +224,10 @@ export const targetNotEditable = function(mapBrowserEvent) {
* @api * @api
*/ */
export const mouseOnly = function(mapBrowserEvent) { export const mouseOnly = function(mapBrowserEvent) {
assert(mapBrowserEvent instanceof MapBrowserPointerEvent, 56); // mapBrowserEvent must originate from a pointer event const pointerEvent = /** @type {import("../MapBrowserPointerEvent").default} */ (mapBrowserEvent).pointerEvent;
assert(pointerEvent !== undefined, 56); // mapBrowserEvent must originate from a pointer event
// see http://www.w3.org/TR/pointerevents/#widl-PointerEvent-pointerType // see http://www.w3.org/TR/pointerevents/#widl-PointerEvent-pointerType
return /** @type {MapBrowserPointerEvent} */ (mapBrowserEvent).pointerEvent.pointerType == 'mouse'; return pointerEvent.pointerType == 'mouse';
}; };
@@ -241,7 +241,7 @@ export const mouseOnly = function(mapBrowserEvent) {
* @api * @api
*/ */
export const primaryAction = function(mapBrowserEvent) { export const primaryAction = function(mapBrowserEvent) {
assert(mapBrowserEvent instanceof MapBrowserPointerEvent, 56); // mapBrowserEvent must originate from a pointer event const pointerEvent = /** @type {import("../MapBrowserPointerEvent").default} */ (mapBrowserEvent).pointerEvent;
const pointerEvent = /** @type {MapBrowserPointerEvent} */ (mapBrowserEvent).pointerEvent; assert(pointerEvent !== undefined, 56); // mapBrowserEvent must originate from a pointer event
return pointerEvent.isPrimary && pointerEvent.button === 0; return pointerEvent.isPrimary && pointerEvent.button === 0;
}; };
+1 -3
View File
@@ -494,9 +494,7 @@ export function getCorner(extent, corner) {
} else { } else {
assert(false, 13); // Invalid corner assert(false, 13); // Invalid corner
} }
return ( return coordinate;
/** @type {!import("./coordinate.js").Coordinate} */ (coordinate)
);
} }
+8 -8
View File
@@ -3,7 +3,6 @@
*/ */
import {VOID} from './functions.js'; import {VOID} from './functions.js';
import FormatType from './format/FormatType.js'; import FormatType from './format/FormatType.js';
import VectorSource from './source/Vector';
/** /**
* {@link module:ol/source/Vector} sources use a function of this type to * {@link module:ol/source/Vector} sources use a function of this type to
@@ -17,7 +16,7 @@ import VectorSource from './source/Vector';
* *
* The function is responsible for loading the features and adding them to the * The function is responsible for loading the features and adding them to the
* source. * source.
* @typedef {function(this:(VectorSource|import("./VectorTile.js").default), import("./extent.js").Extent, number, * @typedef {function(this:(import("./source/Vector").default|import("./VectorTile.js").default), import("./extent.js").Extent, number,
* import("./proj/Projection.js").default)} FeatureLoader * import("./proj/Projection.js").default)} FeatureLoader
* @api * @api
*/ */
@@ -39,10 +38,10 @@ import VectorSource from './source/Vector';
/** /**
* @param {string|FeatureUrlFunction} url Feature URL service. * @param {string|FeatureUrlFunction} url Feature URL service.
* @param {import("./format/Feature.js").default} format Feature format. * @param {import("./format/Feature.js").default} format Feature format.
* @param {function(this:import("./VectorTile.js").default, Array<import("./Feature.js").default>, import("./proj/Projection.js").default, import("./extent.js").Extent)|function(this:VectorSource, Array<import("./Feature.js").default>)} success * @param {function(this:import("./VectorTile.js").default, Array<import("./Feature.js").default>, import("./proj/Projection.js").default, import("./extent.js").Extent)|function(this:import("./source/Vector").default, Array<import("./Feature.js").default>)} success
* Function called with the loaded features and optionally with the data * Function called with the loaded features and optionally with the data
* projection. Called with the vector tile or source as `this`. * projection. Called with the vector tile or source as `this`.
* @param {function(this:import("./VectorTile.js").default)|function(this:VectorSource)} failure * @param {function(this:import("./VectorTile.js").default)|function(this:import("./source/Vector").default)} failure
* Function called when loading failed. Called with the vector tile or * Function called when loading failed. Called with the vector tile or
* source as `this`. * source as `this`.
* @return {FeatureLoader} The feature loader. * @return {FeatureLoader} The feature loader.
@@ -53,7 +52,7 @@ export function loadFeaturesXhr(url, format, success, failure) {
* @param {import("./extent.js").Extent} extent Extent. * @param {import("./extent.js").Extent} extent Extent.
* @param {number} resolution Resolution. * @param {number} resolution Resolution.
* @param {import("./proj/Projection.js").default} projection Projection. * @param {import("./proj/Projection.js").default} projection Projection.
* @this {VectorSource|import("./VectorTile.js").default} * @this {import("./source/Vector").default|import("./VectorTile.js").default}
*/ */
function(extent, resolution, projection) { function(extent, resolution, projection) {
const xhr = new XMLHttpRequest(); const xhr = new XMLHttpRequest();
@@ -121,11 +120,12 @@ export function xhr(url, format) {
* @param {Array<import("./Feature.js").default>} features The loaded features. * @param {Array<import("./Feature.js").default>} features The loaded features.
* @param {import("./proj/Projection.js").default} dataProjection Data * @param {import("./proj/Projection.js").default} dataProjection Data
* projection. * projection.
* @this {VectorSource|import("./VectorTile.js").default} * @this {import("./source/Vector").default|import("./VectorTile.js").default}
*/ */
function(features, dataProjection) { function(features, dataProjection) {
if (this instanceof VectorSource) { const sourceOrTile = /** @type {?} */ (this);
this.addFeatures(features); if (typeof sourceOrTile.addFeatures === 'function') {
/** @type {import("./source/Vector").default} */ (sourceOrTile).addFeatures(features);
} }
}, /* FIXME handle error */ VOID); }, /* FIXME handle error */ VOID);
} }
+12 -13
View File
@@ -1,7 +1,6 @@
/** /**
* @module ol/format/Feature * @module ol/format/Feature
*/ */
import Geometry from '../geom/Geometry.js';
import {assign} from '../obj.js'; import {assign} from '../obj.js';
import {get as getProjection, equivalent as equivalentProjection, transformExtent} from '../proj.js'; import {get as getProjection, equivalent as equivalentProjection, transformExtent} from '../proj.js';
@@ -151,7 +150,7 @@ class FeatureFormat {
* @abstract * @abstract
* @param {Document|Node|Object|string} source Source. * @param {Document|Node|Object|string} source Source.
* @param {ReadOptions=} opt_options Read options. * @param {ReadOptions=} opt_options Read options.
* @return {Geometry} Geometry. * @return {import("../geom/Geometry.js").default} Geometry.
*/ */
readGeometry(source, opt_options) {} readGeometry(source, opt_options) {}
@@ -188,7 +187,7 @@ class FeatureFormat {
* Write a single geometry in this format. * Write a single geometry in this format.
* *
* @abstract * @abstract
* @param {Geometry} geometry Geometry. * @param {import("../geom/Geometry.js").default} geometry Geometry.
* @param {WriteOptions=} opt_options Write options. * @param {WriteOptions=} opt_options Write options.
* @return {string} Result. * @return {string} Result.
*/ */
@@ -198,10 +197,10 @@ class FeatureFormat {
export default FeatureFormat; export default FeatureFormat;
/** /**
* @param {Geometry|import("../extent.js").Extent} geometry Geometry. * @param {import("../geom/Geometry.js").default|import("../extent.js").Extent} 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)=} opt_options Options.
* @return {Geometry|import("../extent.js").Extent} Transformed geometry. * @return {import("../geom/Geometry.js").default|import("../extent.js").Extent} Transformed geometry.
*/ */
export function transformWithOptions(geometry, write, opt_options) { export function transformWithOptions(geometry, write, opt_options) {
const featureProjection = opt_options ? const featureProjection = opt_options ?
@@ -209,28 +208,28 @@ export function transformWithOptions(geometry, write, opt_options) {
const dataProjection = opt_options ? const dataProjection = opt_options ?
getProjection(opt_options.dataProjection) : null; getProjection(opt_options.dataProjection) : null;
/** /**
* @type {Geometry|import("../extent.js").Extent} * @type {import("../geom/Geometry.js").default|import("../extent.js").Extent}
*/ */
let transformed; let transformed;
if (featureProjection && dataProjection && if (featureProjection && dataProjection &&
!equivalentProjection(featureProjection, dataProjection)) { !equivalentProjection(featureProjection, dataProjection)) {
if (geometry instanceof Geometry) { if (Array.isArray(geometry)) {
transformed = (write ? geometry.clone() : geometry).transform(
write ? featureProjection : dataProjection,
write ? dataProjection : featureProjection);
} else {
// FIXME this is necessary because GML treats extents // FIXME this is necessary because GML treats extents
// as geometries // as geometries
transformed = transformExtent( transformed = transformExtent(
geometry, geometry,
dataProjection, dataProjection,
featureProjection); featureProjection);
} else {
transformed = (write ? /** @type {import("../geom/Geometry").default} */ (geometry).clone() : geometry).transform(
write ? featureProjection : dataProjection,
write ? dataProjection : featureProjection);
} }
} else { } else {
transformed = geometry; transformed = geometry;
} }
if (write && opt_options && /** @type {WriteOptions} */ (opt_options).decimals !== undefined && if (write && opt_options && /** @type {WriteOptions} */ (opt_options).decimals !== undefined &&
transformed instanceof Geometry) { !Array.isArray(transformed)) {
const power = Math.pow(10, /** @type {WriteOptions} */ (opt_options).decimals); const power = Math.pow(10, /** @type {WriteOptions} */ (opt_options).decimals);
// if decimals option on write, round each coordinate appropriately // if decimals option on write, round each coordinate appropriately
/** /**
@@ -244,7 +243,7 @@ export function transformWithOptions(geometry, write, opt_options) {
return coordinates; return coordinates;
}; };
if (transformed === geometry) { if (transformed === geometry) {
transformed = transformed.clone(); transformed = /** @type {import("../geom/Geometry").default} */ (geometry).clone();
} }
transformed.applyTransform(transform); transformed.applyTransform(transform);
} }
+1 -2
View File
@@ -5,7 +5,6 @@ import {createOrUpdate} from '../extent.js';
import {transformWithOptions} from '../format/Feature.js'; import {transformWithOptions} from '../format/Feature.js';
import GMLBase, {GMLNS} from '../format/GMLBase.js'; import GMLBase, {GMLNS} from '../format/GMLBase.js';
import {writeStringTextNode} from '../format/xsd.js'; import {writeStringTextNode} from '../format/xsd.js';
import Geometry from '../geom/Geometry.js';
import {assign} from '../obj.js'; import {assign} from '../obj.js';
import {get as getProjection, transformExtent} from '../proj.js'; import {get as getProjection, transformExtent} from '../proj.js';
import {createElementNS, getAllTextContent, makeArrayPusher, makeChildAppender, import {createElementNS, getAllTextContent, makeArrayPusher, makeChildAppender,
@@ -196,7 +195,7 @@ class GML2 extends GMLBase {
if (value !== null) { if (value !== null) {
keys.push(key); keys.push(key);
values.push(value); values.push(value);
if (key == geometryName || value instanceof Geometry) { if (key == geometryName || typeof /** @type {?} */ (value).getSimplifiedGeometry === 'function') {
if (!(key in context.serializers[featureNS])) { if (!(key in context.serializers[featureNS])) {
context.serializers[featureNS][key] = makeChildAppender( context.serializers[featureNS][key] = makeChildAppender(
this.writeGeometryElement, this); this.writeGeometryElement, this);
+1 -2
View File
@@ -6,7 +6,6 @@ import {createOrUpdate} from '../extent.js';
import {transformWithOptions} from '../format/Feature.js'; import {transformWithOptions} from '../format/Feature.js';
import GMLBase, {GMLNS} from '../format/GMLBase.js'; import GMLBase, {GMLNS} from '../format/GMLBase.js';
import {readNonNegativeIntegerString, writeStringTextNode} from '../format/xsd.js'; import {readNonNegativeIntegerString, writeStringTextNode} from '../format/xsd.js';
import Geometry from '../geom/Geometry.js';
import GeometryLayout from '../geom/GeometryLayout.js'; import GeometryLayout from '../geom/GeometryLayout.js';
import LineString from '../geom/LineString.js'; import LineString from '../geom/LineString.js';
import MultiLineString from '../geom/MultiLineString.js'; import MultiLineString from '../geom/MultiLineString.js';
@@ -774,7 +773,7 @@ class GML3 extends GMLBase {
if (value !== null) { if (value !== null) {
keys.push(key); keys.push(key);
values.push(value); values.push(value);
if (key == geometryName || value instanceof Geometry) { if (key == geometryName || typeof /** @type {?} */ (value).getSimplifiedGeometry === 'function') {
if (!(key in context.serializers[featureNS])) { if (!(key in context.serializers[featureNS])) {
context.serializers[featureNS][key] = makeChildAppender( context.serializers[featureNS][key] = makeChildAppender(
this.writeGeometryElement, this); this.writeGeometryElement, this);
+4 -3
View File
@@ -7,6 +7,7 @@ import {transformWithOptions} from '../format/Feature.js';
import XMLFeature from '../format/XMLFeature.js'; import XMLFeature from '../format/XMLFeature.js';
import {readString, readDecimal, readNonNegativeInteger, readDateTime, writeStringTextNode, writeNonNegativeIntegerTextNode, writeDecimalTextNode, writeDateTimeTextNode} from '../format/xsd.js'; import {readString, readDecimal, readNonNegativeInteger, readDateTime, writeStringTextNode, writeNonNegativeIntegerTextNode, writeDecimalTextNode, writeDateTimeTextNode} from '../format/xsd.js';
import GeometryLayout from '../geom/GeometryLayout.js'; import GeometryLayout from '../geom/GeometryLayout.js';
import GeometryType from '../geom/GeometryType.js';
import LineString from '../geom/LineString.js'; import LineString from '../geom/LineString.js';
import MultiLineString from '../geom/MultiLineString.js'; import MultiLineString from '../geom/MultiLineString.js';
import Point from '../geom/Point.js'; import Point from '../geom/Point.js';
@@ -782,7 +783,7 @@ function writeRte(node, feature, objectStack) {
const context = {node: node}; const context = {node: node};
context['properties'] = properties; context['properties'] = properties;
const geometry = feature.getGeometry(); const geometry = feature.getGeometry();
if (geometry instanceof LineString) { if (geometry.getType() == GeometryType.LINE_STRING) {
const lineString = /** @type {LineString} */ (transformWithOptions(geometry, true, options)); const lineString = /** @type {LineString} */ (transformWithOptions(geometry, true, options));
context['geometryLayout'] = lineString.getLayout(); context['geometryLayout'] = lineString.getLayout();
properties['rtept'] = lineString.getCoordinates(); properties['rtept'] = lineString.getCoordinates();
@@ -808,7 +809,7 @@ function writeTrk(node, feature, objectStack) {
const context = {node: node}; const context = {node: node};
context['properties'] = properties; context['properties'] = properties;
const geometry = feature.getGeometry(); const geometry = feature.getGeometry();
if (geometry instanceof MultiLineString) { if (geometry.getType() == GeometryType.MULTI_LINE_STRING) {
const multiLineString = /** @type {MultiLineString} */ (transformWithOptions(geometry, true, options)); const multiLineString = /** @type {MultiLineString} */ (transformWithOptions(geometry, true, options));
properties['trkseg'] = multiLineString.getLineStrings(); properties['trkseg'] = multiLineString.getLineStrings();
} }
@@ -847,7 +848,7 @@ function writeWpt(node, feature, objectStack) {
const context = objectStack[objectStack.length - 1]; const context = objectStack[objectStack.length - 1];
context['properties'] = feature.getProperties(); context['properties'] = feature.getProperties();
const geometry = feature.getGeometry(); const geometry = feature.getGeometry();
if (geometry instanceof Point) { if (geometry.getType() == GeometryType.POINT) {
const point = /** @type {Point} */ (transformWithOptions(geometry, true, options)); const point = /** @type {Point} */ (transformWithOptions(geometry, true, options));
context['geometryLayout'] = point.getLayout(); context['geometryLayout'] = point.getLayout();
writeWptType(node, point.getCoordinates(), objectStack); writeWptType(node, point.getCoordinates(), objectStack);
+21 -21
View File
@@ -26,7 +26,7 @@ import IconOrigin from '../style/IconOrigin.js';
import Stroke from '../style/Stroke.js'; import Stroke from '../style/Stroke.js';
import Style from '../style/Style.js'; import Style from '../style/Style.js';
import Text from '../style/Text.js'; import Text from '../style/Text.js';
import {createElementNS, getAllTextContent, isDocument, isNode, makeArrayExtender, import {createElementNS, getAllTextContent, isDocument, makeArrayExtender,
makeArrayPusher, makeChildAppender, makeObjectPropertySetter, makeArrayPusher, makeChildAppender, makeObjectPropertySetter,
makeReplacer, makeSequence, makeSimpleNodeFactory, makeStructureNS, makeReplacer, makeSequence, makeSimpleNodeFactory, makeStructureNS,
OBJECT_PROPERTY_NODE_FACTORY, parse, parseNode, pushParseAndPop, OBJECT_PROPERTY_NODE_FACTORY, parse, parseNode, pushParseAndPop,
@@ -639,15 +639,15 @@ class KML extends XMLFeature {
* @api * @api
*/ */
readName(source) { readName(source) {
if (isDocument(source)) { if (!source) {
return this.readNameFromDocument(/** @type {Document} */ (source)); return undefined;
} else if (isNode(source)) {
return this.readNameFromNode(/** @type {Element} */ (source));
} else if (typeof source === 'string') { } else if (typeof source === 'string') {
const doc = parse(source); const doc = parse(source);
return this.readNameFromDocument(doc); return this.readNameFromDocument(doc);
} else if (isDocument(source)) {
return this.readNameFromDocument(/** @type {Document} */ (source));
} else { } else {
return undefined; return this.readNameFromNode(/** @type {Element} */ (source));
} }
} }
@@ -703,15 +703,15 @@ class KML extends XMLFeature {
*/ */
readNetworkLinks(source) { readNetworkLinks(source) {
const networkLinks = []; const networkLinks = [];
if (isDocument(source)) { if (typeof source === 'string') {
extend(networkLinks, this.readNetworkLinksFromDocument(
/** @type {Document} */ (source)));
} else if (isNode(source)) {
extend(networkLinks, this.readNetworkLinksFromNode(
/** @type {Element} */ (source)));
} else if (typeof source === 'string') {
const doc = parse(source); const doc = parse(source);
extend(networkLinks, this.readNetworkLinksFromDocument(doc)); extend(networkLinks, this.readNetworkLinksFromDocument(doc));
} else if (isDocument(source)) {
extend(networkLinks, this.readNetworkLinksFromDocument(
/** @type {Document} */ (source)));
} else {
extend(networkLinks, this.readNetworkLinksFromNode(
/** @type {Element} */ (source)));
} }
return networkLinks; return networkLinks;
} }
@@ -765,15 +765,15 @@ class KML extends XMLFeature {
*/ */
readRegion(source) { readRegion(source) {
const regions = []; const regions = [];
if (isDocument(source)) { if (typeof source === 'string') {
extend(regions, this.readRegionFromDocument(
/** @type {Document} */ (source)));
} else if (isNode(source)) {
extend(regions, this.readRegionFromNode(
/** @type {Element} */ (source)));
} else if (typeof source === 'string') {
const doc = parse(source); const doc = parse(source);
extend(regions, this.readRegionFromDocument(doc)); extend(regions, this.readRegionFromDocument(doc));
} else if (isDocument(source)) {
extend(regions, this.readRegionFromDocument(
/** @type {Document} */ (source)));
} else {
extend(regions, this.readRegionFromNode(
/** @type {Element} */ (source)));
} }
return regions; return regions;
} }
@@ -2897,7 +2897,7 @@ function writeStyle(node, style, objectStack) {
const strokeStyle = style.getStroke(); const strokeStyle = style.getStroke();
const imageStyle = style.getImage(); const imageStyle = style.getImage();
const textStyle = style.getText(); const textStyle = style.getText();
if (imageStyle instanceof Icon) { if (imageStyle && typeof /** @type {?} */ (imageStyle).getSrc === 'function') {
properties['IconStyle'] = imageStyle; properties['IconStyle'] = imageStyle;
} }
if (textStyle) { if (textStyle) {
+16 -17
View File
@@ -8,10 +8,9 @@ import GMLBase, {GMLNS} from '../format/GMLBase.js';
import {and as andFilter, bbox as bboxFilter} from '../format/filter.js'; import {and as andFilter, bbox as bboxFilter} from '../format/filter.js';
import XMLFeature from '../format/XMLFeature.js'; import XMLFeature from '../format/XMLFeature.js';
import {readNonNegativeIntegerString, readNonNegativeInteger, writeStringTextNode} from '../format/xsd.js'; import {readNonNegativeIntegerString, readNonNegativeInteger, writeStringTextNode} from '../format/xsd.js';
import Geometry from '../geom/Geometry.js';
import {assign} from '../obj.js'; import {assign} from '../obj.js';
import {get as getProjection} from '../proj.js'; import {get as getProjection} from '../proj.js';
import {createElementNS, isDocument, isNode, makeArrayPusher, makeChildAppender, import {createElementNS, isDocument, makeArrayPusher, makeChildAppender,
makeObjectPropertySetter, makeSimpleNodeFactory, parse, parseNode, makeObjectPropertySetter, makeSimpleNodeFactory, parse, parseNode,
pushParseAndPop, pushSerializeAndPop, XML_SCHEMA_INSTANCE_URI} from '../xml.js'; pushParseAndPop, pushSerializeAndPop, XML_SCHEMA_INSTANCE_URI} from '../xml.js';
@@ -288,16 +287,16 @@ class WFS extends XMLFeature {
* @api * @api
*/ */
readTransactionResponse(source) { readTransactionResponse(source) {
if (isDocument(source)) { if (!source) {
return this.readTransactionResponseFromDocument( return undefined;
/** @type {Document} */ (source));
} else if (isNode(source)) {
return this.readTransactionResponseFromNode(/** @type {Element} */ (source));
} else if (typeof source === 'string') { } else if (typeof source === 'string') {
const doc = parse(source); const doc = parse(source);
return this.readTransactionResponseFromDocument(doc); return this.readTransactionResponseFromDocument(doc);
} else if (isDocument(source)) {
return this.readTransactionResponseFromDocument(
/** @type {Document} */ (source));
} else { } else {
return undefined; return this.readTransactionResponseFromNode(/** @type {Element} */ (source));
} }
} }
@@ -310,17 +309,17 @@ class WFS extends XMLFeature {
* @api * @api
*/ */
readFeatureCollectionMetadata(source) { readFeatureCollectionMetadata(source) {
if (isDocument(source)) { if (!source) {
return this.readFeatureCollectionMetadataFromDocument( return undefined;
/** @type {Document} */ (source));
} else if (isNode(source)) {
return this.readFeatureCollectionMetadataFromNode(
/** @type {Element} */ (source));
} else if (typeof source === 'string') { } else if (typeof source === 'string') {
const doc = parse(source); const doc = parse(source);
return this.readFeatureCollectionMetadataFromDocument(doc); return this.readFeatureCollectionMetadataFromDocument(doc);
} else if (isDocument(source)) {
return this.readFeatureCollectionMetadataFromDocument(
/** @type {Document} */ (source));
} else { } else {
return undefined; return this.readFeatureCollectionMetadataFromNode(
/** @type {Element} */ (source));
} }
} }
@@ -694,7 +693,7 @@ function writeUpdate(node, feature, objectStack) {
const value = feature.get(keys[i]); const value = feature.get(keys[i]);
if (value !== undefined) { if (value !== undefined) {
let name = keys[i]; let name = keys[i];
if (value instanceof Geometry) { if (value && typeof /** @type {?} */ (value).getSimplifiedGeometry === 'function') {
name = geometryName; name = geometryName;
} }
values.push({name: name, value: value}); values.push({name: name, value: value});
@@ -725,7 +724,7 @@ function writeProperty(node, pair, objectStack) {
if (pair.value !== undefined && pair.value !== null) { if (pair.value !== undefined && pair.value !== null) {
const value = createElementNS(WFSNS, 'Value'); const value = createElementNS(WFSNS, 'Value');
node.appendChild(value); node.appendChild(value);
if (pair.value instanceof Geometry) { if (pair.value && typeof /** @type {?} */ (pair.value).getSimplifiedGeometry === 'function') {
if (gmlVersion === 2) { if (gmlVersion === 2) {
GML2.prototype.writeGeometryElement(value, GML2.prototype.writeGeometryElement(value,
pair.value, objectStack); pair.value, objectStack);
+4 -5
View File
@@ -13,7 +13,6 @@ import MultiPoint from '../geom/MultiPoint.js';
import MultiPolygon from '../geom/MultiPolygon.js'; import MultiPolygon from '../geom/MultiPolygon.js';
import Point from '../geom/Point.js'; import Point from '../geom/Point.js';
import Polygon from '../geom/Polygon.js'; import Polygon from '../geom/Polygon.js';
import SimpleGeometry from '../geom/SimpleGeometry.js';
/** /**
@@ -823,7 +822,7 @@ function encodeMultiPolygonGeometry(geom) {
} }
/** /**
* @param {SimpleGeometry} geom SimpleGeometry geometry. * @param {import("../geom/SimpleGeometry.js").default} geom SimpleGeometry geometry.
* @return {string} Potential dimensional information for WKT type. * @return {string} Potential dimensional information for WKT type.
*/ */
function encodeGeometryLayout(geom) { function encodeGeometryLayout(geom) {
@@ -856,7 +855,7 @@ const GeometryEncoder = {
/** /**
* Encode a geometry as WKT. * Encode a geometry as WKT.
* @param {import("../geom/Geometry.js").default} geom The geometry to encode. * @param {!import("../geom/Geometry.js").default} geom The geometry to encode.
* @return {string} WKT string for the geometry. * @return {string} WKT string for the geometry.
*/ */
function encode(geom) { function encode(geom) {
@@ -864,8 +863,8 @@ function encode(geom) {
const geometryEncoder = GeometryEncoder[type]; const geometryEncoder = GeometryEncoder[type];
const enc = geometryEncoder(geom); const enc = geometryEncoder(geom);
type = type.toUpperCase(); type = type.toUpperCase();
if (geom instanceof SimpleGeometry) { if (typeof /** @type {?} */ (geom).getFlatCoordinates === 'function') {
const dimInfo = encodeGeometryLayout(geom); const dimInfo = encodeGeometryLayout(/** @type {import("../geom/SimpleGeometry.js").default} */ (geom));
if (dimInfo.length > 0) { if (dimInfo.length > 0) {
type += ' ' + dimInfo; type += ' ' + dimInfo;
} }
+6 -6
View File
@@ -1,7 +1,7 @@
/** /**
* @module ol/format/XML * @module ol/format/XML
*/ */
import {isDocument, isNode, parse} from '../xml.js'; import {isDocument, parse} from '../xml.js';
/** /**
* @classdesc * @classdesc
@@ -18,15 +18,15 @@ class XML {
* @api * @api
*/ */
read(source) { read(source) {
if (isDocument(source)) { if (!source) {
return this.readFromDocument(/** @type {Document} */ (source)); return null;
} else if (isNode(source)) {
return this.readFromNode(/** @type {Element} */ (source));
} else if (typeof source === 'string') { } else if (typeof source === 'string') {
const doc = parse(source); const doc = parse(source);
return this.readFromDocument(doc); return this.readFromDocument(doc);
} else if (isDocument(source)) {
return this.readFromDocument(/** @type {Document} */ (source));
} else { } else {
return null; return this.readFromNode(/** @type {Element} */ (source));
} }
} }
+23 -23
View File
@@ -4,7 +4,7 @@
import {extend} from '../array.js'; import {extend} from '../array.js';
import FeatureFormat from '../format/Feature.js'; import FeatureFormat from '../format/Feature.js';
import FormatType from '../format/FormatType.js'; import FormatType from '../format/FormatType.js';
import {isDocument, isNode, parse} from '../xml.js'; import {isDocument, parse} from '../xml.js';
/** /**
* @classdesc * @classdesc
@@ -41,15 +41,15 @@ class XMLFeature extends FeatureFormat {
* @api * @api
*/ */
readFeature(source, opt_options) { readFeature(source, opt_options) {
if (isDocument(source)) { if (!source) {
return this.readFeatureFromDocument(/** @type {Document} */ (source), opt_options); return null;
} else if (isNode(source)) {
return this.readFeatureFromNode(/** @type {Node} */ (source), opt_options);
} 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, opt_options);
} else if (isDocument(source)) {
return this.readFeatureFromDocument(/** @type {Document} */ (source), opt_options);
} else { } else {
return null; return this.readFeatureFromNode(/** @type {Node} */ (source), opt_options);
} }
} }
@@ -85,16 +85,16 @@ class XMLFeature extends FeatureFormat {
* @api * @api
*/ */
readFeatures(source, opt_options) { readFeatures(source, opt_options) {
if (isDocument(source)) { if (!source) {
return this.readFeaturesFromDocument( return [];
/** @type {Document} */ (source), opt_options);
} else if (isNode(source)) {
return this.readFeaturesFromNode(/** @type {Node} */ (source), opt_options);
} 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, opt_options);
} else if (isDocument(source)) {
return this.readFeaturesFromDocument(
/** @type {Document} */ (source), opt_options);
} else { } else {
return []; return this.readFeaturesFromNode(/** @type {Node} */ (source), opt_options);
} }
} }
@@ -128,16 +128,16 @@ class XMLFeature extends FeatureFormat {
* @inheritDoc * @inheritDoc
*/ */
readGeometry(source, opt_options) { readGeometry(source, opt_options) {
if (isDocument(source)) { if (!source) {
return this.readGeometryFromDocument( return null;
/** @type {Document} */ (source), opt_options);
} else if (isNode(source)) {
return this.readGeometryFromNode(/** @type {Node} */ (source), opt_options);
} 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, opt_options);
} else if (isDocument(source)) {
return this.readGeometryFromDocument(
/** @type {Document} */ (source), opt_options);
} else { } else {
return null; return this.readGeometryFromNode(/** @type {Node} */ (source), opt_options);
} }
} }
@@ -169,15 +169,15 @@ class XMLFeature extends FeatureFormat {
* @api * @api
*/ */
readProjection(source) { readProjection(source) {
if (isDocument(source)) { if (!source) {
return this.readProjectionFromDocument(/** @type {Document} */ (source)); return null;
} else if (isNode(source)) {
return this.readProjectionFromNode(/** @type {Node} */ (source));
} else if (typeof source === 'string') { } else if (typeof source === 'string') {
const doc = parse(source); const doc = parse(source);
return this.readProjectionFromDocument(doc); return this.readProjectionFromDocument(doc);
} else if (isDocument(source)) {
return this.readProjectionFromDocument(/** @type {Document} */ (source));
} else { } else {
return null; return this.readProjectionFromNode(/** @type {Node} */ (source));
} }
} }
+4 -4
View File
@@ -56,7 +56,7 @@ import {createEditingStyle} from '../style/Style.js';
* @property {import("../events/condition.js").Condition} [finishCondition] A function * @property {import("../events/condition.js").Condition} [finishCondition] A function
* that takes an {@link module:ol/MapBrowserEvent~MapBrowserEvent} and returns a * that takes an {@link module:ol/MapBrowserEvent~MapBrowserEvent} and returns a
* boolean to indicate whether the drawing can be finished. * boolean to indicate whether the drawing can be finished.
* @property {import("../style/Style.js").default|Array<import("../style/Style.js").default>|import("../style/Style.js").StyleFunction} [style] * @property {import("../style/Style.js").StyleLike} [style]
* Style for sketch features. * Style for sketch features.
* @property {GeometryFunction} [geometryFunction] * @property {GeometryFunction} [geometryFunction]
* Function that is called when a geometry's coordinates are updated. * Function that is called when a geometry's coordinates are updated.
@@ -206,7 +206,7 @@ class Draw extends PointerInteraction {
this.downPx_ = null; this.downPx_ = null;
/** /**
* @type {any} * @type {?}
* @private * @private
*/ */
this.downTimeout_; this.downTimeout_;
@@ -734,12 +734,12 @@ class Draw extends PointerInteraction {
} }
/** @type {LineString} */ /** @type {LineString} */
let sketchLineGeom; let sketchLineGeom;
if (geometry instanceof Polygon && if (geometry.getType() == GeometryType.POLYGON &&
this.mode_ !== Mode.POLYGON) { this.mode_ !== Mode.POLYGON) {
if (!this.sketchLine_) { if (!this.sketchLine_) {
this.sketchLine_ = new Feature(); this.sketchLine_ = new Feature();
} }
const ring = geometry.getLinearRing(0); const ring = /** @type {Polygon} */ (geometry).getLinearRing(0);
sketchLineGeom = /** @type {LineString} */ (this.sketchLine_.getGeometry()); sketchLineGeom = /** @type {LineString} */ (this.sketchLine_.getGeometry());
if (!sketchLineGeom) { if (!sketchLineGeom) {
sketchLineGeom = new LineString(ring.getFlatCoordinates(), ring.getLayout()); sketchLineGeom = new LineString(ring.getFlatCoordinates(), ring.getLayout());
+3 -4
View File
@@ -3,7 +3,6 @@
*/ */
import Feature from '../Feature.js'; import Feature from '../Feature.js';
import MapBrowserEventType from '../MapBrowserEventType.js'; import MapBrowserEventType from '../MapBrowserEventType.js';
import MapBrowserPointerEvent from '../MapBrowserPointerEvent.js';
import {squaredDistanceToSegment, closestOnSegment, distance as coordinateDistance, squaredDistance as squaredCoordinateDistance} from '../coordinate.js'; import {squaredDistanceToSegment, closestOnSegment, distance as coordinateDistance, squaredDistance as squaredCoordinateDistance} from '../coordinate.js';
import Event from '../events/Event.js'; import Event from '../events/Event.js';
import {boundingExtent, getArea} from '../extent.js'; import {boundingExtent, getArea} from '../extent.js';
@@ -20,12 +19,12 @@ import {createEditingStyle} from '../style/Style.js';
* @typedef {Object} Options * @typedef {Object} Options
* @property {import("../extent.js").Extent} [extent] Initial extent. Defaults to no * @property {import("../extent.js").Extent} [extent] Initial extent. Defaults to no
* initial extent. * initial extent.
* @property {import("../style/Style.js").default|Array<import("../style/Style.js").default>|import("../style/Style.js").StyleFunction} [boxStyle] * @property {import("../style/Style.js").StyleLike} [boxStyle]
* Style for the drawn extent box. Defaults to * Style for the drawn extent box. Defaults to
* {@link module:ol/style/Style~createEditing()['Polygon']} * {@link module:ol/style/Style~createEditing()['Polygon']}
* @property {number} [pixelTolerance=10] Pixel tolerance for considering the * @property {number} [pixelTolerance=10] Pixel tolerance for considering the
* pointer close enough to a segment or vertex for editing. * pointer close enough to a segment or vertex for editing.
* @property {import("../style/Style.js").default|Array<import("../style/Style.js").default>|import("../style/Style.js").StyleFunction} [pointerStyle] * @property {import("../style/Style.js").StyleLike} [pointerStyle]
* Style for the cursor used to draw the extent. Defaults to * Style for the cursor used to draw the extent. Defaults to
* {@link module:ol/style/Style~createEditing()['Point']} * {@link module:ol/style/Style~createEditing()['Point']}
* @property {boolean} [wrapX=false] Wrap the drawn extent across multiple maps * @property {boolean} [wrapX=false] Wrap the drawn extent across multiple maps
@@ -276,7 +275,7 @@ class ExtentInteraction extends PointerInteraction {
* @inheritDoc * @inheritDoc
*/ */
handleEvent(mapBrowserEvent) { handleEvent(mapBrowserEvent) {
if (!(mapBrowserEvent instanceof MapBrowserPointerEvent)) { if (!(/** @type {import("../MapBrowserPointerEvent.js").default} */ (mapBrowserEvent).pointerEvent)) {
return true; return true;
} }
//display pointer (if not dragging) //display pointer (if not dragging)
+5 -6
View File
@@ -6,7 +6,6 @@ import Collection from '../Collection.js';
import CollectionEventType from '../CollectionEventType.js'; import CollectionEventType from '../CollectionEventType.js';
import Feature from '../Feature.js'; import Feature from '../Feature.js';
import MapBrowserEventType from '../MapBrowserEventType.js'; import MapBrowserEventType from '../MapBrowserEventType.js';
import MapBrowserPointerEvent from '../MapBrowserPointerEvent.js';
import {equals} from '../array.js'; import {equals} from '../array.js';
import {equals as coordinatesEqual, distance as coordinateDistance, squaredDistance as squaredCoordinateDistance, squaredDistanceToSegment, closestOnSegment} from '../coordinate.js'; import {equals as coordinatesEqual, distance as coordinateDistance, squaredDistance as squaredCoordinateDistance, squaredDistanceToSegment, closestOnSegment} from '../coordinate.js';
import {listen, unlisten} from '../events.js'; import {listen, unlisten} from '../events.js';
@@ -87,7 +86,7 @@ const ModifyEventType = {
* features. Default is {@link module:ol/events/condition~always}. * features. Default is {@link module:ol/events/condition~always}.
* @property {number} [pixelTolerance=10] Pixel tolerance for considering the * @property {number} [pixelTolerance=10] Pixel tolerance for considering the
* pointer close enough to a segment or vertex for editing. * pointer close enough to a segment or vertex for editing.
* @property {import("../style/Style.js").default|Array<import("../style/Style.js").default>|import("../style/Style.js").StyleFunction} [style] * @property {import("../style/Style.js").StyleLike} [style]
* Style used for the features being modified. By default the default edit * Style used for the features being modified. By default the default edit
* style is used (see {@link module:ol/style}). * style is used (see {@link module:ol/style}).
* @property {VectorSource} [source] The vector source with * @property {VectorSource} [source] The vector source with
@@ -111,7 +110,7 @@ export class ModifyEvent extends Event {
* @param {ModifyEventType} type Type. * @param {ModifyEventType} type Type.
* @param {Collection<Feature>} features * @param {Collection<Feature>} features
* The features modified. * The features modified.
* @param {MapBrowserPointerEvent} mapBrowserPointerEvent * @param {import("../MapBrowserPointerEvent.js").default} mapBrowserPointerEvent
* Associated {@link module:ol/MapBrowserPointerEvent}. * Associated {@link module:ol/MapBrowserPointerEvent}.
*/ */
constructor(type, features, mapBrowserPointerEvent) { constructor(type, features, mapBrowserPointerEvent) {
@@ -324,7 +323,7 @@ class Modify extends PointerInteraction {
this.handleFeatureRemove_, this); this.handleFeatureRemove_, this);
/** /**
* @type {MapBrowserPointerEvent} * @type {import("../MapBrowserPointerEvent.js").default}
* @private * @private
*/ */
this.lastPointerEvent_ = null; this.lastPointerEvent_ = null;
@@ -349,7 +348,7 @@ class Modify extends PointerInteraction {
} }
/** /**
* @param {MapBrowserPointerEvent} evt Map browser event * @param {import("../MapBrowserPointerEvent.js").default} evt Map browser event
* @private * @private
*/ */
willModifyFeatures_(evt) { willModifyFeatures_(evt) {
@@ -666,7 +665,7 @@ class Modify extends PointerInteraction {
* @override * @override
*/ */
handleEvent(mapBrowserEvent) { handleEvent(mapBrowserEvent) {
if (!(mapBrowserEvent instanceof MapBrowserPointerEvent)) { if (!(/** @type {import("../MapBrowserPointerEvent.js").default} */ (mapBrowserEvent).pointerEvent)) {
return true; return true;
} }
this.lastPointerEvent_ = mapBrowserEvent; this.lastPointerEvent_ = mapBrowserEvent;
+2 -2
View File
@@ -108,7 +108,7 @@ class MouseWheelZoom extends Interaction {
/** /**
* @private * @private
* @type {any} * @type {?}
*/ */
this.timeoutId_; this.timeoutId_;
@@ -126,7 +126,7 @@ class MouseWheelZoom extends Interaction {
this.trackpadEventGap_ = 400; this.trackpadEventGap_ = 400;
/** /**
* @type {any} * @type {?}
*/ */
this.trackpadTimeoutId_; this.trackpadTimeoutId_;
+11 -12
View File
@@ -2,17 +2,16 @@
* @module ol/interaction/Pointer * @module ol/interaction/Pointer
*/ */
import MapBrowserEventType from '../MapBrowserEventType.js'; import MapBrowserEventType from '../MapBrowserEventType.js';
import MapBrowserPointerEvent from '../MapBrowserPointerEvent.js';
import Interaction from '../interaction/Interaction.js'; import Interaction from '../interaction/Interaction.js';
import {getValues} from '../obj.js'; import {getValues} from '../obj.js';
/** /**
* @typedef {Object} Options * @typedef {Object} Options
* @property {function(MapBrowserPointerEvent):boolean} [handleDownEvent] * @property {function(import("../MapBrowserPointerEvent.js").default):boolean} [handleDownEvent]
* Function handling "down" events. If the function returns `true` then a drag * Function handling "down" events. If the function returns `true` then a drag
* sequence is started. * sequence is started.
* @property {function(MapBrowserPointerEvent)} [handleDragEvent] * @property {function(import("../MapBrowserPointerEvent.js").default)} [handleDragEvent]
* Function handling "drag" events. This function is called on "move" events * Function handling "drag" events. This function is called on "move" events
* during a drag sequence. * during a drag sequence.
* @property {function(import("../MapBrowserEvent.js").default):boolean} [handleEvent] * @property {function(import("../MapBrowserEvent.js").default):boolean} [handleEvent]
@@ -20,11 +19,11 @@ import {getValues} from '../obj.js';
* dispatched to the map. The function may return `false` to prevent the * dispatched to the map. The function may return `false` to prevent the
* propagation of the event to other interactions in the map's interactions * propagation of the event to other interactions in the map's interactions
* chain. * chain.
* @property {function(MapBrowserPointerEvent)} [handleMoveEvent] * @property {function(import("../MapBrowserPointerEvent.js").default)} [handleMoveEvent]
* Function handling "move" events. This function is called on "move" events, * Function handling "move" events. This function is called on "move" events,
* also during a drag sequence (so during a drag sequence both the * also during a drag sequence (so during a drag sequence both the
* `handleDragEvent` function and this function are called). * `handleDragEvent` function and this function are called).
* @property {function(MapBrowserPointerEvent):boolean} [handleUpEvent] * @property {function(import("../MapBrowserPointerEvent.js").default):boolean} [handleUpEvent]
* Function handling "up" events. If the function returns `false` then the * Function handling "up" events. If the function returns `false` then the
* current drag sequence is stopped. * current drag sequence is stopped.
* @property {function(boolean):boolean} [stopDown] * @property {function(boolean):boolean} [stopDown]
@@ -96,7 +95,7 @@ class PointerInteraction extends Interaction {
/** /**
* Handle pointer down events. * Handle pointer down events.
* @param {MapBrowserPointerEvent} mapBrowserEvent Event. * @param {import("../MapBrowserPointerEvent.js").default} mapBrowserEvent Event.
* @return {boolean} If the event was consumed. * @return {boolean} If the event was consumed.
* @protected * @protected
*/ */
@@ -106,7 +105,7 @@ class PointerInteraction extends Interaction {
/** /**
* Handle pointer drag events. * Handle pointer drag events.
* @param {MapBrowserPointerEvent} mapBrowserEvent Event. * @param {import("../MapBrowserPointerEvent.js").default} mapBrowserEvent Event.
* @protected * @protected
*/ */
handleDragEvent(mapBrowserEvent) {} handleDragEvent(mapBrowserEvent) {}
@@ -119,7 +118,7 @@ class PointerInteraction extends Interaction {
* @api * @api
*/ */
handleEvent(mapBrowserEvent) { handleEvent(mapBrowserEvent) {
if (!(mapBrowserEvent instanceof MapBrowserPointerEvent)) { if (!(/** @type {import("../MapBrowserPointerEvent.js").default} */ (mapBrowserEvent).pointerEvent)) {
return true; return true;
} }
@@ -149,14 +148,14 @@ class PointerInteraction extends Interaction {
/** /**
* Handle pointer move events. * Handle pointer move events.
* @param {MapBrowserPointerEvent} mapBrowserEvent Event. * @param {import("../MapBrowserPointerEvent.js").default} mapBrowserEvent Event.
* @protected * @protected
*/ */
handleMoveEvent(mapBrowserEvent) {} handleMoveEvent(mapBrowserEvent) {}
/** /**
* Handle pointer up events. * Handle pointer up events.
* @param {MapBrowserPointerEvent} mapBrowserEvent Event. * @param {import("../MapBrowserPointerEvent.js").default} mapBrowserEvent Event.
* @return {boolean} If the event was consumed. * @return {boolean} If the event was consumed.
* @protected * @protected
*/ */
@@ -175,7 +174,7 @@ class PointerInteraction extends Interaction {
} }
/** /**
* @param {MapBrowserPointerEvent} mapBrowserEvent Event. * @param {import("../MapBrowserPointerEvent.js").default} mapBrowserEvent Event.
* @private * @private
*/ */
updateTrackedPointers_(mapBrowserEvent) { updateTrackedPointers_(mapBrowserEvent) {
@@ -216,7 +215,7 @@ export function centroid(pointerEvents) {
/** /**
* @param {MapBrowserPointerEvent} mapBrowserEvent Event. * @param {import("../MapBrowserPointerEvent.js").default} mapBrowserEvent Event.
* @return {boolean} Whether the event is a pointerdown, pointerdrag * @return {boolean} Whether the event is a pointerdown, pointerdrag
* or pointerup event. * or pointerup event.
*/ */
+1 -1
View File
@@ -60,7 +60,7 @@ const SelectEventType = {
* in the map and should return `true` for layers that you want to be * in the map and should return `true` for layers that you want to be
* selectable. If the option is absent, all visible layers will be considered * selectable. If the option is absent, all visible layers will be considered
* selectable. * selectable.
* @property {import("../style/Style.js").default|Array<import("../style/Style.js").default>|import("../style/Style.js").StyleFunction} [style] * @property {import("../style/Style.js").StyleLike} [style]
* Style for the selected features. By default the default edit style is used * Style for the selected features. By default the default edit style is used
* (see {@link module:ol/style}). * (see {@link module:ol/style}).
* @property {import("../events/condition.js").Condition} [removeCondition] A function * @property {import("../events/condition.js").Condition} [removeCondition] A function
+15 -14
View File
@@ -2,7 +2,6 @@
* @module ol/interaction/Snap * @module ol/interaction/Snap
*/ */
import {getUid} from '../util.js'; import {getUid} from '../util.js';
import {CollectionEvent} from '../Collection.js';
import CollectionEventType from '../CollectionEventType.js'; import CollectionEventType from '../CollectionEventType.js';
import {distance as coordinateDistance, squaredDistance as squaredCoordinateDistance, closestOnCircle, closestOnSegment, squaredDistanceToSegment} from '../coordinate.js'; import {distance as coordinateDistance, squaredDistance as squaredCoordinateDistance, closestOnCircle, closestOnSegment, squaredDistanceToSegment} from '../coordinate.js';
import {listen, unlistenByKey} from '../events.js'; import {listen, unlistenByKey} from '../events.js';
@@ -13,7 +12,6 @@ import GeometryType from '../geom/GeometryType.js';
import {fromCircle} from '../geom/Polygon.js'; import {fromCircle} from '../geom/Polygon.js';
import PointerInteraction from '../interaction/Pointer.js'; import PointerInteraction from '../interaction/Pointer.js';
import {getValues} from '../obj.js'; import {getValues} from '../obj.js';
import {VectorSourceEvent} from '../source/Vector.js';
import VectorEventType from '../source/VectorEventType.js'; import VectorEventType from '../source/VectorEventType.js';
import RBush from '../structs/RBush.js'; import RBush from '../structs/RBush.js';
@@ -44,6 +42,19 @@ import RBush from '../structs/RBush.js';
*/ */
/**
* @param {import("../source/Vector.js").VectorSourceEvent|import("../Collection.js").CollectionEvent} evt Event.
* @return {import("../Feature.js").default} Feature.
*/
function getFeatureFromEvent(evt) {
if (/** @type {import("../source/Vector.js").VectorSourceEvent} */ (evt).feature) {
return /** @type {import("../source/Vector.js").VectorSourceEvent} */ (evt).feature;
} else if (/** @type {import("../Collection.js").CollectionEvent} */ (evt).element) {
return /** @type {import("../Feature.js").default} */ (/** @type {import("../Collection.js").CollectionEvent} */ (evt).element);
}
}
/** /**
* @classdesc * @classdesc
* Handles snapping of vector features while modifying or drawing them. The * Handles snapping of vector features while modifying or drawing them. The
@@ -259,12 +270,7 @@ class Snap extends PointerInteraction {
* @private * @private
*/ */
handleFeatureAdd_(evt) { handleFeatureAdd_(evt) {
let feature; const feature = getFeatureFromEvent(evt);
if (evt instanceof VectorSourceEvent) {
feature = evt.feature;
} else if (evt instanceof CollectionEvent) {
feature = /** @type {import("../Feature.js").default} */ (evt.element);
}
this.addFeature(feature); this.addFeature(feature);
} }
@@ -273,12 +279,7 @@ class Snap extends PointerInteraction {
* @private * @private
*/ */
handleFeatureRemove_(evt) { handleFeatureRemove_(evt) {
let feature; const feature = getFeatureFromEvent(evt);
if (evt instanceof VectorSourceEvent) {
feature = evt.feature;
} else if (evt instanceof CollectionEvent) {
feature = /** @type {import("../Feature.js").default} */ (evt.element);
}
this.removeFeature(feature); this.removeFeature(feature);
} }
+1 -2
View File
@@ -84,9 +84,8 @@ class LayerGroup extends BaseLayer {
if (Array.isArray(layers)) { if (Array.isArray(layers)) {
layers = new Collection(layers.slice(), {unique: true}); layers = new Collection(layers.slice(), {unique: true});
} else { } else {
assert(layers instanceof Collection, assert(typeof /** @type {?} */ (layers).getArray === 'function',
43); // Expected `layers` to be an array or a `Collection` 43); // Expected `layers` to be an array or a `Collection`
layers = layers;
} }
} else { } else {
layers = new Collection(undefined, {unique: true}); layers = new Collection(undefined, {unique: true});
+3 -3
View File
@@ -41,7 +41,7 @@ import {createDefaultStyle, toFunction as toStyleFunction} from '../style/Style.
* @property {boolean} [declutter=false] Declutter images and text. Decluttering is applied to all * @property {boolean} [declutter=false] Declutter images and text. Decluttering is applied to all
* image and text styles, and the priority is defined by the z-index of the style. Lower z-index * image and text styles, and the priority is defined by the z-index of the style. Lower z-index
* means higher priority. * means higher priority.
* @property {import("../style/Style.js").default|Array<import("../style/Style.js").default>|import("../style/Style.js").StyleFunction} [style] Layer style. See * @property {import("../style/Style.js").StyleLike} [style] Layer style. See
* {@link module:ol/style} for default style which will be used if this is not defined. * {@link module:ol/style} for default style which will be used if this is not defined.
* @property {boolean} [updateWhileAnimating=false] When set to `true` and `renderMode` * @property {boolean} [updateWhileAnimating=false] When set to `true` and `renderMode`
* is `vector`, feature batches will be recreated during animations. This means that no * is `vector`, feature batches will be recreated during animations. This means that no
@@ -119,7 +119,7 @@ class VectorLayer extends Layer {
/** /**
* User provided style. * User provided style.
* @type {import("../style/Style.js").default|Array<import("../style/Style.js").default>|import("../style/Style.js").StyleFunction} * @type {import("../style/Style.js").StyleLike}
* @private * @private
*/ */
this.style_ = null; this.style_ = null;
@@ -196,7 +196,7 @@ class VectorLayer extends Layer {
/** /**
* Get the style for features. This returns whatever was passed to the `style` * Get the style for features. This returns whatever was passed to the `style`
* option at construction or to the `setStyle` method. * option at construction or to the `setStyle` method.
* @return {import("../style/Style.js").default|Array<import("../style/Style.js").default>|import("../style/Style.js").StyleFunction} * @return {import("../style/Style.js").StyleLike}
* Layer style. * Layer style.
* @api * @api
*/ */
+2 -2
View File
@@ -70,7 +70,7 @@ export const RenderType = {
* image and text styles, and the priority is defined by the z-index of the style. Lower z-index * image and text styles, and the priority is defined by the z-index of the style. Lower z-index
* means higher priority. When set to `true`, a `renderMode` of `'image'` will be overridden with * means higher priority. When set to `true`, a `renderMode` of `'image'` will be overridden with
* `'hybrid'`. * `'hybrid'`.
* @property {import("../style/Style.js").default|Array<import("../style/Style.js").default>|import("../style/Style.js").StyleFunction} [style] Layer style. See * @property {import("../style/Style.js").StyleLike} [style] Layer style. See
* {@link module:ol/style} for default style which will be used if this is not defined. * {@link module:ol/style} for default style which will be used if this is not defined.
* @property {boolean} [updateWhileAnimating=false] When set to `true`, feature batches will be * @property {boolean} [updateWhileAnimating=false] When set to `true`, feature batches will be
* recreated during animations. This means that no vectors will be shown clipped, but the setting * recreated during animations. This means that no vectors will be shown clipped, but the setting
@@ -82,7 +82,7 @@ export const RenderType = {
* means no preloading. * means no preloading.
* @property {import("../render.js").OrderFunction} [renderOrder] Render order. Function to be used when sorting * @property {import("../render.js").OrderFunction} [renderOrder] Render order. Function to be used when sorting
* features before rendering. By default features are drawn in the order that they are created. * features before rendering. By default features are drawn in the order that they are created.
* @property {import("../style/Style.js").default|Array<import("../style/Style.js").default>|import("../style/Style.js").StyleFunction} [style] Layer style. See * @property {import("../style/Style.js").StyleLike} [style] Layer style. See
* {@link module:ol/style} for default style which will be used if this is not defined. * {@link module:ol/style} for default style which will be used if this is not defined.
* @property {boolean} [useInterimTilesOnError=true] Use interim tiles on error. * @property {boolean} [useInterimTilesOnError=true] Use interim tiles on error.
*/ */
+1 -1
View File
@@ -137,7 +137,7 @@ class TouchSource extends EventSource {
/** /**
* @private * @private
* @type {any} * @type {?}
*/ */
this.resetId_; this.resetId_;
+2 -1
View File
@@ -5,6 +5,7 @@
import {getUid} from '../util.js'; import {getUid} from '../util.js';
import {assert} from '../asserts.js'; import {assert} from '../asserts.js';
import Feature from '../Feature.js'; import Feature from '../Feature.js';
import GeometryType from '../geom/GeometryType.js';
import {scale as scaleCoordinate, add as addCoordinate} from '../coordinate.js'; import {scale as scaleCoordinate, add as addCoordinate} from '../coordinate.js';
import {listen} from '../events.js'; import {listen} from '../events.js';
import EventType from '../events/EventType.js'; import EventType from '../events/EventType.js';
@@ -76,7 +77,7 @@ class Cluster extends VectorSource {
*/ */
this.geometryFunction = options.geometryFunction || function(feature) { this.geometryFunction = options.geometryFunction || function(feature) {
const geometry = /** @type {Point} */ (feature.getGeometry()); const geometry = /** @type {Point} */ (feature.getGeometry());
assert(geometry instanceof Point, assert(geometry.getType() == GeometryType.POINT,
10); // The default `geometryFunction` can only handle `Point` geometries 10); // The default `geometryFunction` can only handle `Point` geometries
return geometry; return geometry;
}; };
+1 -4
View File
@@ -230,10 +230,7 @@ class ImageSource extends Source {
* @param {string} src Source. * @param {string} src Source.
*/ */
export function defaultImageLoadFunction(image, src) { export function defaultImageLoadFunction(image, src) {
const img = image.getImage(); /** @type {HTMLImageElement|HTMLVideoElement} */ (image.getImage()).src = src;
if (img instanceof HTMLImageElement || img instanceof HTMLVideoElement) {
img.src = src;
}
} }
+13 -13
View File
@@ -11,7 +11,6 @@ import EventType from '../events/EventType.js';
import {Processor} from 'pixelworks/lib/index'; import {Processor} from 'pixelworks/lib/index';
import {equals, getCenter, getHeight, getWidth} from '../extent.js'; import {equals, getCenter, getHeight, getWidth} from '../extent.js';
import LayerType from '../LayerType.js'; import LayerType from '../LayerType.js';
import Layer from '../layer/Layer.js';
import ImageLayer from '../layer/Image.js'; import ImageLayer from '../layer/Image.js';
import TileLayer from '../layer/Tile.js'; import TileLayer from '../layer/Tile.js';
import {assign} from '../obj.js'; import {assign} from '../obj.js';
@@ -19,7 +18,6 @@ import CanvasImageLayerRenderer from '../renderer/canvas/ImageLayer.js';
import CanvasTileLayerRenderer from '../renderer/canvas/TileLayer.js'; import CanvasTileLayerRenderer from '../renderer/canvas/TileLayer.js';
import ImageSource from '../source/Image.js'; import ImageSource from '../source/Image.js';
import SourceState from '../source/State.js'; import SourceState from '../source/State.js';
import TileSource from '../source/Tile.js';
import {create as createTransform} from '../transform.js'; import {create as createTransform} from '../transform.js';
@@ -488,20 +486,22 @@ function createRenderers(sources) {
/** /**
* Create a renderer for the provided source. * Create a renderer for the provided source.
* @param {import("./Source.js").default|import("../layer/Layer.js").default} source The source. * @param {import("./Source.js").default|import("../layer/Layer.js").default} layerOrSource The layer or source.
* @return {import("../renderer/canvas/Layer.js").default} The renderer. * @return {import("../renderer/canvas/Layer.js").default} The renderer.
*/ */
function createRenderer(source) { function createRenderer(layerOrSource) {
const tileSource = /** @type {import("./Tile.js").default} */ (layerOrSource);
const imageSource = /** @type {import("./Image.js").default} */ (layerOrSource);
const layer = /** @type {import("../layer/Layer.js").default} */ (layerOrSource);
let renderer = null; let renderer = null;
if (source instanceof TileSource) { if (typeof tileSource.getTile === 'function') {
renderer = createTileRenderer(source); renderer = createTileRenderer(tileSource);
} else if (source instanceof ImageSource) { } else if (typeof imageSource.getImage === 'function') {
renderer = createImageRenderer(source); renderer = createImageRenderer(imageSource);
} else if (source instanceof TileLayer) { } else if (layer.getType() === LayerType.TILE) {
renderer = new CanvasTileLayerRenderer(source); renderer = new CanvasTileLayerRenderer(/** @type {import("../layer/Tile.js").default} */ (layer));
} else if (source instanceof Layer && } else if (layer.getType() == LayerType.IMAGE || layer.getType() == LayerType.VECTOR) {
(source.getType() == LayerType.IMAGE || source.getType() == LayerType.VECTOR)) { renderer = new CanvasImageLayerRenderer(/** @type {import("../layer/Image.js").default} */ (layer));
renderer = new CanvasImageLayerRenderer(source);
} }
return renderer; return renderer;
} }
+1 -4
View File
@@ -392,10 +392,7 @@ class TileImage extends UrlTile {
* @param {string} src Source. * @param {string} src Source.
*/ */
function defaultTileLoadFunction(imageTile, src) { function defaultTileLoadFunction(imageTile, src) {
const image = imageTile.getImage(); /** @type {HTMLImageElement|HTMLVideoElement} */ (imageTile.getImage()).src = src;
if (image instanceof HTMLImageElement || image instanceof HTMLVideoElement) {
image.src = src;
}
} }
export default TileImage; export default TileImage;
+3 -3
View File
@@ -258,11 +258,11 @@ class VectorSource extends Source {
this.featuresCollection_ = null; this.featuresCollection_ = null;
let collection, features; let collection, features;
if (options.features instanceof Collection) { if (Array.isArray(options.features)) {
features = options.features;
} else if (options.features) {
collection = options.features; collection = options.features;
features = collection.getArray(); features = collection.getArray();
} else if (Array.isArray(options.features)) {
features = options.features;
} }
if (!useSpatialIndex && collection === undefined) { if (!useSpatialIndex && collection === undefined) {
collection = new Collection(features); collection = new Collection(features);
+8 -6
View File
@@ -76,13 +76,15 @@ class Fill {
*/ */
getChecksum() { getChecksum() {
if (this.checksum_ === undefined) { if (this.checksum_ === undefined) {
if ( const color = this.color_;
this.color_ instanceof CanvasPattern || if (color) {
this.color_ instanceof CanvasGradient if (Array.isArray(color) || typeof color == 'string') {
) { this.checksum_ = 'f' + asString(/** @type {import("../Color.js").Color|string} */ (color));
this.checksum_ = getUid(this.color_).toString(); } else {
this.checksum_ = getUid(this.color_).toString();
}
} else { } else {
this.checksum_ = 'f' + (this.color_ ? asString(this.color_) : '-'); this.checksum_ = 'f-';
} }
} }
+1 -1
View File
@@ -149,7 +149,7 @@ class Icon extends ImageStyle {
5); // `imgSize` must be set when `image` is provided 5); // `imgSize` must be set when `image` is provided
if ((src === undefined || src.length === 0) && image) { if ((src === undefined || src.length === 0) && image) {
src = image instanceof HTMLImageElement && image.src || getUid(image).toString(); src = /** @type {HTMLImageElement} */ (image).src || getUid(image).toString();
} }
assert(src !== undefined && src.length > 0, assert(src !== undefined && src.length > 0,
6); // A defined and non-empty `src` or `image` must be provided 6); // A defined and non-empty `src` or `image` must be provided
+2 -2
View File
@@ -34,8 +34,8 @@ class IconImage extends EventTarget {
*/ */
this.image_ = !image ? new Image() : image; this.image_ = !image ? new Image() : image;
if (crossOrigin !== null && this.image_ instanceof HTMLImageElement) { if (crossOrigin !== null) {
this.image_.crossOrigin = crossOrigin; /** @type {HTMLImageElement} */ (this.image_).crossOrigin = crossOrigin;
} }
/** /**
+9 -6
View File
@@ -87,7 +87,6 @@
* ``` * ```
*/ */
import {assert} from '../asserts.js'; import {assert} from '../asserts.js';
import Geometry from '../geom/Geometry.js';
import GeometryType from '../geom/GeometryType.js'; import GeometryType from '../geom/GeometryType.js';
import CircleStyle from '../style/Circle.js'; import CircleStyle from '../style/Circle.js';
import Fill from '../style/Fill.js'; import Fill from '../style/Fill.js';
@@ -103,6 +102,10 @@ import Stroke from '../style/Stroke.js';
* @typedef {function(import("../Feature.js").FeatureLike, number):(Style|Array<Style>)} StyleFunction * @typedef {function(import("../Feature.js").FeatureLike, number):(Style|Array<Style>)} StyleFunction
*/ */
/**
* A {@link Style}, an array of {@link Style}, or a {@link StyleFunction}.
* @typedef {Style|Array<Style>|StyleFunction} StyleLike
*/
/** /**
* A function that takes an {@link module:ol/Feature} as argument and returns an * A function that takes an {@link module:ol/Feature} as argument and returns an
@@ -137,7 +140,6 @@ import Stroke from '../style/Stroke.js';
* @property {number} [zIndex] Z index. * @property {number} [zIndex] Z index.
*/ */
/** /**
* @classdesc * @classdesc
* Container for vector feature rendering styles. Any changes made to the style * Container for vector feature rendering styles. Any changes made to the style
@@ -214,8 +216,8 @@ class Style {
*/ */
clone() { clone() {
let geometry = this.getGeometry(); let geometry = this.getGeometry();
if (geometry instanceof Geometry) { if (geometry && typeof geometry === 'object') {
geometry = geometry.clone(); geometry = /** @type {import("../geom/Geometry.js").default} */ (geometry).clone();
} }
return new Style({ return new Style({
geometry: geometry, geometry: geometry,
@@ -411,9 +413,10 @@ export function toFunction(obj) {
if (Array.isArray(obj)) { if (Array.isArray(obj)) {
styles = obj; styles = obj;
} else { } else {
assert(obj instanceof Style, assert(typeof /** @type {?} */ (obj).getZIndex === 'function',
41); // Expected an `Style` or an array of `Style` 41); // Expected an `Style` or an array of `Style`
styles = [obj]; const style = /** @type {Style} */ (obj);
styles = [style];
} }
styleFunction = function() { styleFunction = function() {
return styles; return styles;
+4 -13
View File
@@ -89,20 +89,11 @@ export function getAllTextContent_(node, normalizeWhitespace, accumulator) {
/** /**
* @param {?} value Value. * @param {Object} object Object.
* @return {boolean} Is document. * @return {boolean} Is a document.
*/ */
export function isDocument(value) { export function isDocument(object) {
return value instanceof Document; return 'documentElement' in object;
}
/**
* @param {?} value Value.
* @return {boolean} Is node.
*/
export function isNode(value) {
return value instanceof Node;
} }