diff --git a/src/VectorEncoder.ts b/src/VectorEncoder.ts index d65973d..4b2cbeb 100644 --- a/src/VectorEncoder.ts +++ b/src/VectorEncoder.ts @@ -187,34 +187,31 @@ export default class VectorEncoder { // handling more cases than we actually do let geometry: any = style.getGeometry(); let geojsonFeature; - // 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 && ((typeof geometry === 'object' && geometry instanceof Object) || (typeof geometry === 'function' && geometry(feature))) { - const styledFeature = feature.clone(); - if (geometry instanceof Object && typeof geometry === 'object') { - styledFeature.setGeometry(geometry); - } - else { - styledFeature.setGeometry(geometry(feature)); - } - 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); });