Skip to content

Commit 1ab3ac1

Browse files
Aymeric DucheinNeonox31
Aymeric Duchein
authored andcommitted
feat(view): add zoom change output
1 parent ba78923 commit 1ab3ac1

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

projects/ngx-openlayers/src/lib/view.component.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Component, Input, OnInit, OnChanges, OnDestroy, SimpleChanges } from '@angular/core';
2-
import { View, Extent, Coordinate } from 'openlayers';
1+
import { Component, Input, OnInit, OnChanges, OnDestroy, SimpleChanges, EventEmitter, Output } from '@angular/core';
2+
import { View, Extent, ObjectEvent, Coordinate } from 'openlayers';
33
import { MapComponent } from './map.component';
44

55
@Component({
@@ -42,12 +42,17 @@ export class ViewComponent implements OnInit, OnChanges, OnDestroy {
4242
@Input()
4343
zoomAnimation = false;
4444

45+
@Output()
46+
onChangeZoom: EventEmitter<ObjectEvent> = new EventEmitter<ObjectEvent>();
47+
4548
constructor(private host: MapComponent) {}
4649

4750
ngOnInit() {
4851
// console.log('creating ol.View instance with: ', this);
4952
this.instance = new View(this);
5053
this.host.instance.setView(this.instance);
54+
55+
this.instance.on('change:zoom', (event: ObjectEvent) => this.onChangeZoom.emit(event));
5156
}
5257

5358
ngOnChanges(changes: SimpleChanges) {

src/app/basic/basic.component.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Component } from '@angular/core';
44
selector: 'app-root',
55
template: `
66
<aol-map [width]="'100%'" [height]="'100%'">
7-
<aol-view [zoom]="zoom">
7+
<aol-view [zoom]="zoom" (onChangeZoom)="onChangeZoom($event)">
88
<aol-coordinate [x]="5" [y]="45" [srid]="'EPSG:4326'"></aol-coordinate>
99
</aol-view>
1010
<aol-layer-tile [opacity]="opacity">
@@ -86,4 +86,8 @@ export class BasicComponent {
8686
this.opacity = Math.max(this.opacity - 0.1, 0);
8787
console.log('opacity: ', this.opacity);
8888
}
89+
90+
onChangeZoom(evt) {
91+
console.log('Zoom changed:', evt);
92+
}
8993
}

0 commit comments

Comments
 (0)