Skip to content

Commit 4dc9852

Browse files
samuel-girardNeonox31
authored andcommitted
feat(overviewmap): refresh overview when the view changes
1 parent 3f0c228 commit 4dc9852

File tree

5 files changed

+44
-6
lines changed

5 files changed

+44
-6
lines changed

projects/ngx-openlayers/src/lib/controls/overviewmap.component.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, Input, OnDestroy, OnInit } from '@angular/core';
1+
import { Component, Input, OnDestroy, OnInit, OnChanges, SimpleChanges } from '@angular/core';
22
import { Layer } from 'ol/layer';
33
import { View } from 'ol';
44
import { OverviewMap } from 'ol/control';
@@ -10,7 +10,7 @@ import { MapComponent } from '../map.component';
1010
<ng-content></ng-content>
1111
`,
1212
})
13-
export class ControlOverviewMapComponent implements OnInit, OnDestroy {
13+
export class ControlOverviewMapComponent implements OnInit, OnChanges, OnDestroy {
1414
instance: OverviewMap;
1515
@Input()
1616
collapsed: boolean;
@@ -29,17 +29,26 @@ export class ControlOverviewMapComponent implements OnInit, OnDestroy {
2929
@Input()
3030
view: View;
3131

32-
constructor(private map: MapComponent) {
33-
// console.log('instancing aol-control-overviewmap');
34-
}
32+
constructor(private map: MapComponent) {}
3533

3634
ngOnInit() {
3735
this.instance = new OverviewMap(this);
3836
this.map.instance.addControl(this.instance);
3937
}
4038

4139
ngOnDestroy() {
42-
// console.log('removing aol-control-overviewmap');
4340
this.map.instance.removeControl(this.instance);
4441
}
42+
43+
ngOnChanges(changes: SimpleChanges) {
44+
if (this.instance != null && changes.hasOwnProperty('view')) {
45+
this.reloadInstance();
46+
}
47+
}
48+
49+
private reloadInstance() {
50+
this.map.instance.removeControl(this.instance);
51+
this.instance = new OverviewMap(this);
52+
this.map.instance.addControl(this.instance);
53+
}
4554
}

src/app/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import { MarkerComponent } from './marker/marker.component';
2626
import { ArcgisImageComponent } from './arcgis-image/arcgis-image.component';
2727
import { ImageWMSComponent } from './image-wms/image-wms.component';
2828
import { ViewProjectionUpdateComponent } from './view-projection-update/view-projection-update.component';
29+
import { OverviewComponent } from './overview/overview.component';
2930

3031
@NgModule({
3132
declarations: [
@@ -48,6 +49,7 @@ import { ViewProjectionUpdateComponent } from './view-projection-update/view-pro
4849
MarkerComponent,
4950
ArcgisImageComponent,
5051
ImageWMSComponent,
52+
OverviewComponent,
5153
ViewProjectionUpdateComponent,
5254
],
5355
imports: [BrowserModule, FormsModule, AppRoutingModule, AngularOpenlayersModule, ReactiveFormsModule],

src/app/app.routing.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { MarkerComponent } from './marker/marker.component';
1919
import { ArcgisImageComponent } from './arcgis-image/arcgis-image.component';
2020
import { ImageWMSComponent } from './image-wms/image-wms.component';
2121
import { ViewProjectionUpdateComponent } from './view-projection-update/view-projection-update.component';
22+
import { OverviewComponent } from './overview/overview.component';
2223

2324
const routes: Routes = [
2425
{ path: '', component: ExamplesListComponent },
@@ -43,6 +44,7 @@ const routes: Routes = [
4344
{ path: 'arcgis-image', component: ArcgisImageComponent },
4445
{ path: 'image-wms', component: ImageWMSComponent },
4546
{ path: 'view-projection-update', component: ViewProjectionUpdateComponent },
47+
{ path: 'overview', component: OverviewComponent },
4648
],
4749
},
4850
{ path: '**', redirectTo: '' },

src/app/example-list.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,10 @@ export const examplesList = [
9999
description: 'Dynamically update view projection.',
100100
routerLink: 'view-projection-update',
101101
},
102+
{
103+
title: 'Overview',
104+
description: 'Overview of map',
105+
routerLink: 'overview',
106+
openLayersLink: 'https://openlayers.org/en/latest/examples/overviewmap.html',
107+
},
102108
];
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Component } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-root',
5+
template: `
6+
<aol-map width="50%" height="50%">
7+
<aol-interaction-default></aol-interaction-default>
8+
<aol-control-defaults></aol-control-defaults>
9+
<aol-control-overviewmap></aol-control-overviewmap>
10+
<aol-view #view [zoom]="zoom">
11+
<aol-coordinate [x]="5" [y]="45" [srid]="'EPSG:4326'"></aol-coordinate>
12+
</aol-view>
13+
<aol-layer-tile #osm [opacity]="1"> <aol-source-osm></aol-source-osm> </aol-layer-tile>
14+
</aol-map>
15+
`,
16+
})
17+
export class OverviewComponent {
18+
public zoom = 15;
19+
}

0 commit comments

Comments
 (0)