Skip to content

Commit

Permalink
feat(view): add zoom change output
Browse files Browse the repository at this point in the history
  • Loading branch information
Aymeric Duchein authored and Neonox31 committed Oct 17, 2018
1 parent ba78923 commit 1ab3ac1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 7 additions & 2 deletions projects/ngx-openlayers/src/lib/view.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, Input, OnInit, OnChanges, OnDestroy, SimpleChanges } from '@angular/core';
import { View, Extent, Coordinate } from 'openlayers';
import { Component, Input, OnInit, OnChanges, OnDestroy, SimpleChanges, EventEmitter, Output } from '@angular/core';
import { View, Extent, ObjectEvent, Coordinate } from 'openlayers';
import { MapComponent } from './map.component';

@Component({
Expand Down Expand Up @@ -42,12 +42,17 @@ export class ViewComponent implements OnInit, OnChanges, OnDestroy {
@Input()
zoomAnimation = false;

@Output()
onChangeZoom: EventEmitter<ObjectEvent> = new EventEmitter<ObjectEvent>();

constructor(private host: MapComponent) {}

ngOnInit() {
// console.log('creating ol.View instance with: ', this);
this.instance = new View(this);
this.host.instance.setView(this.instance);

this.instance.on('change:zoom', (event: ObjectEvent) => this.onChangeZoom.emit(event));
}

ngOnChanges(changes: SimpleChanges) {
Expand Down
6 changes: 5 additions & 1 deletion src/app/basic/basic.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Component } from '@angular/core';
selector: 'app-root',
template: `
<aol-map [width]="'100%'" [height]="'100%'">
<aol-view [zoom]="zoom">
<aol-view [zoom]="zoom" (onChangeZoom)="onChangeZoom($event)">
<aol-coordinate [x]="5" [y]="45" [srid]="'EPSG:4326'"></aol-coordinate>
</aol-view>
<aol-layer-tile [opacity]="opacity">
Expand Down Expand Up @@ -86,4 +86,8 @@ export class BasicComponent {
this.opacity = Math.max(this.opacity - 0.1, 0);
console.log('opacity: ', this.opacity);
}

onChangeZoom(evt) {
console.log('Zoom changed:', evt);
}
}

0 comments on commit 1ab3ac1

Please sign in to comment.