diff --git a/types/openlayers/index.d.ts b/types/openlayers/index.d.ts index 37cac7e65d..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) @@ -1715,7 +1716,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 +6413,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 +6425,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 +8473,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 +8485,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 +10832,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 +10982,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 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 //