UNPKG

expo-osm-sdk

Version:

OpenStreetMap component for React Native with Expo

178 lines (142 loc) β€’ 5.48 kB
# 🌐 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**