Skip to content

Commit 631c3ee

Browse files
committed
fix(showcase): update all examples
1 parent e6d24b1 commit 631c3ee

34 files changed

+473
-552
lines changed

apps/showcase/src/app/demo/demo-index.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ <h3 matSubheader>{{ cat }}</h3>
5050
'/demo/' + (isEditMode ? '/edit/' : '') + route.path
5151
"
5252
routerLinkActive="active"
53+
(isActiveChange)="scrollInToActiveLink($event, exampleLink)"
5354
[routerLinkActiveOptions]="
5455
$any({
5556
_routerLinkActiveWakeUpHack_: isEditMode,

apps/showcase/src/app/demo/demo-index.component.ts

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
1-
import {
2-
afterNextRender,
3-
Component,
4-
computed,
5-
ElementRef,
6-
inject,
7-
QueryList,
8-
signal,
9-
ViewChildren,
10-
} from '@angular/core';
1+
import { Component, computed, inject, signal } from '@angular/core';
112
import {
123
MatSlideToggleChange,
134
MatSlideToggleModule,
@@ -28,7 +19,7 @@ import { MatDividerModule } from '@angular/material/divider';
2819
import { FormsModule } from '@angular/forms';
2920
import { MatFormFieldModule } from '@angular/material/form-field';
3021
import { MatInputModule } from '@angular/material/input';
31-
import { MatListModule } from '@angular/material/list';
22+
import { MatListModule, type MatListItem } from '@angular/material/list';
3223
import { MapResizeSignal } from './examples/mgl-map-resize.directive';
3324
import { MatButtonModule } from '@angular/material/button';
3425

@@ -57,7 +48,7 @@ export class DemoIndexComponent {
5748
private readonly activatedRoute = inject(ActivatedRoute);
5849
private readonly mapResizeSignal = inject(MapResizeSignal);
5950

60-
categories: Category[];
51+
categories = Object.values(Category);
6152
searchTerm = signal('');
6253
routesByCategory = computed(() => {
6354
const searchTerm = this.searchTerm();
@@ -77,17 +68,6 @@ export class DemoIndexComponent {
7768
sidenavIsOpen = true;
7869
isEditMode = !!this.activatedRoute.snapshot.firstChild?.params['demoUrl'];
7970

80-
@ViewChildren('exampleLink', { read: ElementRef })
81-
exampleLinks: QueryList<ElementRef>;
82-
83-
constructor() {
84-
this.categories = Object.values(Category);
85-
86-
afterNextRender(() => {
87-
this.scrollInToActiveExampleLink();
88-
});
89-
}
90-
9171
toggleSidenav() {
9272
this.sidenavIsOpen = !this.sidenavIsOpen;
9373
}
@@ -106,15 +86,13 @@ export class DemoIndexComponent {
10686
this.mapResizeSignal.set(undefined);
10787
}
10888

109-
private scrollInToActiveExampleLink() {
110-
const activeLink = this.exampleLinks.find((elm) =>
111-
(elm.nativeElement as HTMLElement).classList.contains('active'),
112-
);
113-
if (activeLink) {
114-
scrollIntoView(activeLink.nativeElement as HTMLElement, {
115-
block: 'center',
116-
scrollMode: 'if-needed',
117-
});
89+
scrollInToActiveLink(isActive: boolean, item: MatListItem) {
90+
if (!isActive) {
91+
return;
11892
}
93+
scrollIntoView(item._elementRef.nativeElement as HTMLElement, {
94+
block: 'center',
95+
scrollMode: 'if-needed',
96+
});
11997
}
12098
}

apps/showcase/src/app/demo/examples/3d-buildings.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import { MglMapResizeDirective } from './mgl-map-resize.directive';
77
selector: 'showcase-demo',
88
template: `
99
<mgl-map
10-
[style]="'mapbox://styles/mapbox/light-v9'"
10+
[style]="'mapbox://styles/mapbox/light-v11'"
1111
[zoom]="[15.5]"
1212
[center]="[-74.0066, 40.7135]"
1313
[pitch]="[45]"
1414
[bearing]="[-17.6]"
15+
[antialias]="true"
1516
(mapLoad)="onLoad($event.target)"
1617
>
1718
<mgl-layer

apps/showcase/src/app/demo/examples/add-image-generated.component.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1-
import { Component, OnInit } from '@angular/core';
1+
import { Component, signal } from '@angular/core';
22
import { MapComponent, LayerComponent, ImageComponent } from 'ngx-mapbox-gl';
33
import { MglMapResizeDirective } from './mgl-map-resize.directive';
44

55
@Component({
66
selector: 'showcase-demo',
77
template: `
8-
<mgl-map [style]="'mapbox://styles/mapbox/streets-v12'">
8+
<mgl-map
9+
[style]="'mapbox://styles/mapbox/streets-v12'"
10+
[center]="[0, 0]"
11+
[zoom]="[2]"
12+
>
913
<mgl-image
1014
id="gradient"
1115
[data]="{
1216
width: 64,
1317
height: 64,
14-
data: imageData,
18+
data: imageData(),
1519
}"
1620
/>
1721
<mgl-layer
@@ -45,12 +49,8 @@ import { MglMapResizeDirective } from './mgl-map-resize.directive';
4549
],
4650
styleUrls: ['./examples.css'],
4751
})
48-
export class AddImageGeneratedComponent implements OnInit {
49-
imageData: Uint8Array;
50-
51-
ngOnInit() {
52-
this.imageData = this.generateImage();
53-
}
52+
export class AddImageGeneratedComponent {
53+
imageData = signal<Uint8Array>(this.generateImage());
5454

5555
private generateImage() {
5656
const width = 64; // The image will be 64 pixels square

apps/showcase/src/app/demo/examples/add-image-missing-generated.component.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Component } from '@angular/core';
2-
import { NgForOf } from '@angular/common';
32
import { MapComponent, LayerComponent, ImageComponent } from 'ngx-mapbox-gl';
43
import { MglMapResizeDirective } from './mgl-map-resize.directive';
54

@@ -8,13 +7,13 @@ import { MglMapResizeDirective } from './mgl-map-resize.directive';
87
template: `
98
<mgl-map
109
[style]="'mapbox://styles/mapbox/streets-v12'"
10+
[center]="[0, 0]"
11+
[zoom]="[2]"
1112
(styleImageMissing)="generateImage($event)"
1213
>
13-
<mgl-image
14-
*ngFor="let imageData of imagesData; trackBy: trackByImage"
15-
[id]="imageData.id"
16-
[data]="imageData"
17-
/>
14+
@for (imageData of imagesData; track trackByImage(imageData)) {
15+
<mgl-image [id]="imageData.id" [data]="imageData" />
16+
}
1817
<mgl-layer
1918
id="points"
2019
type="symbol"
@@ -67,7 +66,6 @@ import { MglMapResizeDirective } from './mgl-map-resize.directive';
6766
MglMapResizeDirective,
6867
LayerComponent,
6968
ImageComponent,
70-
NgForOf,
7169
],
7270
styleUrls: ['./examples.css'],
7371
})
@@ -111,7 +109,7 @@ export class AddImageMissingGeneratedComponent {
111109
this.imagesData = [...this.imagesData, imageData];
112110
}
113111

114-
trackByImage(_idx: number, image: { id: string }) {
112+
trackByImage(image: { id: string }) {
115113
return image.id;
116114
}
117115
}
Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,53 @@
1-
import { Component } from '@angular/core';
2-
import { NgIf } from '@angular/common';
1+
import { Component, signal } from '@angular/core';
32
import { MapComponent, LayerComponent, ImageComponent } from 'ngx-mapbox-gl';
43
import { MglMapResizeDirective } from './mgl-map-resize.directive';
54

65
@Component({
76
selector: 'showcase-demo',
87
template: `
9-
<mgl-map [style]="'mapbox://styles/mapbox/streets-v12'">
8+
<mgl-map
9+
[style]="'mapbox://styles/mapbox/dark-v11'"
10+
[center]="[-77.432, 25.0306]"
11+
[zoom]="[10]"
12+
>
1013
<mgl-image
1114
id="cat"
12-
url="https://upload.wikimedia.org/wikipedia/commons/thumb/6/60/Cat_silhouette.svg/400px-Cat_silhouette.svg.png"
13-
(imageLoaded)="imageLoaded = true"
15+
url="https://docs.mapbox.com/mapbox-gl-js/assets/cat.png"
16+
(imageLoaded)="imageLoaded.set(true)"
1417
/>
15-
<mgl-layer
16-
*ngIf="imageLoaded"
17-
id="points"
18-
type="symbol"
19-
[source]="{
20-
type: 'geojson',
21-
data: {
22-
type: 'FeatureCollection',
23-
features: [
24-
{
25-
type: 'Feature',
26-
properties: {},
27-
geometry: {
28-
type: 'Point',
29-
coordinates: [0, 0],
18+
@if (imageLoaded()) {
19+
<mgl-layer
20+
id="points"
21+
type="symbol"
22+
[source]="{
23+
type: 'geojson',
24+
data: {
25+
type: 'FeatureCollection',
26+
features: [
27+
{
28+
type: 'Feature',
29+
properties: {},
30+
geometry: {
31+
type: 'Point',
32+
coordinates: [-77.4144, 25.0759],
33+
},
3034
},
31-
},
32-
],
33-
},
34-
}"
35-
[layout]="{ 'icon-image': 'cat', 'icon-size': 0.25 }"
36-
/>
35+
],
36+
},
37+
}"
38+
[layout]="{ 'icon-image': 'cat', 'icon-size': 0.25 }"
39+
/>
40+
}
3741
</mgl-map>
3842
`,
3943
imports: [
4044
MapComponent,
4145
MglMapResizeDirective,
4246
LayerComponent,
4347
ImageComponent,
44-
NgIf,
4548
],
4649
styleUrls: ['./examples.css'],
4750
})
4851
export class AddImageComponent {
49-
imageLoaded = false;
52+
imageLoaded = signal(false);
5053
}

apps/showcase/src/app/demo/examples/attribution-position.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { MglMapResizeDirective } from './mgl-map-resize.directive';
1010
selector: 'showcase-demo',
1111
template: `
1212
<mgl-map
13-
[style]="'mapbox://styles/mapbox/light-v9'"
13+
[style]="'mapbox://styles/mapbox/light-v11'"
1414
[center]="[-77.04, 38.907]"
1515
[zoom]="[11.15]"
1616
[attributionControl]="false"
Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { Component } from '@angular/core';
2-
import { NgForOf } from '@angular/common';
1+
import { Component, signal } from '@angular/core';
32
import { MapMouseEvent } from 'mapbox-gl';
43
import { MglMapResizeDirective } from './mgl-map-resize.directive';
54
import {
@@ -13,27 +12,29 @@ import {
1312
selector: 'showcase-demo',
1413
template: `
1514
<mgl-map
16-
[style]="'mapbox://styles/mapbox/light-v9'"
17-
[zoom]="[8]"
18-
[center]="center"
19-
[cursorStyle]="cursorStyle"
15+
[style]="'mapbox://styles/mapbox/light-v11'"
16+
[zoom]="[7.2]"
17+
[center]="center()"
18+
[cursorStyle]="cursorStyle()"
2019
>
21-
<mgl-geojson-source id="symbols-source">
22-
<mgl-feature
23-
*ngFor="let geometry of geometries"
24-
[geometry]="geometry"
25-
/>
20+
<mgl-geojson-source id="points">
21+
@for (geometry of geometries; track $index) {
22+
<mgl-feature [geometry]="geometry" />
23+
}
2624
</mgl-geojson-source>
2725
<mgl-layer
28-
id="symbols"
29-
type="symbol"
30-
source="symbols-source"
31-
[layout]="{
32-
'icon-image': 'rocket-15',
26+
id="circle"
27+
type="circle"
28+
source="points"
29+
[paint]="{
30+
'circle-color': '#4264fb',
31+
'circle-radius': 8,
32+
'circle-stroke-width': 2,
33+
'circle-stroke-color': '#ffffff',
3334
}"
3435
(layerClick)="centerMapTo($event)"
35-
(layerMouseEnter)="cursorStyle = 'pointer'"
36-
(layerMouseLeave)="cursorStyle = ''"
36+
(layerMouseEnter)="cursorStyle.set('pointer')"
37+
(layerMouseLeave)="cursorStyle.set('')"
3738
/>
3839
</mgl-map>
3940
`,
@@ -43,32 +44,31 @@ import {
4344
GeoJSONSourceComponent,
4445
FeatureComponent,
4546
LayerComponent,
46-
NgForOf,
4747
],
4848
styleUrls: ['./examples.css'],
4949
})
5050
export class CenterOnSymbolComponent {
51-
cursorStyle: string;
51+
cursorStyle = signal('');
5252

53-
center: [number, number] = [-90.96, -0.47];
53+
center = signal<[number, number]>([-90.96, -0.47]);
5454

5555
geometries = [
5656
{
5757
type: 'Point' as const,
58-
coordinates: [-91.395263671875, -0.9145729757782163],
58+
coordinates: [-91.3952, -0.9145],
5959
},
6060
{
6161
type: 'Point' as const,
62-
coordinates: [-90.32958984375, -0.6344474832838974],
62+
coordinates: [-90.3295, -0.6344],
6363
},
6464
{
6565
type: 'Point' as const,
66-
coordinates: [-91.34033203125, 0.01647949196029245],
66+
coordinates: [-91.3403, 0.0164],
6767
},
6868
];
6969

7070
centerMapTo(evt: MapMouseEvent) {
7171
// eslint-disable-next-line @typescript-eslint/no-explicit-any
72-
this.center = (evt as any).features[0].geometry.coordinates;
72+
this.center.set((evt as any).features[0].geometry.coordinates);
7373
}
7474
}

apps/showcase/src/app/demo/examples/cluster-html.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Component, OnInit, input } from '@angular/core';
2-
import { NgForOf, NgStyle } from '@angular/common';
2+
import { NgStyle } from '@angular/common';
33
import {
44
type CircleLayerSpecification,
55
type SymbolLayerSpecification,

apps/showcase/src/app/demo/examples/cluster.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
selector: 'showcase-demo',
1212
template: `
1313
<mgl-map
14-
[style]="'mapbox://styles/mapbox/dark-v9'"
14+
[style]="'mapbox://styles/mapbox/dark-v11'"
1515
[zoom]="[3]"
1616
[center]="[-103.59179687498357, 40.66995747013945]"
1717
>

0 commit comments

Comments
 (0)