-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add on:open and on:close to Popup * typescript types for dispatch * changeset
- Loading branch information
1 parent
d3a923a
commit d464803
Showing
10 changed files
with
165 additions
and
14 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,5 @@ | ||
--- | ||
"svelte-maplibre": minor | ||
--- | ||
|
||
Add on:open and on:close events to Popup |
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
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
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,87 @@ | ||
<script lang="ts"> | ||
import MapLibre from '$lib/MapLibre.svelte'; | ||
import DefaultMarker from '$lib/DefaultMarker.svelte'; | ||
import { mapClasses } from '../styles'; | ||
import code from './+page.svelte?raw'; | ||
import serverCode from './[id]/+server.ts?raw'; | ||
import CodeSample from '$site/CodeSample.svelte'; | ||
import Popup from '$lib/Popup.svelte'; | ||
const markers = [ | ||
{ | ||
lngLat: [-122.2993, 47.4464], | ||
label: 'SEA', | ||
name: 'Seattle', | ||
}, | ||
{ | ||
lngLat: [-159.3438, 21.9788], | ||
label: 'LIH', | ||
name: 'Lihue', | ||
}, | ||
{ | ||
lngLat: [2.5479, 49.0097], | ||
label: 'CDG', | ||
name: 'Paris Charles de Gaulle', | ||
}, | ||
{ | ||
lngLat: [-58.5348, -34.82], | ||
label: 'EZE', | ||
name: 'Ministro Pistarini', | ||
}, | ||
{ | ||
lngLat: [18.6021, -33.9715], | ||
label: 'CPT', | ||
name: 'Cape Town', | ||
}, | ||
{ | ||
lngLat: [121.0165, 14.5123], | ||
label: 'MNL', | ||
name: 'Ninoy Aquino', | ||
}, | ||
]; | ||
interface APIResponse { | ||
width: number; | ||
height: number; | ||
} | ||
let cache: Record<string, APIResponse> = {}; | ||
</script> | ||
|
||
<MapLibre | ||
style="https://basemaps.cartocdn.com/gl/positron-gl-style/style.json" | ||
class={mapClasses} | ||
standardControls | ||
zoom={1} | ||
center={[-20, 0]} | ||
> | ||
{#each markers as { lngLat, name }} | ||
<!-- Unlike the custom marker example, default markers do not have mouse events, | ||
and popups only support the default openOn="click" behavior --> | ||
<DefaultMarker {lngLat} draggable> | ||
<Popup | ||
offset={[0, -10]} | ||
on:open={async () => { | ||
if (!(name in cache)) { | ||
const resp = await fetch(`/examples/popup_remote/${name}`); | ||
const result = await resp.json(); | ||
cache[name] = result; | ||
// trigger reactivity | ||
cache = cache; | ||
} | ||
}} | ||
> | ||
{#if name in cache} | ||
{@const result = cache[name]} | ||
<div class="text-lg font-bold">{name}</div> | ||
<img alt="kitten" src={`http://placekitten.com/${result.width}/${result.height}`} /> | ||
{:else} | ||
<div>Loading...</div> | ||
{/if} | ||
</Popup> | ||
</DefaultMarker> | ||
{/each} | ||
</MapLibre> | ||
|
||
<CodeSample {code} /> | ||
<CodeSample code={serverCode} language="typescript" startBoundary="" endBoundary="" /> |
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,7 @@ | ||
import type { PageLoad } from './$types'; | ||
|
||
export const load: PageLoad = () => { | ||
return { | ||
title: 'Remote Popup Data', | ||
}; | ||
}; |
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,18 @@ | ||
import { json } from '@sveltejs/kit'; | ||
|
||
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms)); | ||
|
||
/** | ||
* This is a very contrived example. | ||
*/ | ||
export async function GET({ params }) { | ||
const { id } = params; | ||
// make this request take one second | ||
await sleep(1000); | ||
// return some meaningless data | ||
return json({ | ||
id, | ||
width: 10 * id.length, | ||
height: 12 * id.length, | ||
}); | ||
} |