Merge pull request #7811 from fredj/rm_ol.FeatureStyleFunction
Remove ol.FeatureStyleFunction support
This commit is contained in:
@@ -73,14 +73,13 @@ const Feature = function(opt_geometryOrProperties) {
|
||||
/**
|
||||
* User provided style.
|
||||
* @private
|
||||
* @type {ol.style.Style|Array.<ol.style.Style>|
|
||||
* ol.FeatureStyleFunction}
|
||||
* @type {ol.style.Style|Array.<ol.style.Style>|ol.StyleFunction}
|
||||
*/
|
||||
this.style_ = null;
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @type {ol.FeatureStyleFunction|undefined}
|
||||
* @type {ol.StyleFunction|undefined}
|
||||
*/
|
||||
this.styleFunction_ = undefined;
|
||||
|
||||
@@ -172,8 +171,7 @@ Feature.prototype.getGeometryName = function() {
|
||||
/**
|
||||
* Get the feature's style. Will return what was provided to the
|
||||
* {@link ol.Feature#setStyle} method.
|
||||
* @return {ol.style.Style|Array.<ol.style.Style>|
|
||||
* ol.FeatureStyleFunction|ol.StyleFunction} The feature style.
|
||||
* @return {ol.style.Style|Array.<ol.style.Style>|ol.StyleFunction} The feature style.
|
||||
* @api
|
||||
*/
|
||||
Feature.prototype.getStyle = function() {
|
||||
@@ -183,7 +181,7 @@ Feature.prototype.getStyle = function() {
|
||||
|
||||
/**
|
||||
* Get the feature's style function.
|
||||
* @return {ol.FeatureStyleFunction|undefined} Return a function
|
||||
* @return {ol.StyleFunction|undefined} Return a function
|
||||
* representing the current style of this feature.
|
||||
* @api
|
||||
*/
|
||||
@@ -233,8 +231,7 @@ Feature.prototype.setGeometry = function(geometry) {
|
||||
* Set the style for the feature. This can be a single style object, an array
|
||||
* of styles, or a function that takes a resolution and returns an array of
|
||||
* styles. If it is `null` the feature has no style (a `null` style).
|
||||
* @param {ol.style.Style|Array.<ol.style.Style>|
|
||||
* ol.FeatureStyleFunction|ol.StyleFunction} style Style for this feature.
|
||||
* @param {ol.style.Style|Array.<ol.style.Style>|ol.StyleFunction} style Style for this feature.
|
||||
* @api
|
||||
* @fires ol.events.Event#event:change
|
||||
*/
|
||||
@@ -284,21 +281,13 @@ Feature.prototype.setGeometryName = function(name) {
|
||||
* Convert the provided object into a feature style function. Functions passed
|
||||
* through unchanged. Arrays of ol.style.Style or single style objects wrapped
|
||||
* in a new feature style function.
|
||||
* @param {ol.FeatureStyleFunction|!Array.<ol.style.Style>|!ol.style.Style} obj
|
||||
* @param {ol.StyleFunction|!Array.<ol.style.Style>|!ol.style.Style} obj
|
||||
* A feature style function, a single style, or an array of styles.
|
||||
* @return {ol.FeatureStyleFunction} A style function.
|
||||
* @return {ol.StyleFunction} A style function.
|
||||
*/
|
||||
Feature.createStyleFunction = function(obj) {
|
||||
let styleFunction;
|
||||
|
||||
if (typeof obj === 'function') {
|
||||
if (obj.length == 2) {
|
||||
styleFunction = function(resolution) {
|
||||
return /** @type {ol.StyleFunction} */ (obj)(this, resolution);
|
||||
};
|
||||
} else {
|
||||
styleFunction = obj;
|
||||
}
|
||||
return obj;
|
||||
} else {
|
||||
/**
|
||||
* @type {Array.<ol.style.Style>}
|
||||
@@ -311,10 +300,9 @@ Feature.createStyleFunction = function(obj) {
|
||||
41); // Expected an `ol.style.Style` or an array of `ol.style.Style`
|
||||
styles = [obj];
|
||||
}
|
||||
styleFunction = function() {
|
||||
return function() {
|
||||
return styles;
|
||||
};
|
||||
}
|
||||
return styleFunction;
|
||||
};
|
||||
export default Feature;
|
||||
|
||||
@@ -388,31 +388,31 @@ function createNameStyleFunction(foundStyle, name) {
|
||||
* styles.
|
||||
* @param {boolean|undefined} showPointNames true to show names for point
|
||||
* placemarks.
|
||||
* @return {ol.FeatureStyleFunction} Feature style function.
|
||||
* @return {ol.StyleFunction} Feature style function.
|
||||
*/
|
||||
function createFeatureStyleFunction(style, styleUrl,
|
||||
defaultStyle, sharedStyles, showPointNames) {
|
||||
|
||||
return (
|
||||
/**
|
||||
* @param {number} resolution Resolution.
|
||||
* @return {Array.<ol.style.Style>} Style.
|
||||
* @this {ol.Feature}
|
||||
*/
|
||||
function(resolution) {
|
||||
* @param {ol.Feature} feature feature.
|
||||
* @param {number} resolution Resolution.
|
||||
* @return {Array.<ol.style.Style>} Style.
|
||||
*/
|
||||
function(feature, resolution) {
|
||||
let drawName = showPointNames;
|
||||
/** @type {ol.style.Style|undefined} */
|
||||
let nameStyle;
|
||||
let name = '';
|
||||
if (drawName) {
|
||||
if (this.getGeometry()) {
|
||||
drawName = (this.getGeometry().getType() ===
|
||||
GeometryType.POINT);
|
||||
const geometry = feature.getGeometry();
|
||||
if (geometry) {
|
||||
drawName = geometry.getType() === GeometryType.POINT;
|
||||
}
|
||||
}
|
||||
|
||||
if (drawName) {
|
||||
name = /** @type {string} */ (this.get('name'));
|
||||
name = /** @type {string} */ (feature.get('name'));
|
||||
drawName = drawName && name;
|
||||
}
|
||||
|
||||
@@ -2707,7 +2707,7 @@ function writePlacemark(node, feature, objectStack) {
|
||||
if (styleFunction) {
|
||||
// FIXME the styles returned by the style function are supposed to be
|
||||
// resolution-independent here
|
||||
const styles = styleFunction.call(feature, 0);
|
||||
const styles = styleFunction(feature, 0);
|
||||
if (styles) {
|
||||
const style = Array.isArray(styles) ? styles[0] : styles;
|
||||
if (this.writeStyles_) {
|
||||
|
||||
@@ -364,14 +364,9 @@ CanvasVectorLayerRenderer.prototype.prepareFrame = function(frameState, layerSta
|
||||
*/
|
||||
const render = function(feature) {
|
||||
let styles;
|
||||
let styleFunction = feature.getStyleFunction();
|
||||
const styleFunction = feature.getStyleFunction() || vectorLayer.getStyleFunction();
|
||||
if (styleFunction) {
|
||||
styles = styleFunction.call(feature, resolution);
|
||||
} else {
|
||||
styleFunction = vectorLayer.getStyleFunction();
|
||||
if (styleFunction) {
|
||||
styles = styleFunction(feature, resolution);
|
||||
}
|
||||
styles = styleFunction(feature, resolution);
|
||||
}
|
||||
if (styles) {
|
||||
const dirty = this.renderFeature(
|
||||
@@ -384,8 +379,8 @@ CanvasVectorLayerRenderer.prototype.prepareFrame = function(frameState, layerSta
|
||||
const features = [];
|
||||
vectorSource.forEachFeatureInExtent(extent,
|
||||
/**
|
||||
* @param {ol.Feature} feature Feature.
|
||||
*/
|
||||
* @param {ol.Feature} feature Feature.
|
||||
*/
|
||||
function(feature) {
|
||||
features.push(feature);
|
||||
}, this);
|
||||
|
||||
@@ -201,18 +201,12 @@ CanvasVectorTileLayerRenderer.prototype.createReplayGroup_ = function(
|
||||
*/
|
||||
const render = function(feature) {
|
||||
let styles;
|
||||
let styleFunction = feature.getStyleFunction();
|
||||
const styleFunction = feature.getStyleFunction() || layer.getStyleFunction();
|
||||
if (styleFunction) {
|
||||
styles = styleFunction.call(/** @type {ol.Feature} */ (feature), resolution);
|
||||
} else {
|
||||
styleFunction = layer.getStyleFunction();
|
||||
if (styleFunction) {
|
||||
styles = styleFunction(feature, resolution);
|
||||
}
|
||||
styles = styleFunction(feature, resolution);
|
||||
}
|
||||
if (styles) {
|
||||
const dirty = this.renderFeature(feature, squaredTolerance, styles,
|
||||
replayGroup);
|
||||
const dirty = this.renderFeature(feature, squaredTolerance, styles, replayGroup);
|
||||
this.dirty_ = this.dirty_ || dirty;
|
||||
replayState.dirty = replayState.dirty || dirty;
|
||||
}
|
||||
|
||||
@@ -266,14 +266,9 @@ WebGLVectorLayerRenderer.prototype.prepareFrame = function(frameState, layerStat
|
||||
*/
|
||||
const render = function(feature) {
|
||||
let styles;
|
||||
let styleFunction = feature.getStyleFunction();
|
||||
const styleFunction = feature.getStyleFunction() || vectorLayer.getStyleFunction();
|
||||
if (styleFunction) {
|
||||
styles = styleFunction.call(feature, resolution);
|
||||
} else {
|
||||
styleFunction = vectorLayer.getStyleFunction();
|
||||
if (styleFunction) {
|
||||
styles = styleFunction(feature, resolution);
|
||||
}
|
||||
styles = styleFunction(feature, resolution);
|
||||
}
|
||||
if (styles) {
|
||||
const dirty = this.renderFeature(
|
||||
@@ -286,8 +281,8 @@ WebGLVectorLayerRenderer.prototype.prepareFrame = function(frameState, layerStat
|
||||
const features = [];
|
||||
vectorSource.forEachFeatureInExtent(extent,
|
||||
/**
|
||||
* @param {ol.Feature} feature Feature.
|
||||
*/
|
||||
* @param {ol.Feature} feature Feature.
|
||||
*/
|
||||
function(feature) {
|
||||
features.push(feature);
|
||||
}, this);
|
||||
|
||||
@@ -289,17 +289,6 @@ ol.Extent;
|
||||
ol.FeatureLoader;
|
||||
|
||||
|
||||
/**
|
||||
* A function that returns an array of {@link ol.style.Style styles} given a
|
||||
* resolution. The `this` keyword inside the function references the
|
||||
* {@link ol.Feature} to be styled.
|
||||
*
|
||||
* @typedef {function(this: ol.Feature, number):
|
||||
* (ol.style.Style|Array.<ol.style.Style>)}
|
||||
*/
|
||||
ol.FeatureStyleFunction;
|
||||
|
||||
|
||||
/**
|
||||
* {@link ol.source.Vector} sources use a function of this type to get the url
|
||||
* to load features from.
|
||||
|
||||
Reference in New Issue
Block a user