Skip to content

Commit

Permalink
Support function in geometries:
Browse files Browse the repository at this point in the history
- Issue : in some cases, the style.getGeometry() function would return a function rather than an object, causing issues when trying to set the geometry later in the code as we were calling geometry(undefined) instead of geometry(feature).

- Fix : we check that the geometry is either an object, or a function which returns a non-null / non-undefined value, and we also use the function the geometry contains when it's not an Object.
  • Loading branch information
ltkum committed Oct 17, 2024
1 parent 16c2d3f commit 6b5e7cf
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/VectorEncoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,17 @@ export default class VectorEncoder {
// handling more cases than we actually do
let geometry: any = style.getGeometry();
let geojsonFeature;
if (geometry) {
// In some cases, the geometries are objects, in other cases they're features.
// We need to make sure that either the geometry is an object, or that the feature it contains returns
// a non-null / non-undefined value.
if (geometry && ((geometry instanceof Object && typeof geometry === 'object') || geometry(feature))) {
const styledFeature = feature.clone();
styledFeature.setGeometry(geometry);
if (geometry instanceof Object && typeof geometry === 'object') {
styledFeature.setGeometry(geometry);
}
else {
styledFeature.setGeometry(geometry(feature));
}
geojsonFeature = this.geojsonFormat.writeFeatureObject(styledFeature);
geojsonFeatures.push(geojsonFeature);
} else {
Expand Down

0 comments on commit 6b5e7cf

Please sign in to comment.