Skip to content

Commit 868e69f

Browse files
committed
add doc
1 parent 9e21cbd commit 868e69f

File tree

37 files changed

+3994
-211
lines changed

37 files changed

+3994
-211
lines changed

.github/workflows/deploy-docs.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# .github/workflows/deploy-docs.yml
2+
3+
name: Deploy Docs to GitHub Pages
4+
5+
on:
6+
# Runs on pushes targeting the main branch
7+
push:
8+
branches:
9+
- main
10+
11+
# Allows you to run this workflow manually from the Actions tab
12+
workflow_dispatch:
13+
14+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
15+
permissions:
16+
contents: read
17+
pages: write
18+
id-token: write
19+
20+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
21+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
22+
concurrency:
23+
group: 'pages'
24+
cancel-in-progress: false
25+
26+
jobs:
27+
# Build job
28+
build:
29+
runs-on: ubuntu-latest
30+
steps:
31+
- name: Checkout
32+
uses: actions/checkout@v4
33+
- name: Set up Node.js
34+
uses: actions/setup-node@v4
35+
with:
36+
node-version: 20 # Or your preferred Node.js version
37+
- name: Setup pnpm
38+
uses: pnpm/action-setup@v3
39+
with:
40+
version: 10 # Or your preferred pnpm version
41+
- name: Install dependencies
42+
run: pnpm install
43+
- name: Build with SvelteKit
44+
# Run the build command defined in your package.json
45+
# Ensure this builds the static site to the 'docs' directory
46+
run: pnpm run build
47+
env:
48+
NODE_ENV: production # Ensure correct base path is used
49+
- name: Setup Pages
50+
uses: actions/configure-pages@v5
51+
- name: Upload artifact
52+
uses: actions/upload-pages-artifact@v3
53+
with:
54+
# Upload the 'docs' directory (or your adapter's output directory)
55+
path: ./docs
56+
57+
# Deployment job
58+
deploy:
59+
environment:
60+
name: github-pages
61+
url: ${{ steps.deployment.outputs.page_url }}
62+
runs-on: ubuntu-latest
63+
needs: build
64+
steps:
65+
- name: Deploy to GitHub Pages
66+
id: deployment
67+
uses: actions/deploy-pages@v4

README.md

Lines changed: 96 additions & 103 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,38 @@
6262
"types": "./dist/DirectionsRenderer.svelte.d.ts",
6363
"svelte": "./dist/DirectionsRenderer.svelte"
6464
},
65+
"./MapControl.svelte": {
66+
"types": "./dist/controls/MapControl.svelte.d.ts",
67+
"svelte": "./dist/controls/MapControl.svelte"
68+
},
69+
"./TrafficLayer.svelte": {
70+
"types": "./dist/layers/TrafficLayer.svelte.d.ts",
71+
"svelte": "./dist/layers/TrafficLayer.svelte"
72+
},
73+
"./TransitLayer.svelte": {
74+
"types": "./dist/layers/TransitLayer.svelte.d.ts",
75+
"svelte": "./dist/layers/TransitLayer.svelte"
76+
},
77+
"./BicyclingLayer.svelte": {
78+
"types": "./dist/layers/BicyclingLayer.svelte.d.ts",
79+
"svelte": "./dist/layers/BicyclingLayer.svelte"
80+
},
81+
"./KmlLayer.svelte": {
82+
"types": "./dist/layers/KmlLayer.svelte.d.ts",
83+
"svelte": "./dist/layers/KmlLayer.svelte"
84+
},
85+
"./Autocomplete.svelte": {
86+
"types": "./dist/places/Autocomplete.svelte.d.ts",
87+
"svelte": "./dist/places/Autocomplete.svelte"
88+
},
89+
"./OverlayView.svelte": {
90+
"types": "./dist/overlay/OverlayView.svelte.d.ts",
91+
"svelte": "./dist/overlay/OverlayView.svelte"
92+
},
93+
"./StreetViewPanorama.svelte": {
94+
"types": "./dist/street-view/StreetViewPanorama.svelte.d.ts",
95+
"svelte": "./dist/street-view/StreetViewPanorama.svelte"
96+
},
6597
"./GoogleMap.svelte": {
6698
"types": "./dist/GoogleMap.svelte.d.ts",
6799
"svelte": "./dist/GoogleMap.svelte"
@@ -90,11 +122,12 @@
90122
"!dist/**/*.spec.*"
91123
],
92124
"peerDependencies": {
93-
"svelte": "^4.0.0"
125+
"svelte": "^5.0.0"
94126
},
95127
"license": "MIT",
96128
"devDependencies": {
97129
"@sveltejs/adapter-auto": "^6.0.0",
130+
"@sveltejs/adapter-static": "^3.0.8",
98131
"@sveltejs/kit": "^2.20.8",
99132
"@sveltejs/package": "^2.3.11",
100133
"@sveltejs/vite-plugin-svelte": "^4.0.4",

pnpm-lock.yaml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/lib/Marker.svelte

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,11 @@
228228
onZindexChanged
229229
);
230230
}
231+
232+
// Function to get the marker instance
233+
export function getMarkerInstance(): google.maps.Marker | null {
234+
return marker;
235+
}
231236
</script>
232237

233238
<!-- Marker does not render anything itself, it just controls the Google Maps Marker object -->

src/lib/controls/MapControl.svelte

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<script lang="ts">
2+
import { getContext, onDestroy, onMount } from 'svelte';
3+
import { BROWSER as browser } from 'esm-env';
4+
import type { APIProviderContext } from '../APIProvider.svelte'; // Use relative path
5+
6+
// --- Props ---
7+
export let position: google.maps.ControlPosition;
8+
9+
// --- Internal State ---
10+
let controlWrapper: HTMLDivElement | null = null;
11+
let isMounted = false;
12+
let controlIndex: number | undefined = undefined;
13+
14+
// --- Context ---
15+
const { status, googleMapsApi } = getContext<APIProviderContext>('svelte-google-maps-api');
16+
const map = getContext<google.maps.Map>('map');
17+
18+
// --- Lifecycle ---
19+
onMount(() => {
20+
isMounted = true;
21+
// Add control once the map is ready and the wrapper div is created
22+
addControl();
23+
});
24+
25+
onDestroy(() => {
26+
removeControl();
27+
});
28+
29+
// --- Logic ---
30+
function addControl() {
31+
if (!browser || !map || !googleMapsApi || !controlWrapper || !isMounted || $status !== 'loaded')
32+
return;
33+
34+
// Ensure the position is valid
35+
if (position === undefined || position === null) {
36+
console.error('[MapControl] position prop is required.');
37+
return;
38+
}
39+
40+
try {
41+
// Check if the controls array for the position exists
42+
if (!map.controls[position]) {
43+
// This case should ideally not happen with valid ControlPosition enum values
44+
// but adding a safeguard.
45+
console.warn(
46+
`[MapControl] Controls array for position ${position} not found. Cannot add control.`
47+
);
48+
return;
49+
}
50+
// Remove existing control from the same instance if it exists (e.g., on position change)
51+
removeControl();
52+
// Add the wrapper div containing the slot content to the map controls
53+
controlIndex = map.controls[position].push(controlWrapper) - 1;
54+
console.log('[MapControl] Control added to position:', position, 'at index:', controlIndex);
55+
} catch (error) {
56+
console.error('[MapControl] Error adding control:', error);
57+
}
58+
}
59+
60+
function removeControl() {
61+
if (browser && map && googleMapsApi && controlWrapper && controlIndex !== undefined) {
62+
try {
63+
// Find the control array for the *previous* position if position changed,
64+
// or use the current position if unmounting.
65+
// Note: Simple removal might be complex if position changes dynamically.
66+
// This basic removal assumes the position hasn't changed between add and remove,
67+
// or handles unmount cleanup.
68+
69+
const controlsArray = map.controls[position];
70+
if (controlsArray) {
71+
// Attempt to remove the specific element instance.
72+
// Direct removal by index can be unreliable if other controls are added/removed.
73+
// A safer approach is to find the element and remove it.
74+
let found = false;
75+
for (let i = 0; i < controlsArray.getLength(); i++) {
76+
if (controlsArray.getAt(i) === controlWrapper) {
77+
controlsArray.removeAt(i);
78+
found = true;
79+
console.log('[MapControl] Control removed from position:', position);
80+
break;
81+
}
82+
}
83+
if (!found) {
84+
// Fallback or warning if element wasn't found (might happen if externally manipulated)
85+
console.warn('[MapControl] Could not find control element to remove.');
86+
}
87+
}
88+
} catch (error) {
89+
console.error('[MapControl] Error removing control:', error);
90+
}
91+
controlIndex = undefined;
92+
}
93+
}
94+
95+
// Re-add control if map or position changes after mount
96+
$: if (isMounted && map && googleMapsApi && $status === 'loaded') {
97+
addControl();
98+
}
99+
</script>
100+
101+
<!-- This div wraps the slot content and is added to the map controls -->
102+
<div bind:this={controlWrapper}>
103+
<slot />
104+
</div>

src/lib/index.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,24 @@ export {
2626
DirectionsRenderer
2727
};
2828

29-
// Export types as well
29+
// Export layers
30+
export * from './layers/TrafficLayer.svelte';
31+
export * from './layers/TransitLayer.svelte';
32+
export * from './layers/BicyclingLayer.svelte';
33+
export * from './layers/KmlLayer.svelte';
34+
export * from './HeatmapLayer.svelte';
35+
export * from './GroundOverlay.svelte';
36+
37+
// Export places
38+
export * from './places/Autocomplete.svelte';
39+
40+
// Export overlay
41+
export * from './overlay/OverlayView.svelte';
42+
43+
// Export street view
44+
export * from './street-view/StreetViewPanorama.svelte';
45+
46+
// Export controls
47+
export * from './controls/MapControl.svelte';
48+
3049
export * from './types/googleMap.js';
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<script lang="ts">
2+
// Simple Layer Component Boilerplate (e.g., for TrafficLayer, TransitLayer, BicyclingLayer)
3+
import { getContext, onDestroy } from 'svelte';
4+
import { BROWSER as browser } from 'esm-env';
5+
import type { APIProviderContext } from '../APIProvider.svelte';
6+
7+
// --- Props ---
8+
// export let options: google.maps.BicyclingLayerOptions | undefined = undefined;
9+
10+
// --- Events ---
11+
export let onLoad: ((layer: google.maps.BicyclingLayer) => void) | undefined = undefined; // Adjust type
12+
export let onUnmount: ((layer: google.maps.BicyclingLayer) => void) | undefined = undefined; // Adjust type
13+
14+
// --- Internal State ---
15+
let layerInstance: google.maps.BicyclingLayer | null = null; // Adjust type
16+
17+
// --- Context ---
18+
const { status, googleMapsApi } = getContext<APIProviderContext>('svelte-google-maps-api');
19+
const map = getContext<google.maps.Map>('map');
20+
21+
// --- Initialization ---
22+
function initializeLayer() {
23+
if (!browser || $status !== 'loaded' || !googleMapsApi || !map || layerInstance) return;
24+
25+
if (!googleMapsApi.BicyclingLayer) {
26+
// Adjust class name
27+
console.error('[BicyclingLayer] google.maps.BicyclingLayer not available.'); // Adjust log
28+
return;
29+
}
30+
31+
// No options for constructor
32+
try {
33+
layerInstance = new googleMapsApi.BicyclingLayer(); // Adjust class name
34+
layerInstance.setMap(map); // Set map after creation
35+
onLoad?.(layerInstance);
36+
} catch (error) {
37+
console.error('[BicyclingLayer] Error creating instance:', error); // Adjust log
38+
}
39+
}
40+
41+
// --- Reactive Updates ---
42+
// $: if (layerInstance && options) {
43+
// layerInstance.setOptions(options);
44+
// }
45+
46+
// --- Lifecycle ---
47+
onDestroy(() => {
48+
if (layerInstance) {
49+
onUnmount?.(layerInstance);
50+
layerInstance.setMap(null);
51+
layerInstance = null;
52+
}
53+
});
54+
55+
// Initialize when ready
56+
$: if ($status === 'loaded' && map && !layerInstance) {
57+
initializeLayer();
58+
}
59+
</script>
60+
61+
<!-- This layer component does not render any DOM element itself -->

0 commit comments

Comments
 (0)