-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Popup events #130
Merged
Merged
Popup events #130
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, | ||
}); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you make this a Vercel edge function as detailed at https://kit.svelte.dev/docs/adapter-vercel#deployment-configuration?
Since edge functions are billed for CPU time, not clock time, it will help prevent unexpected billing surprises if a lot of people unexpectedly start hitting this page.