mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-09-01 08:12:32 +00:00
direction markers
This commit is contained in:
@@ -278,6 +278,12 @@ export const basemaps: { [key: string]: string | Style; } = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Object.values(basemaps).forEach((basemap) => {
|
||||||
|
if (typeof basemap === 'object') {
|
||||||
|
basemap["glyphs"] = "mapbox://fonts/mapbox/{fontstack}/{range}.pbf";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
export const overlays: { [key: string]: AnySourceData; } = {
|
export const overlays: { [key: string]: AnySourceData; } = {
|
||||||
cyclOSMlite: {
|
cyclOSMlite: {
|
||||||
type: 'raster',
|
type: 'raster',
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
import type { GPXFile } from "gpx";
|
import type { GPXFile } from "gpx";
|
||||||
import { map, selectFiles, currentTool, Tool } from "$lib/stores";
|
import { map, selectFiles, currentTool, Tool } from "$lib/stores";
|
||||||
|
import { settings } from "$lib/db";
|
||||||
import { get, type Readable } from "svelte/store";
|
import { get, type Readable } from "svelte/store";
|
||||||
import mapboxgl from "mapbox-gl";
|
import mapboxgl from "mapbox-gl";
|
||||||
|
|
||||||
@@ -36,6 +37,8 @@ function decrementColor(color: string) {
|
|||||||
colorCount[color]--;
|
colorCount[color]--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { directionMarkers } = settings;
|
||||||
|
|
||||||
export class GPXLayer {
|
export class GPXLayer {
|
||||||
map: mapboxgl.Map;
|
map: mapboxgl.Map;
|
||||||
fileId: string;
|
fileId: string;
|
||||||
@@ -44,7 +47,7 @@ export class GPXLayer {
|
|||||||
popup: mapboxgl.Popup;
|
popup: mapboxgl.Popup;
|
||||||
popupElement: HTMLElement;
|
popupElement: HTMLElement;
|
||||||
markers: mapboxgl.Marker[] = [];
|
markers: mapboxgl.Marker[] = [];
|
||||||
unsubscribe: () => void;
|
unsubscribe: Function[] = [];
|
||||||
|
|
||||||
updateBinded: () => void = this.update.bind(this);
|
updateBinded: () => void = this.update.bind(this);
|
||||||
selectOnClickBinded: (e: any) => void = this.selectOnClick.bind(this);
|
selectOnClickBinded: (e: any) => void = this.selectOnClick.bind(this);
|
||||||
@@ -56,7 +59,8 @@ export class GPXLayer {
|
|||||||
this.layerColor = getColor();
|
this.layerColor = getColor();
|
||||||
this.popup = popup;
|
this.popup = popup;
|
||||||
this.popupElement = popupElement;
|
this.popupElement = popupElement;
|
||||||
this.unsubscribe = file.subscribe(this.update.bind(this));
|
this.unsubscribe.push(file.subscribe(this.updateBinded));
|
||||||
|
this.unsubscribe.push(directionMarkers.subscribe(this.updateBinded));
|
||||||
|
|
||||||
this.map.on('style.load', this.updateBinded);
|
this.map.on('style.load', this.updateBinded);
|
||||||
}
|
}
|
||||||
@@ -99,6 +103,33 @@ export class GPXLayer {
|
|||||||
this.map.on('mouseenter', this.fileId, toPointerCursor);
|
this.map.on('mouseenter', this.fileId, toPointerCursor);
|
||||||
this.map.on('mouseleave', this.fileId, toDefaultCursor);
|
this.map.on('mouseleave', this.fileId, toDefaultCursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (get(directionMarkers)) {
|
||||||
|
if (!this.map.getLayer(this.fileId + '-direction')) {
|
||||||
|
this.map.addLayer({
|
||||||
|
id: this.fileId + '-direction',
|
||||||
|
type: 'symbol',
|
||||||
|
source: this.fileId,
|
||||||
|
layout: {
|
||||||
|
'text-field': '>',
|
||||||
|
'text-keep-upright': false,
|
||||||
|
'text-max-angle': 361,
|
||||||
|
'symbol-placement': 'line',
|
||||||
|
'symbol-spacing': 25,
|
||||||
|
},
|
||||||
|
paint: {
|
||||||
|
'text-color': 'white',
|
||||||
|
'text-halo-width': 0.5,
|
||||||
|
'text-halo-color': 'white'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (this.map.getLayer(this.fileId + '-direction')) {
|
||||||
|
this.map.removeLayer(this.fileId + '-direction');
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (e) { // No reliable way to check if the map is ready to add sources and layers
|
} catch (e) { // No reliable way to check if the map is ready to add sources and layers
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -142,6 +173,9 @@ export class GPXLayer {
|
|||||||
this.map.off('mouseleave', this.fileId, toDefaultCursor);
|
this.map.off('mouseleave', this.fileId, toDefaultCursor);
|
||||||
this.map.off('style.load', this.updateBinded);
|
this.map.off('style.load', this.updateBinded);
|
||||||
|
|
||||||
|
if (this.map.getLayer(this.fileId + '-direction')) {
|
||||||
|
this.map.removeLayer(this.fileId + '-direction');
|
||||||
|
}
|
||||||
if (this.map.getLayer(this.fileId)) {
|
if (this.map.getLayer(this.fileId)) {
|
||||||
this.map.removeLayer(this.fileId);
|
this.map.removeLayer(this.fileId);
|
||||||
}
|
}
|
||||||
@@ -153,7 +187,7 @@ export class GPXLayer {
|
|||||||
marker.remove();
|
marker.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.unsubscribe();
|
this.unsubscribe.forEach((unsubscribe) => unsubscribe());
|
||||||
|
|
||||||
decrementColor(this.layerColor);
|
decrementColor(this.layerColor);
|
||||||
}
|
}
|
||||||
@@ -162,6 +196,9 @@ export class GPXLayer {
|
|||||||
if (this.map.getLayer(this.fileId)) {
|
if (this.map.getLayer(this.fileId)) {
|
||||||
this.map.moveLayer(this.fileId);
|
this.map.moveLayer(this.fileId);
|
||||||
}
|
}
|
||||||
|
if (this.map.getLayer(this.fileId + '-direction')) {
|
||||||
|
this.map.moveLayer(this.fileId + '-direction');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
selectOnClick(e: any) {
|
selectOnClick(e: any) {
|
||||||
|
Reference in New Issue
Block a user