From 124fccf12787283e9db220749ca37acadad750ef Mon Sep 17 00:00:00 2001 From: Kevin Schmidt Date: Fri, 14 Sep 2018 15:57:21 -0600 Subject: [PATCH] Fix style TypeScript errors --- src/ol/style/Atlas.js | 2 +- src/ol/style/Fill.js | 2 +- src/ol/style/Icon.js | 2 +- src/ol/style/IconImage.js | 4 ++-- src/ol/style/Image.js | 14 ++++++++++++++ src/ol/style/RegularShape.js | 13 ++++++++----- src/ol/style/Stroke.js | 2 +- src/ol/style/Style.js | 3 ++- 8 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/ol/style/Atlas.js b/src/ol/style/Atlas.js index 8df1e168bb..a2fbbd71e2 100644 --- a/src/ol/style/Atlas.js +++ b/src/ol/style/Atlas.js @@ -192,7 +192,7 @@ class Atlas { * @param {AtlasBlock} newBlock2 The 2nd block to add. */ updateBlocks_(index, newBlock1, newBlock2) { - const args = [index, 1]; + const args = /** @type {Array<*>} */ ([index, 1]); if (newBlock1.width > 0 && newBlock1.height > 0) { args.push(newBlock1); } diff --git a/src/ol/style/Fill.js b/src/ol/style/Fill.js index 3ff449d64f..116f1b997b 100644 --- a/src/ol/style/Fill.js +++ b/src/ol/style/Fill.js @@ -47,7 +47,7 @@ class Fill { clone() { const color = this.getColor(); return new Fill({ - color: (color && color.slice) ? color.slice() : color || undefined + color: Array.isArray(color) ? color.slice() : color || undefined }); } diff --git a/src/ol/style/Icon.js b/src/ol/style/Icon.js index f0309df9d5..9ca81686a4 100644 --- a/src/ol/style/Icon.js +++ b/src/ol/style/Icon.js @@ -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.src || getUid(image).toString(); + src = image instanceof HTMLImageElement && image.src || getUid(image).toString(); } assert(src !== undefined && src.length > 0, 6); // A defined and non-empty `src` or `image` must be provided diff --git a/src/ol/style/IconImage.js b/src/ol/style/IconImage.js index 6bb3ac0001..e85106bcb8 100644 --- a/src/ol/style/IconImage.js +++ b/src/ol/style/IconImage.js @@ -34,7 +34,7 @@ class IconImage extends EventTarget { */ this.image_ = !image ? new Image() : image; - if (crossOrigin !== null) { + if (crossOrigin !== null && this.image_ instanceof HTMLImageElement) { this.image_.crossOrigin = crossOrigin; } @@ -194,7 +194,7 @@ class IconImage extends EventTarget { this.handleImageLoad_, this) ]; try { - this.image_.src = this.src_; + /** @type {HTMLImageElement} */ (this.image_).src = this.src_; } catch (e) { this.handleImageError_(); } diff --git a/src/ol/style/Image.js b/src/ol/style/Image.js index 92a4bfe82c..acbcb76514 100644 --- a/src/ol/style/Image.js +++ b/src/ol/style/Image.js @@ -51,6 +51,20 @@ class ImageStyle { } + /** + * Clones the style. + * @return {ImageStyle} The cloned style. + * @api + */ + clone() { + return new ImageStyle({ + opacity: this.getOpacity(), + scale: this.getScale(), + rotation: this.getRotation(), + rotateWithView: this.getRotateWithView() + }); + } + /** * Get the symbolizer opacity. * @return {number} Opacity. diff --git a/src/ol/style/RegularShape.js b/src/ol/style/RegularShape.js index 5170bd8c7c..776176a298 100644 --- a/src/ol/style/RegularShape.js +++ b/src/ol/style/RegularShape.js @@ -2,6 +2,7 @@ * @module ol/style/RegularShape */ +import {asString} from '../color.js'; import {asColorLike} from '../colorlike.js'; import {createCanvasContext2D} from '../dom.js'; import {CANVAS_LINE_DASH} from '../has.js'; @@ -301,7 +302,9 @@ class RegularShape extends ImageStyle { /** * @inheritDoc */ - listenImageChange(listener, thisArg) {} + listenImageChange(listener, thisArg) { + return undefined; + } /** * @inheritDoc @@ -471,8 +474,8 @@ class RegularShape extends ImageStyle { context.setLineDash(renderOptions.lineDash); context.lineDashOffset = renderOptions.lineDashOffset; } - context.lineCap = renderOptions.lineCap; - context.lineJoin = renderOptions.lineJoin; + context.lineCap = /** @type {CanvasLineCap} */ (renderOptions.lineCap); + context.lineJoin = /** @type {CanvasLineJoin} */ (renderOptions.lineJoin); context.miterLimit = renderOptions.miterLimit; context.stroke(); } @@ -534,7 +537,7 @@ class RegularShape extends ImageStyle { } } - context.fillStyle = defaultFillStyle; + context.fillStyle = asString(defaultFillStyle); context.fill(); if (this.stroke_) { context.strokeStyle = renderOptions.strokeStyle; @@ -575,7 +578,7 @@ class RegularShape extends ImageStyle { this.radius_, this.radius2_, this.angle_, this.points_]; } - return this.checksums_[0]; + return /** @type {string} */ (this.checksums_[0]); } } diff --git a/src/ol/style/Stroke.js b/src/ol/style/Stroke.js index f1891a0b79..4b058aae26 100644 --- a/src/ol/style/Stroke.js +++ b/src/ol/style/Stroke.js @@ -93,7 +93,7 @@ class Stroke { clone() { const color = this.getColor(); return new Stroke({ - color: (color && color.slice) ? color.slice() : color || undefined, + color: Array.isArray(color) ? color.slice() : color || undefined, lineCap: this.getLineCap(), lineDash: this.getLineDash() ? this.getLineDash().slice() : undefined, lineDashOffset: this.getLineDashOffset(), diff --git a/src/ol/style/Style.js b/src/ol/style/Style.js index 888e344987..cf5a986170 100644 --- a/src/ol/style/Style.js +++ b/src/ol/style/Style.js @@ -87,6 +87,7 @@ * ``` */ 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'; @@ -214,7 +215,7 @@ class Style { */ clone() { let geometry = this.getGeometry(); - if (geometry && geometry.clone) { + if (geometry instanceof Geometry) { geometry = geometry.clone(); } return new Style({