expo-osm-sdk
Version:
OpenStreetMap component for React Native with Expo
178 lines (142 loc) β’ 5.48 kB
Markdown
# π Web Map Implementation Options
## Current Status (v1.0.85)
The current `OSMView.web.tsx` provides a **safe fallback** that:
- β
Prevents crashes on web platforms
- β
Shows map configuration information
- β
Handles all props and events safely
- β Does NOT render actual interactive maps
## π Future Web Map Options
### Option 1: React-Leaflet Integration β **RECOMMENDED**
**Pros:**
- β
**OpenStreetMap native** - matches your SDK philosophy
- β
**Free and open source** - no API keys required
- β
**Full feature support** - markers, polylines, user location
- β
**Lightweight** - small bundle size
- β
**Similar API** - easy to map your props
**Implementation:**
```bash
# Additional peer dependencies
npm install react-leaflet leaflet
npm install @types/leaflet --dev
```
```tsx
// Enhanced OSMView.web.tsx
import { MapContainer, TileLayer, Marker, Polyline, Circle } from 'react-leaflet';
import 'leaflet/dist/leaflet.css';
export default function OSMView(props) {
const { initialCenter, initialZoom, markers, polylines, onPress } = props;
return (
<MapContainer
center={[initialCenter.latitude, initialCenter.longitude]}
zoom={initialZoom}
style={{ height: '100%', width: '100%' }}
onClick={(e) => onPress?.({ latitude: e.latlng.lat, longitude: e.latlng.lng })}
>
<TileLayer url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" />
{markers.map(marker => (
<Marker
key={marker.id}
position={[marker.coordinate.latitude, marker.coordinate.longitude]}
eventHandlers={{
click: () => onMarkerPress?.(marker.id, marker.coordinate)
}}
/>
))}
{polylines.map(polyline => (
<Polyline
key={polyline.id}
positions={polyline.coordinates.map(c => [c.latitude, c.longitude])}
color={polyline.strokeColor}
/>
))}
</MapContainer>
);
}
```
### Option 2: Mapbox GL Web
**Pros:**
- β
**Vector maps** - similar to native implementation
- β
**High performance** - WebGL rendering
- β
**Smooth animations** - 60fps interactions
- β
**Advanced styling** - custom map styles
**Cons:**
- β **Requires API key** - not free for high usage
- β **Larger bundle** - heavier than Leaflet
- β **Commercial restrictions** - licensing considerations
### Option 3: Google Maps JavaScript API
**Pros:**
- β
**Familiar to users** - most common web maps
- β
**Rich features** - places, directions, street view
- β
**High quality** - satellite imagery, traffic data
**Cons:**
- β **Requires API key** - costs money
- β **Not OpenStreetMap** - different data source
- β **Google dependencies** - vendor lock-in
### Option 4: Hybrid Approach
**Smart fallback system:**
```tsx
// Check if web map dependencies are available
const hasLeaflet = typeof window !== 'undefined' && window.L;
const hasMapbox = typeof window !== 'undefined' && window.mapboxgl;
if (hasLeaflet) {
return <LeafletMap {...props} />;
} else if (hasMapbox) {
return <MapboxMap {...props} />;
} else {
return <FallbackMap {...props} />; // Current implementation
}
```
## π Comparison Table
| Feature | Current Fallback | React-Leaflet | Mapbox GL | Google Maps |
|---------|------------------|---------------|-----------|-------------|
| **Real Maps** | β No | β
Yes | β
Yes | β
Yes |
| **OpenStreetMap** | N/A | β
Native | β οΈ Optional | β No |
| **API Key Required** | β No | β No | β
Yes | β
Yes |
| **Bundle Size** | π’ Tiny | π‘ Medium | π΄ Large | π‘ Medium |
| **Performance** | N/A | π‘ Good | π’ Excellent | π‘ Good |
| **Cost** | π’ Free | π’ Free | π΄ Paid | π΄ Paid |
| **Setup Complexity** | π’ None | π‘ Easy | π΄ Complex | π‘ Medium |
## π― **Recommended Approach**
### Phase 1: Enhanced Fallback (Current v1.0.85)
- β
Safe, stable fallback for all users
- β
No additional dependencies
- β
Professional developer experience
### Phase 2: React-Leaflet Integration (v1.1.0)
- β
Add optional web map support
- β
Peer dependency approach (user choice)
- β
Maintain backward compatibility
### Phase 3: Advanced Features (v1.2.0+)
- β
Multiple web map provider support
- β
Smart provider detection
- β
Feature parity with native
## π‘ **Developer Experience**
### Current (Safe Fallback):
```tsx
import { OSMView } from 'expo-osm-sdk';
// Works everywhere, shows fallback UI on web
<OSMView initialCenter={{ latitude: 22.57, longitude: 88.36 }} />
```
### Future (Optional Web Maps):
```tsx
// Option A: Automatic web maps if dependencies available
import { OSMView } from 'expo-osm-sdk';
// + npm install react-leaflet leaflet (optional)
// Option B: Explicit web map provider
import { OSMView } from 'expo-osm-sdk';
import 'expo-osm-sdk/web'; // Enables web maps
// Option C: Hybrid configuration
<OSMView
webMapProvider="leaflet" // 'leaflet' | 'mapbox' | 'google' | 'fallback'
webMapApiKey="xxx" // Only if needed
/>
```
## π **Next Steps**
1. **Ship v1.0.85** with safe fallback (current implementation)
2. **Gather feedback** from community about web map needs
3. **Implement React-Leaflet** integration if there's demand
4. **Add more providers** based on user requests
---
**What would you prefer?**
- π‘οΈ **Ship safe fallback now** (v1.0.85)
- πΊοΈ **Add React-Leaflet integration** (v1.1.0)
- π€ **Get community feedback first**