Skip to content

Commit

Permalink
feat(igo-toast) provite zoom to feature for mobile devices
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Étienne Lord authored and mbarbeau committed Oct 17, 2018
1 parent 09c2d36 commit 5de0afb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions projects/geo/src/lib/toast/toast.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
</mat-icon>
</button>

<button mat-icon-button panelRightButton class="igo-icon-button" (click)="zoomToFeatureExtent()" *ngIf="feature.geometry">
<mat-icon>zoom_in</mat-icon>
</button>

<igo-feature-details [feature]="feature"></igo-feature-details>
</igo-panel>

Expand Down
22 changes: 22 additions & 0 deletions projects/geo/src/lib/toast/toast.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Component, Input, Output, EventEmitter } from '@angular/core';

import { FlexibleState } from '@igo2/common';
import olFormatGeoJSON from 'ol/format/GeoJSON';
import { Feature } from '../feature/shared/feature.interface';
import { IgoMap } from '../map/shared/map';

@Component({
selector: 'igo-toast',
Expand All @@ -13,6 +15,7 @@ export class ToastComponent {
UP: 'swipeup',
DOWN: 'swipedown'
};
private format = new olFormatGeoJSON();

@Input()
get expanded(): boolean {
Expand All @@ -24,6 +27,15 @@ export class ToastComponent {
}
private _expanded: boolean;

@Input()
get map(): IgoMap {
return this._map;
}
set map(value: IgoMap) {
this._map = value;
}
private _map: IgoMap;

@Input()
get feature(): Feature {
return this._feature;
Expand All @@ -44,6 +56,16 @@ export class ToastComponent {
this.opened.emit(this.expanded);
}

zoomToFeatureExtent() {
if (this.feature.geometry) {
const olFeature = this.format.readFeature(this.feature, {
dataProjection: this.feature.projection,
featureProjection: this.map.projection
});
this.map.zoomToFeature(olFeature);
}
}

swipe(action: string) {
if (action === ToastComponent.SWIPE_ACTION.UP) {
if (!this.expanded) {
Expand Down

0 comments on commit 5de0afb

Please sign in to comment.