Replace instanceof checks with other logic
This commit is contained in:
@@ -76,13 +76,15 @@ class Fill {
|
||||
*/
|
||||
getChecksum() {
|
||||
if (this.checksum_ === undefined) {
|
||||
if (
|
||||
this.color_ instanceof CanvasPattern ||
|
||||
this.color_ instanceof CanvasGradient
|
||||
) {
|
||||
this.checksum_ = getUid(this.color_).toString();
|
||||
const color = this.color_;
|
||||
if (color) {
|
||||
if (Array.isArray(color) || typeof color == 'string') {
|
||||
this.checksum_ = 'f' + asString(/** @type {import("../Color.js").Color|string} */ (color));
|
||||
} else {
|
||||
this.checksum_ = getUid(this.color_).toString();
|
||||
}
|
||||
} else {
|
||||
this.checksum_ = 'f' + (this.color_ ? asString(this.color_) : '-');
|
||||
this.checksum_ = 'f-';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -149,7 +149,7 @@ class Icon extends ImageStyle {
|
||||
5); // `imgSize` must be set when `image` is provided
|
||||
|
||||
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,
|
||||
6); // A defined and non-empty `src` or `image` must be provided
|
||||
|
||||
@@ -34,8 +34,8 @@ class IconImage extends EventTarget {
|
||||
*/
|
||||
this.image_ = !image ? new Image() : image;
|
||||
|
||||
if (crossOrigin !== null && this.image_ instanceof HTMLImageElement) {
|
||||
this.image_.crossOrigin = crossOrigin;
|
||||
if (crossOrigin !== null) {
|
||||
/** @type {HTMLImageElement} */ (this.image_).crossOrigin = crossOrigin;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -87,7 +87,6 @@
|
||||
* ```
|
||||
*/
|
||||
import {assert} from '../asserts.js';
|
||||
import Geometry from '../geom/Geometry.js';
|
||||
import GeometryType from '../geom/GeometryType.js';
|
||||
import CircleStyle from '../style/Circle.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
|
||||
*/
|
||||
|
||||
/**
|
||||
* 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
|
||||
@@ -137,7 +140,6 @@ import Stroke from '../style/Stroke.js';
|
||||
* @property {number} [zIndex] Z index.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @classdesc
|
||||
* Container for vector feature rendering styles. Any changes made to the style
|
||||
@@ -214,8 +216,8 @@ class Style {
|
||||
*/
|
||||
clone() {
|
||||
let geometry = this.getGeometry();
|
||||
if (geometry instanceof Geometry) {
|
||||
geometry = geometry.clone();
|
||||
if (geometry && typeof geometry === 'object') {
|
||||
geometry = /** @type {import("../geom/Geometry.js").default} */ (geometry).clone();
|
||||
}
|
||||
return new Style({
|
||||
geometry: geometry,
|
||||
@@ -411,9 +413,10 @@ export function toFunction(obj) {
|
||||
if (Array.isArray(obj)) {
|
||||
styles = obj;
|
||||
} else {
|
||||
assert(obj instanceof Style,
|
||||
assert(typeof /** @type {?} */ (obj).getZIndex === 'function',
|
||||
41); // Expected an `Style` or an array of `Style`
|
||||
styles = [obj];
|
||||
const style = /** @type {Style} */ (obj);
|
||||
styles = [style];
|
||||
}
|
||||
styleFunction = function() {
|
||||
return styles;
|
||||
|
||||
Reference in New Issue
Block a user