From 5e20e8decdf6434c66a84d5d8e2ba14d1fc56636 Mon Sep 17 00:00:00 2001 From: Michael Parry Date: Mon, 3 Jun 2019 11:56:37 +0200 Subject: [PATCH] feat(graticule): unregister on destroy Hangle graticule destruction. Add graticule example. --- .../src/lib/graticule.component.ts | 8 ++- src/app/app.module.ts | 2 + src/app/app.routing.ts | 2 + src/app/example-list.ts | 6 +++ src/app/graticule/graticule.component.ts | 51 +++++++++++++++++++ 5 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 src/app/graticule/graticule.component.ts diff --git a/projects/ngx-openlayers/src/lib/graticule.component.ts b/projects/ngx-openlayers/src/lib/graticule.component.ts index e21dd60c..e432ef25 100644 --- a/projects/ngx-openlayers/src/lib/graticule.component.ts +++ b/projects/ngx-openlayers/src/lib/graticule.component.ts @@ -1,4 +1,4 @@ -import { Component, Input, AfterContentInit, OnChanges, SimpleChanges } from '@angular/core'; +import { Component, Input, AfterContentInit, OnChanges, SimpleChanges, OnDestroy } from '@angular/core'; import { Graticule } from 'ol'; import { Stroke } from 'ol/style'; import { MapComponent } from './map.component'; @@ -7,7 +7,7 @@ import { MapComponent } from './map.component'; selector: 'aol-graticule', template: '', }) -export class GraticuleComponent implements AfterContentInit, OnChanges { +export class GraticuleComponent implements AfterContentInit, OnChanges, OnDestroy { instance: any; public componentType = 'graticule'; @@ -50,4 +50,8 @@ export class GraticuleComponent implements AfterContentInit, OnChanges { }); this.instance.setMap(this.map.instance); } + + ngOnDestroy(): void { + this.instance.setMap(null); + } } diff --git a/src/app/app.module.ts b/src/app/app.module.ts index f12d13ed..03410ab8 100755 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -31,6 +31,7 @@ import { OverviewComponent } from './overview/overview.component'; import { TileJsonComponent } from './tile-json/tile-json.component'; import { SelectInteractionComponent } from './select-interaction/select-interaction.component'; import { ImageStaticComponent } from './image-static/image-static.component'; +import { GraticuleComponent } from './graticule/graticule.component'; @NgModule({ declarations: [ @@ -59,6 +60,7 @@ import { ImageStaticComponent } from './image-static/image-static.component'; TileJsonComponent, OverviewComponent, ViewProjectionUpdateComponent, + GraticuleComponent, ], imports: [BrowserModule, FormsModule, AppRoutingModule, AngularOpenlayersModule, ReactiveFormsModule], providers: [], diff --git a/src/app/app.routing.ts b/src/app/app.routing.ts index 5a06a6ac..30d3b44f 100644 --- a/src/app/app.routing.ts +++ b/src/app/app.routing.ts @@ -24,6 +24,7 @@ import { OverviewComponent } from './overview/overview.component'; import { TileJsonComponent } from './tile-json/tile-json.component'; import { SelectInteractionComponent } from './select-interaction/select-interaction.component'; import { ImageStaticComponent } from './image-static/image-static.component'; +import { GraticuleComponent } from './graticule/graticule.component'; const routes: Routes = [ { path: '', component: ExamplesListComponent }, @@ -53,6 +54,7 @@ const routes: Routes = [ { path: 'image-static', component: ImageStaticComponent }, { path: 'select-interaction', component: SelectInteractionComponent }, { path: 'tile-json', component: TileJsonComponent }, + { path: 'graticule', component: GraticuleComponent }, ], }, { path: '**', redirectTo: '' }, diff --git a/src/app/example-list.ts b/src/app/example-list.ts index 626c332a..4e5414a1 100644 --- a/src/app/example-list.ts +++ b/src/app/example-list.ts @@ -129,4 +129,10 @@ export const examplesList = [ routerLink: 'tile-json', openLayersLink: 'https://openlayers.org/en/latest/examples/tilejson.html', }, + { + title: 'Graticule', + description: 'Example of using aol-graticule. This example shows how to add a graticule overlay to a map', + routerLink: 'graticule', + openLayersLink: 'https://openlayers.org/en/latest/examples/graticule.html', + }, ]; diff --git a/src/app/graticule/graticule.component.ts b/src/app/graticule/graticule.component.ts new file mode 100644 index 00000000..3acf0289 --- /dev/null +++ b/src/app/graticule/graticule.component.ts @@ -0,0 +1,51 @@ +import { Component } from '@angular/core'; +import { Stroke } from 'ol/style'; + +@Component({ + selector: 'app-root', + template: ` + + + + + + + + + + + + + +
+ + +
+ `, + styles: [ + ` + :host { + display: flex; + } + + aol-map { + width: 80%; + } + + .controls { + width: 18%; + padding: 1rem; + } + `, + ], +}) +export class GraticuleComponent { + public zoom = 4; + public opacity = 1.0; + public shownGraticule = true; + public graticuleStyle = new Stroke({ + color: 'rgba(255,120,0,0.9)', + width: 2, + lineDash: [0.5, 4], + }); +}