No need to have a mutable_ flag
Instead, educate users to call setStyle.
This commit is contained in:
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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`.
|
||||
|
||||
@@ -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.<number>} 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;
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user