### Basic mapcn-svelte Map Component Usage in Svelte
Source: https://mapcn-svelte.vercel.app/docs/installation
Example of how to import and use the Map and MapControls components from mapcn-svelte within a Svelte application. It demonstrates setting the initial center and zoom level for the map.
```svelte
```
--------------------------------
### Install mapcn-svelte Map Component
Source: https://mapcn-svelte.vercel.app/docs/installation
Command to add the map component to your project using npx. This command also installs `maplibre-gl` as a dependency.
```bash
npx shadcn-svelte@latest add https://mapcn-svelte.dev/r/map.json
```
--------------------------------
### Route Planning with Multiple Options (OSRM API)
Source: https://mapcn-svelte.vercel.app/docs/routes
Illustrates how to display multiple route options and allow user selection, fetching real driving directions from the OSRM API. Users can click on a route or use buttons to switch between them.
```svelte
{#if routes.length > 0}
{#each routes as route, index}
{/each}
{/if}
```
--------------------------------
### Basic Route Drawing with MapRoute
Source: https://mapcn-svelte.vercel.app/docs/routes
Demonstrates how to draw a basic route with numbered stop markers along the path using the MapRoute component. This is useful for displaying simple directions or trails.
```svelte
```
--------------------------------
### MarkerTooltip Component
Source: https://mapcn-svelte.vercel.app/docs/api-reference
Renders a tooltip that appears on hover. It must be used inside `MapMarker` and extends MapLibre GL's PopupOptions, excluding 'className', 'closeButton', and 'closeOnClick'.
```APIDOC
## MarkerTooltip Component
### Description
Renders a tooltip that appears on hover. Must be used inside `MapMarker`.
Extends PopupOptions from MapLibre GL (excluding `className`, `closeButton`, and `closeOnClick`).
### Props
- **children** (`Snippet`) - Tooltip content.
- **className** (`string`) - Additional CSS classes for the tooltip container.
```
--------------------------------
### Accessing Map Instance with Svelte Context
Source: https://mapcn-svelte.vercel.app/docs/api-reference
Demonstrates how to access the MapLibre GL map instance and its loading state within a Svelte component using the `getContext` function. This is crucial for interacting with the map API directly.
```typescript
import { getContext } from "svelte";
import type MapLibreGL from "maplibre-gl";
const mapCtx = getContext({
getMap: () => MapLibreGL.Map | null,
isLoaded: () => boolean,
}("map");
const map = mapCtx.getMap();
const isLoaded = mapCtx.isLoaded();
```
--------------------------------
### Map Component API
Source: https://mapcn-svelte.vercel.app/docs/api-reference
The root container component that initializes MapLibre GL and provides context to child components. It automatically handles theme switching between light and dark modes.
```APIDOC
## Map Component API
### Description
The root container component that initializes MapLibre GL and provides context to child components. Automatically handles theme switching between light and dark modes.
Extends MapOptions from MapLibre GL (excluding `container` and `style`).
### Props
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```html
```
### Response
#### Success Response (200)
This component does not have a direct response, but it provides context to child components.
#### Response Example
N/A
```
--------------------------------
### MarkerContent Component API
Source: https://mapcn-svelte.vercel.app/docs/api-reference
Renders the visual content of a marker. Must be used inside `MapMarker`. If no children are provided, it renders a default blue dot marker.
```APIDOC
## MarkerContent Component API
### Description
Renders the visual content of a marker. Must be used inside `MapMarker`. If no children provided, renders a default blue dot marker.
### Props
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```html
Location Name
Some details here...
```
### Response
#### Success Response (200)
This component renders content within a marker and does not have a direct response.
#### Response Example
N/A
```
--------------------------------
### Access Map Instance and Listen to Events in Svelte Child Component
Source: https://mapcn-svelte.vercel.app/docs/advanced-usage
This snippet demonstrates how to access the MapLibre GL map instance from a child Svelte component using `getContext` and set up event listeners with `onMount`. It allows for dynamic interaction with the map, such as logging click coordinates. Ensure the child component is rendered within the `