Skip to content

Commit 27b1529

Browse files
Aymeric DucheinNeonox31
authored andcommitted
feat(view): add change:resolution and change:center outputs
1 parent 0ed47a3 commit 27b1529

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,15 @@ export class ViewComponent implements OnInit, OnChanges, OnDestroy {
4343
center: Coordinate;
4444
@Input()
4545
projection: string;
46-
4746
@Input()
4847
zoomAnimation = false;
4948

5049
@Output()
5150
onChangeZoom: EventEmitter<ObjectEvent> = new EventEmitter<ObjectEvent>();
51+
@Output()
52+
onChangeResolution: EventEmitter<ObjectEvent> = new EventEmitter<ObjectEvent>();
53+
@Output()
54+
onChangeCenter: EventEmitter<ObjectEvent> = new EventEmitter<ObjectEvent>();
5255

5356
constructor(private host: MapComponent) {}
5457

@@ -58,6 +61,8 @@ export class ViewComponent implements OnInit, OnChanges, OnDestroy {
5861
this.host.instance.setView(this.instance);
5962

6063
this.instance.on('change:zoom', (event: ObjectEvent) => this.onChangeZoom.emit(event));
64+
this.instance.on('change:resolution', (event: ObjectEvent) => this.onChangeResolution.emit(event));
65+
this.instance.on('change:center', (event: ObjectEvent) => this.onChangeCenter.emit(event));
6166
}
6267

6368
ngOnChanges(changes: SimpleChanges) {

src/app/basic/basic.component.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ import { Component } from '@angular/core';
44
selector: 'app-root',
55
template: `
66
<aol-map [width]="'100%'" [height]="'100%'">
7-
<aol-view [zoom]="zoom" (onChangeZoom)="onChangeZoom($event)">
7+
<aol-view
8+
[zoom]="zoom"
9+
(onChangeResolution)="onChangeResolution($event)"
10+
(onChangeZoom)="onChangeZoom($event)"
11+
(onChangeCenter)="onChangeCenter($event)"
12+
>
813
<aol-coordinate [x]="5" [y]="45" [srid]="'EPSG:4326'"></aol-coordinate>
914
</aol-view>
1015
<aol-layer-tile [opacity]="opacity"> <aol-source-osm></aol-source-osm> </aol-layer-tile>
@@ -44,6 +49,8 @@ import { Component } from '@angular/core';
4449
<span>opacity:</span><button (click)="increaseOpacity()">+</button><button (click)="decreaseOpacity()">-</button
4550
><br />
4651
<span>zoom:</span><button (click)="increaseZoom()">+</button><button (click)="decreaseZoom()">-</button><br />
52+
<span>latitude:</span><button (click)="increaseLat()">+</button><button (click)="decreaseLat()">-</button><br />
53+
<span>longitude:</span><button (click)="increaseLon()">+</button><button (click)="decreaseLon()">-</button><br />
4754
</div>
4855
`,
4956
styles: [
@@ -67,6 +74,8 @@ export class BasicComponent {
6774
public zoom = 15;
6875
public opacity = 1.0;
6976
public width = 5;
77+
public lon = 5;
78+
public lat = 45;
7079

7180
increaseZoom() {
7281
this.zoom = Math.min(this.zoom + 1, 18);
@@ -78,6 +87,26 @@ export class BasicComponent {
7887
console.log('zoom: ', this.zoom);
7988
}
8089

90+
increaseLat() {
91+
this.lat = Math.max(-90, Math.min(90, this.lat + 1));
92+
console.log('lat: ', this.lat);
93+
}
94+
95+
decreaseLat() {
96+
this.lat = Math.max(-90, Math.min(90, this.lat - 1));
97+
console.log('lat: ', this.lat);
98+
}
99+
100+
increaseLon() {
101+
this.lon = Math.max(-180, Math.min(180, this.lat + 1));
102+
console.log('lon: ', this.lon);
103+
}
104+
105+
decreaseLon() {
106+
this.lon = Math.max(-180, Math.min(180, this.lat - 1));
107+
console.log('lon: ', this.lon);
108+
}
109+
81110
increaseOpacity() {
82111
this.opacity = Math.min(this.opacity + 0.1, 1);
83112
console.log('opacity: ', this.opacity);
@@ -88,6 +117,14 @@ export class BasicComponent {
88117
console.log('opacity: ', this.opacity);
89118
}
90119

120+
onChangeResolution(evt) {
121+
console.log('Resolution changed:', evt);
122+
}
123+
124+
onChangeCenter(evt) {
125+
console.log('Center changed:', evt);
126+
}
127+
91128
onChangeZoom(evt) {
92129
console.log('Zoom changed:', evt);
93130
}

0 commit comments

Comments
 (0)