Skip to content

Commit

Permalink
fix(overlay): fix errors when trying to overlay a feature withotu geo…
Browse files Browse the repository at this point in the history
…metry
  • Loading branch information
cbourget authored and mbarbeau committed May 1, 2017
1 parent 29ba202 commit 81407e6
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/lib/overlay/shared/overlay.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down

0 comments on commit 81407e6

Please sign in to comment.