Allow style function to return a style
This commit is contained in:
@@ -290,7 +290,8 @@ ol.Feature.prototype.setGeometryName = function(name) {
|
|||||||
* resolution. The `this` keyword inside the function references the
|
* resolution. The `this` keyword inside the function references the
|
||||||
* {@link ol.Feature} to be styled.
|
* {@link ol.Feature} to be styled.
|
||||||
*
|
*
|
||||||
* @typedef {function(this: ol.Feature, number): Array.<ol.style.Style>}
|
* @typedef {function(this: ol.Feature, number):
|
||||||
|
* (ol.style.Style|Array.<ol.style.Style>)}
|
||||||
* @api stable
|
* @api stable
|
||||||
*/
|
*/
|
||||||
ol.FeatureStyleFunction;
|
ol.FeatureStyleFunction;
|
||||||
|
|||||||
@@ -321,7 +321,8 @@ 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 {Array.<ol.style.Style>} styles Array of styles
|
* @param {(ol.style.Style|Array.<ol.style.Style>)} styles The style or array of
|
||||||
|
* styles.
|
||||||
* @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.
|
||||||
*/
|
*/
|
||||||
@@ -330,12 +331,19 @@ ol.renderer.canvas.VectorLayer.prototype.renderFeature =
|
|||||||
if (!styles) {
|
if (!styles) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var i, ii, loading = false;
|
var loading = false;
|
||||||
for (i = 0, ii = styles.length; i < ii; ++i) {
|
if (goog.isArray(styles)) {
|
||||||
|
for (var i = 0, ii = styles.length; i < ii; ++i) {
|
||||||
loading = ol.renderer.vector.renderFeature(
|
loading = ol.renderer.vector.renderFeature(
|
||||||
replayGroup, feature, styles[i],
|
replayGroup, feature, styles[i],
|
||||||
ol.renderer.vector.getSquaredTolerance(resolution, pixelRatio),
|
ol.renderer.vector.getSquaredTolerance(resolution, pixelRatio),
|
||||||
this.handleStyleImageChange_, this) || loading;
|
this.handleStyleImageChange_, this) || loading;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
loading = ol.renderer.vector.renderFeature(
|
||||||
|
replayGroup, feature, styles,
|
||||||
|
ol.renderer.vector.getSquaredTolerance(resolution, pixelRatio),
|
||||||
|
this.handleStyleImageChange_, this) || loading;
|
||||||
|
}
|
||||||
return loading;
|
return loading;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -201,13 +201,20 @@ ol.renderer.canvas.VectorTileLayer.prototype.createReplayGroup = function(tile,
|
|||||||
*/
|
*/
|
||||||
function renderFeature(feature) {
|
function renderFeature(feature) {
|
||||||
var styles;
|
var styles;
|
||||||
if (feature.getStyleFunction()) {
|
var styleFunction = feature.getStyleFunction();
|
||||||
|
if (styleFunction) {
|
||||||
goog.asserts.assertInstanceof(feature, ol.Feature, 'Got an ol.Feature');
|
goog.asserts.assertInstanceof(feature, ol.Feature, 'Got an ol.Feature');
|
||||||
styles = feature.getStyleFunction().call(feature, resolution);
|
styles = styleFunction.call(feature, resolution);
|
||||||
} else if (layer.getStyleFunction()) {
|
} else {
|
||||||
styles = layer.getStyleFunction()(feature, resolution);
|
styleFunction = layer.getStyleFunction();
|
||||||
|
if (styleFunction) {
|
||||||
|
styles = styleFunction(feature, resolution);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (styles) {
|
if (styles) {
|
||||||
|
if (!goog.isArray(styles)) {
|
||||||
|
styles = [styles];
|
||||||
|
}
|
||||||
var dirty = this.renderFeature(feature, squaredTolerance, styles,
|
var dirty = this.renderFeature(feature, squaredTolerance, styles,
|
||||||
replayGroup);
|
replayGroup);
|
||||||
this.dirty_ = this.dirty_ || dirty;
|
this.dirty_ = this.dirty_ || dirty;
|
||||||
@@ -423,7 +430,8 @@ ol.renderer.canvas.VectorTileLayer.prototype.prepareFrame =
|
|||||||
/**
|
/**
|
||||||
* @param {ol.Feature|ol.render.Feature} feature Feature.
|
* @param {ol.Feature|ol.render.Feature} feature Feature.
|
||||||
* @param {number} squaredTolerance Squared tolerance.
|
* @param {number} squaredTolerance Squared tolerance.
|
||||||
* @param {Array.<ol.style.Style>} styles Array of styles
|
* @param {(ol.style.Style|Array.<ol.style.Style>)} styles The style or array of
|
||||||
|
* styles.
|
||||||
* @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.
|
||||||
*/
|
*/
|
||||||
@@ -432,11 +440,17 @@ ol.renderer.canvas.VectorTileLayer.prototype.renderFeature =
|
|||||||
if (!styles) {
|
if (!styles) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var i, ii, loading = false;
|
var loading = false;
|
||||||
for (i = 0, ii = styles.length; i < ii; ++i) {
|
if (goog.isArray(styles)) {
|
||||||
|
for (var i = 0, ii = styles.length; i < ii; ++i) {
|
||||||
loading = ol.renderer.vector.renderFeature(
|
loading = ol.renderer.vector.renderFeature(
|
||||||
replayGroup, feature, styles[i], squaredTolerance,
|
replayGroup, feature, styles[i], squaredTolerance,
|
||||||
this.handleStyleImageChange_, this) || loading;
|
this.handleStyleImageChange_, this) || loading;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
loading = ol.renderer.vector.renderFeature(
|
||||||
|
replayGroup, feature, styles, squaredTolerance,
|
||||||
|
this.handleStyleImageChange_, this) || loading;
|
||||||
|
}
|
||||||
return loading;
|
return loading;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -329,7 +329,8 @@ ol.renderer.dom.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 {Array.<ol.style.Style>} styles Array of styles
|
* @param {(ol.style.Style|Array.<ol.style.Style>)} styles The style or array of
|
||||||
|
* styles.
|
||||||
* @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.
|
||||||
*/
|
*/
|
||||||
@@ -338,12 +339,19 @@ ol.renderer.dom.VectorLayer.prototype.renderFeature =
|
|||||||
if (!styles) {
|
if (!styles) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var i, ii, loading = false;
|
var loading = false;
|
||||||
for (i = 0, ii = styles.length; i < ii; ++i) {
|
if (goog.isArray(styles)) {
|
||||||
|
for (var i = 0, ii = styles.length; i < ii; ++i) {
|
||||||
loading = ol.renderer.vector.renderFeature(
|
loading = ol.renderer.vector.renderFeature(
|
||||||
replayGroup, feature, styles[i],
|
replayGroup, feature, styles[i],
|
||||||
ol.renderer.vector.getSquaredTolerance(resolution, pixelRatio),
|
ol.renderer.vector.getSquaredTolerance(resolution, pixelRatio),
|
||||||
this.handleStyleImageChange_, this) || loading;
|
this.handleStyleImageChange_, this) || loading;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
loading = ol.renderer.vector.renderFeature(
|
||||||
|
replayGroup, feature, styles,
|
||||||
|
ol.renderer.vector.getSquaredTolerance(resolution, pixelRatio),
|
||||||
|
this.handleStyleImageChange_, this) || loading;
|
||||||
|
}
|
||||||
return loading;
|
return loading;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -297,7 +297,8 @@ ol.renderer.webgl.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 {Array.<ol.style.Style>} styles Array of styles
|
* @param {(ol.style.Style|Array.<ol.style.Style>)} styles The style or array of
|
||||||
|
* styles.
|
||||||
* @param {ol.render.webgl.ReplayGroup} replayGroup Replay group.
|
* @param {ol.render.webgl.ReplayGroup} replayGroup Replay group.
|
||||||
* @return {boolean} `true` if an image is loading.
|
* @return {boolean} `true` if an image is loading.
|
||||||
*/
|
*/
|
||||||
@@ -306,12 +307,19 @@ ol.renderer.webgl.VectorLayer.prototype.renderFeature =
|
|||||||
if (!styles) {
|
if (!styles) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var i, ii, loading = false;
|
var loading = false;
|
||||||
for (i = 0, ii = styles.length; i < ii; ++i) {
|
if (goog.isArray(styles)) {
|
||||||
|
for (var i = 0, ii = styles.length; i < ii; ++i) {
|
||||||
loading = ol.renderer.vector.renderFeature(
|
loading = ol.renderer.vector.renderFeature(
|
||||||
replayGroup, feature, styles[i],
|
replayGroup, feature, styles[i],
|
||||||
ol.renderer.vector.getSquaredTolerance(resolution, pixelRatio),
|
ol.renderer.vector.getSquaredTolerance(resolution, pixelRatio),
|
||||||
this.handleStyleImageChange_, this) || loading;
|
this.handleStyleImageChange_, this) || loading;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
loading = ol.renderer.vector.renderFeature(
|
||||||
|
replayGroup, feature, styles,
|
||||||
|
ol.renderer.vector.getSquaredTolerance(resolution, pixelRatio),
|
||||||
|
this.handleStyleImageChange_, this) || loading;
|
||||||
|
}
|
||||||
return loading;
|
return loading;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -199,7 +199,7 @@ ol.style.Style.prototype.setZIndex = function(zIndex) {
|
|||||||
* {@link ol.style.Style}. This way e.g. a vector layer can be styled.
|
* {@link ol.style.Style}. This way e.g. a vector layer can be styled.
|
||||||
*
|
*
|
||||||
* @typedef {function((ol.Feature|ol.render.Feature), number):
|
* @typedef {function((ol.Feature|ol.render.Feature), number):
|
||||||
* Array.<ol.style.Style>}
|
* (ol.style.Style|Array.<ol.style.Style>)}
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
ol.style.StyleFunction;
|
ol.style.StyleFunction;
|
||||||
|
|||||||
Reference in New Issue
Block a user