Skip to content

Commit 3f0c228

Browse files
samuel-girardNeonox31
authored andcommitted
feat(view): dynamically update view projection
1 parent f0d4dd1 commit 3f0c228

File tree

5 files changed

+89
-0
lines changed

5 files changed

+89
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ export class ViewComponent implements OnInit, OnChanges, OnDestroy {
8181
this.instance.setZoom(changes[key].currentValue);
8282
}
8383
break;
84+
case 'projection':
85+
this.instance = new View(this);
86+
this.host.instance.setView(this.instance);
87+
break;
8488
default:
8589
break;
8690
}

src/app/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { ColorSelectHoverComponent } from './color-select-hover/color-select-hov
2525
import { MarkerComponent } from './marker/marker.component';
2626
import { ArcgisImageComponent } from './arcgis-image/arcgis-image.component';
2727
import { ImageWMSComponent } from './image-wms/image-wms.component';
28+
import { ViewProjectionUpdateComponent } from './view-projection-update/view-projection-update.component';
2829

2930
@NgModule({
3031
declarations: [
@@ -47,6 +48,7 @@ import { ImageWMSComponent } from './image-wms/image-wms.component';
4748
MarkerComponent,
4849
ArcgisImageComponent,
4950
ImageWMSComponent,
51+
ViewProjectionUpdateComponent,
5052
],
5153
imports: [BrowserModule, FormsModule, AppRoutingModule, AngularOpenlayersModule, ReactiveFormsModule],
5254
providers: [],

src/app/app.routing.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { ColorSelectHoverComponent } from './color-select-hover/color-select-hov
1818
import { MarkerComponent } from './marker/marker.component';
1919
import { ArcgisImageComponent } from './arcgis-image/arcgis-image.component';
2020
import { ImageWMSComponent } from './image-wms/image-wms.component';
21+
import { ViewProjectionUpdateComponent } from './view-projection-update/view-projection-update.component';
2122

2223
const routes: Routes = [
2324
{ path: '', component: ExamplesListComponent },
@@ -41,6 +42,7 @@ const routes: Routes = [
4142
{ path: 'raster', component: RasterComponent },
4243
{ path: 'arcgis-image', component: ArcgisImageComponent },
4344
{ path: 'image-wms', component: ImageWMSComponent },
45+
{ path: 'view-projection-update', component: ViewProjectionUpdateComponent },
4446
],
4547
},
4648
{ path: '**', redirectTo: '' },

src/app/example-list.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,9 @@ export const examplesList = [
9494
routerLink: 'image-wms',
9595
openLayersLink: 'https://openlayers.org/en/latest/examples/image-load-events.html',
9696
},
97+
{
98+
title: 'View projection update',
99+
description: 'Dynamically update view projection.',
100+
routerLink: 'view-projection-update',
101+
},
97102
];
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import { Component } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-root',
5+
template: `
6+
<aol-map [width]="'100%'" [height]="'100%'">
7+
<aol-interaction-default></aol-interaction-default>
8+
<aol-view [zoom]="2" [projection]="viewProjection">
9+
<aol-coordinate [x]="0" [y]="0" [srid]="'EPSG:4326'"></aol-coordinate>
10+
</aol-view>
11+
<aol-layer-tile> <aol-source-osm></aol-source-osm> </aol-layer-tile>
12+
<aol-layer-vector>
13+
<aol-source-vector>
14+
<aol-feature>
15+
<aol-geometry-point>
16+
<aol-coordinate [x]="5" [y]="45" [srid]="'EPSG:4326'"></aol-coordinate>
17+
</aol-geometry-point>
18+
<aol-style>
19+
<aol-style-circle [radius]="10">
20+
<aol-style-stroke [color]="'black'" [width]="2"></aol-style-stroke>
21+
<aol-style-fill [color]="'green'"></aol-style-fill>
22+
</aol-style-circle>
23+
</aol-style>
24+
</aol-feature>
25+
<aol-feature>
26+
<aol-geometry-point>
27+
<aol-coordinate [x]="5.1" [y]="45.1" [srid]="'EPSG:4326'"></aol-coordinate>
28+
</aol-geometry-point>
29+
<aol-style>
30+
<aol-style-icon
31+
[src]="'assets/marker.png'"
32+
[anchor]="[0.5, 1]"
33+
[anchorXUnits]="'fraction'"
34+
[anchorYUnits]="'fraction'"
35+
[scale]="0.1"
36+
[anchorOrigin]="'top-left'"
37+
>
38+
</aol-style-icon>
39+
</aol-style>
40+
</aol-feature>
41+
</aol-source-vector>
42+
</aol-layer-vector>
43+
</aol-map>
44+
<div class="controls">
45+
Current projection:
46+
<select (change)="onProjectionChange($event)">
47+
<option value="EPSG:3857">EPSG:3857</option>
48+
<option value="EPSG:4326">EPSG:4326</option>
49+
</select>
50+
</div>
51+
`,
52+
styles: [
53+
`
54+
:host {
55+
display: flex;
56+
}
57+
58+
aol-map {
59+
width: 70%;
60+
}
61+
62+
.controls {
63+
width: 28%;
64+
padding: 1rem;
65+
}
66+
`,
67+
],
68+
})
69+
export class ViewProjectionUpdateComponent {
70+
public viewProjection = 'EPSG:3857';
71+
72+
onProjectionChange(evt) {
73+
console.log(`Projection changed to ${evt.target.value}`);
74+
this.viewProjection = evt.target.value;
75+
}
76+
}

0 commit comments

Comments
 (0)