mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2026-02-06 00:13:09 +00:00
improve layer stacking
This commit is contained in:
@@ -48,7 +48,7 @@
|
|||||||
language = 'en';
|
language = 'en';
|
||||||
}
|
}
|
||||||
|
|
||||||
map.init(PUBLIC_MAPBOX_TOKEN, language, hash, geocoder, geolocate);
|
map.init(language, hash, geocoder, geolocate);
|
||||||
});
|
});
|
||||||
|
|
||||||
onDestroy(() => {
|
onDestroy(() => {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { gpxStatistics } from '$lib/logic/statistics';
|
|||||||
import { getConvertedDistanceToKilometers } from '$lib/units';
|
import { getConvertedDistanceToKilometers } from '$lib/units';
|
||||||
import type { GeoJSONSource } from 'mapbox-gl';
|
import type { GeoJSONSource } from 'mapbox-gl';
|
||||||
import { get } from 'svelte/store';
|
import { get } from 'svelte/store';
|
||||||
import { map } from '$lib/components/map/map';
|
import { ANCHOR_LAYER_KEY, map } from '$lib/components/map/map';
|
||||||
import { allHidden } from '$lib/logic/hidden';
|
import { allHidden } from '$lib/logic/hidden';
|
||||||
|
|
||||||
const { distanceMarkers, distanceUnits } = settings;
|
const { distanceMarkers, distanceUnits } = settings;
|
||||||
@@ -44,7 +44,8 @@ export class DistanceMarkers {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (!map_.getLayer('distance-markers')) {
|
if (!map_.getLayer('distance-markers')) {
|
||||||
map_.addLayer({
|
map_.addLayer(
|
||||||
|
{
|
||||||
id: 'distance-markers',
|
id: 'distance-markers',
|
||||||
type: 'symbol',
|
type: 'symbol',
|
||||||
source: 'distance-markers',
|
source: 'distance-markers',
|
||||||
@@ -79,9 +80,9 @@ export class DistanceMarkers {
|
|||||||
'text-halo-width': 2,
|
'text-halo-width': 2,
|
||||||
'text-halo-color': 'white',
|
'text-halo-color': 'white',
|
||||||
},
|
},
|
||||||
});
|
},
|
||||||
} else {
|
ANCHOR_LAYER_KEY.distanceMarkers
|
||||||
map_.moveLayer('distance-markers');
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (map_.getLayer('distance-markers')) {
|
if (map_.getLayer('distance-markers')) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { get, type Readable } from 'svelte/store';
|
import { get, type Readable } from 'svelte/store';
|
||||||
import mapboxgl, { type FilterSpecification } from 'mapbox-gl';
|
import mapboxgl, { type FilterSpecification } from 'mapbox-gl';
|
||||||
import { map } from '$lib/components/map/map';
|
import { ANCHOR_LAYER_KEY, map } from '$lib/components/map/map';
|
||||||
import { waypointPopup, trackpointPopup } from './gpx-layer-popup';
|
import { waypointPopup, trackpointPopup } from './gpx-layer-popup';
|
||||||
import {
|
import {
|
||||||
ListTrackSegmentItem,
|
ListTrackSegmentItem,
|
||||||
@@ -196,7 +196,8 @@ export class GPXLayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!_map.getLayer(this.fileId)) {
|
if (!_map.getLayer(this.fileId)) {
|
||||||
_map.addLayer({
|
_map.addLayer(
|
||||||
|
{
|
||||||
id: this.fileId,
|
id: this.fileId,
|
||||||
type: 'line',
|
type: 'line',
|
||||||
source: this.fileId,
|
source: this.fileId,
|
||||||
@@ -209,7 +210,9 @@ export class GPXLayer {
|
|||||||
'line-width': ['get', 'width'],
|
'line-width': ['get', 'width'],
|
||||||
'line-opacity': ['get', 'opacity'],
|
'line-opacity': ['get', 'opacity'],
|
||||||
},
|
},
|
||||||
});
|
},
|
||||||
|
ANCHOR_LAYER_KEY.tracks
|
||||||
|
);
|
||||||
|
|
||||||
_map.on('click', this.fileId, this.layerOnClickBinded);
|
_map.on('click', this.fileId, this.layerOnClickBinded);
|
||||||
_map.on('contextmenu', this.fileId, this.layerOnContextMenuBinded);
|
_map.on('contextmenu', this.fileId, this.layerOnContextMenuBinded);
|
||||||
@@ -232,7 +235,8 @@ export class GPXLayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!_map.getLayer(this.fileId + '-waypoints')) {
|
if (!_map.getLayer(this.fileId + '-waypoints')) {
|
||||||
_map.addLayer({
|
_map.addLayer(
|
||||||
|
{
|
||||||
id: this.fileId + '-waypoints',
|
id: this.fileId + '-waypoints',
|
||||||
type: 'symbol',
|
type: 'symbol',
|
||||||
source: this.fileId + '-waypoints',
|
source: this.fileId + '-waypoints',
|
||||||
@@ -243,7 +247,9 @@ export class GPXLayer {
|
|||||||
'icon-padding': 0,
|
'icon-padding': 0,
|
||||||
'icon-allow-overlap': true,
|
'icon-allow-overlap': true,
|
||||||
},
|
},
|
||||||
});
|
},
|
||||||
|
ANCHOR_LAYER_KEY.waypoints
|
||||||
|
);
|
||||||
|
|
||||||
_map.on(
|
_map.on(
|
||||||
'mouseenter',
|
'mouseenter',
|
||||||
@@ -292,7 +298,7 @@ export class GPXLayer {
|
|||||||
'text-halo-color': 'white',
|
'text-halo-color': 'white',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
_map.getLayer('distance-markers') ? 'distance-markers' : undefined
|
ANCHOR_LAYER_KEY.directionMarkers
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -393,13 +399,13 @@ export class GPXLayer {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (_map.getLayer(this.fileId)) {
|
if (_map.getLayer(this.fileId)) {
|
||||||
_map.moveLayer(this.fileId);
|
_map.moveLayer(this.fileId, ANCHOR_LAYER_KEY.tracks);
|
||||||
}
|
}
|
||||||
if (_map.getLayer(this.fileId + '-waypoints')) {
|
if (_map.getLayer(this.fileId + '-waypoints')) {
|
||||||
_map.moveLayer(this.fileId + '-waypoints');
|
_map.moveLayer(this.fileId + '-waypoints', ANCHOR_LAYER_KEY.waypoints);
|
||||||
}
|
}
|
||||||
if (_map.getLayer(this.fileId + '-direction')) {
|
if (_map.getLayer(this.fileId + '-direction')) {
|
||||||
_map.moveLayer(this.fileId + '-direction');
|
_map.moveLayer(this.fileId + '-direction', ANCHOR_LAYER_KEY.directionMarkers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { overpassQueryData } from '$lib/assets/layers';
|
|||||||
import { MapPopup } from '$lib/components/map/map-popup';
|
import { MapPopup } from '$lib/components/map/map-popup';
|
||||||
import { settings } from '$lib/logic/settings';
|
import { settings } from '$lib/logic/settings';
|
||||||
import { db } from '$lib/db';
|
import { db } from '$lib/db';
|
||||||
|
import { ANCHOR_LAYER_KEY } from '$lib/components/map/map';
|
||||||
|
|
||||||
const { currentOverpassQueries } = settings;
|
const { currentOverpassQueries } = settings;
|
||||||
|
|
||||||
@@ -85,7 +86,8 @@ export class OverpassLayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!this.map.getLayer('overpass')) {
|
if (!this.map.getLayer('overpass')) {
|
||||||
this.map.addLayer({
|
this.map.addLayer(
|
||||||
|
{
|
||||||
id: 'overpass',
|
id: 'overpass',
|
||||||
type: 'symbol',
|
type: 'symbol',
|
||||||
source: 'overpass',
|
source: 'overpass',
|
||||||
@@ -95,7 +97,9 @@ export class OverpassLayer {
|
|||||||
'icon-padding': 0,
|
'icon-padding': 0,
|
||||||
'icon-allow-overlap': ['step', ['zoom'], false, 14, true],
|
'icon-allow-overlap': ['step', ['zoom'], false, 14, true],
|
||||||
},
|
},
|
||||||
});
|
},
|
||||||
|
ANCHOR_LAYER_KEY.overpass
|
||||||
|
);
|
||||||
|
|
||||||
this.map.on('mouseenter', 'overpass', this.onHoverBinded);
|
this.map.on('mouseenter', 'overpass', this.onHoverBinded);
|
||||||
this.map.on('click', 'overpass', this.onHoverBinded);
|
this.map.on('click', 'overpass', this.onHoverBinded);
|
||||||
|
|||||||
@@ -20,6 +20,28 @@ let fitBoundsOptions: mapboxgl.MapOptions['fitBoundsOptions'] = {
|
|||||||
easing: () => 1,
|
easing: () => 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const emptySource: mapboxgl.GeoJSONSourceSpecification = {
|
||||||
|
type: 'geojson',
|
||||||
|
data: {
|
||||||
|
type: 'FeatureCollection',
|
||||||
|
features: [],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
export const ANCHOR_LAYER_KEY = {
|
||||||
|
mapillary: 'mapillary-end',
|
||||||
|
tracks: 'tracks-end',
|
||||||
|
directionMarkers: 'direction-markers-end',
|
||||||
|
distanceMarkers: 'distance-markers-end',
|
||||||
|
interactions: 'interactions-end',
|
||||||
|
overpass: 'overpass-end',
|
||||||
|
waypoints: 'waypoints-end',
|
||||||
|
};
|
||||||
|
const anchorLayers: mapboxgl.LayerSpecification[] = Object.values(ANCHOR_LAYER_KEY).map((id) => ({
|
||||||
|
id: id,
|
||||||
|
type: 'symbol',
|
||||||
|
source: 'empty-source',
|
||||||
|
}));
|
||||||
|
|
||||||
export class MapboxGLMap {
|
export class MapboxGLMap {
|
||||||
private _map: Writable<mapboxgl.Map | null> = writable(null);
|
private _map: Writable<mapboxgl.Map | null> = writable(null);
|
||||||
private _onLoadCallbacks: ((map: mapboxgl.Map) => void)[] = [];
|
private _onLoadCallbacks: ((map: mapboxgl.Map) => void)[] = [];
|
||||||
@@ -29,19 +51,15 @@ export class MapboxGLMap {
|
|||||||
return this._map.subscribe(run, invalidate);
|
return this._map.subscribe(run, invalidate);
|
||||||
}
|
}
|
||||||
|
|
||||||
init(
|
init(language: string, hash: boolean, geocoder: boolean, geolocate: boolean) {
|
||||||
accessToken: string,
|
|
||||||
language: string,
|
|
||||||
hash: boolean,
|
|
||||||
geocoder: boolean,
|
|
||||||
geolocate: boolean
|
|
||||||
) {
|
|
||||||
const map = new mapboxgl.Map({
|
const map = new mapboxgl.Map({
|
||||||
container: 'map',
|
container: 'map',
|
||||||
style: {
|
style: {
|
||||||
version: 8,
|
version: 8,
|
||||||
sources: {},
|
sources: {
|
||||||
layers: [],
|
'empty-source': emptySource,
|
||||||
|
},
|
||||||
|
layers: anchorLayers,
|
||||||
imports: [
|
imports: [
|
||||||
{
|
{
|
||||||
id: 'basemap',
|
id: 'basemap',
|
||||||
@@ -50,11 +68,6 @@ export class MapboxGLMap {
|
|||||||
{
|
{
|
||||||
id: 'overlays',
|
id: 'overlays',
|
||||||
url: '',
|
url: '',
|
||||||
data: {
|
|
||||||
version: 8,
|
|
||||||
sources: {},
|
|
||||||
layers: [],
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import mapboxgl, { type LayerSpecification, type VectorSourceSpecification } fro
|
|||||||
import { Viewer, type ViewerBearingEvent } from 'mapillary-js/dist/mapillary.module';
|
import { Viewer, type ViewerBearingEvent } from 'mapillary-js/dist/mapillary.module';
|
||||||
import 'mapillary-js/dist/mapillary.css';
|
import 'mapillary-js/dist/mapillary.css';
|
||||||
import { mapCursor, MapCursorState } from '$lib/logic/map-cursor';
|
import { mapCursor, MapCursorState } from '$lib/logic/map-cursor';
|
||||||
|
import { ANCHOR_LAYER_KEY } from '$lib/components/map/map';
|
||||||
|
|
||||||
const mapillarySource: VectorSourceSpecification = {
|
const mapillarySource: VectorSourceSpecification = {
|
||||||
type: 'vector',
|
type: 'vector',
|
||||||
@@ -99,10 +100,10 @@ export class MapillaryLayer {
|
|||||||
this.map.addSource('mapillary', mapillarySource);
|
this.map.addSource('mapillary', mapillarySource);
|
||||||
}
|
}
|
||||||
if (!this.map.getLayer('mapillary-sequence')) {
|
if (!this.map.getLayer('mapillary-sequence')) {
|
||||||
this.map.addLayer(mapillarySequenceLayer);
|
this.map.addLayer(mapillarySequenceLayer, ANCHOR_LAYER_KEY.mapillary);
|
||||||
}
|
}
|
||||||
if (!this.map.getLayer('mapillary-image')) {
|
if (!this.map.getLayer('mapillary-image')) {
|
||||||
this.map.addLayer(mapillaryImageLayer);
|
this.map.addLayer(mapillaryImageLayer, ANCHOR_LAYER_KEY.mapillary);
|
||||||
}
|
}
|
||||||
this.map.on('style.load', this.addBinded);
|
this.map.on('style.load', this.addBinded);
|
||||||
this.map.on('mouseenter', 'mapillary-image', this.onMouseEnterBinded);
|
this.map.on('mouseenter', 'mapillary-image', this.onMouseEnterBinded);
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
import { onDestroy, onMount } from 'svelte';
|
import { onDestroy, onMount } from 'svelte';
|
||||||
import { getURLForLanguage } from '$lib/utils';
|
import { getURLForLanguage } from '$lib/utils';
|
||||||
import { Trash2 } from '@lucide/svelte';
|
import { Trash2 } from '@lucide/svelte';
|
||||||
import { map } from '$lib/components/map/map';
|
import { ANCHOR_LAYER_KEY, map } from '$lib/components/map/map';
|
||||||
import type { GeoJSONSource } from 'mapbox-gl';
|
import type { GeoJSONSource } from 'mapbox-gl';
|
||||||
import { selection } from '$lib/logic/selection';
|
import { selection } from '$lib/logic/selection';
|
||||||
import { fileActions } from '$lib/logic/file-actions';
|
import { fileActions } from '$lib/logic/file-actions';
|
||||||
@@ -63,7 +63,8 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (!$map.getLayer('rectangle')) {
|
if (!$map.getLayer('rectangle')) {
|
||||||
$map.addLayer({
|
$map.addLayer(
|
||||||
|
{
|
||||||
id: 'rectangle',
|
id: 'rectangle',
|
||||||
type: 'fill',
|
type: 'fill',
|
||||||
source: 'rectangle',
|
source: 'rectangle',
|
||||||
@@ -71,7 +72,9 @@
|
|||||||
'fill-color': 'SteelBlue',
|
'fill-color': 'SteelBlue',
|
||||||
'fill-opacity': 0.5,
|
'fill-opacity': 0.5,
|
||||||
},
|
},
|
||||||
});
|
},
|
||||||
|
ANCHOR_LAYER_KEY.interactions
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { ListItem, ListTrackSegmentItem } from '$lib/components/file-list/file-list';
|
import { ListItem, ListTrackSegmentItem } from '$lib/components/file-list/file-list';
|
||||||
import { map } from '$lib/components/map/map';
|
import { ANCHOR_LAYER_KEY, map } from '$lib/components/map/map';
|
||||||
import { fileActions } from '$lib/logic/file-actions';
|
import { fileActions } from '$lib/logic/file-actions';
|
||||||
import { GPXFileStateCollectionObserver, type GPXFileState } from '$lib/logic/file-state';
|
import { GPXFileStateCollectionObserver, type GPXFileState } from '$lib/logic/file-state';
|
||||||
import { selection } from '$lib/logic/selection';
|
import { selection } from '$lib/logic/selection';
|
||||||
@@ -144,7 +144,8 @@ export class ReducedGPXLayerCollection {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (!map_.getLayer('simplified')) {
|
if (!map_.getLayer('simplified')) {
|
||||||
map_.addLayer({
|
map_.addLayer(
|
||||||
|
{
|
||||||
id: 'simplified',
|
id: 'simplified',
|
||||||
type: 'line',
|
type: 'line',
|
||||||
source: 'simplified',
|
source: 'simplified',
|
||||||
@@ -152,9 +153,9 @@ export class ReducedGPXLayerCollection {
|
|||||||
'line-color': 'white',
|
'line-color': 'white',
|
||||||
'line-width': 3,
|
'line-width': 3,
|
||||||
},
|
},
|
||||||
});
|
},
|
||||||
} else {
|
ANCHOR_LAYER_KEY.interactions
|
||||||
map_.moveLayer('simplified');
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { get } from 'svelte/store';
|
|||||||
import { fileStateCollection } from '$lib/logic/file-state';
|
import { fileStateCollection } from '$lib/logic/file-state';
|
||||||
import { fileActions } from '$lib/logic/file-actions';
|
import { fileActions } from '$lib/logic/file-actions';
|
||||||
import { mapCursor, MapCursorState } from '$lib/logic/map-cursor';
|
import { mapCursor, MapCursorState } from '$lib/logic/map-cursor';
|
||||||
|
import { ANCHOR_LAYER_KEY } from '$lib/components/map/map';
|
||||||
|
|
||||||
export class SplitControls {
|
export class SplitControls {
|
||||||
map: mapboxgl.Map;
|
map: mapboxgl.Map;
|
||||||
@@ -108,7 +109,8 @@ export class SplitControls {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!this.map.getLayer('split-controls')) {
|
if (!this.map.getLayer('split-controls')) {
|
||||||
this.map.addLayer({
|
this.map.addLayer(
|
||||||
|
{
|
||||||
id: 'split-controls',
|
id: 'split-controls',
|
||||||
type: 'symbol',
|
type: 'symbol',
|
||||||
source: 'split-controls',
|
source: 'split-controls',
|
||||||
@@ -118,14 +120,14 @@ export class SplitControls {
|
|||||||
'icon-padding': 0,
|
'icon-padding': 0,
|
||||||
},
|
},
|
||||||
filter: ['<=', ['get', 'minZoom'], ['zoom']],
|
filter: ['<=', ['get', 'minZoom'], ['zoom']],
|
||||||
});
|
},
|
||||||
|
ANCHOR_LAYER_KEY.interactions
|
||||||
|
);
|
||||||
|
|
||||||
this.map.on('mouseenter', 'split-controls', this.layerOnMouseEnterBinded);
|
this.map.on('mouseenter', 'split-controls', this.layerOnMouseEnterBinded);
|
||||||
this.map.on('mouseleave', 'split-controls', this.layerOnMouseLeaveBinded);
|
this.map.on('mouseleave', 'split-controls', this.layerOnMouseLeaveBinded);
|
||||||
this.map.on('click', 'split-controls', this.layerOnClickBinded);
|
this.map.on('click', 'split-controls', this.layerOnClickBinded);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.map.moveLayer('split-controls');
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// No reliable way to check if the map is ready to add sources and layers
|
// No reliable way to check if the map is ready to add sources and layers
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user