From 04bc9ff0df041656ed2268de6290de091d0c64e7 Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Thu, 11 Jun 2020 13:52:50 +0200 Subject: [PATCH] Improve types and docs for getStyle/setStyle --- src/ol/Feature.js | 19 +++++++++++-------- src/ol/interaction/Select.js | 7 ++++--- src/ol/layer/BaseVector.js | 22 +++++++++++----------- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/ol/Feature.js b/src/ol/Feature.js index 590094057f..e636bb4b40 100644 --- a/src/ol/Feature.js +++ b/src/ol/Feature.js @@ -178,7 +178,7 @@ class Feature extends BaseObject { /** * Get the feature's style. Will return what was provided to the * {@link module:ol/Feature~Feature#setStyle} method. - * @return {import("./style/Style.js").StyleLike} The feature style. + * @return {import("./style/Style.js").StyleLike|undefined} The feature style. * @api */ getStyle() { @@ -234,16 +234,19 @@ class Feature extends BaseObject { } /** - * 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 {import("./style/Style.js").StyleLike} style Style for this feature. + * Set the style for the feature to override the layer style. This can be a + * single style object, an array of styles, or a function that takes a + * resolution and returns an array of styles. To unset the feature style, call + * `setStyle()` without arguments or a falsey value. + * @param {import("./style/Style.js").StyleLike=} opt_style Style for this feature. * @api * @fires module:ol/events/Event~BaseEvent#event:change */ - setStyle(style) { - this.style_ = style; - this.styleFunction_ = !style ? undefined : createStyleFunction(style); + setStyle(opt_style) { + this.style_ = opt_style; + this.styleFunction_ = !opt_style + ? undefined + : createStyleFunction(opt_style); this.changed(); } diff --git a/src/ol/interaction/Select.js b/src/ol/interaction/Select.js index 82addd7c35..4d35046606 100644 --- a/src/ol/interaction/Select.js +++ b/src/ol/interaction/Select.js @@ -55,9 +55,10 @@ const SelectEventType = { * in the map and should return `true` for layers that you want to be * selectable. If the option is absent, all visible layers will be considered * selectable. - * @property {import("../style/Style.js").StyleLike} [style] + * @property {import("../style/Style.js").StyleLike|null} [style] * Style for the selected features. By default the default edit style is used - * (see {@link module:ol/style}). + * (see {@link module:ol/style}). Set to `null` if this interaction should not apply + * any style changes for selected features. * If set to a falsey value, the selected feature's style will not change. * @property {import("../events/condition.js").Condition} [removeCondition] A function * that takes an {@link module:ol/MapBrowserEvent~MapBrowserEvent} and returns a @@ -367,7 +368,7 @@ class Select extends Interaction { } /** - * @return {import("../style/Style.js").default|Array.|import("../style/Style.js").StyleFunction|null} Select style. + * @return {import("../style/Style.js").StyleLike|null} Select style. */ getStyle() { return this.style_; diff --git a/src/ol/layer/BaseVector.js b/src/ol/layer/BaseVector.js index cf0a0ff891..c0562bed93 100644 --- a/src/ol/layer/BaseVector.js +++ b/src/ol/layer/BaseVector.js @@ -43,8 +43,9 @@ import { * is defined by the z-index of the layer, the `zIndex` of the style and the render order of features. * Higher z-index means higher priority. Within the same z-index, a feature rendered before another has * higher priority. - * @property {import("../style/Style.js").StyleLike} [style] Layer style. See - * {@link module:ol/style} for default style which will be used if this is not defined. + * @property {import("../style/Style.js").StyleLike|null} [style] Layer style. When set to `null`, only + * features that have their own style will be rendered. See {@link module:ol/style} for default style + * which will be used if this is not set. * @property {boolean} [updateWhileAnimating=false] When set to `true`, feature batches will * be recreated during animations. This means that no vectors will be shown clipped, but the * setting will have a performance impact for large amounts of vector data. When set to `false`, @@ -181,8 +182,7 @@ class BaseVectorLayer extends Layer { /** * Get the style for features. This returns whatever was passed to the `style` * option at construction or to the `setStyle` method. - * @return {import("../style/Style.js").StyleLike} - * Layer style. + * @return {import("../style/Style.js").StyleLike|null|undefined} Layer style. * @api */ getStyle() { @@ -225,17 +225,17 @@ class BaseVectorLayer extends Layer { /** * 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. If it is `undefined` the default style is used. If - * it is `null` the layer has no style (a `null` style), so only features - * that have their own styles will be rendered in the layer. See + * an array of styles. If set to `null`, the layer has no style (a `null` style), + * so only features that have their own styles will be rendered in the layer. Call + * `setStyle()` without arguments to reset to the default style. See * {@link module:ol/style} for information on the default style. - * @param {import("../style/Style.js").default|Array|import("../style/Style.js").StyleFunction|null|undefined} style Layer style. + * @param {(import("../style/Style.js").StyleLike|null)=} opt_style Layer style. * @api */ - setStyle(style) { - this.style_ = style !== undefined ? style : createDefaultStyle; + setStyle(opt_style) { + this.style_ = opt_style !== undefined ? opt_style : createDefaultStyle; this.styleFunction_ = - style === null ? undefined : toStyleFunction(this.style_); + opt_style === null ? undefined : toStyleFunction(this.style_); this.changed(); } }