From 589666cc2b65fc884d66fed78f34ac05cf7b33b8 Mon Sep 17 00:00:00 2001 From: Guillaume Beraudo Date: Thu, 16 Aug 2018 11:48:03 +0200 Subject: [PATCH 1/3] Accept null styles When a style is null, OpenLayers does not render the associated feature. --- types/openlayers/index.d.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/types/openlayers/index.d.ts b/types/openlayers/index.d.ts index 37cac7e65d..70af9ba081 100644 --- a/types/openlayers/index.d.ts +++ b/types/openlayers/index.d.ts @@ -1715,7 +1715,7 @@ export class Feature extends Object { * representing the current style of this feature. * @api stable */ - getStyleFunction(): (ol.FeatureStyleFunction); + getStyleFunction(): (ol.FeatureStyleFunction | undefined); /** * Set the default geometry for the feature. This will update the property @@ -6412,7 +6412,7 @@ export namespace layer { * @return Layer style function. * @api stable */ - getStyleFunction(): (ol.StyleFunction); + getStyleFunction(): (ol.StyleFunction | undefined); /** * Set the style for features. This can be a single style object, an array @@ -6424,7 +6424,7 @@ export namespace layer { * @param style Layer style. * @api stable */ - setStyle(style: (ol.style.Style | ol.style.Style[] | ol.StyleFunction | null)): void; + setStyle(style: (ol.style.Style | ol.style.Style[] | ol.StyleFunction | null | undefined)): void; } /** @@ -8472,7 +8472,7 @@ export namespace source { * @return Layer style function. * @api stable */ - getStyleFunction(): (ol.StyleFunction); + getStyleFunction(): (ol.StyleFunction | undefined); /** * Set the style for features. This can be a single style object, an array @@ -8484,7 +8484,7 @@ export namespace source { * @param style Layer style. * @api stable */ - setStyle(style: (ol.style.Style | ol.style.Style[] | ol.StyleFunction)): void; + setStyle(style: (ol.style.Style | ol.style.Style[] | ol.StyleFunction | null | undefined)): void; } /** @@ -10831,7 +10831,7 @@ export type FeatureLoader = (extent: ol.Extent, resolution: number, proj: ol.pro * {@link ol.Feature} to be styled. * */ -export type FeatureStyleFunction = (resolution: number) => (ol.style.Style | ol.style.Style[]); +export type FeatureStyleFunction = (resolution: number) => (ol.style.Style | ol.style.Style[] | null); /** * {@link ol.source.Vector} sources use a function of this type to get the url @@ -10981,7 +10981,7 @@ export interface StyleImageOptions { * or an array of them. This way e.g. a vector layer can be styled. * */ -export type StyleFunction = (feature: (ol.Feature | ol.render.Feature), resolution: number) => (ol.style.Style | ol.style.Style[]); +export type StyleFunction = (feature: (ol.Feature | ol.render.Feature), resolution: number) => (ol.style.Style | ol.style.Style[] | null); /** * A function that takes an {@link ol.Feature} as argument and returns an From 991d316a389abc66fc2c1c8abde5ecb170cee22e Mon Sep 17 00:00:00 2001 From: Guillaume Beraudo Date: Thu, 16 Aug 2018 13:54:12 +0200 Subject: [PATCH 2/3] Add tests --- types/openlayers/openlayers-tests.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/types/openlayers/openlayers-tests.ts b/types/openlayers/openlayers-tests.ts index 6e28ad4cd2..d631a9e9bb 100644 --- a/types/openlayers/openlayers-tests.ts +++ b/types/openlayers/openlayers-tests.ts @@ -418,6 +418,14 @@ feature.setStyle(styleArray); feature.setStyle(featureStyleFunction); feature.setStyle(styleFunction); feature.setProperties(object); +const nullStyleFunction = (feature: (ol.Feature|ol.render.Feature), resolution: number): null => { + return null; +}; +const nullFeatureStyleFunction = (resolution: number): null => { + return null; +}; +feature.setStyle(nullStyleFunction); +feature.setStyle(nullFeatureStyleFunction); // // ol.View @@ -573,6 +581,10 @@ const vectorLayer: ol.layer.Vector = new ol.layer.Vector({ zIndex: -1 }); +vectorLayer.setStyle(nullStyleFunction); +vectorLayer.setStyle(null); +vectorLayer.setStyle(undefined); + // // ol.layer.VectorTile // From 10dc37c95dfb92b7ab01bee928b7f590ff663c26 Mon Sep 17 00:00:00 2001 From: Guillaume Beraudo Date: Thu, 16 Aug 2018 11:54:43 +0200 Subject: [PATCH 3/3] Add myself to Definitions by to get notified of the changes --- types/openlayers/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/openlayers/index.d.ts b/types/openlayers/index.d.ts index 70af9ba081..3214bad15c 100644 --- a/types/openlayers/index.d.ts +++ b/types/openlayers/index.d.ts @@ -9,6 +9,7 @@ // Yair Tawil // Pierre Marchand // Hauke Stieler +// Guillaume Beraudo // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // Definitions partially generated using tsd-jsdoc (https://github.com/englercj/tsd-jsdoc)