Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(journey-maps): upgrade maplibre to 4.7.1 #2421

Merged
merged 5 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"@angular/platform-server": "19.0.0-rc.1",
"@angular/router": "19.0.0-rc.1",
"@stackblitz/sdk": "1.11.0",
"maplibre-gl": "3.6.2",
"maplibre-gl": "4.7.1",
"rxjs": "7.8.1",
"tslib": "2.7.0",
"zone.js": "0.15.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import 'https://unpkg.com/maplibre-gl@3.6.1/dist/maplibre-gl.css';
@import 'https://unpkg.com/maplibre-gl@4.7.1/dist/maplibre-gl.css';

sbb-notification.api-key-info {
margin-bottom: 30px;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import 'https://unpkg.com/maplibre-gl@3.6.1/dist/maplibre-gl.css';
@import 'https://unpkg.com/maplibre-gl@4.7.1/dist/maplibre-gl.css';

sbb-notification.api-key-info {
margin-bottom: 30px;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import 'https://unpkg.com/maplibre-gl@3.6.1/dist/maplibre-gl.css';
@import 'https://unpkg.com/maplibre-gl@4.7.1/dist/maplibre-gl.css';

sbb-notification.api-key-info {
margin-bottom: 30px;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import 'https://unpkg.com/maplibre-gl@3.6.1/dist/maplibre-gl.css';
@import 'https://unpkg.com/maplibre-gl@4.7.1/dist/maplibre-gl.css';

sbb-notification.api-key-info {
margin-bottom: 30px;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import 'https://unpkg.com/maplibre-gl@3.6.1/dist/maplibre-gl.css';
@import 'https://unpkg.com/maplibre-gl@4.7.1/dist/maplibre-gl.css';

sbb-notification.api-key-info {
margin-bottom: 30px;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import 'https://unpkg.com/maplibre-gl@3.6.1/dist/maplibre-gl.css';
@import 'https://unpkg.com/maplibre-gl@4.7.1/dist/maplibre-gl.css';

sbb-notification.api-key-info {
margin-bottom: 30px;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import 'https://unpkg.com/maplibre-gl@3.6.1/dist/maplibre-gl.css';
@import 'https://unpkg.com/maplibre-gl@4.7.1/dist/maplibre-gl.css';

sbb-notification.api-key-info {
margin-bottom: 30px;
Expand Down
16 changes: 9 additions & 7 deletions src/journey-maps/angular/angular.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ npm install --save-dev @types/geojson
```

**NOTE** \
The `maplibre-gl` version compatible with this version of `journey-maps` is `3.x.y`.
The `maplibre-gl` version compatible with this version of `journey-maps` is `4.x.y`.

### Reference the CSS

Expand All @@ -31,12 +31,14 @@ You should add the following two CSS files to your application:

You can add them for example in the `styles` array of your `angular.json` file:

```json lines
"styles": [
"src/styles.scss",
"node_modules/maplibre-gl/dist/maplibre-gl.css"
"node_modules/@sbb-esta/angular/typography.css"
],
```json
{
"styles": [
"src/styles.scss",
"node_modules/maplibre-gl/dist/maplibre-gl.css",
"node_modules/@sbb-esta/angular/typography.css"
]
}
```

### i18n
Expand Down
49 changes: 24 additions & 25 deletions src/journey-maps/angular/services/map/map-marker-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ export class SbbMapMarkerService {
this.markerLayers = [SBB_MARKER_LAYER];
this.markerLayersSelected = [SBB_MARKER_LAYER_SELECTED];

const markerCategoryMappings = (((map.getStyle().metadata as any) ?? {})[
SBB_METADATA_MAPPINGS
] ?? []) as SbbMarkerCategoryMapping[];
const markerCategoryMappings = ((map.getStyle().metadata as any)?.[SBB_METADATA_MAPPINGS] ??
[]) as SbbMarkerCategoryMapping[];
for (const mapping of markerCategoryMappings) {
this.sources.push(mapping.source);
this.markerLayers.push(mapping.layer);
Expand Down Expand Up @@ -116,11 +115,9 @@ export class SbbMapMarkerService {
center: LngLatLike,
offset: PointLike = [0, 0],
): void {
this._getPrimaryMarkerSource(map).getClusterExpansionZoom(clusterId, (err, zoom) => {
if (zoom) {
this._easeTo(map, center, { zoom: zoom + 0.1, offset });
}
});
this._getPrimaryMarkerSource(map)
.getClusterExpansionZoom(clusterId)
.then((zoom) => zoom && this._easeTo(map, center, { zoom: zoom + 0.1, offset }));
}

onMarkerClicked(
Expand Down Expand Up @@ -154,7 +151,7 @@ export class SbbMapMarkerService {
filter: ['in', 'id', marker.id],
});

if (features && features.length) {
if (features?.length) {
// Marker is already visible on map.
// Center map to marker.
this._easeTo(map, marker.position as LngLatLike);
Expand Down Expand Up @@ -224,24 +221,26 @@ export class SbbMapMarkerService {
found: boolean[] = [],
): void {
const clusterId = cluster.properties?.cluster_id;
this._getPrimaryMarkerSource(map).getClusterChildren(clusterId, (e1, children) => {
// Skip processing if marker has been found
if (!found.length) {
for (const child of children ?? []) {
if (child.id === marker.id) {
found.push(true);
this._zoomToCluster(
map,
clusterId,
marker.position as LngLatLike,
this._getSelectedMarkerOffset(map),
);
} else if (child.properties?.cluster === true) {
this._zoomUntilMarkerVisible(map, child, marker, found);
this._getPrimaryMarkerSource(map)
.getClusterChildren(clusterId)
.then((children) => {
// Skip processing if marker has been found
if (!found.length) {
for (const child of children ?? []) {
if (child.id === marker.id) {
found.push(true);
this._zoomToCluster(
map,
clusterId,
marker.position as LngLatLike,
this._getSelectedMarkerOffset(map),
);
} else if (child.properties?.cluster === true) {
this._zoomUntilMarkerVisible(map, child, marker, found);
}
}
}
}
});
});
}

unselectFeature(map: MaplibreMap): void {
Expand Down
19 changes: 6 additions & 13 deletions src/journey-maps/angular/services/map/map-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export class SbbMapService {
* Emulate moving the map with the keyboard's arrow keys
*/
pan(map: MaplibreMap, dir: SbbDirection): void {
const xDir = dir === 'west' ? 1 : dir === 'east' ? -1 : 0;
const yDir = dir === 'north' ? 1 : dir === 'south' ? -1 : 0;
const directionMap = { west: [1, 0], east: [-1, 0], north: [0, 1], south: [0, -1] };
const [xDir, yDir] = directionMap[dir];

// same default values as KeyboardHandler.keydown() in mapbox's keyboard.js
const panStep = 100; // pixels
Expand All @@ -38,9 +38,10 @@ export class SbbMapService {
}

addMissingImage(map: MaplibreMap, name: string, icon: string): void {
map.loadImage(icon, (error: any, image: any) =>
this._imageLoadedCallback(map, name, error, image),
);
map
.loadImage(icon)
.then(({ data: image }) => map.addImage(name, image, { pixelRatio: 2 }))
.catch((reason) => console.warn(reason));
}

verifySources(map: MaplibreMap, sourceIds: string[]): void {
Expand All @@ -52,14 +53,6 @@ export class SbbMapService {
}
}

private _imageLoadedCallback(map: MaplibreMap, name: string, error: any, image: any): void {
if (error) {
console.error(error);
} else {
map.addImage(name, image, { pixelRatio: 2 });
}
}

private _centerMap(
map: MaplibreMap,
center: LngLatLike | undefined,
Expand Down
16 changes: 9 additions & 7 deletions src/journey-maps/esri-plugin/esri-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Utilize this component when you need to depict Esri Feature Layers on a MapLibre

### Compatibility

The `maplibre-gl` version compatible with this version of `journey-maps` is `3.x.y`.
The `maplibre-gl` version compatible with this version of `journey-maps` is `4.x.y`.

You can even use our [Journey-Maps-Client](https://angular.app.sbb.ch/journey-maps/components/angular/overview) as well.

Expand All @@ -17,12 +17,14 @@ You should add the following two CSS files to your application:

You can add them for example in the `styles` array of your `angular.json` file:

```json lines
"styles": [
"src/styles.scss",
"node_modules/maplibre-gl/dist/maplibre-gl.css"
"node_modules/@sbb-esta/angular/typography.css"
],
```json
{
"styles": [
"src/styles.scss",
"node_modules/maplibre-gl/dist/maplibre-gl.css",
"node_modules/@sbb-esta/angular/typography.css"
]
}
```

### Usage
Expand Down
2 changes: 1 addition & 1 deletion src/journey-maps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@angular/common": "0.0.0-NG",
"@angular/core": "0.0.0-NG",
"@types/geojson": ">=7946",
"maplibre-gl": "^3.6.2"
"maplibre-gl": "^4.7.1"
},
"ng-update": {
"packageGroup": [
Expand Down
10 changes: 9 additions & 1 deletion src/showcase/app/shared/shared.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PortalModule } from '@angular/cdk/portal';
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { SbbAccordionModule } from '@sbb-esta/angular/accordion';
Expand All @@ -11,7 +12,14 @@ import { PackageViewerComponent } from './package-viewer/package-viewer.componen

@NgModule({
declarations: [MarkdownViewerComponent, ModeNotificationToastComponent, PackageViewerComponent],
imports: [PortalModule, SbbButtonModule, SbbSidebarModule, SbbAccordionModule, RouterModule],
imports: [
PortalModule,
SbbButtonModule,
SbbSidebarModule,
SbbAccordionModule,
RouterModule,
CommonModule,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @swiss-chris

],
exports: [MarkdownViewerComponent, PackageViewerComponent],
})
export class SharedModule {}
2 changes: 1 addition & 1 deletion src/showcase/assets/stack-blitz/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@angular/router": "^18.0.0",
"@sbb-esta/angular": "^${version}",
"@sbb-esta/journey-maps": "^${version}",
"maplibre-gl": "^3.6.2",
"maplibre-gl": "^4.7.1",
"rxjs": "~7.8.1",
"tslib": "^2.6.2",
"zone.js": "~0.14.0"
Expand Down
Loading
Loading