Skip to content

Commit

Permalink
feat(graticule): unregister on destroy
Browse files Browse the repository at this point in the history
Hangle graticule destruction.
Add graticule example.
  • Loading branch information
kekel87 authored and Yakoust committed Jun 4, 2019
1 parent 410f876 commit 5e20e8d
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 2 deletions.
8 changes: 6 additions & 2 deletions projects/ngx-openlayers/src/lib/graticule.component.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -7,7 +7,7 @@ import { MapComponent } from './map.component';
selector: 'aol-graticule',
template: '<ng-content></ng-content>',
})
export class GraticuleComponent implements AfterContentInit, OnChanges {
export class GraticuleComponent implements AfterContentInit, OnChanges, OnDestroy {
instance: any;
public componentType = 'graticule';

Expand Down Expand Up @@ -50,4 +50,8 @@ export class GraticuleComponent implements AfterContentInit, OnChanges {
});
this.instance.setMap(this.map.instance);
}

ngOnDestroy(): void {
this.instance.setMap(null);
}
}
2 changes: 2 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -59,6 +60,7 @@ import { ImageStaticComponent } from './image-static/image-static.component';
TileJsonComponent,
OverviewComponent,
ViewProjectionUpdateComponent,
GraticuleComponent,
],
imports: [BrowserModule, FormsModule, AppRoutingModule, AngularOpenlayersModule, ReactiveFormsModule],
providers: [],
Expand Down
2 changes: 2 additions & 0 deletions src/app/app.routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -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: '' },
Expand Down
6 changes: 6 additions & 0 deletions src/app/example-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
];
51 changes: 51 additions & 0 deletions src/app/graticule/graticule.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { Component } from '@angular/core';
import { Stroke } from 'ol/style';

@Component({
selector: 'app-root',
template: `
<aol-map width="100%" height="100%">
<aol-interaction-default></aol-interaction-default>
<aol-control-defaults></aol-control-defaults>
<aol-control-fullscreen></aol-control-fullscreen>
<aol-view [zoom]="zoom"> <aol-coordinate [x]="-10997148" [y]="4569099"></aol-coordinate> </aol-view>
<aol-layer-tile>
<aol-source-osm></aol-source-osm>
</aol-layer-tile>
<aol-graticule *ngIf="shownGraticule" [strokeStyle]="graticuleStyle" [showLabels]="true"></aol-graticule>
</aol-map>
<div class="controls">
<input type="checkbox" id="graticule" name="graticule" [(ngModel)]="shownGraticule" />
<label for="graticule">Toggle graticule</label>
</div>
`,
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],
});
}

0 comments on commit 5e20e8d

Please sign in to comment.