mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2026-02-20 14:49:08 +00:00
layer instead of markers for routing controls
This commit is contained in:
@@ -5,6 +5,10 @@
|
|||||||
|
|
||||||
map.onLoad((map_) => {
|
map.onLoad((map_) => {
|
||||||
map_.on('contextmenu', (e) => {
|
map_.on('contextmenu', (e) => {
|
||||||
|
if (map_.queryRenderedFeatures(e.point, { layers: ['routing-controls'] }).length) {
|
||||||
|
// Clicked on routing control, ignoring
|
||||||
|
return;
|
||||||
|
}
|
||||||
trackpointPopup?.setItem({
|
trackpointPopup?.setItem({
|
||||||
item: new TrackPoint({
|
item: new TrackPoint({
|
||||||
attributes: {
|
attributes: {
|
||||||
|
|||||||
@@ -287,6 +287,7 @@ export class GPXLayer {
|
|||||||
_map.addSource(this.fileId + '-waypoints', {
|
_map.addSource(this.fileId + '-waypoints', {
|
||||||
type: 'geojson',
|
type: 'geojson',
|
||||||
data: this.currentWaypointData,
|
data: this.currentWaypointData,
|
||||||
|
promoteId: 'waypointIndex',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -645,7 +646,17 @@ export class GPXLayer {
|
|||||||
| GeoJSONSource
|
| GeoJSONSource
|
||||||
| undefined;
|
| undefined;
|
||||||
if (waypointSource) {
|
if (waypointSource) {
|
||||||
waypointSource.setData(this.currentWaypointData!);
|
waypointSource.updateData({
|
||||||
|
update: [
|
||||||
|
{
|
||||||
|
id: this.draggedWaypointIndex,
|
||||||
|
newGeometry: {
|
||||||
|
type: 'Point',
|
||||||
|
coordinates: [e.lngLat.lng, e.lngLat.lat],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,17 +50,20 @@ export class StartEndMarkers {
|
|||||||
const slicedStatistics = get(slicedGPXStatistics);
|
const slicedStatistics = get(slicedGPXStatistics);
|
||||||
const hovered = get(hoveredPoint);
|
const hovered = get(hoveredPoint);
|
||||||
const hidden = get(allHidden);
|
const hidden = get(allHidden);
|
||||||
if (statistics.global.length > 0 && tool !== Tool.ROUTING && !hidden) {
|
if (!hidden) {
|
||||||
|
const data: GeoJSON.FeatureCollection = {
|
||||||
|
type: 'FeatureCollection',
|
||||||
|
features: [],
|
||||||
|
};
|
||||||
|
|
||||||
|
if (statistics.global.length > 0 && tool !== Tool.ROUTING) {
|
||||||
const start = statistics
|
const start = statistics
|
||||||
.getTrackPoint(slicedStatistics?.[1] ?? 0)!
|
.getTrackPoint(slicedStatistics?.[1] ?? 0)!
|
||||||
.trkpt.getCoordinates();
|
.trkpt.getCoordinates();
|
||||||
const end = statistics
|
const end = statistics
|
||||||
.getTrackPoint(slicedStatistics?.[2] ?? statistics.global.length - 1)!
|
.getTrackPoint(slicedStatistics?.[2] ?? statistics.global.length - 1)!
|
||||||
.trkpt.getCoordinates();
|
.trkpt.getCoordinates();
|
||||||
const data: GeoJSON.FeatureCollection = {
|
data.features.push({
|
||||||
type: 'FeatureCollection',
|
|
||||||
features: [
|
|
||||||
{
|
|
||||||
type: 'Feature',
|
type: 'Feature',
|
||||||
geometry: {
|
geometry: {
|
||||||
type: 'Point',
|
type: 'Point',
|
||||||
@@ -69,8 +72,8 @@ export class StartEndMarkers {
|
|||||||
properties: {
|
properties: {
|
||||||
icon: 'start-marker',
|
icon: 'start-marker',
|
||||||
},
|
},
|
||||||
},
|
});
|
||||||
{
|
data.features.push({
|
||||||
type: 'Feature',
|
type: 'Feature',
|
||||||
geometry: {
|
geometry: {
|
||||||
type: 'Point',
|
type: 'Point',
|
||||||
@@ -79,9 +82,8 @@ export class StartEndMarkers {
|
|||||||
properties: {
|
properties: {
|
||||||
icon: 'end-marker',
|
icon: 'end-marker',
|
||||||
},
|
},
|
||||||
},
|
});
|
||||||
],
|
}
|
||||||
};
|
|
||||||
|
|
||||||
if (hovered) {
|
if (hovered) {
|
||||||
data.features.push({
|
data.features.push({
|
||||||
|
|||||||
@@ -142,21 +142,7 @@ export class MapLayerEventManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _handleMouseMove(e: maplibregl.MapMouseEvent) {
|
private _handleMouseMove(e: maplibregl.MapMouseEvent) {
|
||||||
const layerIds = this._filterLayersIntersectingBounds(
|
const featuresByLayer = this._getRenderedFeaturesByLayer(e);
|
||||||
Object.keys(this._listeners),
|
|
||||||
this._getBounds(e.point)
|
|
||||||
);
|
|
||||||
const features =
|
|
||||||
layerIds.length > 0
|
|
||||||
? this._map.queryRenderedFeatures(e.point, { layers: layerIds })
|
|
||||||
: [];
|
|
||||||
const featuresByLayer: Record<string, maplibregl.MapGeoJSONFeature[]> = {};
|
|
||||||
features.forEach((f) => {
|
|
||||||
if (!featuresByLayer[f.layer.id]) {
|
|
||||||
featuresByLayer[f.layer.id] = [];
|
|
||||||
}
|
|
||||||
featuresByLayer[f.layer.id].push(f);
|
|
||||||
});
|
|
||||||
Object.keys(this._listeners).forEach((layerId) => {
|
Object.keys(this._listeners).forEach((layerId) => {
|
||||||
const features = featuresByLayer[layerId] || [];
|
const features = featuresByLayer[layerId] || [];
|
||||||
const listener = this._listeners[layerId];
|
const listener = this._listeners[layerId];
|
||||||
@@ -183,7 +169,6 @@ export class MapLayerEventManager {
|
|||||||
listener.mouseleaves.forEach((l) => l(event));
|
listener.mouseleaves.forEach((l) => l(event));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
listener.features = features;
|
|
||||||
}
|
}
|
||||||
if (features.length > 0 && listener.mousemoves.length > 0) {
|
if (features.length > 0 && listener.mousemoves.length > 0) {
|
||||||
const event = new maplibregl.MapMouseEvent('mousemove', e.target, e.originalEvent, {
|
const event = new maplibregl.MapMouseEvent('mousemove', e.target, e.originalEvent, {
|
||||||
@@ -191,15 +176,19 @@ export class MapLayerEventManager {
|
|||||||
});
|
});
|
||||||
listener.mousemoves.forEach((l) => l(event));
|
listener.mousemoves.forEach((l) => l(event));
|
||||||
}
|
}
|
||||||
|
listener.features = features;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private _handleMouseClick(type: string, e: maplibregl.MapMouseEvent) {
|
private _handleMouseClick(type: string, e: maplibregl.MapMouseEvent) {
|
||||||
Object.values(this._listeners).forEach((listener) => {
|
const featuresByLayer = this._getRenderedFeaturesByLayer(e);
|
||||||
if (listener.features.length > 0) {
|
Object.keys(this._listeners).forEach((layerId) => {
|
||||||
|
const features = featuresByLayer[layerId] || [];
|
||||||
|
const listener = this._listeners[layerId];
|
||||||
|
if (features.length > 0) {
|
||||||
if (type === 'click' && listener.clicks.length > 0) {
|
if (type === 'click' && listener.clicks.length > 0) {
|
||||||
const event = new maplibregl.MapMouseEvent('click', e.target, e.originalEvent, {
|
const event = new maplibregl.MapMouseEvent('click', e.target, e.originalEvent, {
|
||||||
features: listener.features,
|
features: features,
|
||||||
});
|
});
|
||||||
listener.clicks.forEach((l) => l(event));
|
listener.clicks.forEach((l) => l(event));
|
||||||
} else if (type === 'contextmenu' && listener.contextmenus.length > 0) {
|
} else if (type === 'contextmenu' && listener.contextmenus.length > 0) {
|
||||||
@@ -208,7 +197,7 @@ export class MapLayerEventManager {
|
|||||||
e.target,
|
e.target,
|
||||||
e.originalEvent,
|
e.originalEvent,
|
||||||
{
|
{
|
||||||
features: listener.features,
|
features: features,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
listener.contextmenus.forEach((l) => l(event));
|
listener.contextmenus.forEach((l) => l(event));
|
||||||
@@ -218,7 +207,7 @@ export class MapLayerEventManager {
|
|||||||
e.target,
|
e.target,
|
||||||
e.originalEvent,
|
e.originalEvent,
|
||||||
{
|
{
|
||||||
features: listener.features,
|
features: features,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
listener.mousedowns.forEach((l) => l(event));
|
listener.mousedowns.forEach((l) => l(event));
|
||||||
@@ -228,21 +217,7 @@ export class MapLayerEventManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _handleTouchStart(e: maplibregl.MapTouchEvent) {
|
private _handleTouchStart(e: maplibregl.MapTouchEvent) {
|
||||||
const layerIds = this._filterLayersIntersectingBounds(
|
const featuresByLayer = this._getRenderedFeaturesByLayer(e);
|
||||||
Object.keys(this._listeners).filter(
|
|
||||||
(layerId) => this._listeners[layerId].touchstarts.length > 0
|
|
||||||
),
|
|
||||||
this._getBounds(e.point)
|
|
||||||
);
|
|
||||||
if (layerIds.length === 0) return;
|
|
||||||
const features = this._map.queryRenderedFeatures(e.points[0], { layers: layerIds });
|
|
||||||
const featuresByLayer: Record<string, maplibregl.MapGeoJSONFeature[]> = {};
|
|
||||||
features.forEach((f) => {
|
|
||||||
if (!featuresByLayer[f.layer.id]) {
|
|
||||||
featuresByLayer[f.layer.id] = [];
|
|
||||||
}
|
|
||||||
featuresByLayer[f.layer.id].push(f);
|
|
||||||
});
|
|
||||||
Object.keys(this._listeners).forEach((layerId) => {
|
Object.keys(this._listeners).forEach((layerId) => {
|
||||||
const features = featuresByLayer[layerId] || [];
|
const features = featuresByLayer[layerId] || [];
|
||||||
const listener = this._listeners[layerId];
|
const listener = this._listeners[layerId];
|
||||||
@@ -284,4 +259,23 @@ export class MapLayerEventManager {
|
|||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _getRenderedFeaturesByLayer(e: maplibregl.MapMouseEvent | maplibregl.MapTouchEvent) {
|
||||||
|
const layerIds = this._filterLayersIntersectingBounds(
|
||||||
|
Object.keys(this._listeners),
|
||||||
|
this._getBounds(e.point)
|
||||||
|
);
|
||||||
|
const features =
|
||||||
|
layerIds.length > 0
|
||||||
|
? this._map.queryRenderedFeatures(e.point, { layers: layerIds })
|
||||||
|
: [];
|
||||||
|
const featuresByLayer: Record<string, maplibregl.MapGeoJSONFeature[]> = {};
|
||||||
|
features.forEach((f) => {
|
||||||
|
if (!featuresByLayer[f.layer.id]) {
|
||||||
|
featuresByLayer[f.layer.id] = [];
|
||||||
|
}
|
||||||
|
featuresByLayer[f.layer.id].push(f);
|
||||||
|
});
|
||||||
|
return featuresByLayer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ export const ANCHOR_LAYER_KEY = {
|
|||||||
interactions: 'interactions-end',
|
interactions: 'interactions-end',
|
||||||
overpass: 'overpass-end',
|
overpass: 'overpass-end',
|
||||||
waypoints: 'waypoints-end',
|
waypoints: 'waypoints-end',
|
||||||
|
routingControls: 'routing-controls-end',
|
||||||
};
|
};
|
||||||
const anchorLayers: maplibregl.LayerSpecification[] = Object.values(ANCHOR_LAYER_KEY).map((id) => ({
|
const anchorLayers: maplibregl.LayerSpecification[] = Object.values(ANCHOR_LAYER_KEY).map((id) => ({
|
||||||
id: id,
|
id: id,
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -7,7 +7,8 @@ export enum MapCursorState {
|
|||||||
TOOL_WITH_CROSSHAIR,
|
TOOL_WITH_CROSSHAIR,
|
||||||
WAYPOINT_HOVER,
|
WAYPOINT_HOVER,
|
||||||
WAYPOINT_DRAGGING,
|
WAYPOINT_DRAGGING,
|
||||||
TRACKPOINT_DRAGGING,
|
ANCHOR_HOVER,
|
||||||
|
ANCHOR_DRAGGING,
|
||||||
SCISSORS,
|
SCISSORS,
|
||||||
SPLIT_CONTROL,
|
SPLIT_CONTROL,
|
||||||
MAPILLARY_HOVER,
|
MAPILLARY_HOVER,
|
||||||
@@ -20,7 +21,8 @@ const cursorStyles = {
|
|||||||
[MapCursorState.LAYER_HOVER]: 'pointer',
|
[MapCursorState.LAYER_HOVER]: 'pointer',
|
||||||
[MapCursorState.WAYPOINT_HOVER]: 'pointer',
|
[MapCursorState.WAYPOINT_HOVER]: 'pointer',
|
||||||
[MapCursorState.WAYPOINT_DRAGGING]: 'grabbing',
|
[MapCursorState.WAYPOINT_DRAGGING]: 'grabbing',
|
||||||
[MapCursorState.TRACKPOINT_DRAGGING]: 'grabbing',
|
[MapCursorState.ANCHOR_HOVER]: 'pointer',
|
||||||
|
[MapCursorState.ANCHOR_DRAGGING]: 'grabbing',
|
||||||
[MapCursorState.TOOL_WITH_CROSSHAIR]: 'crosshair',
|
[MapCursorState.TOOL_WITH_CROSSHAIR]: 'crosshair',
|
||||||
[MapCursorState.SCISSORS]: scissorsCursor,
|
[MapCursorState.SCISSORS]: scissorsCursor,
|
||||||
[MapCursorState.SPLIT_CONTROL]: 'pointer',
|
[MapCursorState.SPLIT_CONTROL]: 'pointer',
|
||||||
|
|||||||
@@ -197,9 +197,9 @@ export function getElevation(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function loadSVGIcon(map: maplibregl.Map, id: string, svg: string) {
|
export function loadSVGIcon(map: maplibregl.Map, id: string, svg: string, size: number = 100) {
|
||||||
if (!map.hasImage(id)) {
|
if (!map.hasImage(id)) {
|
||||||
let icon = new Image(100, 100);
|
let icon = new Image(size, size);
|
||||||
icon.onload = () => {
|
icon.onload = () => {
|
||||||
if (!map.hasImage(id)) {
|
if (!map.hasImage(id)) {
|
||||||
map.addImage(id, icon);
|
map.addImage(id, icon);
|
||||||
|
|||||||
Reference in New Issue
Block a user