Merge pull request #2394 from tonio/style_order

Give precedence to feature styles
This commit is contained in:
Bart van den Eijnden
2014-07-25 11:34:24 +02:00
14 changed files with 248 additions and 182 deletions

View File

@@ -1718,7 +1718,7 @@ olx.interaction.DragZoomOptions.prototype.style;
* snapTolerance: (number|undefined),
* type: ol.geom.GeometryType,
* minPointsPerRing: (number|undefined),
* style: (ol.style.Style|Array.<ol.style.Style>|ol.feature.StyleFunction|undefined),
* style: (ol.style.Style|Array.<ol.style.Style>|ol.style.StyleFunction|undefined),
* geometryName: (string|undefined),
* condition: (ol.events.ConditionType|undefined)}}
* @api
@@ -1765,7 +1765,7 @@ olx.interaction.DrawOptions.prototype.minPointsPerRing;
/**
* Style for sketch features.
* @type {ol.style.Style|Array.<ol.style.Style>|ol.feature.StyleFunction|undefined}
* @type {ol.style.Style|Array.<ol.style.Style>|ol.style.StyleFunction|undefined}
*/
olx.interaction.DrawOptions.prototype.style;
@@ -1846,7 +1846,7 @@ olx.interaction.KeyboardZoomOptions.prototype.delta;
/**
* @typedef {{deleteCondition: (ol.events.ConditionType|undefined),
* pixelTolerance: (number|undefined),
* style: (ol.style.Style|Array.<ol.style.Style>|ol.feature.StyleFunction|undefined),
* style: (ol.style.Style|Array.<ol.style.Style>|ol.style.StyleFunction|undefined),
* features: ol.Collection}}
* @api
*/
@@ -1873,7 +1873,7 @@ olx.interaction.ModifyOptions.prototype.pixelTolerance;
/**
* FeatureOverlay style.
* @type {ol.style.Style|Array.<ol.style.Style>|ol.feature.StyleFunction|undefined}
* @type {ol.style.Style|Array.<ol.style.Style>|ol.style.StyleFunction|undefined}
*/
olx.interaction.ModifyOptions.prototype.style;
@@ -1931,7 +1931,7 @@ olx.interaction.PinchZoomOptions.prototype.duration;
* @typedef {{addCondition: (ol.events.ConditionType|undefined),
* condition: (ol.events.ConditionType|undefined),
* layers: (Array.<ol.layer.Layer>|function(ol.layer.Layer): boolean|undefined),
* style: (ol.style.Style|Array.<ol.style.Style>|ol.feature.StyleFunction|undefined),
* style: (ol.style.Style|Array.<ol.style.Style>|ol.style.StyleFunction|undefined),
* removeCondition: (ol.events.ConditionType|undefined),
* toggleCondition: (ol.events.ConditionType|undefined)}}
* @api
@@ -1976,7 +1976,7 @@ olx.interaction.SelectOptions.prototype.layers;
/**
* Style for the selected features (those in the FeatureOverlay).
* @type {ol.style.Style|Array.<ol.style.Style>|ol.feature.StyleFunction|undefined}
* @type {ol.style.Style|Array.<ol.style.Style>|ol.style.StyleFunction|undefined}
*/
olx.interaction.SelectOptions.prototype.style;
@@ -2501,7 +2501,7 @@ olx.layer.TileOptions.prototype.useInterimTilesOnError;
* opacity: (number|undefined),
* saturation: (number|undefined),
* source: ol.source.Vector,
* style: (ol.style.Style|Array.<ol.style.Style>|ol.feature.StyleFunction|undefined),
* style: (ol.style.Style|Array.<ol.style.Style>|ol.style.StyleFunction|undefined),
* visible: (boolean|undefined)}}
* @api
*/
@@ -2583,7 +2583,7 @@ olx.layer.VectorOptions.prototype.source;
/**
* Layer style.
* @type {ol.style.Style|Array.<ol.style.Style>|ol.feature.StyleFunction|undefined}
* @type {ol.style.Style|Array.<ol.style.Style>|ol.style.StyleFunction|undefined}
*/
olx.layer.VectorOptions.prototype.style;
@@ -2598,7 +2598,7 @@ olx.layer.VectorOptions.prototype.visible;
/**
* @typedef {{features: (Array.<ol.Feature>|ol.Collection|undefined),
* map: (ol.Map|undefined),
* style: (ol.style.Style|Array.<ol.style.Style>|ol.feature.StyleFunction|undefined)}}
* style: (ol.style.Style|Array.<ol.style.Style>|ol.style.StyleFunction|undefined)}}
* @api
*/
olx.FeatureOverlayOptions;
@@ -2620,7 +2620,7 @@ olx.FeatureOverlayOptions.prototype.map;
/**
* Feature style.
* @type {ol.style.Style|Array.<ol.style.Style>|ol.feature.StyleFunction|undefined}
* @type {ol.style.Style|Array.<ol.style.Style>|ol.style.StyleFunction|undefined}
*/
olx.FeatureOverlayOptions.prototype.style;
@@ -3549,7 +3549,7 @@ olx.source.ImageCanvasOptions.prototype.state;
* ratio: (number|undefined),
* resolutions: (Array.<number>|undefined),
* source: ol.source.Vector,
* style: (ol.style.Style|Array.<ol.style.Style>|ol.feature.StyleFunction|undefined)}}
* style: (ol.style.Style|Array.<ol.style.Style>|ol.style.StyleFunction|undefined)}}
* @api
*/
olx.source.ImageVectorOptions;
@@ -3602,7 +3602,7 @@ olx.source.ImageVectorOptions.prototype.source;
/**
* Style to use when rendering features to the canvas.
* @type {ol.style.Style|Array.<ol.style.Style>|ol.feature.StyleFunction|undefined}
* @type {ol.style.Style|Array.<ol.style.Style>|ol.style.StyleFunction|undefined}
*/
olx.source.ImageVectorOptions.prototype.style;

View File

@@ -291,69 +291,6 @@ ol.Feature.prototype.setGeometryName = function(name) {
ol.feature.FeatureStyleFunction;
/**
* Default style function for features.
* @param {number} resolution Resolution.
* @return {Array.<ol.style.Style>} Style.
* @this {ol.Feature}
*/
ol.feature.defaultFeatureStyleFunction = function(resolution) {
var fill = new ol.style.Fill({
color: 'rgba(255,255,255,0.4)'
});
var stroke = new ol.style.Stroke({
color: '#3399CC',
width: 1.25
});
var styles = [
new ol.style.Style({
image: new ol.style.Circle({
fill: fill,
stroke: stroke,
radius: 5
}),
fill: fill,
stroke: stroke
})
];
// now that we've run it the first time,
// replace the function with a constant version
ol.feature.defaultFeatureStyleFunction =
/** @type {function(this:ol.Feature):Array.<ol.style.Style>} */(
function(resolution) {
return styles;
});
return styles;
};
/**
* A function that takes an {@link ol.Feature} and a `{number}` representing
* the view's resolution. The function should return an array of
* {@link ol.style.Style}. This way e.g. a vector layer can be styled.
*
* @typedef {function(ol.Feature, number): Array.<ol.style.Style>}
* @api
*/
ol.feature.StyleFunction;
/**
* @param {ol.Feature} feature Feature.
* @param {number} resolution Resolution.
* @return {Array.<ol.style.Style>} Style.
*/
ol.feature.defaultStyleFunction = function(feature, resolution) {
var featureStyleFunction = feature.getStyleFunction();
if (!goog.isDef(featureStyleFunction)) {
featureStyleFunction = ol.feature.defaultFeatureStyleFunction;
}
return featureStyleFunction.call(feature, resolution);
};
/**
* Convert the provided object into a feature style function. Functions passed
* through unchanged. Arrays of ol.style.Style or single style objects wrapped
@@ -388,39 +325,6 @@ ol.feature.createFeatureStyleFunction = function(obj) {
};
/**
* Convert the provided object into a style function. Functions passed through
* unchanged. Arrays of ol.style.Style or single style objects wrapped in a
* new style function.
* @param {ol.feature.StyleFunction|Array.<ol.style.Style>|ol.style.Style} obj
* A style function, a single style, or an array of styles.
* @return {ol.feature.StyleFunction} A style function.
*/
ol.feature.createStyleFunction = function(obj) {
/**
* @type {ol.feature.StyleFunction}
*/
var styleFunction;
if (goog.isFunction(obj)) {
styleFunction = /** @type {ol.feature.StyleFunction} */ (obj);
} else {
/**
* @type {Array.<ol.style.Style>}
*/
var styles;
if (goog.isArray(obj)) {
styles = obj;
} else {
goog.asserts.assertInstanceof(obj, ol.style.Style);
styles = [obj];
}
styleFunction = goog.functions.constant(styles);
}
return styleFunction;
};
/**
* Default styles for editing features.
* @return {Object.<ol.geom.GeometryType, Array.<ol.style.Style>>} Styles

View File

@@ -8,9 +8,9 @@ goog.require('goog.object');
goog.require('ol.Collection');
goog.require('ol.CollectionEventType');
goog.require('ol.Feature');
goog.require('ol.feature');
goog.require('ol.render.EventType');
goog.require('ol.renderer.vector');
goog.require('ol.style.Style');
@@ -63,19 +63,18 @@ ol.FeatureOverlay = function(opt_options) {
/**
* @private
* @type {ol.style.Style|Array.<ol.style.Style>|ol.feature.StyleFunction}
* @type {ol.style.Style|Array.<ol.style.Style>|ol.style.StyleFunction}
*/
this.style_ = null;
/**
* @private
* @type {ol.feature.StyleFunction|undefined}
* @type {ol.style.StyleFunction|undefined}
*/
this.styleFunction_ = undefined;
if (goog.isDef(options.style)) {
this.setStyle(options.style);
}
this.setStyle(goog.isDef(options.style) ?
options.style : ol.style.defaultStyleFunction);
if (goog.isDef(options.features)) {
if (goog.isArray(options.features)) {
@@ -169,7 +168,7 @@ ol.FeatureOverlay.prototype.handleMapPostCompose_ = function(event) {
}
var styleFunction = this.styleFunction_;
if (!goog.isDef(styleFunction)) {
styleFunction = ol.feature.defaultStyleFunction;
styleFunction = ol.style.defaultStyleFunction;
}
var replayGroup = /** @type {ol.render.IReplayGroup} */
(event.replayGroup);
@@ -270,13 +269,13 @@ ol.FeatureOverlay.prototype.setMap = function(map) {
* Set the style for features. This can be a single style object, an array
* of styles, or a function that takes a feature and resolution and returns
* an array of styles.
* @param {ol.style.Style|Array.<ol.style.Style>|ol.feature.StyleFunction} style
* @param {ol.style.Style|Array.<ol.style.Style>|ol.style.StyleFunction} style
* Overlay style.
* @api
*/
ol.FeatureOverlay.prototype.setStyle = function(style) {
this.style_ = style;
this.styleFunction_ = ol.feature.createStyleFunction(style);
this.styleFunction_ = ol.style.createStyleFunction(style);
this.render_();
};
@@ -284,7 +283,7 @@ ol.FeatureOverlay.prototype.setStyle = function(style) {
/**
* Get the style for features. This returns whatever was passed to the `style`
* option at construction or to the `setStyle` method.
* @return {ol.style.Style|Array.<ol.style.Style>|ol.feature.StyleFunction}
* @return {ol.style.Style|Array.<ol.style.Style>|ol.style.StyleFunction}
* Overlay style.
* @api
*/
@@ -295,7 +294,7 @@ ol.FeatureOverlay.prototype.getStyle = function() {
/**
* Get the style function.
* @return {ol.feature.StyleFunction|undefined} Style function.
* @return {ol.style.StyleFunction|undefined} Style function.
* @api
*/
ol.FeatureOverlay.prototype.getStyleFunction = function() {

View File

@@ -205,7 +205,7 @@ goog.inherits(ol.interaction.Draw, ol.interaction.Pointer);
/**
* @return {ol.feature.StyleFunction} Styles.
* @return {ol.style.StyleFunction} Styles.
*/
ol.interaction.Draw.getDefaultStyleFunction = function() {
var styles = ol.feature.createDefaultEditingStyles();

View File

@@ -769,7 +769,7 @@ ol.interaction.Modify.prototype.updateSegmentIndices_ = function(
/**
* @return {ol.feature.StyleFunction} Styles.
* @return {ol.style.StyleFunction} Styles.
*/
ol.interaction.Modify.getDefaultStyleFunction = function() {
var style = ol.feature.createDefaultEditingStyles();

View File

@@ -204,7 +204,7 @@ ol.interaction.Select.prototype.setMap = function(map) {
/**
* @return {ol.feature.StyleFunction} Styles.
* @return {ol.style.StyleFunction} Styles.
*/
ol.interaction.Select.getDefaultStyleFunction = function() {
var styles = ol.feature.createDefaultEditingStyles();

View File

@@ -1,8 +1,8 @@
goog.provide('ol.layer.Vector');
goog.require('goog.object');
goog.require('ol.feature');
goog.require('ol.layer.Layer');
goog.require('ol.style.Style');
/**
@@ -39,21 +39,20 @@ ol.layer.Vector = function(opt_options) {
/**
* User provided style.
* @type {ol.style.Style|Array.<ol.style.Style>|ol.feature.StyleFunction}
* @type {ol.style.Style|Array.<ol.style.Style>|ol.style.StyleFunction}
* @private
*/
this.style_ = null;
/**
* Style function for use within the library.
* @type {ol.feature.StyleFunction|undefined}
* @type {ol.style.StyleFunction|undefined}
* @private
*/
this.styleFunction_ = undefined;
if (goog.isDef(options.style)) {
this.setStyle(options.style);
}
this.setStyle(goog.isDefAndNotNull(options.style) ?
options.style : ol.style.defaultStyleFunction);
};
goog.inherits(ol.layer.Vector, ol.layer.Layer);
@@ -72,7 +71,7 @@ ol.layer.Vector.prototype.getRenderOrder = function() {
/**
* Get the style for features. This returns whatever was passed to the `style`
* option at construction or to the `setStyle` method.
* @return {ol.style.Style|Array.<ol.style.Style>|ol.feature.StyleFunction}
* @return {ol.style.Style|Array.<ol.style.Style>|ol.style.StyleFunction}
* Layer style.
* @api
*/
@@ -83,7 +82,7 @@ ol.layer.Vector.prototype.getStyle = function() {
/**
* Get the style function.
* @return {ol.feature.StyleFunction|undefined} Layer style function.
* @return {ol.style.StyleFunction|undefined} Layer style function.
* @api
*/
ol.layer.Vector.prototype.getStyleFunction = function() {
@@ -104,12 +103,12 @@ ol.layer.Vector.prototype.setRenderOrder = function(renderOrder) {
* Set the style for features. This can be a single style object, an array
* of styles, or a function that takes a feature and resolution and returns
* an array of styles.
* @param {ol.style.Style|Array.<ol.style.Style>|ol.feature.StyleFunction} style
* @param {ol.style.Style|Array.<ol.style.Style>|ol.style.StyleFunction} style
* Layer style.
* @api
*/
ol.layer.Vector.prototype.setStyle = function(style) {
this.style_ = style;
this.styleFunction_ = ol.feature.createStyleFunction(style);
this.styleFunction_ = ol.style.createStyleFunction(style);
this.dispatchChangeEvent();
};

View File

@@ -6,7 +6,6 @@ goog.require('goog.events');
goog.require('ol.ViewHint');
goog.require('ol.dom');
goog.require('ol.extent');
goog.require('ol.feature');
goog.require('ol.layer.Vector');
goog.require('ol.render.EventType');
goog.require('ol.render.canvas.ReplayGroup');
@@ -155,7 +154,7 @@ ol.renderer.canvas.VectorLayer.prototype.handleImageChange_ =
ol.renderer.canvas.VectorLayer.prototype.prepareFrame =
function(frameState, layerState) {
var vectorLayer = this.getLayer();
var vectorLayer = /** @type {ol.layer.Vector} */ (this.getLayer());
goog.asserts.assertInstanceof(vectorLayer, ol.layer.Vector);
var vectorSource = vectorLayer.getSource();
goog.asserts.assertInstanceof(vectorSource, ol.source.Vector);
@@ -202,10 +201,6 @@ ol.renderer.canvas.VectorLayer.prototype.prepareFrame =
this.dirty_ = false;
var styleFunction = vectorLayer.getStyleFunction();
if (!goog.isDef(styleFunction)) {
styleFunction = ol.feature.defaultStyleFunction;
}
var replayGroup =
new ol.render.canvas.ReplayGroup(
ol.renderer.vector.getTolerance(resolution, pixelRatio), extent,
@@ -217,10 +212,17 @@ ol.renderer.canvas.VectorLayer.prototype.prepareFrame =
* @this {ol.renderer.canvas.VectorLayer}
*/
function(feature) {
goog.asserts.assert(goog.isDef(styleFunction));
var dirty = this.renderFeature(
feature, resolution, pixelRatio, styleFunction, replayGroup);
this.dirty_ = this.dirty_ || dirty;
var styles;
if (goog.isDef(feature.getStyleFunction())) {
styles = feature.getStyleFunction().call(feature, resolution);
} else if (goog.isDef(vectorLayer.getStyleFunction())) {
styles = vectorLayer.getStyleFunction()(feature, resolution);
}
if (goog.isDefAndNotNull(styles)) {
var dirty = this.renderFeature(
feature, resolution, pixelRatio, styles, replayGroup);
this.dirty_ = this.dirty_ || dirty;
}
};
if (!goog.isNull(vectorLayerRenderOrder)) {
/** @type {Array.<ol.Feature>} */
@@ -252,13 +254,12 @@ ol.renderer.canvas.VectorLayer.prototype.prepareFrame =
* @param {ol.Feature} feature Feature.
* @param {number} resolution Resolution.
* @param {number} pixelRatio Pixel ratio.
* @param {ol.feature.StyleFunction} styleFunction Style function.
* @param {Array.<ol.style.Style>} styles Array of styles
* @param {ol.render.canvas.ReplayGroup} replayGroup Replay group.
* @return {boolean} `true` if an image is loading.
*/
ol.renderer.canvas.VectorLayer.prototype.renderFeature =
function(feature, resolution, pixelRatio, styleFunction, replayGroup) {
var styles = styleFunction(feature, resolution);
function(feature, resolution, pixelRatio, styles, replayGroup) {
if (!goog.isDefAndNotNull(styles)) {
return false;
}

View File

@@ -6,11 +6,11 @@ goog.require('goog.events.EventType');
goog.require('goog.vec.Mat4');
goog.require('ol.dom');
goog.require('ol.extent');
goog.require('ol.feature');
goog.require('ol.render.canvas.ReplayGroup');
goog.require('ol.renderer.vector');
goog.require('ol.source.ImageCanvas');
goog.require('ol.source.Vector');
goog.require('ol.style.Style');
goog.require('ol.vec.Mat4');
@@ -42,11 +42,11 @@ ol.source.ImageVector = function(options) {
/**
* @private
* @type {!ol.feature.StyleFunction}
* @type {!ol.style.StyleFunction}
*/
this.styleFunction_ = goog.isDef(options.style) ?
ol.feature.createStyleFunction(options.style) :
ol.feature.defaultStyleFunction;
this.styleFunction_ = goog.isDefAndNotNull(options.style) ?
ol.style.createStyleFunction(options.style) :
ol.style.defaultStyleFunction;
/**
* @private

View File

@@ -1,7 +1,11 @@
goog.provide('ol.style.Style');
goog.require('goog.asserts');
goog.require('goog.functions');
goog.require('ol.style.Circle');
goog.require('ol.style.Fill');
goog.require('ol.style.Image');
goog.require('ol.style.Stroke');
@@ -93,3 +97,84 @@ ol.style.Style.prototype.getText = function() {
ol.style.Style.prototype.getZIndex = function() {
return this.zIndex_;
};
/**
* A function that takes an {@link ol.Feature} and a `{number}` representing
* the view's resolution. The function should return an array of
* {@link ol.style.Style}. This way e.g. a vector layer can be styled.
*
* @typedef {function(ol.Feature, number): Array.<ol.style.Style>}
* @api
*/
ol.style.StyleFunction;
/**
* Convert the provided object into a style function. Functions passed through
* unchanged. Arrays of ol.style.Style or single style objects wrapped in a
* new style function.
* @param {ol.style.StyleFunction|Array.<ol.style.Style>|ol.style.Style} obj
* A style function, a single style, or an array of styles.
* @return {ol.style.StyleFunction} A style function.
*/
ol.style.createStyleFunction = function(obj) {
/**
* @type {ol.style.StyleFunction}
*/
var styleFunction;
if (goog.isFunction(obj)) {
styleFunction = /** @type {ol.style.StyleFunction} */ (obj);
} else {
/**
* @type {Array.<ol.style.Style>}
*/
var styles;
if (goog.isArray(obj)) {
styles = obj;
} else {
goog.asserts.assertInstanceof(obj, ol.style.Style);
styles = [obj];
}
styleFunction = goog.functions.constant(styles);
}
return styleFunction;
};
/**
* @param {ol.Feature} feature Feature.
* @param {number} resolution Resolution.
* @return {Array.<ol.style.Style>} Style.
*/
ol.style.defaultStyleFunction = function(feature, resolution) {
var fill = new ol.style.Fill({
color: 'rgba(255,255,255,0.4)'
});
var stroke = new ol.style.Stroke({
color: '#3399CC',
width: 1.25
});
var styles = [
new ol.style.Style({
image: new ol.style.Circle({
fill: fill,
stroke: stroke,
radius: 5
}),
fill: fill,
stroke: stroke
})
];
// now that we've run it the first time,
// replace the function with a constant version
ol.style.defaultStyleFunction =
/** @type {function(this:ol.Feature):Array.<ol.style.Style>} */(
function(resolution) {
return styles;
});
return styles;
};

View File

@@ -411,35 +411,6 @@ describe('ol.Feature', function() {
});
describe('ol.feature.createStyleFunction()', function() {
var style = new ol.style.Style();
it('creates a style function from a single style', function() {
var styleFunction = ol.feature.createStyleFunction(style);
expect(styleFunction()).to.eql([style]);
});
it('creates a style function from an array of styles', function() {
var styleFunction = ol.feature.createStyleFunction([style]);
expect(styleFunction()).to.eql([style]);
});
it('passes through a function', function() {
var original = function() {
return [style];
};
var styleFunction = ol.feature.createStyleFunction(original);
expect(styleFunction).to.be(original);
});
it('throws on (some) unexpected input', function() {
expect(function() {
ol.feature.createStyleFunction({bogus: 'input'});
}).to.throwException();
});
});
describe('ol.feature.createFeatureStyleFunction()', function() {
var style = new ol.style.Style();

View File

@@ -1,5 +1,7 @@
goog.provide('ol.test.layer.Vector');
goog.require('ol.feature');
describe('ol.layer.Vector', function() {
describe('constructor', function() {
@@ -74,9 +76,10 @@ describe('ol.layer.Vector', function() {
var layer = new ol.layer.Vector({
source: source
});
expect(layer.getStyleFunction()).to.be(undefined);
expect(layer.getStyleFunction()).to.be(ol.style.defaultStyleFunction);
layer.setStyle(style);
expect(layer.getStyleFunction()).to.be.a('function');
expect(layer.getStyleFunction()).not.to.be(
ol.style.defaultStyleFunction);
});
});
@@ -91,7 +94,7 @@ describe('ol.layer.Vector', function() {
source: source
});
expect(layer.getStyle()).to.be(null);
expect(layer.getStyle()).to.be(ol.style.defaultStyleFunction);
layer.setStyle(style);
expect(layer.getStyle()).to.be(style);

View File

@@ -0,0 +1,72 @@
goog.provide('ol.test.renderer.canvas.VectorLayer');
describe('ol.renderer.canvas.VectorLayer', function() {
describe('constructor', function() {
it('creates a new instance', function() {
var map = new ol.Map({
target: document.createElement('div')
});
var layer = new ol.layer.Vector({
source: new ol.source.Vector()
});
var renderer = new ol.renderer.canvas.VectorLayer(map.getRenderer(),
layer);
expect(renderer).to.be.a(ol.renderer.canvas.VectorLayer);
});
it('gives precedence to feature styles over layer styles', function() {
var target = document.createElement('div');
target.style.width = '256px';
target.style.height = '256px';
document.body.appendChild(target);
var map = new ol.Map({
view: new ol.View({
center: [0, 0],
zoom: 0
}),
target: target
});
var layerStyle = [new ol.style.Style({
text: new ol.style.Text({
text: 'layer'
})
})];
var featureStyle = [new ol.style.Style({
text: new ol.style.Text({
text: 'feature'
})
})];
var feature1 = new ol.Feature(new ol.geom.Point([0, 0]));
var feature2 = new ol.Feature(new ol.geom.Point([0, 0]));
feature2.setStyle(featureStyle);
var layer = new ol.layer.Vector({
source: new ol.source.Vector({
features: [feature1, feature2]
}),
style: layerStyle
});
map.addLayer(layer);
var spy = sinon.spy(map.getRenderer().getLayerRenderer(layer),
'renderFeature');
map.renderSync();
expect(spy.getCall(0).args[3]).to.be(layerStyle);
expect(spy.getCall(1).args[3]).to.be(featureStyle);
document.body.removeChild(target);
});
});
});
goog.require('ol.Feature');
goog.require('ol.Map');
goog.require('ol.View');
goog.require('ol.geom.Point');
goog.require('ol.layer.Vector');
goog.require('ol.renderer.canvas.VectorLayer');
goog.require('ol.source.Vector');
goog.require('ol.style.Style');
goog.require('ol.style.Text');

View File

@@ -0,0 +1,32 @@
goog.provide('ol.test.style.Style');
describe('ol.style.createStyleFunction()', function() {
var style = new ol.style.Style();
it('creates a style function from a single style', function() {
var styleFunction = ol.style.createStyleFunction(style);
expect(styleFunction()).to.eql([style]);
});
it('creates a style function from an array of styles', function() {
var styleFunction = ol.style.createStyleFunction([style]);
expect(styleFunction()).to.eql([style]);
});
it('passes through a function', function() {
var original = function() {
return [style];
};
var styleFunction = ol.style.createStyleFunction(original);
expect(styleFunction).to.be(original);
});
it('throws on (some) unexpected input', function() {
expect(function() {
ol.style.createStyleFunction({bogus: 'input'});
}).to.throwException();
});
});
goog.require('ol.style.Style');