Skip to content

Commit

Permalink
use style imports instead of layers to allow stacking mapbox styles, c…
Browse files Browse the repository at this point in the history
…loses #32
  • Loading branch information
vcoppe committed Aug 31, 2024
1 parent 33f3b6c commit 0cb7811
Show file tree
Hide file tree
Showing 9 changed files with 3,112 additions and 1,040 deletions.
1,864 changes: 1,864 additions & 0 deletions website/src/lib/assets/custom/bikerouter-gravel.json

Large diffs are not rendered by default.

396 changes: 279 additions & 117 deletions website/src/lib/assets/layers.ts

Large diffs are not rendered by default.

670 changes: 347 additions & 323 deletions website/src/lib/components/Map.svelte

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions website/src/lib/components/gpx-layer/DistanceMarkers.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@

import { font } from "$lib/assets/layers";
import { settings } from "$lib/db";
import { gpxStatistics } from "$lib/stores";
import { get } from "svelte/store";

const { distanceMarkers, distanceUnits, currentBasemap } = settings;
const { distanceMarkers, distanceUnits } = settings;

export class DistanceMarkers {
map: mapboxgl.Map;
Expand All @@ -17,7 +16,7 @@ export class DistanceMarkers {
this.unsubscribes.push(gpxStatistics.subscribe(this.updateBinded));
this.unsubscribes.push(distanceMarkers.subscribe(this.updateBinded));
this.unsubscribes.push(distanceUnits.subscribe(this.updateBinded));
this.map.on('style.load', this.updateBinded);
this.map.on('style.import.load', this.updateBinded);
}

update() {
Expand All @@ -40,7 +39,7 @@ export class DistanceMarkers {
layout: {
'text-field': ['get', 'distance'],
'text-size': 14,
'text-font': [font[get(currentBasemap)] ?? 'Open Sans Bold'],
'text-font': ['Open Sans Bold'],
'text-padding': 20,
},
paint: {
Expand Down
11 changes: 5 additions & 6 deletions website/src/lib/components/gpx-layer/GPXLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { addSelectItem, selectItem, selection } from "$lib/components/file-list/
import { ListTrackSegmentItem, ListWaypointItem, ListWaypointsItem, ListTrackItem, ListFileItem, ListRootItem } from "$lib/components/file-list/FileList";
import type { Waypoint } from "gpx";
import { getElevation, resetCursor, setGrabbingCursor, setPointerCursor, setScissorsCursor } from "$lib/utils";
import { font } from "$lib/assets/layers";
import { selectedWaypoint } from "$lib/components/toolbar/tools/Waypoint.svelte";
import { MapPin, Square } from "lucide-static";
import { getSymbolKey, symbols } from "$lib/assets/symbols";
Expand Down Expand Up @@ -66,7 +65,7 @@ function getMarkerForSymbol(symbol: string | undefined, layerColor: string) {
</svg>`;
}

const { directionMarkers, verticalFileView, currentBasemap, defaultOpacity, defaultWeight } = settings;
const { directionMarkers, verticalFileView, defaultOpacity, defaultWeight } = settings;

export class GPXLayer {
map: mapboxgl.Map;
Expand Down Expand Up @@ -112,7 +111,7 @@ export class GPXLayer {
}));
this.draggable = get(currentTool) === Tool.WAYPOINT;

this.map.on('style.load', this.updateBinded);
this.map.on('style.import.load', this.updateBinded);
}

update() {
Expand Down Expand Up @@ -170,7 +169,7 @@ export class GPXLayer {
'text-keep-upright': false,
'text-max-angle': 361,
'text-allow-overlap': true,
'text-font': [font[get(currentBasemap)] ?? 'Open Sans Bold'],
'text-font': ['Open Sans Bold'],
'symbol-placement': 'line',
'symbol-spacing': 20,
},
Expand Down Expand Up @@ -294,7 +293,7 @@ export class GPXLayer {

updateMap(map: mapboxgl.Map) {
this.map = map;
this.map.on('style.load', this.updateBinded);
this.map.on('style.import.load', this.updateBinded);
this.update();
}

Expand All @@ -303,7 +302,7 @@ export class GPXLayer {
this.map.off('click', this.fileId, this.layerOnClickBinded);
this.map.off('mouseenter', this.fileId, this.layerOnMouseEnterBinded);
this.map.off('mouseleave', this.fileId, this.layerOnMouseLeaveBinded);
this.map.off('style.load', this.updateBinded);
this.map.off('style.import.load', this.updateBinded);

if (this.map.getLayer(this.fileId + '-direction')) {
this.map.removeLayer(this.fileId + '-direction');
Expand Down
Loading

0 comments on commit 0cb7811

Please sign in to comment.