From a50f6d7a2fe5a4a45a0da63c68c6d51803a82a7b Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Wed, 3 Sep 2014 16:57:50 -0600 Subject: [PATCH 1/6] Mutable symbolizer properties for style functions This change adds setters for symbolizer properties. In addition, it introduces a mutable flag on all styles. By default, this is set to true. ol.style.createStyleFunction sets it to false for all static styles. The new setters assert that the mutable flag is true, so whenever an application tries to set a symbolizer property on a style that was assigned to a vector layer or feature overlay, the assertion will fail. --- examples/vector-layer.js | 47 +++++------ src/ol/style/circlestyle.js | 15 ++++ src/ol/style/fillstyle.js | 27 ++++++- src/ol/style/imagestyle.js | 63 +++++++++++++++ src/ol/style/strokestyle.js | 77 +++++++++++++++++- src/ol/style/style.js | 38 +++++++++ src/ol/style/textstyle.js | 121 ++++++++++++++++++++++++++++ test/spec/ol/featureoverlay.test.js | 3 +- test/spec/ol/style.test.js | 85 +++++++++++++++++++ 9 files changed, 448 insertions(+), 28 deletions(-) diff --git a/examples/vector-layer.js b/examples/vector-layer.js index daf0d3ca75..25f70d6cde 100644 --- a/examples/vector-layer.js +++ b/examples/vector-layer.js @@ -11,37 +11,34 @@ goog.require('ol.style.Style'); goog.require('ol.style.Text'); -var styleCache = {}; +var style = new ol.style.Style({ + fill: new ol.style.Fill({ + color: 'rgba(255, 255, 255, 0.6)' + }), + stroke: new ol.style.Stroke({ + color: '#319FD3', + width: 1 + }), + text: new ol.style.Text({ + font: '12px Calibri,sans-serif', + fill: new ol.style.Fill({ + color: '#000' + }), + stroke: new ol.style.Stroke({ + color: '#fff', + width: 3 + }) + }) +}); +var styles = [style]; var vectorLayer = new ol.layer.Vector({ source: new ol.source.GeoJSON({ projection: 'EPSG:3857', url: 'data/geojson/countries.geojson' }), style: function(feature, resolution) { - var text = resolution < 5000 ? feature.get('name') : ''; - if (!styleCache[text]) { - styleCache[text] = [new ol.style.Style({ - fill: new ol.style.Fill({ - color: 'rgba(255, 255, 255, 0.6)' - }), - stroke: new ol.style.Stroke({ - color: '#319FD3', - width: 1 - }), - text: new ol.style.Text({ - font: '12px Calibri,sans-serif', - text: text, - fill: new ol.style.Fill({ - color: '#000' - }), - stroke: new ol.style.Stroke({ - color: '#fff', - width: 3 - }) - }) - })]; - } - return styleCache[text]; + style.getText().setText(resolution < 5000 ? feature.get('name') : ''); + return styles; } }); diff --git a/src/ol/style/circlestyle.js b/src/ol/style/circlestyle.js index 7f9c268541..e531716ec6 100644 --- a/src/ol/style/circlestyle.js +++ b/src/ol/style/circlestyle.js @@ -172,6 +172,21 @@ ol.style.Circle.prototype.getStroke = function() { }; +/** + * @protected + * @param {boolean} mutable Mutable. + */ +ol.style.Circle.prototype.setMutable = function(mutable) { + if (!goog.isNull(this.stroke_)) { + this.stroke_.setMutable(mutable); + } + if (!goog.isNull(this.fill_)) { + this.fill_.setMutable(mutable); + } + goog.base(this, 'setMutable', mutable); +}; + + /** * @inheritDoc */ diff --git a/src/ol/style/fillstyle.js b/src/ol/style/fillstyle.js index edfad11ae4..6b566deb96 100644 --- a/src/ol/style/fillstyle.js +++ b/src/ol/style/fillstyle.js @@ -1,6 +1,6 @@ goog.provide('ol.style.Fill'); -goog.require('ol.color'); +goog.require('goog.asserts'); @@ -21,6 +21,13 @@ ol.style.Fill = function(opt_options) { * @type {ol.Color|string} */ this.color_ = goog.isDef(options.color) ? options.color : null; + + /** + * @private + * @type {boolean} + */ + this.mutable_ = true; + }; @@ -31,3 +38,21 @@ ol.style.Fill = function(opt_options) { ol.style.Fill.prototype.getColor = function() { return this.color_; }; + + +/** + * @param {ol.Color|string} color Color. + * @api + */ +ol.style.Fill.prototype.setColor = function(color) { + goog.asserts.assert(this.mutable_); + this.color_ = color; +}; + + +/** + * @param {boolean} mutable Mutable. + */ +ol.style.Fill.prototype.setMutable = function(mutable) { + this.mutable_ = mutable; +}; diff --git a/src/ol/style/imagestyle.js b/src/ol/style/imagestyle.js index e5d8bce527..e4db519d23 100644 --- a/src/ol/style/imagestyle.js +++ b/src/ol/style/imagestyle.js @@ -1,6 +1,8 @@ goog.provide('ol.style.Image'); goog.provide('ol.style.ImageState'); +goog.require('goog.asserts'); + /** * @enum {number} @@ -63,6 +65,12 @@ ol.style.Image = function(options) { */ this.snapToPixel_ = options.snapToPixel; + /** + * @private + * @type {boolean} + */ + this.mutable_ = true; + }; @@ -150,6 +158,61 @@ ol.style.Image.prototype.getOrigin = goog.abstractMethod; ol.style.Image.prototype.getSize = goog.abstractMethod; +/** + * @param {number} opacity Opacity. + */ +ol.style.Image.prototype.setOpacity = function(opacity) { + goog.asserts.assert(this.mutable_); + this.opacity_ = opacity; +}; + + +/** + * @param {boolean} rotateWithView Rotate with map. + */ +ol.style.Image.prototype.setRotateWithView = function(rotateWithView) { + goog.asserts.assert(this.mutable_); + this.rotateWithView_ = rotateWithView; +}; + + +/** + * @param {number} rotation Rotation. + * @api + */ +ol.style.Image.prototype.setRotation = function(rotation) { + goog.asserts.assert(this.mutable_); + this.rotation_ = rotation; +}; + + +/** + * @param {number} scale Scale. + * @api + */ +ol.style.Image.prototype.setScale = function(scale) { + goog.asserts.assert(this.mutable_); + this.scale_ = scale; +}; + + +/** + * @param {boolean} snapToPixel Snap to pixel? + */ +ol.style.Image.prototype.setSnapToPixel = function(snapToPixel) { + goog.asserts.assert(this.mutable_); + this.snapToPixel_ = snapToPixel; +}; + + +/** + * @param {boolean} mutable Mutable. + */ +ol.style.Image.prototype.setMutable = function(mutable) { + this.mutable_ = mutable; +}; + + /** * @param {function(this: T, goog.events.Event)} listener Listener function. * @param {T} thisArg Value to use as `this` when executing `listener`. diff --git a/src/ol/style/strokestyle.js b/src/ol/style/strokestyle.js index c5d2e90c91..6e487f974e 100644 --- a/src/ol/style/strokestyle.js +++ b/src/ol/style/strokestyle.js @@ -1,6 +1,6 @@ goog.provide('ol.style.Stroke'); -goog.require('ol.color'); +goog.require('goog.asserts'); @@ -54,6 +54,13 @@ ol.style.Stroke = function(opt_options) { * @type {number|undefined} */ this.width_ = options.width; + + /** + * @private + * @type {boolean} + */ + this.mutable_ = true; + }; @@ -109,3 +116,71 @@ ol.style.Stroke.prototype.getMiterLimit = function() { ol.style.Stroke.prototype.getWidth = function() { return this.width_; }; + + +/** + * @param {ol.Color|string} color Color. + * @api + */ +ol.style.Stroke.prototype.setColor = function(color) { + goog.asserts.assert(this.mutable_); + this.color_ = color; +}; + + +/** + * @param {string|undefined} lineCap Line cap. + * @api + */ +ol.style.Stroke.prototype.setLineCap = function(lineCap) { + goog.asserts.assert(this.mutable_); + this.lineCap_ = lineCap; +}; + + +/** + * @param {Array.} lineDash Line dash. + * @api + */ +ol.style.Stroke.prototype.setLineDash = function(lineDash) { + goog.asserts.assert(this.mutable_); + this.lineDash_ = lineDash; +}; + + +/** + * @param {string|undefined} lineJoin Line join. + * @api + */ +ol.style.Stroke.prototype.setLineJoin = function(lineJoin) { + goog.asserts.assert(this.mutable_); + this.lineJoin_ = lineJoin; +}; + + +/** + * @param {number|undefined} miterLimit Miter limit. + * @api + */ +ol.style.Stroke.prototype.setMiterLimit = function(miterLimit) { + goog.asserts.assert(this.mutable_); + this.miterLimit_ = miterLimit; +}; + + +/** + * @param {number|undefined} width Width. + * @api + */ +ol.style.Stroke.prototype.setWidth = function(width) { + goog.asserts.assert(this.mutable_); + this.width_ = width; +}; + + +/** + * @param {boolean} mutable Mutable. + */ +ol.style.Stroke.prototype.setMutable = function(mutable) { + this.mutable_ = mutable; +}; diff --git a/src/ol/style/style.js b/src/ol/style/style.js index 031b9b59bc..527ca0d3d4 100644 --- a/src/ol/style/style.js +++ b/src/ol/style/style.js @@ -52,6 +52,11 @@ ol.style.Style = function(opt_options) { */ this.zIndex_ = options.zIndex; + /** + * @private + * @type {boolean} + */ + this.mutable_ = true; }; @@ -100,6 +105,36 @@ ol.style.Style.prototype.getZIndex = function() { }; +/** + * @param {number|undefined} zIndex ZIndex. + * @api + */ +ol.style.Style.prototype.setZIndex = function(zIndex) { + goog.asserts.assert(this.mutable_); + this.zIndex_ = zIndex; +}; + + +/** + * @param {boolean} mutable Mutable. + */ +ol.style.Style.prototype.setMutable = function(mutable) { + if (!goog.isNull(this.fill_)) { + this.fill_.setMutable(mutable); + } + if (!goog.isNull(this.image_)) { + this.image_.setMutable(mutable); + } + if (!goog.isNull(this.stroke_)) { + this.stroke_.setMutable(mutable); + } + if (!goog.isNull(this.text_)) { + this.text_.setMutable(mutable); + } + this.mutable_ = mutable; +}; + + /** * A function that takes an {@link ol.Feature} and a `{number}` representing * the view's resolution. The function should return an array of @@ -138,6 +173,9 @@ ol.style.createStyleFunction = function(obj) { goog.asserts.assertInstanceof(obj, ol.style.Style); styles = [obj]; } + for (var i = styles.length - 1; i >= 0; --i) { + styles[i].setMutable(false); + } styleFunction = goog.functions.constant(styles); } return styleFunction; diff --git a/src/ol/style/textstyle.js b/src/ol/style/textstyle.js index 0ea5e73550..e2b8d6474d 100644 --- a/src/ol/style/textstyle.js +++ b/src/ol/style/textstyle.js @@ -1,5 +1,7 @@ goog.provide('ol.style.Text'); +goog.require('goog.asserts'); + /** @@ -73,6 +75,13 @@ ol.style.Text = function(opt_options) { * @type {number} */ this.offsetY_ = goog.isDef(options.offsetY) ? options.offsetY : 0; + + /** + * @private + * @type {boolean} + */ + this.mutable_ = true; + }; @@ -162,3 +171,115 @@ ol.style.Text.prototype.getTextAlign = function() { ol.style.Text.prototype.getTextBaseline = function() { return this.textBaseline_; }; + + +/** + * @param {string|undefined} font Font. + * @api + */ +ol.style.Text.prototype.setFont = function(font) { + goog.asserts.assert(this.mutable_); + this.font_ = font; +}; + + +/** + * @param {number} offsetX Horizontal text offset. + */ +ol.style.Text.prototype.setOffsetX = function(offsetX) { + goog.asserts.assert(this.mutable_); + this.offsetX_ = offsetX; +}; + + +/** + * @param {number} offsetY Vertical text offset. + */ +ol.style.Text.prototype.setOffsetY = function(offsetY) { + goog.asserts.assert(this.mutable_); + this.offsetY_ = offsetY; +}; + + +/** + * @param {ol.style.Fill} fill Fill style. + * @api + */ +ol.style.Text.prototype.setFill = function(fill) { + goog.asserts.assert(this.mutable_); + this.fill_ = fill; +}; + + +/** + * @param {number|undefined} rotation Rotation. + * @api + */ +ol.style.Text.prototype.setRotation = function(rotation) { + goog.asserts.assert(this.mutable_); + this.rotation_ = rotation; +}; + + +/** + * @param {number|undefined} scale Scale. + * @api + */ +ol.style.Text.prototype.setScale = function(scale) { + goog.asserts.assert(this.mutable_); + this.scale_ = scale; +}; + + +/** + * @param {ol.style.Stroke} stroke Stroke style. + * @api + */ +ol.style.Text.prototype.setStroke = function(stroke) { + goog.asserts.assert(this.mutable_); + this.stroke_ = stroke; +}; + + +/** + * @param {string|undefined} text Text. + * @api + */ +ol.style.Text.prototype.setText = function(text) { + goog.asserts.assert(this.mutable_); + this.text_ = text; +}; + + +/** + * @param {string|undefined} textAlign Text align. + * @api + */ +ol.style.Text.prototype.setTextAlign = function(textAlign) { + goog.asserts.assert(this.mutable_); + this.textAlign_ = textAlign; +}; + + +/** + * @param {string|undefined} textBaseline Text baseline. + * @api + */ +ol.style.Text.prototype.setTextBaseline = function(textBaseline) { + goog.asserts.assert(this.mutable_); + this.textBaseline_ = textBaseline; +}; + + +/** + * @param {boolean} mutable Mutable. + */ +ol.style.Text.prototype.setMutable = function(mutable) { + if (!goog.isNull(this.stroke_)) { + this.stroke_.setMutable(mutable); + } + if (!goog.isNull(this.fill_)) { + this.fill_.setMutable(mutable); + } + this.mutable_ = mutable; +}; diff --git a/test/spec/ol/featureoverlay.test.js b/test/spec/ol/featureoverlay.test.js index 47aa06189a..71f8bfc2d0 100644 --- a/test/spec/ol/featureoverlay.test.js +++ b/test/spec/ol/featureoverlay.test.js @@ -16,11 +16,12 @@ describe('ol.FeatureOverlay', function() { expect(featureOverlay.getFeatures().getLength()).to.be(1); }); - it('takes a style', function() { + it('takes a style and makes it immutable', function() { var style = [new ol.style.Style()]; var featureOverlay = new ol.FeatureOverlay({ style: [new ol.style.Style()] }); + style[0].setMutable(false); expect(featureOverlay.getStyle()).to.eql(style); expect(featureOverlay.getStyleFunction()()).to.eql(style); }); diff --git a/test/spec/ol/style.test.js b/test/spec/ol/style.test.js index 17eae20b5e..25710157a4 100644 --- a/test/spec/ol/style.test.js +++ b/test/spec/ol/style.test.js @@ -1,5 +1,55 @@ goog.provide('ol.test.style.Style'); +describe('ol.style.Style', function() { + + describe('#setMutable', function() { + + it('recursively sets the mutable flag', function() { + var style = new ol.style.Style({ + fill: new ol.style.Fill({ + color: 'rgba(255, 255, 255, 0.6)' + }), + stroke: new ol.style.Stroke({ + color: '#319FD3', + width: 1 + }), + text: new ol.style.Text({ + font: '12px Calibri,sans-serif', + fill: new ol.style.Fill({ + color: '#000' + }), + stroke: new ol.style.Stroke({ + color: '#fff', + width: 3 + }) + }) + }); + + expect(function() { + style.setZIndex(1); + }).to.not.throwException(); + + expect(style.mutable_).to.be(true); + expect(style.getFill().mutable_).to.be(true); + expect(style.getStroke().mutable_).to.be(true); + expect(style.getText().mutable_).to.be(true); + expect(style.getText().getStroke().mutable_).to.be(true); + + style.setMutable(false); + + expect(function() { + style.setZIndex(); + }).to.throwException(); + + expect(style.mutable_).to.be(false); + expect(style.getFill().mutable_).to.be(false); + expect(style.getStroke().mutable_).to.be(false); + expect(style.getText().mutable_).to.be(false); + expect(style.getText().getStroke().mutable_).to.be(false); + }); + }); +}); + describe('ol.style.createStyleFunction()', function() { var style = new ol.style.Style(); @@ -27,6 +77,41 @@ describe('ol.style.createStyleFunction()', function() { }).to.throwException(); }); + it('makes styles immutable', function() { + var style = new ol.style.Style({ + fill: new ol.style.Fill({ + color: 'rgba(255, 255, 255, 0.6)' + }), + stroke: new ol.style.Stroke({ + color: '#319FD3', + width: 1 + }), + text: new ol.style.Text({ + font: '12px Calibri,sans-serif', + fill: new ol.style.Fill({ + color: '#000' + }), + stroke: new ol.style.Stroke({ + color: '#fff', + width: 3 + }) + }) + }); + + expect(function() { + style.getFill().setColor('white'); + }).to.not.throwException(); + + ol.style.createStyleFunction(style); + + expect(function() { + style.getFill().setColor('black'); + }).to.throwException(); + + }); }); +goog.require('ol.style.Fill'); +goog.require('ol.style.Stroke'); goog.require('ol.style.Style'); +goog.require('ol.style.Text'); From 13d84e75ad857760f93d87236c1d0f852d813113 Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Wed, 3 Sep 2014 18:31:01 -0600 Subject: [PATCH 2/6] Additional documentation --- src/ol/style/style.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ol/style/style.js b/src/ol/style/style.js index 527ca0d3d4..980ecbd9dd 100644 --- a/src/ol/style/style.js +++ b/src/ol/style/style.js @@ -12,7 +12,9 @@ goog.require('ol.style.Stroke'); /** * @classdesc - * Base class for vector feature rendering styles. + * Container for vector feature rendering styles. Node that styles are only + * mutable as long as they are not assigned to layers, feature overlays or + * features using the respective `setStyle()` methods. * * @constructor * @param {olx.style.StyleOptions=} opt_options Style options. From 0c36d7606b8d1263a9ebb8eb32514a38d947554a Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Thu, 4 Sep 2014 11:47:32 -0600 Subject: [PATCH 3/6] No need to have a mutable_ flag Instead, educate users to call setStyle. --- src/ol/style/circlestyle.js | 15 ------ src/ol/style/fillstyle.js | 21 ++------ src/ol/style/imagestyle.js | 36 ++++++------- src/ol/style/strokestyle.js | 41 +++++++-------- src/ol/style/style.js | 36 ++----------- src/ol/style/textstyle.js | 63 +++++++++++----------- test/spec/ol/featureoverlay.test.js | 3 +- test/spec/ol/style.test.js | 82 ++--------------------------- 8 files changed, 76 insertions(+), 221 deletions(-) diff --git a/src/ol/style/circlestyle.js b/src/ol/style/circlestyle.js index e531716ec6..7f9c268541 100644 --- a/src/ol/style/circlestyle.js +++ b/src/ol/style/circlestyle.js @@ -172,21 +172,6 @@ ol.style.Circle.prototype.getStroke = function() { }; -/** - * @protected - * @param {boolean} mutable Mutable. - */ -ol.style.Circle.prototype.setMutable = function(mutable) { - if (!goog.isNull(this.stroke_)) { - this.stroke_.setMutable(mutable); - } - if (!goog.isNull(this.fill_)) { - this.fill_.setMutable(mutable); - } - goog.base(this, 'setMutable', mutable); -}; - - /** * @inheritDoc */ diff --git a/src/ol/style/fillstyle.js b/src/ol/style/fillstyle.js index 6b566deb96..f79e230b52 100644 --- a/src/ol/style/fillstyle.js +++ b/src/ol/style/fillstyle.js @@ -1,7 +1,5 @@ goog.provide('ol.style.Fill'); -goog.require('goog.asserts'); - /** @@ -21,13 +19,6 @@ ol.style.Fill = function(opt_options) { * @type {ol.Color|string} */ this.color_ = goog.isDef(options.color) ? options.color : null; - - /** - * @private - * @type {boolean} - */ - this.mutable_ = true; - }; @@ -41,18 +32,12 @@ ol.style.Fill.prototype.getColor = function() { /** + * Set the color. Use `setStyle()` on the feature, layer or feature overlay + * for changes to take effect. + * * @param {ol.Color|string} color Color. * @api */ ol.style.Fill.prototype.setColor = function(color) { - goog.asserts.assert(this.mutable_); this.color_ = color; }; - - -/** - * @param {boolean} mutable Mutable. - */ -ol.style.Fill.prototype.setMutable = function(mutable) { - this.mutable_ = mutable; -}; diff --git a/src/ol/style/imagestyle.js b/src/ol/style/imagestyle.js index e4db519d23..089bc9c447 100644 --- a/src/ol/style/imagestyle.js +++ b/src/ol/style/imagestyle.js @@ -1,8 +1,6 @@ goog.provide('ol.style.Image'); goog.provide('ol.style.ImageState'); -goog.require('goog.asserts'); - /** * @enum {number} @@ -65,12 +63,6 @@ ol.style.Image = function(options) { */ this.snapToPixel_ = options.snapToPixel; - /** - * @private - * @type {boolean} - */ - this.mutable_ = true; - }; @@ -159,60 +151,62 @@ ol.style.Image.prototype.getSize = goog.abstractMethod; /** + * Set the zIndex. Use `setStyle()` on the feature, layer or feature overlay + * for changes to take effect. + * * @param {number} opacity Opacity. */ ol.style.Image.prototype.setOpacity = function(opacity) { - goog.asserts.assert(this.mutable_); this.opacity_ = opacity; }; /** + * Set whether to rotate the style with the view. Use `setStyle()` on the + * feature, layer or feature overlay for changes to take effect. + * * @param {boolean} rotateWithView Rotate with map. */ ol.style.Image.prototype.setRotateWithView = function(rotateWithView) { - goog.asserts.assert(this.mutable_); this.rotateWithView_ = rotateWithView; }; /** + * Set the rotation. Use `setStyle()` on the feature, layer or feature overlay + * for changes to take effect. + * * @param {number} rotation Rotation. * @api */ ol.style.Image.prototype.setRotation = function(rotation) { - goog.asserts.assert(this.mutable_); this.rotation_ = rotation; }; /** + * Set the scale. Use `setStyle()` on the feature, layer or feature overlay + * for changes to take effect. + * * @param {number} scale Scale. * @api */ ol.style.Image.prototype.setScale = function(scale) { - goog.asserts.assert(this.mutable_); this.scale_ = scale; }; /** + * Set whether to snap the image to the closest pixel. Use `setStyle()` on the + * feature, layer or feature overlay for changes to take effect. + * * @param {boolean} snapToPixel Snap to pixel? */ ol.style.Image.prototype.setSnapToPixel = function(snapToPixel) { - goog.asserts.assert(this.mutable_); this.snapToPixel_ = snapToPixel; }; -/** - * @param {boolean} mutable Mutable. - */ -ol.style.Image.prototype.setMutable = function(mutable) { - this.mutable_ = mutable; -}; - - /** * @param {function(this: T, goog.events.Event)} listener Listener function. * @param {T} thisArg Value to use as `this` when executing `listener`. diff --git a/src/ol/style/strokestyle.js b/src/ol/style/strokestyle.js index 6e487f974e..4e687d3d15 100644 --- a/src/ol/style/strokestyle.js +++ b/src/ol/style/strokestyle.js @@ -1,7 +1,5 @@ goog.provide('ol.style.Stroke'); -goog.require('goog.asserts'); - /** @@ -54,13 +52,6 @@ ol.style.Stroke = function(opt_options) { * @type {number|undefined} */ this.width_ = options.width; - - /** - * @private - * @type {boolean} - */ - this.mutable_ = true; - }; @@ -119,68 +110,72 @@ ol.style.Stroke.prototype.getWidth = function() { /** + * Set the color. Use `setStyle()` on the feature, layer or feature overlay + * for changes to take effect. + * * @param {ol.Color|string} color Color. * @api */ ol.style.Stroke.prototype.setColor = function(color) { - goog.asserts.assert(this.mutable_); this.color_ = color; }; /** + * Set the line cap. Use `setStyle()` on the feature, layer or feature overlay + * for changes to take effect. + * * @param {string|undefined} lineCap Line cap. * @api */ ol.style.Stroke.prototype.setLineCap = function(lineCap) { - goog.asserts.assert(this.mutable_); this.lineCap_ = lineCap; }; /** + * Set the line dash. Use `setStyle()` on the feature, layer or feature overlay + * for changes to take effect. + * * @param {Array.} lineDash Line dash. * @api */ ol.style.Stroke.prototype.setLineDash = function(lineDash) { - goog.asserts.assert(this.mutable_); this.lineDash_ = lineDash; }; /** + * Set the line join. Use `setStyle()` on the feature, layer or feature overlay + * for changes to take effect. + * * @param {string|undefined} lineJoin Line join. * @api */ ol.style.Stroke.prototype.setLineJoin = function(lineJoin) { - goog.asserts.assert(this.mutable_); this.lineJoin_ = lineJoin; }; /** + * Set the miter limit. Use `setStyle()` on the feature, layer or feature + * overlay for changes to take effect. + * * @param {number|undefined} miterLimit Miter limit. * @api */ ol.style.Stroke.prototype.setMiterLimit = function(miterLimit) { - goog.asserts.assert(this.mutable_); this.miterLimit_ = miterLimit; }; /** + * Set the width. Use `setStyle()` on the feature, layer or feature overlay + * for changes to take effect. + * * @param {number|undefined} width Width. * @api */ ol.style.Stroke.prototype.setWidth = function(width) { - goog.asserts.assert(this.mutable_); this.width_ = width; }; - - -/** - * @param {boolean} mutable Mutable. - */ -ol.style.Stroke.prototype.setMutable = function(mutable) { - this.mutable_ = mutable; -}; diff --git a/src/ol/style/style.js b/src/ol/style/style.js index 980ecbd9dd..cf4c2543c0 100644 --- a/src/ol/style/style.js +++ b/src/ol/style/style.js @@ -12,9 +12,7 @@ goog.require('ol.style.Stroke'); /** * @classdesc - * Container for vector feature rendering styles. Node that styles are only - * mutable as long as they are not assigned to layers, feature overlays or - * features using the respective `setStyle()` methods. + * Container for vector feature rendering styles. * * @constructor * @param {olx.style.StyleOptions=} opt_options Style options. @@ -54,11 +52,6 @@ ol.style.Style = function(opt_options) { */ this.zIndex_ = options.zIndex; - /** - * @private - * @type {boolean} - */ - this.mutable_ = true; }; @@ -108,35 +101,17 @@ ol.style.Style.prototype.getZIndex = function() { /** + * Set the zIndex. Use `setStyle()` on the feature, layer or feature overlay + * for changes to take effect. + * * @param {number|undefined} zIndex ZIndex. * @api */ ol.style.Style.prototype.setZIndex = function(zIndex) { - goog.asserts.assert(this.mutable_); this.zIndex_ = zIndex; }; -/** - * @param {boolean} mutable Mutable. - */ -ol.style.Style.prototype.setMutable = function(mutable) { - if (!goog.isNull(this.fill_)) { - this.fill_.setMutable(mutable); - } - if (!goog.isNull(this.image_)) { - this.image_.setMutable(mutable); - } - if (!goog.isNull(this.stroke_)) { - this.stroke_.setMutable(mutable); - } - if (!goog.isNull(this.text_)) { - this.text_.setMutable(mutable); - } - this.mutable_ = mutable; -}; - - /** * A function that takes an {@link ol.Feature} and a `{number}` representing * the view's resolution. The function should return an array of @@ -175,9 +150,6 @@ ol.style.createStyleFunction = function(obj) { goog.asserts.assertInstanceof(obj, ol.style.Style); styles = [obj]; } - for (var i = styles.length - 1; i >= 0; --i) { - styles[i].setMutable(false); - } styleFunction = goog.functions.constant(styles); } return styleFunction; diff --git a/src/ol/style/textstyle.js b/src/ol/style/textstyle.js index e2b8d6474d..84bc90b283 100644 --- a/src/ol/style/textstyle.js +++ b/src/ol/style/textstyle.js @@ -1,7 +1,5 @@ goog.provide('ol.style.Text'); -goog.require('goog.asserts'); - /** @@ -75,13 +73,6 @@ ol.style.Text = function(opt_options) { * @type {number} */ this.offsetY_ = goog.isDef(options.offsetY) ? options.offsetY : 0; - - /** - * @private - * @type {boolean} - */ - this.mutable_ = true; - }; @@ -174,112 +165,118 @@ ol.style.Text.prototype.getTextBaseline = function() { /** + * Set the font. Use `setStyle()` on the feature, layer or feature overlay + * for changes to take effect. + * * @param {string|undefined} font Font. * @api */ ol.style.Text.prototype.setFont = function(font) { - goog.asserts.assert(this.mutable_); this.font_ = font; }; /** + * Set the x offset. Use `setStyle()` on the feature, layer or feature overlay + * for changes to take effect. + * * @param {number} offsetX Horizontal text offset. */ ol.style.Text.prototype.setOffsetX = function(offsetX) { - goog.asserts.assert(this.mutable_); this.offsetX_ = offsetX; }; /** + * Set the y offset. Use `setStyle()` on the feature, layer or feature overlay + * for changes to take effect. + * * @param {number} offsetY Vertical text offset. */ ol.style.Text.prototype.setOffsetY = function(offsetY) { - goog.asserts.assert(this.mutable_); this.offsetY_ = offsetY; }; /** + * Set the fill. Use `setStyle()` on the feature, layer or feature overlay + * for changes to take effect. + * * @param {ol.style.Fill} fill Fill style. * @api */ ol.style.Text.prototype.setFill = function(fill) { - goog.asserts.assert(this.mutable_); this.fill_ = fill; }; /** + * Set the rotation. Use `setStyle()` on the feature, layer or feature overlay + * for changes to take effect. + * * @param {number|undefined} rotation Rotation. * @api */ ol.style.Text.prototype.setRotation = function(rotation) { - goog.asserts.assert(this.mutable_); this.rotation_ = rotation; }; /** + * Set the scale. Use `setStyle()` on the feature, layer or feature overlay + * for changes to take effect. + * * @param {number|undefined} scale Scale. * @api */ ol.style.Text.prototype.setScale = function(scale) { - goog.asserts.assert(this.mutable_); this.scale_ = scale; }; /** + * Set the stroke. Use `setStyle()` on the feature, layer or feature overlay + * for changes to take effect. + * * @param {ol.style.Stroke} stroke Stroke style. * @api */ ol.style.Text.prototype.setStroke = function(stroke) { - goog.asserts.assert(this.mutable_); this.stroke_ = stroke; }; /** + * Set the text. Use `setStyle()` on the feature, layer or feature overlay + * for changes to take effect. + * * @param {string|undefined} text Text. * @api */ ol.style.Text.prototype.setText = function(text) { - goog.asserts.assert(this.mutable_); this.text_ = text; }; /** + * Set the text alignment. Use `setStyle()` on the feature, layer or feature + * overlay for changes to take effect. + * * @param {string|undefined} textAlign Text align. * @api */ ol.style.Text.prototype.setTextAlign = function(textAlign) { - goog.asserts.assert(this.mutable_); this.textAlign_ = textAlign; }; /** + * Set the text baseline. Use `setStyle()` on the feature, layer or feature + * overlay for changes to take effect. + * * @param {string|undefined} textBaseline Text baseline. * @api */ ol.style.Text.prototype.setTextBaseline = function(textBaseline) { - goog.asserts.assert(this.mutable_); this.textBaseline_ = textBaseline; }; - - -/** - * @param {boolean} mutable Mutable. - */ -ol.style.Text.prototype.setMutable = function(mutable) { - if (!goog.isNull(this.stroke_)) { - this.stroke_.setMutable(mutable); - } - if (!goog.isNull(this.fill_)) { - this.fill_.setMutable(mutable); - } - this.mutable_ = mutable; -}; diff --git a/test/spec/ol/featureoverlay.test.js b/test/spec/ol/featureoverlay.test.js index 71f8bfc2d0..47aa06189a 100644 --- a/test/spec/ol/featureoverlay.test.js +++ b/test/spec/ol/featureoverlay.test.js @@ -16,12 +16,11 @@ describe('ol.FeatureOverlay', function() { expect(featureOverlay.getFeatures().getLength()).to.be(1); }); - it('takes a style and makes it immutable', function() { + it('takes a style', function() { var style = [new ol.style.Style()]; var featureOverlay = new ol.FeatureOverlay({ style: [new ol.style.Style()] }); - style[0].setMutable(false); expect(featureOverlay.getStyle()).to.eql(style); expect(featureOverlay.getStyleFunction()()).to.eql(style); }); diff --git a/test/spec/ol/style.test.js b/test/spec/ol/style.test.js index 25710157a4..8c64cb0497 100644 --- a/test/spec/ol/style.test.js +++ b/test/spec/ol/style.test.js @@ -2,50 +2,13 @@ goog.provide('ol.test.style.Style'); describe('ol.style.Style', function() { - describe('#setMutable', function() { + describe('#setZIndex', function() { - it('recursively sets the mutable flag', function() { - var style = new ol.style.Style({ - fill: new ol.style.Fill({ - color: 'rgba(255, 255, 255, 0.6)' - }), - stroke: new ol.style.Stroke({ - color: '#319FD3', - width: 1 - }), - text: new ol.style.Text({ - font: '12px Calibri,sans-serif', - fill: new ol.style.Fill({ - color: '#000' - }), - stroke: new ol.style.Stroke({ - color: '#fff', - width: 3 - }) - }) - }); + it('sets the zIndex', function() { + var style = new ol.style.Style(); - expect(function() { - style.setZIndex(1); - }).to.not.throwException(); - - expect(style.mutable_).to.be(true); - expect(style.getFill().mutable_).to.be(true); - expect(style.getStroke().mutable_).to.be(true); - expect(style.getText().mutable_).to.be(true); - expect(style.getText().getStroke().mutable_).to.be(true); - - style.setMutable(false); - - expect(function() { - style.setZIndex(); - }).to.throwException(); - - expect(style.mutable_).to.be(false); - expect(style.getFill().mutable_).to.be(false); - expect(style.getStroke().mutable_).to.be(false); - expect(style.getText().mutable_).to.be(false); - expect(style.getText().getStroke().mutable_).to.be(false); + style.setZIndex(0.7); + expect(style.getZIndex()).to.be(0.7); }); }); }); @@ -77,41 +40,6 @@ describe('ol.style.createStyleFunction()', function() { }).to.throwException(); }); - it('makes styles immutable', function() { - var style = new ol.style.Style({ - fill: new ol.style.Fill({ - color: 'rgba(255, 255, 255, 0.6)' - }), - stroke: new ol.style.Stroke({ - color: '#319FD3', - width: 1 - }), - text: new ol.style.Text({ - font: '12px Calibri,sans-serif', - fill: new ol.style.Fill({ - color: '#000' - }), - stroke: new ol.style.Stroke({ - color: '#fff', - width: 3 - }) - }) - }); - - expect(function() { - style.getFill().setColor('white'); - }).to.not.throwException(); - - ol.style.createStyleFunction(style); - - expect(function() { - style.getFill().setColor('black'); - }).to.throwException(); - - }); }); -goog.require('ol.style.Fill'); -goog.require('ol.style.Stroke'); goog.require('ol.style.Style'); -goog.require('ol.style.Text'); From 88c30795d3ed6ae20bd16dceb3b1fcf50110a135 Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Thu, 4 Sep 2014 13:20:25 -0600 Subject: [PATCH 4/6] Doc improvements --- src/ol/style/fillstyle.js | 4 ++-- src/ol/style/imagestyle.js | 22 ++++++++++---------- src/ol/style/strokestyle.js | 24 +++++++++++----------- src/ol/style/style.js | 4 ++-- src/ol/style/textstyle.js | 40 ++++++++++++++++++------------------- 5 files changed, 48 insertions(+), 46 deletions(-) diff --git a/src/ol/style/fillstyle.js b/src/ol/style/fillstyle.js index f79e230b52..1825110453 100644 --- a/src/ol/style/fillstyle.js +++ b/src/ol/style/fillstyle.js @@ -32,8 +32,8 @@ ol.style.Fill.prototype.getColor = function() { /** - * Set the color. Use `setStyle()` on the feature, layer or feature overlay - * for changes to take effect. + * Set the color. Call `setStyle()` or `dispatchChangeEvent()` on feature, layer + * or feature overlay for changes to take effect. * * @param {ol.Color|string} color Color. * @api diff --git a/src/ol/style/imagestyle.js b/src/ol/style/imagestyle.js index 089bc9c447..48b7eb22ba 100644 --- a/src/ol/style/imagestyle.js +++ b/src/ol/style/imagestyle.js @@ -151,8 +151,8 @@ ol.style.Image.prototype.getSize = goog.abstractMethod; /** - * Set the zIndex. Use `setStyle()` on the feature, layer or feature overlay - * for changes to take effect. + * Set the zIndex. Call `setStyle()` or `dispatchChangeEvent()` on feature, + * layer or feature overlay for changes to take effect. * * @param {number} opacity Opacity. */ @@ -162,8 +162,9 @@ ol.style.Image.prototype.setOpacity = function(opacity) { /** - * Set whether to rotate the style with the view. Use `setStyle()` on the - * feature, layer or feature overlay for changes to take effect. + * Set whether to rotate the style with the view. Call `setStyle()` or + * `dispatchChangeEvent()` on feature, layer or feature overlay for changes to + * take effect. * * @param {boolean} rotateWithView Rotate with map. */ @@ -173,8 +174,8 @@ ol.style.Image.prototype.setRotateWithView = function(rotateWithView) { /** - * Set the rotation. Use `setStyle()` on the feature, layer or feature overlay - * for changes to take effect. + * Set the rotation. Call `setStyle()` or `dispatchChangeEvent()` on feature, + * layer or feature overlay for changes to take effect. * * @param {number} rotation Rotation. * @api @@ -185,8 +186,8 @@ ol.style.Image.prototype.setRotation = function(rotation) { /** - * Set the scale. Use `setStyle()` on the feature, layer or feature overlay - * for changes to take effect. + * Set the scale. Call `setStyle()` or `dispatchChangeEvent()` on feature, layer + * or feature overlay for changes to take effect. * * @param {number} scale Scale. * @api @@ -197,8 +198,9 @@ ol.style.Image.prototype.setScale = function(scale) { /** - * Set whether to snap the image to the closest pixel. Use `setStyle()` on the - * feature, layer or feature overlay for changes to take effect. + * Set whether to snap the image to the closest pixel. Call `setStyle()` or + * `dispatchChangeEvent()` on feature, layer or feature overlay for changes to + * take effect. * * @param {boolean} snapToPixel Snap to pixel? */ diff --git a/src/ol/style/strokestyle.js b/src/ol/style/strokestyle.js index 4e687d3d15..3740f77e5b 100644 --- a/src/ol/style/strokestyle.js +++ b/src/ol/style/strokestyle.js @@ -110,8 +110,8 @@ ol.style.Stroke.prototype.getWidth = function() { /** - * Set the color. Use `setStyle()` on the feature, layer or feature overlay - * for changes to take effect. + * Set the color. Call `setStyle()` or `dispatchChangeEvent()` on feature, layer + * or feature overlay for changes to take effect. * * @param {ol.Color|string} color Color. * @api @@ -122,8 +122,8 @@ ol.style.Stroke.prototype.setColor = function(color) { /** - * Set the line cap. Use `setStyle()` on the feature, layer or feature overlay - * for changes to take effect. + * Set the line cap. Call `setStyle()` or `dispatchChangeEvent()` on feature, + * layer or feature overlay for changes to take effect. * * @param {string|undefined} lineCap Line cap. * @api @@ -134,8 +134,8 @@ ol.style.Stroke.prototype.setLineCap = function(lineCap) { /** - * Set the line dash. Use `setStyle()` on the feature, layer or feature overlay - * for changes to take effect. + * Set the line dash. Call `setStyle()` or `dispatchChangeEvent()` on feature, + * layer or feature overlay for changes to take effect. * * @param {Array.} lineDash Line dash. * @api @@ -146,8 +146,8 @@ ol.style.Stroke.prototype.setLineDash = function(lineDash) { /** - * Set the line join. Use `setStyle()` on the feature, layer or feature overlay - * for changes to take effect. + * Set the line join. Call `setStyle()` or `dispatchChangeEvent()` on feature, + * layer or feature overlay for changes to take effect. * * @param {string|undefined} lineJoin Line join. * @api @@ -158,8 +158,8 @@ ol.style.Stroke.prototype.setLineJoin = function(lineJoin) { /** - * Set the miter limit. Use `setStyle()` on the feature, layer or feature - * overlay for changes to take effect. + * Set the miter limit. Call `setStyle()` or `dispatchChangeEvent()` on feature, + * layer or feature overlay for changes to take effect. * * @param {number|undefined} miterLimit Miter limit. * @api @@ -170,8 +170,8 @@ ol.style.Stroke.prototype.setMiterLimit = function(miterLimit) { /** - * Set the width. Use `setStyle()` on the feature, layer or feature overlay - * for changes to take effect. + * Set the width. Call `setStyle()` or `dispatchChangeEvent()` on feature, layer + * or feature overlay for changes to take effect. * * @param {number|undefined} width Width. * @api diff --git a/src/ol/style/style.js b/src/ol/style/style.js index cf4c2543c0..40cadb6f33 100644 --- a/src/ol/style/style.js +++ b/src/ol/style/style.js @@ -101,8 +101,8 @@ ol.style.Style.prototype.getZIndex = function() { /** - * Set the zIndex. Use `setStyle()` on the feature, layer or feature overlay - * for changes to take effect. + * Set the zIndex. Call `setStyle()` or `dispatchChangeEvent()` on feature, + * layer or feature overlay for changes to take effect. * * @param {number|undefined} zIndex ZIndex. * @api diff --git a/src/ol/style/textstyle.js b/src/ol/style/textstyle.js index 84bc90b283..54adbdb001 100644 --- a/src/ol/style/textstyle.js +++ b/src/ol/style/textstyle.js @@ -165,8 +165,8 @@ ol.style.Text.prototype.getTextBaseline = function() { /** - * Set the font. Use `setStyle()` on the feature, layer or feature overlay - * for changes to take effect. + * Set the font. Call `setStyle()` or `dispatchChangeEvent()` on feature, layer + * or feature overlay for changes to take effect. * * @param {string|undefined} font Font. * @api @@ -177,8 +177,8 @@ ol.style.Text.prototype.setFont = function(font) { /** - * Set the x offset. Use `setStyle()` on the feature, layer or feature overlay - * for changes to take effect. + * Set the x offset. Call `setStyle()` or `dispatchChangeEvent()` on feature, + * layer or feature overlay for changes to take effect. * * @param {number} offsetX Horizontal text offset. */ @@ -188,8 +188,8 @@ ol.style.Text.prototype.setOffsetX = function(offsetX) { /** - * Set the y offset. Use `setStyle()` on the feature, layer or feature overlay - * for changes to take effect. + * Set the y offset. Call `setStyle()` or `dispatchChangeEvent()` on feature, + * layer or feature overlay for changes to take effect. * * @param {number} offsetY Vertical text offset. */ @@ -199,8 +199,8 @@ ol.style.Text.prototype.setOffsetY = function(offsetY) { /** - * Set the fill. Use `setStyle()` on the feature, layer or feature overlay - * for changes to take effect. + * Set the fill. Call `setStyle()` or `dispatchChangeEvent()` on feature, layer + * or feature overlay for changes to take effect. * * @param {ol.style.Fill} fill Fill style. * @api @@ -211,8 +211,8 @@ ol.style.Text.prototype.setFill = function(fill) { /** - * Set the rotation. Use `setStyle()` on the feature, layer or feature overlay - * for changes to take effect. + * Set the rotation. Call `setStyle()` or `dispatchChangeEvent()` on feature, + * layer or feature overlay for changes to take effect. * * @param {number|undefined} rotation Rotation. * @api @@ -223,8 +223,8 @@ ol.style.Text.prototype.setRotation = function(rotation) { /** - * Set the scale. Use `setStyle()` on the feature, layer or feature overlay - * for changes to take effect. + * Set the scale. Call `setStyle()` or `dispatchChangeEvent()` on feature, layer + * or feature overlay for changes to take effect. * * @param {number|undefined} scale Scale. * @api @@ -235,8 +235,8 @@ ol.style.Text.prototype.setScale = function(scale) { /** - * Set the stroke. Use `setStyle()` on the feature, layer or feature overlay - * for changes to take effect. + * Set the stroke. Call `setStyle()` or `dispatchChangeEvent()` on feature, + * layer or feature overlay for changes to take effect. * * @param {ol.style.Stroke} stroke Stroke style. * @api @@ -247,8 +247,8 @@ ol.style.Text.prototype.setStroke = function(stroke) { /** - * Set the text. Use `setStyle()` on the feature, layer or feature overlay - * for changes to take effect. + * Set the text. Call `setStyle()` or `dispatchChangeEvent()` on feature, layer + * or feature overlay for changes to take effect. * * @param {string|undefined} text Text. * @api @@ -259,8 +259,8 @@ ol.style.Text.prototype.setText = function(text) { /** - * Set the text alignment. Use `setStyle()` on the feature, layer or feature - * overlay for changes to take effect. + * Set the text alignment. Call `setStyle()` or `dispatchChangeEvent()` on + * feature, layer or feature overlay for changes to take effect. * * @param {string|undefined} textAlign Text align. * @api @@ -271,8 +271,8 @@ ol.style.Text.prototype.setTextAlign = function(textAlign) { /** - * Set the text baseline. Use `setStyle()` on the feature, layer or feature - * overlay for changes to take effect. + * Set the text baseline. Call `setStyle()` or `dispatchChangeEvent()` on + * feature, layer or feature overlay for changes to take effect. * * @param {string|undefined} textBaseline Text baseline. * @api From 0e146396338b4f71ce506e7c5a6a67e76960942d Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Thu, 4 Sep 2014 21:01:50 -0600 Subject: [PATCH 5/6] Update docs for changes proposed in #2684 --- src/ol/style/fillstyle.js | 6 ++-- src/ol/style/imagestyle.js | 32 ++++++++++++-------- src/ol/style/strokestyle.js | 36 ++++++++++++++-------- src/ol/style/style.js | 6 ++-- src/ol/style/textstyle.js | 60 ++++++++++++++++++++++++------------- 5 files changed, 92 insertions(+), 48 deletions(-) diff --git a/src/ol/style/fillstyle.js b/src/ol/style/fillstyle.js index 1825110453..ea17853918 100644 --- a/src/ol/style/fillstyle.js +++ b/src/ol/style/fillstyle.js @@ -32,8 +32,10 @@ ol.style.Fill.prototype.getColor = function() { /** - * Set the color. Call `setStyle()` or `dispatchChangeEvent()` on feature, layer - * or feature overlay for changes to take effect. + * Set the color. When this style is used as a layer, feature or ImageVector + * source style, call `changed()` on the layer, feature or ImageVector source + * for the change to take effect. When used as a FeatureOverlay style, call + * `render()` on the map. * * @param {ol.Color|string} color Color. * @api diff --git a/src/ol/style/imagestyle.js b/src/ol/style/imagestyle.js index 48b7eb22ba..443f5f92ec 100644 --- a/src/ol/style/imagestyle.js +++ b/src/ol/style/imagestyle.js @@ -151,8 +151,10 @@ ol.style.Image.prototype.getSize = goog.abstractMethod; /** - * Set the zIndex. Call `setStyle()` or `dispatchChangeEvent()` on feature, - * layer or feature overlay for changes to take effect. + * Set the opacity. When this style is used as a layer, feature or ImageVector + * source style, call `changed()` on the layer, feature or ImageVector source + * for the change to take effect. When used as a FeatureOverlay style, call + * `render()` on the map. * * @param {number} opacity Opacity. */ @@ -162,9 +164,10 @@ ol.style.Image.prototype.setOpacity = function(opacity) { /** - * Set whether to rotate the style with the view. Call `setStyle()` or - * `dispatchChangeEvent()` on feature, layer or feature overlay for changes to - * take effect. + * Set whether to rotate the style with the view. When this style is used as a + * layer, feature or ImageVector source style, call `changed()` on the layer, + * feature or ImageVector source for the change to take effect. When used as a + * FeatureOverlay style, call `render()` on the map. * * @param {boolean} rotateWithView Rotate with map. */ @@ -174,8 +177,10 @@ ol.style.Image.prototype.setRotateWithView = function(rotateWithView) { /** - * Set the rotation. Call `setStyle()` or `dispatchChangeEvent()` on feature, - * layer or feature overlay for changes to take effect. + * Set the rotation. When this style is used as a layer, feature or ImageVector + * source style, call `changed()` on the layer, feature or ImageVector source + * for the change to take effect. When used as a FeatureOverlay style, call + * `render()` on the map. * * @param {number} rotation Rotation. * @api @@ -186,8 +191,10 @@ ol.style.Image.prototype.setRotation = function(rotation) { /** - * Set the scale. Call `setStyle()` or `dispatchChangeEvent()` on feature, layer - * or feature overlay for changes to take effect. + * Set the scale. When this style is used as a layer, feature or ImageVector + * source style, call `changed()` on the layer, feature or ImageVector source + * for the change to take effect. When used as a FeatureOverlay style, call + * `render()` on the map. * * @param {number} scale Scale. * @api @@ -198,9 +205,10 @@ ol.style.Image.prototype.setScale = function(scale) { /** - * Set whether to snap the image to the closest pixel. Call `setStyle()` or - * `dispatchChangeEvent()` on feature, layer or feature overlay for changes to - * take effect. + * Set whether to snap the image to the closest pixel. When this style is used + * as a layer, feature or ImageVector source style, call `changed()` on the + * layer, feature or ImageVector source for the change to take effect. When used + * as a FeatureOverlay style, call `render()` on the map. * * @param {boolean} snapToPixel Snap to pixel? */ diff --git a/src/ol/style/strokestyle.js b/src/ol/style/strokestyle.js index 3740f77e5b..eeb58776ba 100644 --- a/src/ol/style/strokestyle.js +++ b/src/ol/style/strokestyle.js @@ -110,8 +110,10 @@ ol.style.Stroke.prototype.getWidth = function() { /** - * Set the color. Call `setStyle()` or `dispatchChangeEvent()` on feature, layer - * or feature overlay for changes to take effect. + * Set the color. When this style is used as a layer, feature or ImageVector + * source style, call `changed()` on the layer, feature or ImageVector source + * for the change to take effect. When used as a FeatureOverlay style, call + * `render()` on the map. * * @param {ol.Color|string} color Color. * @api @@ -122,8 +124,10 @@ ol.style.Stroke.prototype.setColor = function(color) { /** - * Set the line cap. Call `setStyle()` or `dispatchChangeEvent()` on feature, - * layer or feature overlay for changes to take effect. + * Set the line cap. When this style is used as a layer, feature or ImageVector + * source style, call `changed()` on the layer, feature or ImageVector source + * for the change to take effect. When used as a FeatureOverlay style, call + * `render()` on the map. * * @param {string|undefined} lineCap Line cap. * @api @@ -134,8 +138,10 @@ ol.style.Stroke.prototype.setLineCap = function(lineCap) { /** - * Set the line dash. Call `setStyle()` or `dispatchChangeEvent()` on feature, - * layer or feature overlay for changes to take effect. + * Set the line dash. When this style is used as a layer, feature or ImageVector + * source style, call `changed()` on the layer, feature or ImageVector source + * for the change to take effect. When used as a FeatureOverlay style, call + * `render()` on the map. * * @param {Array.} lineDash Line dash. * @api @@ -146,8 +152,10 @@ ol.style.Stroke.prototype.setLineDash = function(lineDash) { /** - * Set the line join. Call `setStyle()` or `dispatchChangeEvent()` on feature, - * layer or feature overlay for changes to take effect. + * Set the line join. When this style is used as a layer, feature or ImageVector + * source style, call `changed()` on the layer, feature or ImageVector source + * for the change to take effect. When used as a FeatureOverlay style, call + * `render()` on the map. * * @param {string|undefined} lineJoin Line join. * @api @@ -158,8 +166,10 @@ ol.style.Stroke.prototype.setLineJoin = function(lineJoin) { /** - * Set the miter limit. Call `setStyle()` or `dispatchChangeEvent()` on feature, - * layer or feature overlay for changes to take effect. + * Set the miter limit. When this style is used as a layer, feature or + * ImageVector source style, call `changed()` on the layer, feature or + * ImageVector source for the change to take effect. When used as a + * FeatureOverlay style, call `render()` on the map. * * @param {number|undefined} miterLimit Miter limit. * @api @@ -170,8 +180,10 @@ ol.style.Stroke.prototype.setMiterLimit = function(miterLimit) { /** - * Set the width. Call `setStyle()` or `dispatchChangeEvent()` on feature, layer - * or feature overlay for changes to take effect. + * Set the width. When this style is used as a layer, feature or ImageVector + * source style, call `changed()` on the layer, feature or ImageVector source + * for the change to take effect. When used as a FeatureOverlay style, call + * `render()` on the map. * * @param {number|undefined} width Width. * @api diff --git a/src/ol/style/style.js b/src/ol/style/style.js index 40cadb6f33..653e2818b8 100644 --- a/src/ol/style/style.js +++ b/src/ol/style/style.js @@ -101,8 +101,10 @@ ol.style.Style.prototype.getZIndex = function() { /** - * Set the zIndex. Call `setStyle()` or `dispatchChangeEvent()` on feature, - * layer or feature overlay for changes to take effect. + * Set the zIndex. When this style is used as a layer, feature or ImageVector + * source style, call `changed()` on the layer, feature or ImageVector source + * for the change to take effect. When used as a FeatureOverlay style, call + * `render()` on the map. * * @param {number|undefined} zIndex ZIndex. * @api diff --git a/src/ol/style/textstyle.js b/src/ol/style/textstyle.js index 54adbdb001..a95fcc2291 100644 --- a/src/ol/style/textstyle.js +++ b/src/ol/style/textstyle.js @@ -165,8 +165,10 @@ ol.style.Text.prototype.getTextBaseline = function() { /** - * Set the font. Call `setStyle()` or `dispatchChangeEvent()` on feature, layer - * or feature overlay for changes to take effect. + * Set the font. When this style is used as a layer, feature or ImageVector + * source style, call `changed()` on the layer, feature or ImageVector source + * for the change to take effect. When used as a FeatureOverlay style, call + * `render()` on the map. * * @param {string|undefined} font Font. * @api @@ -177,8 +179,10 @@ ol.style.Text.prototype.setFont = function(font) { /** - * Set the x offset. Call `setStyle()` or `dispatchChangeEvent()` on feature, - * layer or feature overlay for changes to take effect. + * Set the x offset. When this style is used as a layer, feature or ImageVector + * source style, call `changed()` on the layer, feature or ImageVector source + * for the change to take effect. When used as a FeatureOverlay style, call + * `render()` on the map. * * @param {number} offsetX Horizontal text offset. */ @@ -188,8 +192,10 @@ ol.style.Text.prototype.setOffsetX = function(offsetX) { /** - * Set the y offset. Call `setStyle()` or `dispatchChangeEvent()` on feature, - * layer or feature overlay for changes to take effect. + * Set the y offset. When this style is used as a layer, feature or ImageVector + * source style, call `changed()` on the layer, feature or ImageVector source + * for the change to take effect. When used as a FeatureOverlay style, call + * `render()` on the map. * * @param {number} offsetY Vertical text offset. */ @@ -199,8 +205,10 @@ ol.style.Text.prototype.setOffsetY = function(offsetY) { /** - * Set the fill. Call `setStyle()` or `dispatchChangeEvent()` on feature, layer - * or feature overlay for changes to take effect. + * Set the fill. When this style is used as a layer, feature or ImageVector + * source style, call `changed()` on the layer, feature or ImageVector source + * for the change to take effect. When used as a FeatureOverlay style, call + * `render()` on the map. * * @param {ol.style.Fill} fill Fill style. * @api @@ -211,8 +219,10 @@ ol.style.Text.prototype.setFill = function(fill) { /** - * Set the rotation. Call `setStyle()` or `dispatchChangeEvent()` on feature, - * layer or feature overlay for changes to take effect. + * Set the rotation. When this style is used as a layer, feature or ImageVector + * source style, call `changed()` on the layer, feature or ImageVector source + * for the change to take effect. When used as a FeatureOverlay style, call + * `render()` on the map. * * @param {number|undefined} rotation Rotation. * @api @@ -223,8 +233,10 @@ ol.style.Text.prototype.setRotation = function(rotation) { /** - * Set the scale. Call `setStyle()` or `dispatchChangeEvent()` on feature, layer - * or feature overlay for changes to take effect. + * Set the scale. When this style is used as a layer, feature or ImageVector + * source style, call `changed()` on the layer, feature or ImageVector source + * for the change to take effect. When used as a FeatureOverlay style, call + * `render()` on the map. * * @param {number|undefined} scale Scale. * @api @@ -235,8 +247,10 @@ ol.style.Text.prototype.setScale = function(scale) { /** - * Set the stroke. Call `setStyle()` or `dispatchChangeEvent()` on feature, - * layer or feature overlay for changes to take effect. + * Set the stroke. When this style is used as a layer, feature or ImageVector + * source style, call `changed()` on the layer, feature or ImageVector source + * for the change to take effect. When used as a FeatureOverlay style, call + * `render()` on the map. * * @param {ol.style.Stroke} stroke Stroke style. * @api @@ -247,8 +261,10 @@ ol.style.Text.prototype.setStroke = function(stroke) { /** - * Set the text. Call `setStyle()` or `dispatchChangeEvent()` on feature, layer - * or feature overlay for changes to take effect. + * Set the text. When this style is used as a layer, feature or ImageVector + * source style, call `changed()` on the layer, feature or ImageVector source + * for the change to take effect. When used as a FeatureOverlay style, call + * `render()` on the map. * * @param {string|undefined} text Text. * @api @@ -259,8 +275,10 @@ ol.style.Text.prototype.setText = function(text) { /** - * Set the text alignment. Call `setStyle()` or `dispatchChangeEvent()` on - * feature, layer or feature overlay for changes to take effect. + * Set the text alignment. When this style is used as a layer, feature or + * ImageVector source style, call `changed()` on the layer, feature or + * ImageVector source for the change to take effect. When used as a + * FeatureOverlay style, call `render()` on the map. * * @param {string|undefined} textAlign Text align. * @api @@ -271,8 +289,10 @@ ol.style.Text.prototype.setTextAlign = function(textAlign) { /** - * Set the text baseline. Call `setStyle()` or `dispatchChangeEvent()` on - * feature, layer or feature overlay for changes to take effect. + * Set the text baseline. When this style is used as a layer, feature or + * ImageVector source style, call `changed()` on the layer, feature or + * ImageVector source for the change to take effect. When used as a + * FeatureOverlay style, call `render()` on the map. * * @param {string|undefined} textBaseline Text baseline. * @api From 267a9504356d48a4956ebd91e1c9f69f3da70438 Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Thu, 11 Sep 2014 13:13:17 -0700 Subject: [PATCH 6/6] Mention the need to re-render in a single place only --- src/ol/style/fillstyle.js | 5 +--- src/ol/style/imagestyle.js | 25 ++++--------------- src/ol/style/strokestyle.js | 30 +++++----------------- src/ol/style/style.js | 9 +++---- src/ol/style/textstyle.js | 50 ++++++++----------------------------- 5 files changed, 26 insertions(+), 93 deletions(-) diff --git a/src/ol/style/fillstyle.js b/src/ol/style/fillstyle.js index ea17853918..6714445868 100644 --- a/src/ol/style/fillstyle.js +++ b/src/ol/style/fillstyle.js @@ -32,10 +32,7 @@ ol.style.Fill.prototype.getColor = function() { /** - * Set the color. When this style is used as a layer, feature or ImageVector - * source style, call `changed()` on the layer, feature or ImageVector source - * for the change to take effect. When used as a FeatureOverlay style, call - * `render()` on the map. + * Set the color. * * @param {ol.Color|string} color Color. * @api diff --git a/src/ol/style/imagestyle.js b/src/ol/style/imagestyle.js index 443f5f92ec..2f57b34337 100644 --- a/src/ol/style/imagestyle.js +++ b/src/ol/style/imagestyle.js @@ -151,10 +151,7 @@ ol.style.Image.prototype.getSize = goog.abstractMethod; /** - * Set the opacity. When this style is used as a layer, feature or ImageVector - * source style, call `changed()` on the layer, feature or ImageVector source - * for the change to take effect. When used as a FeatureOverlay style, call - * `render()` on the map. + * Set the opacity. * * @param {number} opacity Opacity. */ @@ -164,10 +161,7 @@ ol.style.Image.prototype.setOpacity = function(opacity) { /** - * Set whether to rotate the style with the view. When this style is used as a - * layer, feature or ImageVector source style, call `changed()` on the layer, - * feature or ImageVector source for the change to take effect. When used as a - * FeatureOverlay style, call `render()` on the map. + * Set whether to rotate the style with the view. * * @param {boolean} rotateWithView Rotate with map. */ @@ -177,10 +171,7 @@ ol.style.Image.prototype.setRotateWithView = function(rotateWithView) { /** - * Set the rotation. When this style is used as a layer, feature or ImageVector - * source style, call `changed()` on the layer, feature or ImageVector source - * for the change to take effect. When used as a FeatureOverlay style, call - * `render()` on the map. + * Set the rotation. * * @param {number} rotation Rotation. * @api @@ -191,10 +182,7 @@ ol.style.Image.prototype.setRotation = function(rotation) { /** - * Set the scale. When this style is used as a layer, feature or ImageVector - * source style, call `changed()` on the layer, feature or ImageVector source - * for the change to take effect. When used as a FeatureOverlay style, call - * `render()` on the map. + * Set the scale. * * @param {number} scale Scale. * @api @@ -205,10 +193,7 @@ ol.style.Image.prototype.setScale = function(scale) { /** - * Set whether to snap the image to the closest pixel. When this style is used - * as a layer, feature or ImageVector source style, call `changed()` on the - * layer, feature or ImageVector source for the change to take effect. When used - * as a FeatureOverlay style, call `render()` on the map. + * Set whether to snap the image to the closest pixel. * * @param {boolean} snapToPixel Snap to pixel? */ diff --git a/src/ol/style/strokestyle.js b/src/ol/style/strokestyle.js index eeb58776ba..15e99bf260 100644 --- a/src/ol/style/strokestyle.js +++ b/src/ol/style/strokestyle.js @@ -110,10 +110,7 @@ ol.style.Stroke.prototype.getWidth = function() { /** - * Set the color. When this style is used as a layer, feature or ImageVector - * source style, call `changed()` on the layer, feature or ImageVector source - * for the change to take effect. When used as a FeatureOverlay style, call - * `render()` on the map. + * Set the color. * * @param {ol.Color|string} color Color. * @api @@ -124,10 +121,7 @@ ol.style.Stroke.prototype.setColor = function(color) { /** - * Set the line cap. When this style is used as a layer, feature or ImageVector - * source style, call `changed()` on the layer, feature or ImageVector source - * for the change to take effect. When used as a FeatureOverlay style, call - * `render()` on the map. + * Set the line cap. * * @param {string|undefined} lineCap Line cap. * @api @@ -138,10 +132,7 @@ ol.style.Stroke.prototype.setLineCap = function(lineCap) { /** - * Set the line dash. When this style is used as a layer, feature or ImageVector - * source style, call `changed()` on the layer, feature or ImageVector source - * for the change to take effect. When used as a FeatureOverlay style, call - * `render()` on the map. + * Set the line dash. * * @param {Array.} lineDash Line dash. * @api @@ -152,10 +143,7 @@ ol.style.Stroke.prototype.setLineDash = function(lineDash) { /** - * Set the line join. When this style is used as a layer, feature or ImageVector - * source style, call `changed()` on the layer, feature or ImageVector source - * for the change to take effect. When used as a FeatureOverlay style, call - * `render()` on the map. + * Set the line join. * * @param {string|undefined} lineJoin Line join. * @api @@ -166,10 +154,7 @@ ol.style.Stroke.prototype.setLineJoin = function(lineJoin) { /** - * Set the miter limit. When this style is used as a layer, feature or - * ImageVector source style, call `changed()` on the layer, feature or - * ImageVector source for the change to take effect. When used as a - * FeatureOverlay style, call `render()` on the map. + * Set the miter limit. * * @param {number|undefined} miterLimit Miter limit. * @api @@ -180,10 +165,7 @@ ol.style.Stroke.prototype.setMiterLimit = function(miterLimit) { /** - * Set the width. When this style is used as a layer, feature or ImageVector - * source style, call `changed()` on the layer, feature or ImageVector source - * for the change to take effect. When used as a FeatureOverlay style, call - * `render()` on the map. + * Set the width. * * @param {number|undefined} width Width. * @api diff --git a/src/ol/style/style.js b/src/ol/style/style.js index 653e2818b8..ad45b198c4 100644 --- a/src/ol/style/style.js +++ b/src/ol/style/style.js @@ -12,7 +12,9 @@ goog.require('ol.style.Stroke'); /** * @classdesc - * Container for vector feature rendering styles. + * Container for vector feature rendering styles. Any changes made to the style + * or its children through `set*()` methods will not take effect until the + * feature, layer or FeatureOverlay that uses the style is re-rendered. * * @constructor * @param {olx.style.StyleOptions=} opt_options Style options. @@ -101,10 +103,7 @@ ol.style.Style.prototype.getZIndex = function() { /** - * Set the zIndex. When this style is used as a layer, feature or ImageVector - * source style, call `changed()` on the layer, feature or ImageVector source - * for the change to take effect. When used as a FeatureOverlay style, call - * `render()` on the map. + * Set the zIndex. * * @param {number|undefined} zIndex ZIndex. * @api diff --git a/src/ol/style/textstyle.js b/src/ol/style/textstyle.js index a95fcc2291..df849d9650 100644 --- a/src/ol/style/textstyle.js +++ b/src/ol/style/textstyle.js @@ -165,10 +165,7 @@ ol.style.Text.prototype.getTextBaseline = function() { /** - * Set the font. When this style is used as a layer, feature or ImageVector - * source style, call `changed()` on the layer, feature or ImageVector source - * for the change to take effect. When used as a FeatureOverlay style, call - * `render()` on the map. + * Set the font. * * @param {string|undefined} font Font. * @api @@ -179,10 +176,7 @@ ol.style.Text.prototype.setFont = function(font) { /** - * Set the x offset. When this style is used as a layer, feature or ImageVector - * source style, call `changed()` on the layer, feature or ImageVector source - * for the change to take effect. When used as a FeatureOverlay style, call - * `render()` on the map. + * Set the x offset. * * @param {number} offsetX Horizontal text offset. */ @@ -192,10 +186,7 @@ ol.style.Text.prototype.setOffsetX = function(offsetX) { /** - * Set the y offset. When this style is used as a layer, feature or ImageVector - * source style, call `changed()` on the layer, feature or ImageVector source - * for the change to take effect. When used as a FeatureOverlay style, call - * `render()` on the map. + * Set the y offset. * * @param {number} offsetY Vertical text offset. */ @@ -205,10 +196,7 @@ ol.style.Text.prototype.setOffsetY = function(offsetY) { /** - * Set the fill. When this style is used as a layer, feature or ImageVector - * source style, call `changed()` on the layer, feature or ImageVector source - * for the change to take effect. When used as a FeatureOverlay style, call - * `render()` on the map. + * Set the fill. * * @param {ol.style.Fill} fill Fill style. * @api @@ -219,10 +207,7 @@ ol.style.Text.prototype.setFill = function(fill) { /** - * Set the rotation. When this style is used as a layer, feature or ImageVector - * source style, call `changed()` on the layer, feature or ImageVector source - * for the change to take effect. When used as a FeatureOverlay style, call - * `render()` on the map. + * Set the rotation. * * @param {number|undefined} rotation Rotation. * @api @@ -233,10 +218,7 @@ ol.style.Text.prototype.setRotation = function(rotation) { /** - * Set the scale. When this style is used as a layer, feature or ImageVector - * source style, call `changed()` on the layer, feature or ImageVector source - * for the change to take effect. When used as a FeatureOverlay style, call - * `render()` on the map. + * Set the scale. * * @param {number|undefined} scale Scale. * @api @@ -247,10 +229,7 @@ ol.style.Text.prototype.setScale = function(scale) { /** - * Set the stroke. When this style is used as a layer, feature or ImageVector - * source style, call `changed()` on the layer, feature or ImageVector source - * for the change to take effect. When used as a FeatureOverlay style, call - * `render()` on the map. + * Set the stroke. * * @param {ol.style.Stroke} stroke Stroke style. * @api @@ -261,10 +240,7 @@ ol.style.Text.prototype.setStroke = function(stroke) { /** - * Set the text. When this style is used as a layer, feature or ImageVector - * source style, call `changed()` on the layer, feature or ImageVector source - * for the change to take effect. When used as a FeatureOverlay style, call - * `render()` on the map. + * Set the text. * * @param {string|undefined} text Text. * @api @@ -275,10 +251,7 @@ ol.style.Text.prototype.setText = function(text) { /** - * Set the text alignment. When this style is used as a layer, feature or - * ImageVector source style, call `changed()` on the layer, feature or - * ImageVector source for the change to take effect. When used as a - * FeatureOverlay style, call `render()` on the map. + * Set the text alignment. * * @param {string|undefined} textAlign Text align. * @api @@ -289,10 +262,7 @@ ol.style.Text.prototype.setTextAlign = function(textAlign) { /** - * Set the text baseline. When this style is used as a layer, feature or - * ImageVector source style, call `changed()` on the layer, feature or - * ImageVector source for the change to take effect. When used as a - * FeatureOverlay style, call `render()` on the map. + * Set the text baseline. * * @param {string|undefined} textBaseline Text baseline. * @api