improve zoom on selected POIs, rework zoom buttons and add shortcut

This commit is contained in:
vcoppe 2024-08-26 13:59:01 +02:00
parent 5bd7cf6938
commit df2985c999
4 changed files with 849 additions and 829 deletions

View file

@ -56,8 +56,7 @@
editStyle, editStyle,
exportState, exportState,
ExportState, ExportState,
flyToBounds, centerMapOnSelection
gpxStatistics
} from '$lib/stores'; } from '$lib/stores';
import { import {
copied, copied,
@ -225,13 +224,6 @@
<PaintBucket size="16" class="mr-1" /> <PaintBucket size="16" class="mr-1" />
{$_('menu.style.button')} {$_('menu.style.button')}
</Menubar.Item> </Menubar.Item>
<Menubar.Item
disabled={$selection.size === 0}
on:click={() => flyToBounds($gpxStatistics.global.bounds, $map)}
>
<Maximize size="16" class="mr-1" />
{$_('menu.fly_to_selection')}
</Menubar.Item>
<Menubar.Item <Menubar.Item
on:click={() => { on:click={() => {
if ($allHidden) { if ($allHidden) {
@ -257,6 +249,17 @@
{$_('menu.select_all')} {$_('menu.select_all')}
<Shortcut key="A" ctrl={true} /> <Shortcut key="A" ctrl={true} />
</Menubar.Item> </Menubar.Item>
<Menubar.Item
on:click={() => {
if ($selection.size > 0) {
centerMapOnSelection();
}
}}
>
<Maximize size="16" class="mr-1" />
{$_('menu.center')}
<Shortcut key="⏎" ctrl={true} />
</Menubar.Item>
{#if $verticalFileView} {#if $verticalFileView}
<Menubar.Separator /> <Menubar.Separator />
<Menubar.Item on:click={copySelection} disabled={$selection.size === 0}> <Menubar.Item on:click={copySelection} disabled={$selection.size === 0}>
@ -545,6 +548,10 @@
dbUtils.setHiddenToSelection(true); dbUtils.setHiddenToSelection(true);
} }
e.preventDefault(); e.preventDefault();
} else if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) {
if ($selection.size > 0) {
centerMapOnSelection();
}
} else if (e.key === 'F1') { } else if (e.key === 'F1') {
switchBasemaps(); switchBasemaps();
e.preventDefault(); e.preventDefault();

View file

@ -45,9 +45,8 @@
editMetadata, editMetadata,
editStyle, editStyle,
embedding, embedding,
flyToBounds, centerMapOnSelection,
gpxLayers, gpxLayers,
gpxStatistics,
map map
} from '$lib/stores'; } from '$lib/stores';
import { import {
@ -61,7 +60,6 @@
import { _ } from 'svelte-i18n'; import { _ } from 'svelte-i18n';
import MetadataDialog from './MetadataDialog.svelte'; import MetadataDialog from './MetadataDialog.svelte';
import StyleDialog from './StyleDialog.svelte'; import StyleDialog from './StyleDialog.svelte';
import mapboxgl from 'mapbox-gl';
export let node: GPXTreeElement<AnyGPXTreeElement> | Waypoint[] | Waypoint; export let node: GPXTreeElement<AnyGPXTreeElement> | Waypoint[] | Waypoint;
export let item: ListItem; export let item: ListItem;
@ -227,14 +225,6 @@
{$_('menu.style.button')} {$_('menu.style.button')}
</ContextMenu.Item> </ContextMenu.Item>
{/if} {/if}
<ContextMenu.Item
on:click={() => {
flyToBounds($gpxStatistics.global.bounds, $map);
}}
>
<Maximize size="16" class="mr-1" />
{$_('menu.fly_to')}
</ContextMenu.Item>
<ContextMenu.Item <ContextMenu.Item
on:click={() => { on:click={() => {
if ($allHidden) { if ($allHidden) {
@ -294,8 +284,13 @@
{$_('menu.select_all')} {$_('menu.select_all')}
<Shortcut key="A" ctrl={true} /> <Shortcut key="A" ctrl={true} />
</ContextMenu.Item> </ContextMenu.Item>
<ContextMenu.Separator />
{/if} {/if}
<ContextMenu.Item on:click={centerMapOnSelection}>
<Maximize size="16" class="mr-1" />
{$_('menu.center')}
<Shortcut key="⏎" ctrl={true} />
</ContextMenu.Item>
<ContextMenu.Separator />
<ContextMenu.Item on:click={dbUtils.duplicateSelection}> <ContextMenu.Item on:click={dbUtils.duplicateSelection}>
<Copy size="16" class="mr-1" /> <Copy size="16" class="mr-1" />
{$_('menu.duplicate')} {$_('menu.duplicate')}

View file

@ -151,16 +151,35 @@ export function updateTargetMapBounds(bounds: { southWest: Coordinates; northEas
}); });
} }
export function flyToBounds( export function centerMapOnSelection(
bounds: { southWest: Coordinates; northEast: Coordinates },
map: mapboxgl.Map | null
) { ) {
const mapBoxBounds = new mapboxgl.LngLatBounds([ let selected = get(selection).getSelected();
[bounds.northEast.lon, bounds.northEast.lat], let bounds = new mapboxgl.LngLatBounds();
[bounds.southWest.lon, bounds.southWest.lat]
]); if (selected.find((item) => item instanceof ListWaypointItem)) {
map?.fitBounds(mapBoxBounds, { applyToOrderedSelectedItemsFromFile((fileId, level, items) => {
padding: 80 let file = getFile(fileId);
if (file) {
items.forEach((item) => {
if (item instanceof ListWaypointItem) {
let waypoint = file.wpt[item.getWaypointIndex()];
if (waypoint) {
bounds.extend([waypoint.getLongitude(), waypoint.getLatitude()]);
}
}
});
}
});
} else {
let selectionBounds = get(gpxStatistics).global.bounds;
bounds.setNorthEast(selectionBounds.northEast);
bounds.setSouthWest(selectionBounds.southWest);
}
get(map)?.fitBounds(bounds, {
padding: 80,
easing: () => 1,
maxZoom: 15
}); });
} }

View file

@ -76,9 +76,8 @@
}, },
"hide": "Hide", "hide": "Hide",
"unhide": "Unhide", "unhide": "Unhide",
"open_in": "Open in", "center": "Center",
"fly_to": "Fly to", "open_in": "Open in"
"fly_to_selection": "Fly to selection"
}, },
"toolbar": { "toolbar": {
"routing": { "routing": {