Skip to content

Commit ccae9e0

Browse files
Damien MarestNeonox31
authored andcommitted
feat(source): add UTF grid source
1 parent 4dc9852 commit ccae9e0

File tree

6 files changed

+95
-0
lines changed

6 files changed

+95
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Component, Host, Input, OnInit, forwardRef } from '@angular/core';
2+
import { SourceComponent } from './source.component';
3+
import { LayerTileComponent } from '../layers/layertile.component';
4+
import { UTFGrid } from 'ol/source';
5+
6+
@Component({
7+
selector: 'aol-source-utfgrid',
8+
template: `
9+
<ng-content></ng-content>
10+
`,
11+
providers: [{ provide: SourceComponent, useExisting: forwardRef(() => SourceUTFGridComponent) }],
12+
})
13+
export class SourceUTFGridComponent extends SourceComponent implements OnInit {
14+
instance: UTFGrid;
15+
@Input() tileJSON: JSON;
16+
@Input() url: string;
17+
18+
constructor(@Host() layer: LayerTileComponent) {
19+
super(layer);
20+
}
21+
22+
ngOnInit() {
23+
this.instance = new UTFGrid(this);
24+
this.host.instance.setSource(this.instance);
25+
}
26+
}

projects/ngx-openlayers/src/public_api.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ import { OverlayComponent } from './lib/overlay.component';
7373
import { ContentComponent } from './lib/content.component';
7474
import { AttributionsComponent } from './lib/attributions.component';
7575
import { AttributionComponent } from './lib/attribution.component';
76+
import { SourceUTFGridComponent } from './lib/sources/utfgrid.component';
7677

7778
export {
7879
MapComponent,
@@ -86,6 +87,7 @@ export {
8687
SourceOsmComponent,
8788
SourceBingmapsComponent,
8889
SourceClusterComponent,
90+
SourceUTFGridComponent,
8991
SourceVectorComponent,
9092
SourceXYZComponent,
9193
SourceVectorTileComponent,
@@ -162,6 +164,7 @@ const COMPONENTS = [
162164
SourceOsmComponent,
163165
SourceBingmapsComponent,
164166
SourceClusterComponent,
167+
SourceUTFGridComponent,
165168
SourceVectorComponent,
166169
SourceXYZComponent,
167170
SourceVectorTileComponent,

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 { UTFGridComponent } from './utfgrid/utfgrid.component';
2930
import { OverviewComponent } from './overview/overview.component';
3031

3132
@NgModule({
@@ -48,6 +49,7 @@ import { OverviewComponent } from './overview/overview.component';
4849
ColorSelectHoverComponent,
4950
MarkerComponent,
5051
ArcgisImageComponent,
52+
UTFGridComponent,
5153
ImageWMSComponent,
5254
OverviewComponent,
5355
ViewProjectionUpdateComponent,

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 { UTFGridComponent } from './utfgrid/utfgrid.component';
2223
import { OverviewComponent } from './overview/overview.component';
2324

2425
const routes: Routes = [
@@ -45,6 +46,7 @@ const routes: Routes = [
4546
{ path: 'image-wms', component: ImageWMSComponent },
4647
{ path: 'view-projection-update', component: ViewProjectionUpdateComponent },
4748
{ path: 'overview', component: OverviewComponent },
49+
{ path: 'utf-grid', component: UTFGridComponent },
4850
],
4951
},
5052
{ path: '**', redirectTo: '' },

src/app/example-list.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,10 @@ export const examplesList = [
105105
routerLink: 'overview',
106106
openLayersLink: 'https://openlayers.org/en/latest/examples/overviewmap.html',
107107
},
108+
{
109+
title: 'UTF Grid',
110+
description: 'Example of using aol-source-utfgrid. This example display country flag in an overlay on hover',
111+
routerLink: 'utf-grid',
112+
openLayersLink: 'https://openlayers.org/en/latest/examples/utfgrid.html',
113+
},
108114
];
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { Component, ViewChild } from '@angular/core';
2+
import { SourceUTFGridComponent, ViewComponent } from '../../../projects/ngx-openlayers/src/public_api';
3+
4+
@Component({
5+
selector: 'app-root',
6+
template: `
7+
<aol-map (onPointerMove)="displayInfo($event.coordinate)">
8+
<aol-interaction-default></aol-interaction-default>
9+
<aol-control-defaults></aol-control-defaults>
10+
<aol-control-fullscreen></aol-control-fullscreen>
11+
<aol-view #view [zoom]="2" [center]="[3000000, 3000000]"></aol-view>
12+
<aol-layer-tile> <aol-source-osm></aol-source-osm> </aol-layer-tile>
13+
<aol-layer-tile>
14+
<aol-source-utfgrid
15+
#UTFGrid
16+
[url]="'https://api.tiles.mapbox.com/v4/mapbox.geography-class.json?secure&access_token=' + key"
17+
></aol-source-utfgrid>
18+
</aol-layer-tile>
19+
<aol-overlay *ngIf="coords && info" [positioning]="'BOTTOM_RIGHT'" [stopEvent]="false">
20+
<aol-coordinate [x]="coords[0]" [y]="coords[1]" [srid]="'EPSG:3857'"> </aol-coordinate>
21+
<aol-content>
22+
<img [src]="'data:image/png;base64,' + info['flag_png']" />
23+
</aol-content>
24+
</aol-overlay>
25+
</aol-map>
26+
`,
27+
styles: [
28+
`
29+
:host {
30+
display: flex;
31+
}
32+
33+
aol-map {
34+
width: 70%;
35+
height: 100%;
36+
}
37+
`,
38+
],
39+
})
40+
export class UTFGridComponent {
41+
@ViewChild('UTFGrid') UTFGrid: SourceUTFGridComponent;
42+
@ViewChild('view') view: ViewComponent;
43+
44+
info: any;
45+
coords: Coordinates;
46+
key = 'pk.eyJ1IjoieWFrb3VzdCIsImEiOiJjanVkc3Y0b2cwNWppM3lwaXd5M3JidHRzIn0.rJmuWPJnuKA9MJ9z5RPKZw';
47+
48+
displayInfo(c) {
49+
this.UTFGrid.instance.forDataAtCoordinateAndResolution(c, this.view.instance.getResolution(), data => {
50+
if (data !== null && data !== undefined && data !== '') {
51+
this.info = data;
52+
this.coords = c;
53+
}
54+
});
55+
}
56+
}

0 commit comments

Comments
 (0)