diff --git a/src/ol/colorlike.js b/src/ol/colorlike.js index 834a2f83d7..bd0b0e71bd 100644 --- a/src/ol/colorlike.js +++ b/src/ol/colorlike.js @@ -2,7 +2,6 @@ * @module ol/colorlike */ import _ol_color_ from './color.js'; -var _ol_colorlike_ = {}; /** @@ -10,24 +9,23 @@ var _ol_colorlike_ = {}; * @return {ol.ColorLike} The color as an ol.ColorLike * @api */ -_ol_colorlike_.asColorLike = function(color) { - if (_ol_colorlike_.isColorLike(color)) { +export function asColorLike(color) { + if (isColorLike(color)) { return /** @type {string|CanvasPattern|CanvasGradient} */ (color); } else { return _ol_color_.asString(/** @type {ol.Color} */ (color)); } -}; +} /** * @param {?} color The value that is potentially an ol.ColorLike * @return {boolean} Whether the color is an ol.ColorLike */ -_ol_colorlike_.isColorLike = function(color) { +export function isColorLike(color) { return ( typeof color === 'string' || color instanceof CanvasPattern || color instanceof CanvasGradient ); -}; -export default _ol_colorlike_; +} diff --git a/src/ol/render/canvas/Immediate.js b/src/ol/render/canvas/Immediate.js index 725fd05adb..cc0948ead8 100644 --- a/src/ol/render/canvas/Immediate.js +++ b/src/ol/render/canvas/Immediate.js @@ -7,7 +7,7 @@ import {inherits} from '../../index.js'; import _ol_array_ from '../../array.js'; -import _ol_colorlike_ from '../../colorlike.js'; +import {asColorLike} from '../../colorlike.js'; import {intersects} from '../../extent.js'; import GeometryType from '../../geom/GeometryType.js'; import SimpleGeometry from '../../geom/SimpleGeometry.js'; @@ -829,7 +829,7 @@ _ol_render_canvas_Immediate_.prototype.setFillStrokeStyle = function(fillStyle, } else { var fillStyleColor = fillStyle.getColor(); this.fillState_ = { - fillStyle: _ol_colorlike_.asColorLike(fillStyleColor ? + fillStyle: asColorLike(fillStyleColor ? fillStyleColor : _ol_render_canvas_.defaultFillStyle) }; } @@ -856,7 +856,7 @@ _ol_render_canvas_Immediate_.prototype.setFillStrokeStyle = function(fillStyle, strokeStyleWidth : _ol_render_canvas_.defaultLineWidth), miterLimit: strokeStyleMiterLimit !== undefined ? strokeStyleMiterLimit : _ol_render_canvas_.defaultMiterLimit, - strokeStyle: _ol_colorlike_.asColorLike(strokeStyleColor ? + strokeStyle: asColorLike(strokeStyleColor ? strokeStyleColor : _ol_render_canvas_.defaultStrokeStyle) }; } @@ -912,7 +912,7 @@ _ol_render_canvas_Immediate_.prototype.setTextStyle = function(textStyle) { } else { var textFillStyleColor = textFillStyle.getColor(); this.textFillState_ = { - fillStyle: _ol_colorlike_.asColorLike(textFillStyleColor ? + fillStyle: asColorLike(textFillStyleColor ? textFillStyleColor : _ol_render_canvas_.defaultFillStyle) }; } @@ -940,7 +940,7 @@ _ol_render_canvas_Immediate_.prototype.setTextStyle = function(textStyle) { textStrokeStyleWidth : _ol_render_canvas_.defaultLineWidth, miterLimit: textStrokeStyleMiterLimit !== undefined ? textStrokeStyleMiterLimit : _ol_render_canvas_.defaultMiterLimit, - strokeStyle: _ol_colorlike_.asColorLike(textStrokeStyleColor ? + strokeStyle: asColorLike(textStrokeStyleColor ? textStrokeStyleColor : _ol_render_canvas_.defaultStrokeStyle) }; } diff --git a/src/ol/render/canvas/Replay.js b/src/ol/render/canvas/Replay.js index a576ff7237..1a53f863ed 100644 --- a/src/ol/render/canvas/Replay.js +++ b/src/ol/render/canvas/Replay.js @@ -3,7 +3,7 @@ */ import {getUid, inherits, nullFunction} from '../../index.js'; import _ol_array_ from '../../array.js'; -import _ol_colorlike_ from '../../colorlike.js'; +import {asColorLike} from '../../colorlike.js'; import {buffer, clone, coordinateRelationship, createEmpty, createOrUpdate, createOrUpdateEmpty, extend, extendCoordinate, intersects} from '../../extent.js'; import Relationship from '../../extent/Relationship.js'; @@ -912,14 +912,14 @@ _ol_render_canvas_Replay_.prototype.setFillStrokeStyle = function(fillStyle, str var state = this.state; if (fillStyle) { var fillStyleColor = fillStyle.getColor(); - state.fillStyle = _ol_colorlike_.asColorLike(fillStyleColor ? + state.fillStyle = asColorLike(fillStyleColor ? fillStyleColor : _ol_render_canvas_.defaultFillStyle); } else { state.fillStyle = undefined; } if (strokeStyle) { var strokeStyleColor = strokeStyle.getColor(); - state.strokeStyle = _ol_colorlike_.asColorLike(strokeStyleColor ? + state.strokeStyle = asColorLike(strokeStyleColor ? strokeStyleColor : _ol_render_canvas_.defaultStrokeStyle); var strokeStyleLineCap = strokeStyle.getLineCap(); state.lineCap = strokeStyleLineCap !== undefined ? diff --git a/src/ol/render/canvas/TextReplay.js b/src/ol/render/canvas/TextReplay.js index d44c196dcd..cda2361ef5 100644 --- a/src/ol/render/canvas/TextReplay.js +++ b/src/ol/render/canvas/TextReplay.js @@ -2,7 +2,7 @@ * @module ol/render/canvas/TextReplay */ import {getUid, inherits} from '../../index.js'; -import _ol_colorlike_ from '../../colorlike.js'; +import {asColorLike} from '../../colorlike.js'; import {createCanvasContext2D} from '../../dom.js'; import {intersects} from '../../extent.js'; import _ol_geom_flat_straightchunk_ from '../../geom/flat/straightchunk.js'; @@ -478,7 +478,7 @@ _ol_render_canvas_TextReplay_.prototype.setTextStyle = function(textStyle, declu if (!fillState) { fillState = this.textFillState_ = /** @type {ol.CanvasFillState} */ ({}); } - fillState.fillStyle = _ol_colorlike_.asColorLike( + fillState.fillStyle = asColorLike( textFillStyle.getColor() || _ol_render_canvas_.defaultFillStyle); } @@ -503,7 +503,7 @@ _ol_render_canvas_TextReplay_.prototype.setTextStyle = function(textStyle, declu lineWidth === undefined ? _ol_render_canvas_.defaultLineWidth : lineWidth; strokeState.miterLimit = miterLimit === undefined ? _ol_render_canvas_.defaultMiterLimit : miterLimit; - strokeState.strokeStyle = _ol_colorlike_.asColorLike( + strokeState.strokeStyle = asColorLike( textStrokeStyle.getColor() || _ol_render_canvas_.defaultStrokeStyle); } diff --git a/src/ol/render/webgl/TextReplay.js b/src/ol/render/webgl/TextReplay.js index fb71dd66a1..f83e51b2db 100644 --- a/src/ol/render/webgl/TextReplay.js +++ b/src/ol/render/webgl/TextReplay.js @@ -2,7 +2,7 @@ * @module ol/render/webgl/TextReplay */ import {getUid, inherits} from '../../index.js'; -import _ol_colorlike_ from '../../colorlike.js'; +import {asColorLike} from '../../colorlike.js'; import {createCanvasContext2D} from '../../dom.js'; import GeometryType from '../../geom/GeometryType.js'; import _ol_has_ from '../../has.js'; @@ -359,7 +359,7 @@ _ol_render_webgl_TextReplay_.prototype.setTextStyle = function(textStyle) { state.fillColor = null; } else { var textFillStyleColor = textFillStyle.getColor(); - state.fillColor = _ol_colorlike_.asColorLike(textFillStyleColor ? + state.fillColor = asColorLike(textFillStyleColor ? textFillStyleColor : _ol_render_webgl_.defaultFillStyle); } if (!textStrokeStyle) { @@ -367,7 +367,7 @@ _ol_render_webgl_TextReplay_.prototype.setTextStyle = function(textStyle) { state.lineWidth = 0; } else { var textStrokeStyleColor = textStrokeStyle.getColor(); - state.strokeColor = _ol_colorlike_.asColorLike(textStrokeStyleColor ? + state.strokeColor = asColorLike(textStrokeStyleColor ? textStrokeStyleColor : _ol_render_webgl_.defaultStrokeStyle); state.lineWidth = textStrokeStyle.getWidth() || _ol_render_webgl_.defaultLineWidth; state.lineCap = textStrokeStyle.getLineCap() || _ol_render_webgl_.defaultLineCap; diff --git a/src/ol/style/RegularShape.js b/src/ol/style/RegularShape.js index 91d9f32add..f1c9525dc4 100644 --- a/src/ol/style/RegularShape.js +++ b/src/ol/style/RegularShape.js @@ -2,7 +2,7 @@ * @module ol/style/RegularShape */ import {inherits} from '../index.js'; -import _ol_colorlike_ from '../colorlike.js'; +import {asColorLike} from '../colorlike.js'; import {createCanvasContext2D} from '../dom.js'; import _ol_has_ from '../has.js'; import _ol_ImageState_ from '../ImageState.js'; @@ -327,7 +327,7 @@ _ol_style_RegularShape_.prototype.render_ = function(atlasManager) { if (strokeStyle === null) { strokeStyle = _ol_render_canvas_.defaultStrokeStyle; } - strokeStyle = _ol_colorlike_.asColorLike(strokeStyle); + strokeStyle = asColorLike(strokeStyle); strokeWidth = this.stroke_.getWidth(); if (strokeWidth === undefined) { strokeWidth = _ol_render_canvas_.defaultLineWidth; @@ -457,7 +457,7 @@ _ol_style_RegularShape_.prototype.draw_ = function(renderOptions, context, x, y) if (color === null) { color = _ol_render_canvas_.defaultFillStyle; } - context.fillStyle = _ol_colorlike_.asColorLike(color); + context.fillStyle = asColorLike(color); context.fill(); } if (this.stroke_) {