From 81407e688ff8c42b0c937cc58f41ed059e13cba5 Mon Sep 17 00:00:00 2001 From: cbourget Date: Mon, 1 May 2017 10:31:53 -0400 Subject: [PATCH] fix(overlay): fix errors when trying to overlay a feature withotu geometry --- src/lib/overlay/shared/overlay.directive.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/lib/overlay/shared/overlay.directive.ts b/src/lib/overlay/shared/overlay.directive.ts index 3cec5acc65..a05e9aae21 100644 --- a/src/lib/overlay/shared/overlay.directive.ts +++ b/src/lib/overlay/shared/overlay.directive.ts @@ -75,31 +75,37 @@ export class OverlayDirective implements OnInit, OnDestroy { const extent = ol.extent.createEmpty(); - let featureExtent; + let featureExtent, geometry; features.forEach((feature: Feature) => { const olFeature = this.format.readFeature(feature, { dataProjection: feature.projection, featureProjection: this.map.projection }); + geometry = olFeature.getGeometry(); featureExtent = this.getFeatureExtent(feature); if (ol.extent.isEmpty(featureExtent)) { - featureExtent = olFeature.getGeometry().getExtent(); + if (geometry !== null) { + featureExtent = geometry.getExtent(); + } } ol.extent.extend(extent, featureExtent); this.addMarker(olFeature); }, this); - if (action === 'zoom') { - this.map.zoomToExtent(extent); - } else if (action === 'move') { - this.map.moveToExtent(extent); + if (!ol.extent.isEmpty(featureExtent)) { + if (action === 'zoom') { + this.map.zoomToExtent(extent); + } else if (action === 'move') { + this.map.moveToExtent(extent); + } } } private addMarker(feature: ol.Feature) { const geometry = feature.getGeometry(); + if (geometry === null) { return; } let marker; if (geometry.getType() === 'Point') {