mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2026-04-27 22:05:54 +00:00
Compare commits
21 Commits
16b8988fa7
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
17559913fd | ||
|
|
dd9aba3adb | ||
|
|
55590d68a6 | ||
|
|
bd40fbae74 | ||
|
|
690cbc49cc | ||
|
|
8e9f16c460 | ||
|
|
36b16ddeef | ||
|
|
c60b64f24f | ||
|
|
fdb6fe4e52 | ||
|
|
0bf168e67e | ||
|
|
d762a45eb9 | ||
|
|
548ab9a459 | ||
|
|
315c1f6a61 | ||
|
|
98257bee12 | ||
|
|
5561b7d9fe | ||
|
|
320887206c | ||
|
|
04a1bf6a55 | ||
|
|
0989371874 | ||
|
|
3dcd6e52d3 | ||
|
|
0f06d0d461 | ||
|
|
db33310a10 |
@@ -142,6 +142,7 @@ export class MapLayerEventManager {
|
||||
}
|
||||
|
||||
private _handleMouseMove(e: maplibregl.MapMouseEvent) {
|
||||
if (e.originalEvent.buttons > 0) return;
|
||||
const featuresByLayer = this._getRenderedFeaturesByLayer(e);
|
||||
Object.keys(this._listeners).forEach((layerId) => {
|
||||
const features = featuresByLayer[layerId] || [];
|
||||
|
||||
@@ -81,8 +81,13 @@ export class StyleManager {
|
||||
|
||||
let basemap = get(currentBasemap);
|
||||
const basemapInfo = basemaps[basemap] ?? custom[basemap]?.value ?? basemaps[defaultBasemap];
|
||||
const basemapStyle = await this.get(basemapInfo);
|
||||
|
||||
let basemapStyle = basemaps.openStreetMap as maplibregl.StyleSpecification;
|
||||
try {
|
||||
basemapStyle = await this.get(basemapInfo);
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
}
|
||||
this.merge(style, basemapStyle);
|
||||
|
||||
if (this._maptilerKey !== '') {
|
||||
@@ -109,45 +114,52 @@ export class StyleManager {
|
||||
if (!layers[overlay]) {
|
||||
if (this._pastOverlays.has(overlay)) {
|
||||
const overlayInfo = custom[overlay]?.value ?? overlays[overlay];
|
||||
const overlayStyle = await this.get(overlayInfo);
|
||||
for (let layer of overlayStyle.layers ?? []) {
|
||||
if (map_.getLayer(layer.id)) {
|
||||
map_.removeLayer(layer.id);
|
||||
try {
|
||||
const overlayStyle = await this.get(overlayInfo);
|
||||
for (let layer of overlayStyle.layers ?? []) {
|
||||
if (map_.getLayer(layer.id)) {
|
||||
map_.removeLayer(layer.id);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// Should not happen
|
||||
}
|
||||
this._pastOverlays.delete(overlay);
|
||||
}
|
||||
} else {
|
||||
const overlayInfo = custom[overlay]?.value ?? overlays[overlay];
|
||||
const overlayStyle = await this.get(overlayInfo);
|
||||
const opacity = overlayOpacities[overlay];
|
||||
try {
|
||||
const overlayStyle = await this.get(overlayInfo);
|
||||
const opacity = overlayOpacities[overlay];
|
||||
|
||||
for (let sourceId in overlayStyle.sources) {
|
||||
if (!map_.getSource(sourceId)) {
|
||||
map_.addSource(sourceId, overlayStyle.sources[sourceId]);
|
||||
}
|
||||
}
|
||||
|
||||
for (let layer of overlayStyle.layers ?? []) {
|
||||
if (!map_.getLayer(layer.id)) {
|
||||
if (opacity !== undefined) {
|
||||
if (layer.type === 'raster') {
|
||||
if (!layer.paint) {
|
||||
layer.paint = {};
|
||||
}
|
||||
layer.paint['raster-opacity'] = opacity;
|
||||
} else if (layer.type === 'hillshade') {
|
||||
if (!layer.paint) {
|
||||
layer.paint = {};
|
||||
}
|
||||
layer.paint['hillshade-exaggeration'] = opacity / 2;
|
||||
}
|
||||
for (let sourceId in overlayStyle.sources) {
|
||||
if (!map_.getSource(sourceId)) {
|
||||
map_.addSource(sourceId, overlayStyle.sources[sourceId]);
|
||||
}
|
||||
map_.addLayer(layer, ANCHOR_LAYER_KEY.overlays);
|
||||
}
|
||||
}
|
||||
|
||||
this._pastOverlays.add(overlay);
|
||||
for (let layer of overlayStyle.layers ?? []) {
|
||||
if (!map_.getLayer(layer.id)) {
|
||||
if (opacity !== undefined) {
|
||||
if (layer.type === 'raster') {
|
||||
if (!layer.paint) {
|
||||
layer.paint = {};
|
||||
}
|
||||
layer.paint['raster-opacity'] = opacity;
|
||||
} else if (layer.type === 'hillshade') {
|
||||
if (!layer.paint) {
|
||||
layer.paint = {};
|
||||
}
|
||||
layer.paint['hillshade-exaggeration'] = opacity / 2;
|
||||
}
|
||||
}
|
||||
map_.addLayer(layer, ANCHOR_LAYER_KEY.overlays);
|
||||
}
|
||||
}
|
||||
this._pastOverlays.add(overlay);
|
||||
} catch (e) {
|
||||
console.error(e.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {}
|
||||
@@ -181,6 +193,9 @@ export class StyleManager {
|
||||
styleUrl = styleUrl.replace(maptilerKeyPlaceHolder, this._maptilerKey);
|
||||
}
|
||||
const response = await fetch(styleUrl, { cache: 'force-cache' });
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error fetching style "${styleInfo}": ${response.status}`);
|
||||
}
|
||||
const style = await response.json();
|
||||
return style;
|
||||
} else {
|
||||
|
||||
@@ -57,8 +57,10 @@ export class RoutingControls {
|
||||
|
||||
updateControlsBinded: () => void = this.updateControls.bind(this);
|
||||
appendAnchorBinded: (e: MapMouseEvent) => void = this.appendAnchor.bind(this);
|
||||
addIntermediateAnchorBinded: (e: MapMouseEvent) => void = this.addIntermediateAnchor.bind(this);
|
||||
|
||||
draggedAnchorIndex: number | null = null;
|
||||
lastDraggedAnchorEventTime: number = 0;
|
||||
draggingStartingPosition: maplibregl.Point = new maplibregl.Point(0, 0);
|
||||
onMouseEnterBinded: () => void = this.onMouseEnter.bind(this);
|
||||
onMouseLeaveBinded: () => void = this.onMouseLeave.bind(this);
|
||||
@@ -133,6 +135,7 @@ export class RoutingControls {
|
||||
map_.on('style.load', this.updateControlsBinded);
|
||||
map_.on('click', this.appendAnchorBinded);
|
||||
layerEventManager.on('mousemove', this.fileId, this.showTemporaryAnchorBinded);
|
||||
layerEventManager.on('click', this.fileId, this.addIntermediateAnchorBinded);
|
||||
|
||||
this.fileUnsubscribe = this.file.subscribe(this.updateControlsBinded);
|
||||
}
|
||||
@@ -237,6 +240,7 @@ export class RoutingControls {
|
||||
map_?.off('style.load', this.updateControlsBinded);
|
||||
map_?.off('click', this.appendAnchorBinded);
|
||||
layerEventManager?.off('mousemove', this.fileId, this.showTemporaryAnchorBinded);
|
||||
layerEventManager?.off('click', this.fileId, this.addIntermediateAnchorBinded);
|
||||
map_?.off('mousemove', this.updateTemporaryAnchorBinded);
|
||||
|
||||
this.layers.forEach((layer) => {
|
||||
@@ -521,12 +525,19 @@ export class RoutingControls {
|
||||
if (get(streetViewEnabled) && get(streetViewSource) === 'google') {
|
||||
return;
|
||||
}
|
||||
if (
|
||||
this.draggedAnchorIndex !== null ||
|
||||
Date.now() - this.lastDraggedAnchorEventTime < 100
|
||||
) {
|
||||
// Exit if anchor is being dragged
|
||||
return;
|
||||
}
|
||||
if (
|
||||
e.target.queryRenderedFeatures(e.point, {
|
||||
layers: [...this.layers.values()].map((layer) => layer.id),
|
||||
layers: [this.fileId, ...[...this.layers.values()].map((layer) => layer.id)],
|
||||
}).length
|
||||
) {
|
||||
// Clicked on routing control, ignoring
|
||||
// Clicked on routing control or layer, ignoring
|
||||
return;
|
||||
}
|
||||
this.appendAnchorWithCoordinates({
|
||||
@@ -598,6 +609,15 @@ export class RoutingControls {
|
||||
await this.routeBetweenAnchors([lastAnchor, newAnchor], [lastAnchorPoint, newAnchorPoint]);
|
||||
}
|
||||
|
||||
addIntermediateAnchor(e: maplibregl.MapMouseEvent) {
|
||||
e.preventDefault();
|
||||
|
||||
if (this.temporaryAnchor !== null) {
|
||||
this.turnIntoPermanentAnchor();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
getNeighbouringAnchors(anchor: Anchor): [Anchor | null, Anchor | null] {
|
||||
let previousAnchor: Anchor | null = null;
|
||||
let nextAnchor: Anchor | null = null;
|
||||
@@ -818,8 +838,11 @@ export class RoutingControls {
|
||||
onClick(e: MapLayerMouseEvent) {
|
||||
e.preventDefault();
|
||||
|
||||
if (this.temporaryAnchor !== null) {
|
||||
this.turnIntoPermanentAnchor();
|
||||
if (
|
||||
this.draggedAnchorIndex !== null ||
|
||||
Date.now() - this.lastDraggedAnchorEventTime < 100
|
||||
) {
|
||||
// Exit if anchor is being dragged
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -908,6 +931,8 @@ export class RoutingControls {
|
||||
lat: e.lngLat.lat,
|
||||
lon: e.lngLat.lng,
|
||||
});
|
||||
|
||||
this.lastDraggedAnchorEventTime = Date.now();
|
||||
}
|
||||
|
||||
onMouseUp(e: MapLayerMouseEvent | MapLayerTouchEvent) {
|
||||
@@ -946,6 +971,7 @@ export class RoutingControls {
|
||||
}
|
||||
|
||||
this.draggedAnchorIndex = null;
|
||||
this.lastDraggedAnchorEventTime = Date.now();
|
||||
}
|
||||
|
||||
showTemporaryAnchor(e: MapLayerMouseEvent) {
|
||||
|
||||
Reference in New Issue
Block a user