Give precedence to feature style
This commit is contained in:
@@ -1662,7 +1662,7 @@ olx.interaction.DragZoomOptions.prototype.style;
|
|||||||
* snapTolerance: (number|undefined),
|
* snapTolerance: (number|undefined),
|
||||||
* type: ol.geom.GeometryType,
|
* type: ol.geom.GeometryType,
|
||||||
* minPointsPerRing: (number|undefined),
|
* 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),
|
* geometryName: (string|undefined),
|
||||||
* condition: (ol.events.ConditionType|undefined)}}
|
* condition: (ol.events.ConditionType|undefined)}}
|
||||||
* @api
|
* @api
|
||||||
@@ -1709,7 +1709,7 @@ olx.interaction.DrawOptions.prototype.minPointsPerRing;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Style for sketch features.
|
* 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;
|
olx.interaction.DrawOptions.prototype.style;
|
||||||
|
|
||||||
@@ -1790,7 +1790,7 @@ olx.interaction.KeyboardZoomOptions.prototype.delta;
|
|||||||
/**
|
/**
|
||||||
* @typedef {{deleteCondition: (ol.events.ConditionType|undefined),
|
* @typedef {{deleteCondition: (ol.events.ConditionType|undefined),
|
||||||
* pixelTolerance: (number|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}}
|
* features: ol.Collection}}
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@@ -1817,7 +1817,7 @@ olx.interaction.ModifyOptions.prototype.pixelTolerance;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* FeatureOverlay style.
|
* 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;
|
olx.interaction.ModifyOptions.prototype.style;
|
||||||
|
|
||||||
@@ -1875,7 +1875,7 @@ olx.interaction.PinchZoomOptions.prototype.duration;
|
|||||||
* @typedef {{addCondition: (ol.events.ConditionType|undefined),
|
* @typedef {{addCondition: (ol.events.ConditionType|undefined),
|
||||||
* condition: (ol.events.ConditionType|undefined),
|
* condition: (ol.events.ConditionType|undefined),
|
||||||
* layers: (Array.<ol.layer.Layer>|function(ol.layer.Layer): boolean|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),
|
* removeCondition: (ol.events.ConditionType|undefined),
|
||||||
* toggleCondition: (ol.events.ConditionType|undefined)}}
|
* toggleCondition: (ol.events.ConditionType|undefined)}}
|
||||||
* @api
|
* @api
|
||||||
@@ -1920,7 +1920,7 @@ olx.interaction.SelectOptions.prototype.layers;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Style for the selected features (those in the FeatureOverlay).
|
* 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;
|
olx.interaction.SelectOptions.prototype.style;
|
||||||
|
|
||||||
@@ -2400,7 +2400,7 @@ olx.layer.TileOptions.prototype.useInterimTilesOnError;
|
|||||||
* opacity: (number|undefined),
|
* opacity: (number|undefined),
|
||||||
* saturation: (number|undefined),
|
* saturation: (number|undefined),
|
||||||
* source: ol.source.Vector,
|
* 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)}}
|
* visible: (boolean|undefined)}}
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@@ -2474,7 +2474,7 @@ olx.layer.VectorOptions.prototype.source;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Layer style.
|
* 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;
|
olx.layer.VectorOptions.prototype.style;
|
||||||
|
|
||||||
@@ -2489,7 +2489,7 @@ olx.layer.VectorOptions.prototype.visible;
|
|||||||
/**
|
/**
|
||||||
* @typedef {{features: (Array.<ol.Feature>|ol.Collection|undefined),
|
* @typedef {{features: (Array.<ol.Feature>|ol.Collection|undefined),
|
||||||
* map: (ol.Map|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
|
* @api
|
||||||
*/
|
*/
|
||||||
olx.FeatureOverlayOptions;
|
olx.FeatureOverlayOptions;
|
||||||
@@ -2511,7 +2511,7 @@ olx.FeatureOverlayOptions.prototype.map;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Feature style.
|
* 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;
|
olx.FeatureOverlayOptions.prototype.style;
|
||||||
|
|
||||||
@@ -3529,7 +3529,7 @@ olx.source.ImageCanvasOptions.prototype.state;
|
|||||||
* ratio: (number|undefined),
|
* ratio: (number|undefined),
|
||||||
* resolutions: (Array.<number>|undefined),
|
* resolutions: (Array.<number>|undefined),
|
||||||
* source: ol.source.Vector,
|
* 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
|
* @api
|
||||||
*/
|
*/
|
||||||
olx.source.ImageVectorOptions;
|
olx.source.ImageVectorOptions;
|
||||||
@@ -3589,7 +3589,7 @@ olx.source.ImageVectorOptions.prototype.source;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Style to use when rendering features to the canvas.
|
* 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;
|
olx.source.ImageVectorOptions.prototype.style;
|
||||||
|
|
||||||
|
|||||||
@@ -291,69 +291,6 @@ ol.Feature.prototype.setGeometryName = function(name) {
|
|||||||
ol.feature.FeatureStyleFunction;
|
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
|
* Convert the provided object into a feature style function. Functions passed
|
||||||
* through unchanged. Arrays of ol.style.Style or single style objects wrapped
|
* 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.
|
* Default styles for editing features.
|
||||||
* @return {Object.<ol.geom.GeometryType, Array.<ol.style.Style>>} Styles
|
* @return {Object.<ol.geom.GeometryType, Array.<ol.style.Style>>} Styles
|
||||||
|
|||||||
@@ -8,9 +8,9 @@ goog.require('goog.object');
|
|||||||
goog.require('ol.Collection');
|
goog.require('ol.Collection');
|
||||||
goog.require('ol.CollectionEventType');
|
goog.require('ol.CollectionEventType');
|
||||||
goog.require('ol.Feature');
|
goog.require('ol.Feature');
|
||||||
goog.require('ol.feature');
|
|
||||||
goog.require('ol.render.EventType');
|
goog.require('ol.render.EventType');
|
||||||
goog.require('ol.renderer.vector');
|
goog.require('ol.renderer.vector');
|
||||||
|
goog.require('ol.style.defaults');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -63,19 +63,18 @@ ol.FeatureOverlay = function(opt_options) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @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;
|
this.style_ = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {ol.feature.StyleFunction|undefined}
|
* @type {ol.style.StyleFunction|undefined}
|
||||||
*/
|
*/
|
||||||
this.styleFunction_ = undefined;
|
this.styleFunction_ = undefined;
|
||||||
|
|
||||||
if (goog.isDef(options.style)) {
|
this.setStyle(goog.isDef(options.style) ?
|
||||||
this.setStyle(options.style);
|
options.style : ol.style.defaults.styleFunction);
|
||||||
}
|
|
||||||
|
|
||||||
if (goog.isDef(options.features)) {
|
if (goog.isDef(options.features)) {
|
||||||
if (goog.isArray(options.features)) {
|
if (goog.isArray(options.features)) {
|
||||||
@@ -169,7 +168,7 @@ ol.FeatureOverlay.prototype.handleMapPostCompose_ = function(event) {
|
|||||||
}
|
}
|
||||||
var styleFunction = this.styleFunction_;
|
var styleFunction = this.styleFunction_;
|
||||||
if (!goog.isDef(styleFunction)) {
|
if (!goog.isDef(styleFunction)) {
|
||||||
styleFunction = ol.feature.defaultStyleFunction;
|
styleFunction = ol.style.defaults.styleFunction;
|
||||||
}
|
}
|
||||||
var replayGroup = /** @type {ol.render.IReplayGroup} */
|
var replayGroup = /** @type {ol.render.IReplayGroup} */
|
||||||
(event.replayGroup);
|
(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
|
* 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
|
* of styles, or a function that takes a feature and resolution and returns
|
||||||
* an array of styles.
|
* 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.
|
* Overlay style.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
ol.FeatureOverlay.prototype.setStyle = function(style) {
|
ol.FeatureOverlay.prototype.setStyle = function(style) {
|
||||||
this.style_ = style;
|
this.style_ = style;
|
||||||
this.styleFunction_ = ol.feature.createStyleFunction(style);
|
this.styleFunction_ = ol.style.createStyleFunction(style);
|
||||||
this.render_();
|
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`
|
* Get the style for features. This returns whatever was passed to the `style`
|
||||||
* option at construction or to the `setStyle` method.
|
* 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.
|
* Overlay style.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@@ -295,7 +294,7 @@ ol.FeatureOverlay.prototype.getStyle = function() {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the style function.
|
* Get the style function.
|
||||||
* @return {ol.feature.StyleFunction|undefined} Style function.
|
* @return {ol.style.StyleFunction|undefined} Style function.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
ol.FeatureOverlay.prototype.getStyleFunction = function() {
|
ol.FeatureOverlay.prototype.getStyleFunction = function() {
|
||||||
|
|||||||
@@ -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() {
|
ol.interaction.Draw.getDefaultStyleFunction = function() {
|
||||||
var styles = ol.feature.createDefaultEditingStyles();
|
var styles = ol.feature.createDefaultEditingStyles();
|
||||||
|
|||||||
@@ -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() {
|
ol.interaction.Modify.getDefaultStyleFunction = function() {
|
||||||
var style = ol.feature.createDefaultEditingStyles();
|
var style = ol.feature.createDefaultEditingStyles();
|
||||||
|
|||||||
@@ -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() {
|
ol.interaction.Select.getDefaultStyleFunction = function() {
|
||||||
var styles = ol.feature.createDefaultEditingStyles();
|
var styles = ol.feature.createDefaultEditingStyles();
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
goog.provide('ol.layer.Vector');
|
goog.provide('ol.layer.Vector');
|
||||||
|
|
||||||
goog.require('goog.object');
|
goog.require('goog.object');
|
||||||
goog.require('ol.feature');
|
|
||||||
goog.require('ol.layer.Layer');
|
goog.require('ol.layer.Layer');
|
||||||
|
goog.require('ol.style.Style');
|
||||||
|
goog.require('ol.style.defaults');
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -39,21 +40,20 @@ ol.layer.Vector = function(opt_options) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* User provided style.
|
* 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
|
* @private
|
||||||
*/
|
*/
|
||||||
this.style_ = null;
|
this.style_ = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Style function for use within the library.
|
* Style function for use within the library.
|
||||||
* @type {ol.feature.StyleFunction|undefined}
|
* @type {ol.style.StyleFunction|undefined}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this.styleFunction_ = undefined;
|
this.styleFunction_ = undefined;
|
||||||
|
|
||||||
if (goog.isDef(options.style)) {
|
this.setStyle(goog.isDefAndNotNull(options.style) ?
|
||||||
this.setStyle(options.style);
|
options.style : ol.style.defaults.styleFunction);
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
goog.inherits(ol.layer.Vector, ol.layer.Layer);
|
goog.inherits(ol.layer.Vector, ol.layer.Layer);
|
||||||
@@ -72,7 +72,7 @@ ol.layer.Vector.prototype.getRenderOrder = function() {
|
|||||||
/**
|
/**
|
||||||
* Get the style for features. This returns whatever was passed to the `style`
|
* Get the style for features. This returns whatever was passed to the `style`
|
||||||
* option at construction or to the `setStyle` method.
|
* 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.
|
* Layer style.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
@@ -83,7 +83,7 @@ ol.layer.Vector.prototype.getStyle = function() {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the style function.
|
* Get the style function.
|
||||||
* @return {ol.feature.StyleFunction|undefined} Layer style function.
|
* @return {ol.style.StyleFunction|undefined} Layer style function.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
ol.layer.Vector.prototype.getStyleFunction = function() {
|
ol.layer.Vector.prototype.getStyleFunction = function() {
|
||||||
@@ -104,12 +104,12 @@ ol.layer.Vector.prototype.setRenderOrder = function(renderOrder) {
|
|||||||
* Set the style for features. This can be a single style object, an array
|
* 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
|
* of styles, or a function that takes a feature and resolution and returns
|
||||||
* an array of styles.
|
* 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.
|
* Layer style.
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
ol.layer.Vector.prototype.setStyle = function(style) {
|
ol.layer.Vector.prototype.setStyle = function(style) {
|
||||||
this.style_ = style;
|
this.style_ = style;
|
||||||
this.styleFunction_ = ol.feature.createStyleFunction(style);
|
this.styleFunction_ = ol.style.createStyleFunction(style);
|
||||||
this.dispatchChangeEvent();
|
this.dispatchChangeEvent();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ goog.require('goog.events');
|
|||||||
goog.require('ol.ViewHint');
|
goog.require('ol.ViewHint');
|
||||||
goog.require('ol.dom');
|
goog.require('ol.dom');
|
||||||
goog.require('ol.extent');
|
goog.require('ol.extent');
|
||||||
goog.require('ol.feature');
|
|
||||||
goog.require('ol.layer.Vector');
|
goog.require('ol.layer.Vector');
|
||||||
goog.require('ol.render.EventType');
|
goog.require('ol.render.EventType');
|
||||||
goog.require('ol.render.canvas.ReplayGroup');
|
goog.require('ol.render.canvas.ReplayGroup');
|
||||||
@@ -155,7 +154,7 @@ ol.renderer.canvas.VectorLayer.prototype.handleImageChange_ =
|
|||||||
ol.renderer.canvas.VectorLayer.prototype.prepareFrame =
|
ol.renderer.canvas.VectorLayer.prototype.prepareFrame =
|
||||||
function(frameState, layerState) {
|
function(frameState, layerState) {
|
||||||
|
|
||||||
var vectorLayer = this.getLayer();
|
var vectorLayer = /** @type {ol.layer.Vector} */ (this.getLayer());
|
||||||
goog.asserts.assertInstanceof(vectorLayer, ol.layer.Vector);
|
goog.asserts.assertInstanceof(vectorLayer, ol.layer.Vector);
|
||||||
var vectorSource = vectorLayer.getSource();
|
var vectorSource = vectorLayer.getSource();
|
||||||
goog.asserts.assertInstanceof(vectorSource, ol.source.Vector);
|
goog.asserts.assertInstanceof(vectorSource, ol.source.Vector);
|
||||||
@@ -202,10 +201,6 @@ ol.renderer.canvas.VectorLayer.prototype.prepareFrame =
|
|||||||
|
|
||||||
this.dirty_ = false;
|
this.dirty_ = false;
|
||||||
|
|
||||||
var styleFunction = vectorLayer.getStyleFunction();
|
|
||||||
if (!goog.isDef(styleFunction)) {
|
|
||||||
styleFunction = ol.feature.defaultStyleFunction;
|
|
||||||
}
|
|
||||||
var replayGroup =
|
var replayGroup =
|
||||||
new ol.render.canvas.ReplayGroup(
|
new ol.render.canvas.ReplayGroup(
|
||||||
ol.renderer.vector.getTolerance(resolution, pixelRatio), extent,
|
ol.renderer.vector.getTolerance(resolution, pixelRatio), extent,
|
||||||
@@ -217,6 +212,8 @@ ol.renderer.canvas.VectorLayer.prototype.prepareFrame =
|
|||||||
* @this {ol.renderer.canvas.VectorLayer}
|
* @this {ol.renderer.canvas.VectorLayer}
|
||||||
*/
|
*/
|
||||||
function(feature) {
|
function(feature) {
|
||||||
|
var styleFunction = feature.getStyleFunction() ||
|
||||||
|
vectorLayer.getStyleFunction();
|
||||||
goog.asserts.assert(goog.isDef(styleFunction));
|
goog.asserts.assert(goog.isDef(styleFunction));
|
||||||
var dirty = this.renderFeature(
|
var dirty = this.renderFeature(
|
||||||
feature, resolution, pixelRatio, styleFunction, replayGroup);
|
feature, resolution, pixelRatio, styleFunction, replayGroup);
|
||||||
@@ -252,7 +249,7 @@ ol.renderer.canvas.VectorLayer.prototype.prepareFrame =
|
|||||||
* @param {ol.Feature} feature Feature.
|
* @param {ol.Feature} feature Feature.
|
||||||
* @param {number} resolution Resolution.
|
* @param {number} resolution Resolution.
|
||||||
* @param {number} pixelRatio Pixel ratio.
|
* @param {number} pixelRatio Pixel ratio.
|
||||||
* @param {ol.feature.StyleFunction} styleFunction Style function.
|
* @param {ol.style.StyleFunction} styleFunction Style function.
|
||||||
* @param {ol.render.canvas.ReplayGroup} replayGroup Replay group.
|
* @param {ol.render.canvas.ReplayGroup} replayGroup Replay group.
|
||||||
* @return {boolean} `true` if an image is loading.
|
* @return {boolean} `true` if an image is loading.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ goog.require('goog.events.EventType');
|
|||||||
goog.require('goog.vec.Mat4');
|
goog.require('goog.vec.Mat4');
|
||||||
goog.require('ol.dom');
|
goog.require('ol.dom');
|
||||||
goog.require('ol.extent');
|
goog.require('ol.extent');
|
||||||
goog.require('ol.feature');
|
|
||||||
goog.require('ol.render.canvas.ReplayGroup');
|
goog.require('ol.render.canvas.ReplayGroup');
|
||||||
goog.require('ol.renderer.vector');
|
goog.require('ol.renderer.vector');
|
||||||
goog.require('ol.source.ImageCanvas');
|
goog.require('ol.source.ImageCanvas');
|
||||||
goog.require('ol.source.Vector');
|
goog.require('ol.source.Vector');
|
||||||
|
goog.require('ol.style.defaults');
|
||||||
goog.require('ol.vec.Mat4');
|
goog.require('ol.vec.Mat4');
|
||||||
|
|
||||||
|
|
||||||
@@ -42,11 +42,11 @@ ol.source.ImageVector = function(options) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @type {!ol.feature.StyleFunction}
|
* @type {!ol.style.StyleFunction}
|
||||||
*/
|
*/
|
||||||
this.styleFunction_ = goog.isDef(options.style) ?
|
this.styleFunction_ = goog.isDefAndNotNull(options.style) ?
|
||||||
ol.feature.createStyleFunction(options.style) :
|
ol.style.createStyleFunction(options.style) :
|
||||||
ol.feature.defaultStyleFunction;
|
ol.style.defaults.styleFunction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
|
|||||||
43
src/ol/style/defaultsstyle.js
Normal file
43
src/ol/style/defaultsstyle.js
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
goog.provide('ol.style.defaults');
|
||||||
|
|
||||||
|
goog.require('ol.style.Circle');
|
||||||
|
goog.require('ol.style.Fill');
|
||||||
|
goog.require('ol.style.Stroke');
|
||||||
|
goog.require('ol.style.Style');
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ol.Feature} feature Feature.
|
||||||
|
* @param {number} resolution Resolution.
|
||||||
|
* @return {Array.<ol.style.Style>} Style.
|
||||||
|
*/
|
||||||
|
ol.style.defaults.styleFunction = 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.defaults.styleFunction =
|
||||||
|
/** @type {function(this:ol.Feature):Array.<ol.style.Style>} */(
|
||||||
|
function(resolution) {
|
||||||
|
return styles;
|
||||||
|
});
|
||||||
|
|
||||||
|
return styles;
|
||||||
|
};
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
goog.provide('ol.style.Style');
|
goog.provide('ol.style.Style');
|
||||||
|
|
||||||
|
goog.require('goog.asserts');
|
||||||
|
goog.require('goog.functions');
|
||||||
goog.require('ol.style.Fill');
|
goog.require('ol.style.Fill');
|
||||||
goog.require('ol.style.Image');
|
goog.require('ol.style.Image');
|
||||||
|
|
||||||
@@ -93,3 +95,47 @@ ol.style.Style.prototype.getText = function() {
|
|||||||
ol.style.Style.prototype.getZIndex = function() {
|
ol.style.Style.prototype.getZIndex = function() {
|
||||||
return this.zIndex_;
|
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;
|
||||||
|
};
|
||||||
|
|||||||
@@ -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() {
|
describe('ol.feature.createFeatureStyleFunction()', function() {
|
||||||
var style = new ol.style.Style();
|
var style = new ol.style.Style();
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
goog.provide('ol.test.layer.Vector');
|
goog.provide('ol.test.layer.Vector');
|
||||||
|
|
||||||
|
goog.require('ol.feature');
|
||||||
|
|
||||||
describe('ol.layer.Vector', function() {
|
describe('ol.layer.Vector', function() {
|
||||||
|
|
||||||
describe('constructor', function() {
|
describe('constructor', function() {
|
||||||
@@ -74,9 +76,10 @@ describe('ol.layer.Vector', function() {
|
|||||||
var layer = new ol.layer.Vector({
|
var layer = new ol.layer.Vector({
|
||||||
source: source
|
source: source
|
||||||
});
|
});
|
||||||
expect(layer.getStyleFunction()).to.be(undefined);
|
expect(layer.getStyleFunction()).to.be(ol.style.defaults.styleFunction);
|
||||||
layer.setStyle(style);
|
layer.setStyle(style);
|
||||||
expect(layer.getStyleFunction()).to.be.a('function');
|
expect(layer.getStyleFunction()).not.to.be(
|
||||||
|
ol.feature.defaultStyleFunction);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -91,7 +94,7 @@ describe('ol.layer.Vector', function() {
|
|||||||
source: source
|
source: source
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(layer.getStyle()).to.be(null);
|
expect(layer.getStyle()).to.be(ol.style.defaults.styleFunction);
|
||||||
|
|
||||||
layer.setStyle(style);
|
layer.setStyle(style);
|
||||||
expect(layer.getStyle()).to.be(style);
|
expect(layer.getStyle()).to.be(style);
|
||||||
@@ -115,3 +118,4 @@ goog.require('ol.layer.Layer');
|
|||||||
goog.require('ol.layer.Vector');
|
goog.require('ol.layer.Vector');
|
||||||
goog.require('ol.source.Vector');
|
goog.require('ol.source.Vector');
|
||||||
goog.require('ol.style.Style');
|
goog.require('ol.style.Style');
|
||||||
|
goog.require('ol.style.defaults');
|
||||||
|
|||||||
32
test/spec/ol/style.test.js
Normal file
32
test/spec/ol/style.test.js
Normal 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');
|
||||||
Reference in New Issue
Block a user