Merge pull request #8643 from schmidtk/style-typescript-cleanup

Fix style TypeScript errors
This commit is contained in:
Tim Schaub
2018-09-17 14:35:50 -06:00
committed by GitHub
8 changed files with 30 additions and 12 deletions
+1 -1
View File
@@ -192,7 +192,7 @@ class Atlas {
* @param {AtlasBlock} newBlock2 The 2nd block to add. * @param {AtlasBlock} newBlock2 The 2nd block to add.
*/ */
updateBlocks_(index, newBlock1, newBlock2) { updateBlocks_(index, newBlock1, newBlock2) {
const args = [index, 1]; const args = /** @type {Array<*>} */ ([index, 1]);
if (newBlock1.width > 0 && newBlock1.height > 0) { if (newBlock1.width > 0 && newBlock1.height > 0) {
args.push(newBlock1); args.push(newBlock1);
} }
+1 -1
View File
@@ -47,7 +47,7 @@ class Fill {
clone() { clone() {
const color = this.getColor(); const color = this.getColor();
return new Fill({ return new Fill({
color: (color && color.slice) ? color.slice() : color || undefined color: Array.isArray(color) ? color.slice() : color || undefined
}); });
} }
+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.src || getUid(image).toString(); src = image instanceof 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,7 +34,7 @@ class IconImage extends EventTarget {
*/ */
this.image_ = !image ? new Image() : image; this.image_ = !image ? new Image() : image;
if (crossOrigin !== null) { if (crossOrigin !== null && this.image_ instanceof HTMLImageElement) {
this.image_.crossOrigin = crossOrigin; this.image_.crossOrigin = crossOrigin;
} }
@@ -194,7 +194,7 @@ class IconImage extends EventTarget {
this.handleImageLoad_, this) this.handleImageLoad_, this)
]; ];
try { try {
this.image_.src = this.src_; /** @type {HTMLImageElement} */ (this.image_).src = this.src_;
} catch (e) { } catch (e) {
this.handleImageError_(); this.handleImageError_();
} }
+14
View File
@@ -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. * Get the symbolizer opacity.
* @return {number} Opacity. * @return {number} Opacity.
+8 -5
View File
@@ -2,6 +2,7 @@
* @module ol/style/RegularShape * @module ol/style/RegularShape
*/ */
import {asString} from '../color.js';
import {asColorLike} from '../colorlike.js'; import {asColorLike} from '../colorlike.js';
import {createCanvasContext2D} from '../dom.js'; import {createCanvasContext2D} from '../dom.js';
import {CANVAS_LINE_DASH} from '../has.js'; import {CANVAS_LINE_DASH} from '../has.js';
@@ -301,7 +302,9 @@ class RegularShape extends ImageStyle {
/** /**
* @inheritDoc * @inheritDoc
*/ */
listenImageChange(listener, thisArg) {} listenImageChange(listener, thisArg) {
return undefined;
}
/** /**
* @inheritDoc * @inheritDoc
@@ -471,8 +474,8 @@ class RegularShape extends ImageStyle {
context.setLineDash(renderOptions.lineDash); context.setLineDash(renderOptions.lineDash);
context.lineDashOffset = renderOptions.lineDashOffset; context.lineDashOffset = renderOptions.lineDashOffset;
} }
context.lineCap = renderOptions.lineCap; context.lineCap = /** @type {CanvasLineCap} */ (renderOptions.lineCap);
context.lineJoin = renderOptions.lineJoin; context.lineJoin = /** @type {CanvasLineJoin} */ (renderOptions.lineJoin);
context.miterLimit = renderOptions.miterLimit; context.miterLimit = renderOptions.miterLimit;
context.stroke(); context.stroke();
} }
@@ -534,7 +537,7 @@ class RegularShape extends ImageStyle {
} }
} }
context.fillStyle = defaultFillStyle; context.fillStyle = asString(defaultFillStyle);
context.fill(); context.fill();
if (this.stroke_) { if (this.stroke_) {
context.strokeStyle = renderOptions.strokeStyle; context.strokeStyle = renderOptions.strokeStyle;
@@ -575,7 +578,7 @@ class RegularShape extends ImageStyle {
this.radius_, this.radius2_, this.angle_, this.points_]; this.radius_, this.radius2_, this.angle_, this.points_];
} }
return this.checksums_[0]; return /** @type {string} */ (this.checksums_[0]);
} }
} }
+1 -1
View File
@@ -93,7 +93,7 @@ class Stroke {
clone() { clone() {
const color = this.getColor(); const color = this.getColor();
return new Stroke({ return new Stroke({
color: (color && color.slice) ? color.slice() : color || undefined, color: Array.isArray(color) ? color.slice() : color || undefined,
lineCap: this.getLineCap(), lineCap: this.getLineCap(),
lineDash: this.getLineDash() ? this.getLineDash().slice() : undefined, lineDash: this.getLineDash() ? this.getLineDash().slice() : undefined,
lineDashOffset: this.getLineDashOffset(), lineDashOffset: this.getLineDashOffset(),
+2 -1
View File
@@ -87,6 +87,7 @@
* ``` * ```
*/ */
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';
@@ -214,7 +215,7 @@ class Style {
*/ */
clone() { clone() {
let geometry = this.getGeometry(); let geometry = this.getGeometry();
if (geometry && geometry.clone) { if (geometry instanceof Geometry) {
geometry = geometry.clone(); geometry = geometry.clone();
} }
return new Style({ return new Style({