Skip to content

Commit b7749f9

Browse files
Clara BelairNeonox31
authored andcommitted
feat(demo): example of overlay
1 parent 9aa4dab commit b7749f9

File tree

4 files changed

+107
-0
lines changed

4 files changed

+107
-0
lines changed

src/app/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { DrawPolygonComponent } from './draw-polygon/draw-polygon.component';
2020
import { ModifyPolygonComponent } from './modify-polygon/modify-polygon.component';
2121
import { SideBySideComponent } from './side-by-side/side-by-side.component';
2222
import { SwipeComponent } from './swipe/swipe.component';
23+
import { OverlayComponent } from './overlay/overlay.component';
2324

2425
@NgModule({
2526
declarations: [
@@ -37,6 +38,7 @@ import { SwipeComponent } from './swipe/swipe.component';
3738
ModifyPolygonComponent,
3839
SideBySideComponent,
3940
SwipeComponent,
41+
OverlayComponent,
4042
],
4143
imports: [BrowserModule, FormsModule, AppRoutingModule, AngularOpenlayersModule, ReactiveFormsModule],
4244
providers: [],

src/app/app.routing.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { DrawPolygonComponent } from './draw-polygon/draw-polygon.component';
1313
import { ModifyPolygonComponent } from './modify-polygon/modify-polygon.component';
1414
import { SideBySideComponent } from './side-by-side/side-by-side.component';
1515
import { SwipeComponent } from './swipe/swipe.component';
16+
import { OverlayComponent } from './overlay/overlay.component';
1617

1718
const routes: Routes = [
1819
{ path: '', component: ExamplesListComponent },
@@ -29,6 +30,7 @@ const routes: Routes = [
2930
{ path: 'modify-polygon', component: ModifyPolygonComponent },
3031
{ path: 'side-by-side', component: SideBySideComponent },
3132
{ path: 'swipe', component: SwipeComponent },
33+
{ path: 'overlay', component: OverlayComponent },
3234
{ path: 'cluster', component: ClusterComponent },
3335
{ path: 'raster', component: RasterComponent },
3436
],

src/app/example-list.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ export const examplesList = [
5050
routerLink: 'swipe',
5151
openLayersLink: 'https://openlayers.org/en/latest/examples/layer-swipe.html',
5252
},
53+
{
54+
title: 'Overlay',
55+
description: 'Example of using aol-overlay',
56+
routerLink: 'overlay',
57+
openLayersLink: 'https://openlayers.org/en/latest/examples/overlay.html',
58+
},
5359
{
5460
title: 'Cluster',
5561
description: 'Example of using aol-source-cluster. This example shows how to do clustering on point features.',
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import { Component, OnInit } from '@angular/core';
2+
import { Feature as OlFeature, format, geom } from 'openlayers';
3+
4+
@Component({
5+
selector: 'app-display-overlay',
6+
template: `
7+
<aol-map #map width="100%" height="100%">
8+
<aol-interaction-default></aol-interaction-default>
9+
<aol-control-defaults></aol-control-defaults>
10+
11+
<aol-view [zoom]="11">
12+
<aol-coordinate [x]="-2.269282" [y]="46.987247" [srid]="'EPSG:4326'"></aol-coordinate>
13+
</aol-view>
14+
15+
<aol-layer-tile [opacity]="1">
16+
<aol-source-osm></aol-source-osm>
17+
</aol-layer-tile>
18+
19+
<aol-layer-vector>
20+
<aol-source-vector>
21+
<aol-feature>
22+
<aol-geometry-polygon>
23+
<aol-collection-coordinates [coordinates]="feature.geometry.coordinates[0]" [srid]="'EPSG:4326'"></aol-collection-coordinates>
24+
</aol-geometry-polygon>
25+
</aol-feature>
26+
</aol-source-vector>
27+
</aol-layer-vector>
28+
29+
<aol-overlay [positioning]="'center-center'" [stopEvent]="false">
30+
<aol-coordinate
31+
[x]="tooltip.lon"
32+
[y]="tooltip.lat"
33+
[srid]="'EPSG:4326'"
34+
>
35+
</aol-coordinate>
36+
<aol-content>
37+
<div class="tooltip tooltip-static">
38+
{{tooltip.text}}
39+
</div>
40+
</aol-content>
41+
</aol-overlay>
42+
</aol-map>
43+
`,
44+
styles: [
45+
`
46+
.tooltip {
47+
margin-top: 35%;
48+
right: 50%;
49+
position: relative;
50+
border-radius: 4px;
51+
color: white;
52+
padding: 4px 8px;
53+
white-space: nowrap;
54+
}
55+
56+
.tooltip-static {
57+
background-color: #000000;
58+
color: white;
59+
border: 1px solid white;
60+
}
61+
`,
62+
],
63+
})
64+
export class OverlayComponent implements OnInit {
65+
constructor() {}
66+
67+
geoJsonFormat = new format.GeoJSON();
68+
69+
feature = {
70+
type: 'Feature',
71+
properties: {},
72+
geometry: {
73+
type: 'Polygon',
74+
coordinates: [
75+
[
76+
[-2.3565673828124996, 46.92588289494367],
77+
[-2.1148681640624996, 46.92588289494367],
78+
[-2.1148681640624996, 47.04954010021555],
79+
[-2.3565673828124996, 47.04954010021555],
80+
[-2.3565673828124996, 46.92588289494367],
81+
],
82+
],
83+
},
84+
};
85+
86+
tooltip = {
87+
lon: 0,
88+
lat: 0,
89+
text: 'Lorem ipsum dolor sit amet',
90+
};
91+
92+
ngOnInit() {
93+
const olFeature: OlFeature = this.geoJsonFormat.readFeature(this.feature);
94+
const olGeomPolygon = geom.Polygon.fromExtent(olFeature.getGeometry().getExtent());
95+
[, this.tooltip.lat, this.tooltip.lon] = olGeomPolygon.getExtent();
96+
}
97+
}

0 commit comments

Comments
 (0)