Skip to content

Commit

Permalink
Merge pull request #40 from ltkum/main
Browse files Browse the repository at this point in the history
Support function in geometries:
  • Loading branch information
gberaudo authored Nov 4, 2024
2 parents 16c2d3f + 37d6736 commit d306253
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions src/VectorEncoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,26 +187,31 @@ export default class VectorEncoder {
// handling more cases than we actually do
let geometry: any = style.getGeometry();
let geojsonFeature;
if (geometry) {
const styledFeature = feature.clone();
styledFeature.setGeometry(geometry);
geojsonFeature = this.geojsonFormat.writeFeatureObject(styledFeature);
geojsonFeatures.push(geojsonFeature);
} else {
geojsonFeature = origGeojsonFeature;
geometry = feature.getGeometry();
// no need to encode features with no geometry
if (!geometry) {
return;
}
if (!this.customizer_.geometryFilter(geometry)) {
return;
// In some cases, the geometries are objects, in other cases they're functions.
// we need to ensure we're handling functions, wether they return an object or not.
if (typeof geometry === 'function') {
geometry = geometry(feature);
}
if (!isOriginalFeatureAdded) {
if (typeof geometry === 'object') {
const styledFeature = feature.clone();
styledFeature.setGeometry(geometry);
geojsonFeature = this.geojsonFormat.writeFeatureObject(styledFeature);
geojsonFeatures.push(geojsonFeature);
isOriginalFeatureAdded = true;
} else {
geojsonFeature = origGeojsonFeature;
geometry = feature.getGeometry();
// no need to encode features with no geometry
if (!geometry) {
return;
}
if (!this.customizer_.geometryFilter(geometry)) {
return;
}
if (!isOriginalFeatureAdded) {
geojsonFeatures.push(geojsonFeature);
isOriginalFeatureAdded = true;
}
}
}

this.addVectorStyle(mapfishStyleObject, geojsonFeature, style);
});
Expand Down

0 comments on commit d306253

Please sign in to comment.