Skip to content

Commit c3315cb

Browse files
committed
Fix iOS not loading the map at startup
1 parent e0bcb78 commit c3315cb

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

IsraelHiking.Web/src/application/services/map.service.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { inject, Service } from "@angular/core";
22
import { Store } from "@ngxs/store";
3+
import { MAPLIBRE_WORKER_URL } from "@maplibre/ngx-maplibre-gl/config";
34
import type { ErrorEvent, GeoJSONFeature, LayerSpecification, Map, Point, PaddingOptions, SourceSpecification } from "maplibre-gl";
45

56
import { CancelableTimeoutService } from "./cancelable-timeout.service";
@@ -25,6 +26,7 @@ export class MapService {
2526
private readonly databaseService = inject(DatabaseService);
2627
private readonly overpassTurboService = inject(OverpassTurboService);
2728
private readonly store = inject(Store);
29+
private readonly maplibreWorkerUrl = inject(MAPLIBRE_WORKER_URL, { optional: true });
2830

2931
public initializationPromise = new Promise<void>((resolve) => { this.resolve = resolve; });
3032

@@ -46,6 +48,11 @@ export class MapService {
4648
return;
4749
}
4850
const maplibregl = await import("maplibre-gl");
51+
// maplibre only falls back to a worker url next to its own bundle when that bundle is served over http(s).
52+
// In the app the origin is capacitor://localhost, so the fallback yields an empty url and every worker dies on
53+
// creation. ngx-maplibre-gl sets this url too, but only once the first map is created, which is too late since
54+
// the workers are already needed here for the contour protocol below.
55+
maplibregl.setWorkerUrl(this.getFullUrl(this.maplibreWorkerUrl ?? "maplibre-gl-worker.mjs"));
4956
maplibregl.setRTLTextPlugin("./mapbox-gl-rtl-text.js", false);
5057
maplibregl.addProtocol("custom", (params) => this.databaseService.getCustomTile(params.url));
5158
maplibregl.addProtocol("slice", (params) => this.databaseService.getSliceTile(params.url));

0 commit comments

Comments
 (0)