Files
gpx.studio/website/src/lib/components/map/street-view-control/google.ts

34 lines
861 B
TypeScript
Raw Normal View History

2025-10-18 16:10:08 +02:00
import { mapCursor, MapCursorState } from '$lib/logic/map-cursor';
import type mapboxgl from 'mapbox-gl';
2024-06-24 19:41:44 +02:00
export class GoogleRedirect {
map: mapboxgl.Map;
enabled = false;
constructor(map: mapboxgl.Map) {
this.map = map;
}
add() {
if (this.enabled) return;
this.enabled = true;
2025-10-18 16:10:08 +02:00
mapCursor.notify(MapCursorState.STREET_VIEW_CROSSHAIR, true);
2024-06-24 19:41:44 +02:00
this.map.on('click', this.openStreetView);
}
remove() {
if (!this.enabled) return;
this.enabled = false;
2025-10-18 16:10:08 +02:00
mapCursor.notify(MapCursorState.STREET_VIEW_CROSSHAIR, false);
2024-06-24 19:41:44 +02:00
this.map.off('click', this.openStreetView);
}
2025-10-18 16:10:08 +02:00
openStreetView(e: mapboxgl.MapMouseEvent) {
2024-06-24 19:41:44 +02:00
window.open(
`https://www.google.com/maps/@?api=1&map_action=pano&viewpoint=${e.lngLat.lat},${e.lngLat.lng}`
);
}
}