Merge pull request #28171 from gberaudo/fix_style_function_and_nullability

OpenLayers: fix style function and nullability
This commit is contained in:
Daniel Rosenwasser
2018-08-21 13:56:15 -07:00
committed by GitHub
2 changed files with 20 additions and 7 deletions
+8 -7
View File
@@ -9,6 +9,7 @@
// Yair Tawil <https://github.com/yairtawil>
// Pierre Marchand <https://github.com/pierremarc>
// Hauke Stieler <https://github.com/hauke96>
// Guillaume Beraudo <https://github.com/gberaudo>
// 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
+12
View File
@@ -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
//