diff --git a/src/ol/interaction/Draw.js b/src/ol/interaction/Draw.js index 30d7f12c3a..632651b878 100644 --- a/src/ol/interaction/Draw.js +++ b/src/ol/interaction/Draw.js @@ -26,7 +26,7 @@ import PointerInteraction, {handleEvent as handlePointerEvent} from '../interact import InteractionProperty from '../interaction/Property.js'; import VectorLayer from '../layer/Vector.js'; import VectorSource from '../source/Vector.js'; -import Style from '../style/Style.js'; +import {createEditingStyle} from '../style/Style.js'; /** @@ -377,7 +377,7 @@ inherits(Draw, PointerInteraction); * @return {ol.StyleFunction} Styles. */ function getDefaultStyleFunction() { - const styles = Style.createDefaultEditing(); + const styles = createEditingStyle(); return function(feature, resolution) { return styles[feature.getGeometry().getType()]; }; diff --git a/src/ol/interaction/Extent.js b/src/ol/interaction/Extent.js index 9848cc893c..7acb7bbc06 100644 --- a/src/ol/interaction/Extent.js +++ b/src/ol/interaction/Extent.js @@ -15,7 +15,7 @@ import ExtentEventType from '../interaction/ExtentEventType.js'; import PointerInteraction, {handleEvent as handlePointerEvent} from '../interaction/Pointer.js'; import VectorLayer from '../layer/Vector.js'; import VectorSource from '../source/Vector.js'; -import Style from '../style/Style.js'; +import {createEditingStyle} from '../style/Style.js'; /** @@ -263,7 +263,7 @@ function handleUpEvent(mapBrowserEvent) { * @return {ol.StyleFunction} Default Extent style */ function getDefaultExtentStyleFunction() { - const style = Style.createDefaultEditing(); + const style = createEditingStyle(); return function(feature, resolution) { return style[GeometryType.POLYGON]; }; @@ -275,7 +275,7 @@ function getDefaultExtentStyleFunction() { * @return {ol.StyleFunction} Default pointer style */ function getDefaultPointerStyleFunction() { - const style = Style.createDefaultEditing(); + const style = createEditingStyle(); return function(feature, resolution) { return style[GeometryType.POINT]; }; diff --git a/src/ol/interaction/Modify.js b/src/ol/interaction/Modify.js index 52e1690ba2..555d415a7c 100644 --- a/src/ol/interaction/Modify.js +++ b/src/ol/interaction/Modify.js @@ -22,7 +22,7 @@ import VectorLayer from '../layer/Vector.js'; import VectorSource from '../source/Vector.js'; import VectorEventType from '../source/VectorEventType.js'; import RBush from '../structs/RBush.js'; -import Style from '../style/Style.js'; +import {createEditingStyle} from '../style/Style.js'; /** * @classdesc @@ -1180,7 +1180,7 @@ Modify.prototype.updateSegmentIndices_ = function( * @return {ol.StyleFunction} Styles. */ Modify.getDefaultStyleFunction = function() { - const style = Style.createDefaultEditing(); + const style = createEditingStyle(); return function(feature, resolution) { return style[GeometryType.POINT]; }; diff --git a/src/ol/interaction/Select.js b/src/ol/interaction/Select.js index c72eca7411..ba27efdc45 100644 --- a/src/ol/interaction/Select.js +++ b/src/ol/interaction/Select.js @@ -13,7 +13,7 @@ import Interaction from '../interaction/Interaction.js'; import VectorLayer from '../layer/Vector.js'; import {clear} from '../obj.js'; import VectorSource from '../source/Vector.js'; -import Style from '../style/Style.js'; +import {createEditingStyle} from '../style/Style.js'; /** @@ -334,7 +334,7 @@ Select.prototype.setMap = function(map) { * @return {ol.StyleFunction} Styles. */ Select.getDefaultStyleFunction = function() { - const styles = Style.createDefaultEditing(); + const styles = createEditingStyle(); extend(styles[GeometryType.POLYGON], styles[GeometryType.LINE_STRING]); extend(styles[GeometryType.GEOMETRY_COLLECTION], styles[GeometryType.LINE_STRING]); diff --git a/src/ol/layer/Vector.js b/src/ol/layer/Vector.js index 494049a44d..eb8f9e22fd 100644 --- a/src/ol/layer/Vector.js +++ b/src/ol/layer/Vector.js @@ -6,7 +6,7 @@ import LayerType from '../LayerType.js'; import Layer from '../layer/Layer.js'; import VectorRenderType from '../layer/VectorRenderType.js'; import {assign} from '../obj.js'; -import Style from '../style/Style.js'; +import {createDefaultStyle, toFunction as toStyleFunction} from '../style/Style.js'; /** @@ -207,9 +207,9 @@ VectorLayer.prototype.setRenderOrder = function(renderOrder) { * @api */ VectorLayer.prototype.setStyle = function(style) { - this.style_ = style !== undefined ? style : Style.defaultFunction; + this.style_ = style !== undefined ? style : createDefaultStyle; this.styleFunction_ = style === null ? - undefined : Style.createFunction(this.style_); + undefined : toStyleFunction(this.style_); this.changed(); }; diff --git a/src/ol/style/Style.js b/src/ol/style/Style.js index e6cb01eab9..748cf67f05 100644 --- a/src/ol/style/Style.js +++ b/src/ol/style/Style.js @@ -32,7 +32,7 @@ const Style = function(opt_options) { * @private * @type {!ol.StyleGeometryFunction} */ - this.geometryFunction_ = Style.defaultGeometryFunction; + this.geometryFunction_ = defaultGeometryFunction; if (options.geometry !== undefined) { this.setGeometry(options.geometry); @@ -249,7 +249,7 @@ Style.prototype.setGeometry = function(geometry) { return /** @type {ol.geom.Geometry} */ (feature.get(geometry)); }; } else if (!geometry) { - this.geometryFunction_ = Style.defaultGeometryFunction; + this.geometryFunction_ = defaultGeometryFunction; } else if (geometry !== undefined) { this.geometryFunction_ = function() { return /** @type {ol.geom.Geometry} */ (geometry); @@ -278,7 +278,7 @@ Style.prototype.setZIndex = function(zIndex) { * A style function, a single style, or an array of styles. * @return {ol.StyleFunction} A style function. */ -Style.createFunction = function(obj) { +export function toFunction(obj) { let styleFunction; if (typeof obj === 'function') { @@ -300,7 +300,7 @@ Style.createFunction = function(obj) { }; } return styleFunction; -}; +} /** @@ -314,7 +314,7 @@ let defaultStyles = null; * @param {number} resolution Resolution. * @return {Array.} Style. */ -Style.defaultFunction = function(feature, resolution) { +export function createDefaultStyle(feature, resolution) { // We don't use an immediately-invoked function // and a closure so we don't get an error at script evaluation time in // browsers that do not support Canvas. (ol.style.Circle does @@ -341,14 +341,14 @@ Style.defaultFunction = function(feature, resolution) { ]; } return defaultStyles; -}; +} /** * Default styles for editing features. * @return {Object.>} Styles */ -Style.createDefaultEditing = function() { +export function createEditingStyle() { /** @type {Object.>} */ const styles = {}; const white = [255, 255, 255, 1]; @@ -412,7 +412,7 @@ Style.createDefaultEditing = function() { ); return styles; -}; +} /** @@ -421,7 +421,8 @@ Style.createDefaultEditing = function() { * for. * @return {ol.geom.Geometry|ol.render.Feature|undefined} Geometry to render. */ -Style.defaultGeometryFunction = function(feature) { +function defaultGeometryFunction(feature) { return feature.getGeometry(); -}; +} + export default Style; diff --git a/test/spec/ol/layer/vector.test.js b/test/spec/ol/layer/vector.test.js index 533c4db17e..9f88d9c66c 100644 --- a/test/spec/ol/layer/vector.test.js +++ b/test/spec/ol/layer/vector.test.js @@ -1,7 +1,7 @@ import Layer from '../../../../src/ol/layer/Layer.js'; import VectorLayer from '../../../../src/ol/layer/Vector.js'; import VectorSource from '../../../../src/ol/source/Vector.js'; -import Style from '../../../../src/ol/style/Style.js'; +import Style, {createDefaultStyle} from '../../../../src/ol/style/Style.js'; describe('ol.layer.Vector', function() { @@ -74,10 +74,10 @@ describe('ol.layer.Vector', function() { }); it('updates the internal style function', function() { - expect(layer.getStyleFunction()).to.be(Style.defaultFunction); + expect(layer.getStyleFunction()).to.be(createDefaultStyle); layer.setStyle(style); expect(layer.getStyleFunction()).not.to.be( - Style.defaultFunction); + createDefaultStyle); }); it('allows setting an null style', function() { @@ -89,8 +89,8 @@ describe('ol.layer.Vector', function() { it('sets the default style when passing undefined', function() { layer.setStyle(style); layer.setStyle(undefined); - expect(layer.getStyle()).to.be(Style.defaultFunction); - expect(layer.getStyleFunction()).to.be(Style.defaultFunction); + expect(layer.getStyle()).to.be(createDefaultStyle); + expect(layer.getStyleFunction()).to.be(createDefaultStyle); }); }); @@ -105,7 +105,7 @@ describe('ol.layer.Vector', function() { source: source }); - expect(layer.getStyle()).to.be(Style.defaultFunction); + expect(layer.getStyle()).to.be(createDefaultStyle); layer.setStyle(style); expect(layer.getStyle()).to.be(style); diff --git a/test/spec/ol/style/style.test.js b/test/spec/ol/style/style.test.js index 8ee39813eb..3c7274ff7d 100644 --- a/test/spec/ol/style/style.test.js +++ b/test/spec/ol/style/style.test.js @@ -1,6 +1,6 @@ import Feature from '../../../../src/ol/Feature.js'; import Point from '../../../../src/ol/geom/Point.js'; -import Style from '../../../../src/ol/style/Style.js'; +import Style, {toFunction} from '../../../../src/ol/style/Style.js'; import Fill from '../../../../src/ol/style/Fill.js'; import CircleStyle from '../../../../src/ol/style/Circle.js'; import Stroke from '../../../../src/ol/style/Stroke.js'; @@ -240,16 +240,16 @@ describe('ol.style.Style', function() { }); -describe('ol.style.Style.createFunction()', function() { +describe('toFunction()', function() { const style = new Style(); it('creates a style function from a single style', function() { - const styleFunction = Style.createFunction(style); + const styleFunction = toFunction(style); expect(styleFunction()).to.eql([style]); }); it('creates a style function from an array of styles', function() { - const styleFunction = Style.createFunction([style]); + const styleFunction = toFunction([style]); expect(styleFunction()).to.eql([style]); }); @@ -257,13 +257,13 @@ describe('ol.style.Style.createFunction()', function() { const original = function() { return [style]; }; - const styleFunction = Style.createFunction(original); + const styleFunction = toFunction(original); expect(styleFunction).to.be(original); }); it('throws on (some) unexpected input', function() { expect(function() { - Style.createFunction({bogus: 'input'}); + toFunction({bogus: 'input'}); }).to.throwException(); });