-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(It's clunky; clicks to the other layers are not intercepted)
- Loading branch information
1 parent
b53073d
commit c12be28
Showing
4 changed files
with
78 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<script lang="ts"> | ||
import type { MapMouseEvent } from "maplibre-gl"; | ||
import { onDestroy } from "svelte"; | ||
import { map } from "./store"; | ||
export let enabled = false; | ||
let source = "google"; | ||
function on() { | ||
$map!.on("click", onClick); | ||
$map!.getCanvas().style.cursor = "zoom-in"; | ||
} | ||
function off() { | ||
$map!.off("click", onClick); | ||
$map!.getCanvas().style.cursor = "auto"; | ||
} | ||
onDestroy(off); | ||
$: if (enabled) { | ||
on(); | ||
} else { | ||
off(); | ||
} | ||
function onClick(e: MapMouseEvent) { | ||
let lon = e.lngLat.lng; | ||
let lat = e.lngLat.lat; | ||
if (source == "google") { | ||
window.open( | ||
`http://maps.google.com/maps?q=&layer=c&cbll=${lat},${lon}&cbp=11,0,0,0,0`, | ||
"_blank", | ||
); | ||
} else if (source == "bing") { | ||
window.open( | ||
`https://www.bing.com/maps?cp=${lat}~${lon}&style=x`, | ||
"_blank", | ||
); | ||
} | ||
} | ||
function onKeyDown(e: KeyboardEvent) { | ||
if (enabled && e.key == "Escape") { | ||
enabled = false; | ||
} | ||
} | ||
</script> | ||
|
||
<svelte:window on:keydown={onKeyDown} /> | ||
|
||
<label> | ||
<input type="checkbox" bind:checked={enabled} /> | ||
StreetView | ||
</label> | ||
{#if enabled} | ||
<div style="background: grey"> | ||
<label> | ||
<input type="radio" bind:group={source} value="google" /> | ||
Google StreetView | ||
</label> | ||
<label> | ||
<input type="radio" bind:group={source} value="bing" /> | ||
Bing Streetside | ||
</label> | ||
</div> | ||
{/if} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters