```
---
## COMMON PATTERNS
### User Location
```typescript
navigator.geolocation.getCurrentPosition(
(position) => {
const userLocation = [position.coords.longitude, position.coords.latitude];
// Center on user
mapStore.dispatch({
type: 'flyTo',
center: userLocation,
zoom: 15,
duration: 1500
});
// Add marker
mapStore.dispatch({
type: 'addMarker',
marker: {
id: 'user-location',
position: userLocation,
icon: '/icons/user-pin.png'
}
});
},
(error) => console.error('Geolocation error:', error)
);
```
### Draggable Markers
```typescript
mapStore.dispatch({
type: 'addMarker',
marker: {
id: 'draggable-pin',
position: [-74.006, 40.7128],
draggable: true
}
});
// Listen for updates
$effect(() => {
const marker = $mapStore.markers.find(m => m.id === 'draggable-pin');
if (marker) {
console.log('Marker position:', marker.position);
}
});
```
### Layer Toggle
```typescript
let showLayer = $state(true);
$effect(() => {
if (showLayer) {
mapStore.dispatch({
type: 'addLayer',
layer: myLayer
});
} else {
mapStore.dispatch({
type: 'removeLayer',
id: myLayer.id
});
}
});