UNPKG

expo-osm-sdk

Version:

OpenStreetMap component for React Native with Expo

673 lines 19 kB
import React from 'react'; import { ViewStyle } from 'react-native'; /** * Geographic coordinate with latitude and longitude */ export interface Coordinate { latitude: number; longitude: number; } /** * Alternative name for Coordinate (common in mapping libraries) */ export type LatLng = Coordinate; /** * Map region with center and delta values */ export interface MapRegion { latitude: number; longitude: number; latitudeDelta: number; longitudeDelta: number; } /** * Alternative name for MapRegion */ export type Region = MapRegion; /** * Icon configuration for markers */ export interface MarkerIcon { uri?: string; name?: string; size?: number; color?: string; anchor?: { x: number; y: number; }; } /** * Info window configuration */ export interface InfoWindow { title?: string; description?: string; customView?: React.ReactNode; backgroundColor?: string; borderColor?: string; borderRadius?: number; maxWidth?: number; } /** * Camera animation configuration */ export interface CameraAnimationOptions { /** Target latitude */ latitude?: number; /** Target longitude */ longitude?: number; /** Target zoom level (1-20) */ zoom?: number; /** Target pitch/tilt in degrees (0-60) */ pitch?: number; /** Target bearing/heading in degrees (0-360) */ bearing?: number; /** Animation duration in milliseconds */ duration?: number; } /** * Marker animation configuration */ export interface MarkerAnimation { type: 'bounce' | 'pulse' | 'fade' | 'scale' | 'drop'; duration?: number; delay?: number; repeat?: boolean; } /** * Enhanced marker configuration for displaying points on the map */ export interface MarkerConfig { id: string; coordinate: Coordinate; title?: string; description?: string; icon?: MarkerIcon; infoWindow?: InfoWindow; animation?: MarkerAnimation; zIndex?: number; draggable?: boolean; opacity?: number; rotation?: number; visible?: boolean; clustered?: boolean; } /** * Marker clustering configuration */ export interface ClusterConfig { enabled: boolean; radius?: number; maxZoom?: number; minPoints?: number; colors?: string[]; textColor?: string; textSize?: number; } /** * Enhanced OSM View component props */ export interface OSMViewProps { style?: ViewStyle; initialCenter?: Coordinate; initialZoom?: number; initialPitch?: number; initialBearing?: number; tileServerUrl?: string; styleUrl?: string; markers?: MarkerConfig[]; polylines?: PolylineConfig[]; polygons?: PolygonConfig[]; circles?: CircleConfig[]; overlays?: OverlayConfig[]; clustering?: ClusterConfig; showUserLocation?: boolean; followUserLocation?: boolean; userLocationIcon?: MarkerIcon; userLocationTintColor?: string; userLocationAccuracyFillColor?: string; userLocationAccuracyBorderColor?: string; showsCompass?: boolean; showsScale?: boolean; showsZoomControls?: boolean; rotateEnabled?: boolean; scrollEnabled?: boolean; zoomEnabled?: boolean; pitchEnabled?: boolean; onMapReady?: () => void; onRegionChange?: (region: MapRegion) => void; onMarkerPress?: (markerId: string, coordinate: Coordinate) => void; onMarkerDragStart?: (markerId: string, coordinate: Coordinate) => void; onMarkerDrag?: (markerId: string, coordinate: Coordinate) => void; onMarkerDragEnd?: (markerId: string, coordinate: Coordinate) => void; onInfoWindowPress?: (markerId: string) => void; onPolylinePress?: (polylineId: string, coordinate: Coordinate) => void; onPolygonPress?: (polygonId: string, coordinate: Coordinate) => void; onCirclePress?: (circleId: string, coordinate: Coordinate) => void; onOverlayPress?: (overlayId: string) => void; onPress?: (coordinate: Coordinate) => void; onLongPress?: (coordinate: Coordinate) => void; onUserLocationChange?: (coordinate: Coordinate) => void; } /** * Enhanced ref methods available on OSMView component */ export interface OSMViewRef { zoomIn: () => Promise<void>; zoomOut: () => Promise<void>; setZoom: (zoom: number) => Promise<void>; animateToLocation: (latitude: number, longitude: number, zoom?: number) => Promise<void>; animateToRegion: (region: MapRegion, duration?: number) => Promise<void>; fitToMarkers: (markerIds?: string[], padding?: number) => Promise<void>; setPitch: (pitch: number) => Promise<void>; setBearing: (bearing: number) => Promise<void>; getPitch: () => Promise<number>; getBearing: () => Promise<number>; animateCamera: (options: CameraAnimationOptions) => Promise<void>; getCurrentLocation: () => Promise<Coordinate>; startLocationTracking: () => Promise<void>; stopLocationTracking: () => Promise<void>; waitForLocation: (timeoutSeconds: number) => Promise<Coordinate>; isViewReady?: () => Promise<boolean>; addMarker: (marker: MarkerConfig) => Promise<void>; removeMarker: (markerId: string) => Promise<void>; updateMarker: (markerId: string, updates: Partial<MarkerConfig>) => Promise<void>; animateMarker: (markerId: string, animation: MarkerAnimation) => Promise<void>; showInfoWindow: (markerId: string) => Promise<void>; hideInfoWindow: (markerId: string) => Promise<void>; addPolyline: (polyline: PolylineConfig) => Promise<void>; removePolyline: (polylineId: string) => Promise<void>; updatePolyline: (polylineId: string, updates: Partial<PolylineConfig>) => Promise<void>; addPolygon: (polygon: PolygonConfig) => Promise<void>; removePolygon: (polygonId: string) => Promise<void>; updatePolygon: (polygonId: string, updates: Partial<PolygonConfig>) => Promise<void>; addCircle: (circle: CircleConfig) => Promise<void>; removeCircle: (circleId: string) => Promise<void>; updateCircle: (circleId: string, updates: Partial<CircleConfig>) => Promise<void>; addOverlay: (overlay: OverlayConfig) => Promise<void>; removeOverlay: (overlayId: string) => Promise<void>; updateOverlay: (overlayId: string, updates: Partial<OverlayConfig>) => Promise<void>; coordinateForPoint: (point: { x: number; y: number; }) => Promise<Coordinate>; pointForCoordinate: (coordinate: Coordinate) => Promise<{ x: number; y: number; }>; takeSnapshot: (format?: 'png' | 'jpg', quality?: number) => Promise<string>; } /** * Enhanced marker component props */ export interface MarkerProps { coordinate: Coordinate; title?: string; description?: string; icon?: MarkerIcon; infoWindow?: InfoWindow; animation?: MarkerAnimation; zIndex?: number; draggable?: boolean; opacity?: number; rotation?: number; visible?: boolean; onPress?: () => void; onDragStart?: (coordinate: Coordinate) => void; onDrag?: (coordinate: Coordinate) => void; onDragEnd?: (coordinate: Coordinate) => void; onInfoWindowPress?: () => void; } /** * Polyline configuration for drawing lines on the map */ export interface PolylineConfig { id: string; coordinates: Coordinate[]; strokeColor?: string; strokeWidth?: number; strokeOpacity?: number; strokePattern?: 'solid' | 'dashed' | 'dotted'; lineCap?: 'butt' | 'round' | 'square'; lineJoin?: 'miter' | 'round' | 'bevel'; zIndex?: number; visible?: boolean; } /** * Polygon configuration for drawing areas on the map */ export interface PolygonConfig { id: string; coordinates: Coordinate[]; holes?: Coordinate[][]; fillColor?: string; fillOpacity?: number; strokeColor?: string; strokeWidth?: number; strokeOpacity?: number; strokePattern?: 'solid' | 'dashed' | 'dotted'; zIndex?: number; visible?: boolean; } /** * Circle configuration for drawing circles on the map */ export interface CircleConfig { id: string; center: Coordinate; radius: number; fillColor?: string; fillOpacity?: number; strokeColor?: string; strokeWidth?: number; strokeOpacity?: number; strokePattern?: 'solid' | 'dashed' | 'dotted'; zIndex?: number; visible?: boolean; } /** * Custom overlay configuration */ export interface OverlayConfig { id: string; coordinate: Coordinate; width: number; height: number; component: React.ReactNode; anchor?: { x: number; y: number; }; zIndex?: number; visible?: boolean; } /** * Route information for navigation */ export interface Route { coordinates: Coordinate[]; distance: number; duration: number; steps: RouteStep[]; } /** * Individual step in a route */ export interface RouteStep { instruction: string; distance: number; duration: number; coordinate: Coordinate; } /** * Map configuration options */ export interface MapConfig { tileServerUrl?: string; styleUrl?: string; maxZoom?: number; minZoom?: number; attribution?: string; isVectorTiles?: boolean; initialCenter?: Coordinate; initialZoom?: number; } /** * Individual tile configuration interface */ export interface TileConfig { name: string; description: string; isVector: boolean; styleUrl?: string; tileUrl?: string; attribution?: string; } /** * Alternative tile configurations for different use cases */ export declare const TILE_CONFIGS: { readonly openMapTiles: { readonly name: "Carto Voyager"; readonly description: "High-quality production vector tiles with professional styling and global coverage. Uses MapLibre GL for hardware acceleration."; readonly isVector: true; readonly styleUrl: "https://basemaps.cartocdn.com/gl/voyager-gl-style/style.json"; readonly attribution: "© OpenStreetMap contributors, © CARTO"; }; readonly openStreetMap: { readonly name: "OpenStreetMap Raster"; readonly description: "Standard OpenStreetMap raster tiles - reliable and free."; readonly isVector: false; readonly tileUrl: "https://tile.openstreetmap.org/{z}/{x}/{y}.png"; readonly attribution: "© OpenStreetMap contributors"; }; readonly openTopoMap: { readonly name: "OpenTopoMap"; readonly description: "Topographic map based on OpenStreetMap data with contour lines and elevation."; readonly isVector: false; readonly tileUrl: "https://tile.opentopomap.org/{z}/{x}/{y}.png"; readonly attribution: "© OpenStreetMap contributors, SRTM | Style: © OpenTopoMap"; }; readonly humanitarian: { readonly name: "Humanitarian"; readonly description: "Humanitarian OpenStreetMap style optimized for crisis response."; readonly isVector: false; readonly tileUrl: "https://tile-{s}.openstreetmap.fr/hot/{z}/{x}/{y}.png"; readonly attribution: "© OpenStreetMap contributors, Tiles courtesy of Humanitarian OpenStreetMap Team"; }; }; /** * Utility function to detect if a URL is a vector tile style URL */ export declare function isVectorTileUrl(url: string): boolean; /** * Validates a vector tile style URL */ export declare function validateStyleUrl(url: string): void; /** * Gets a default tile configuration by name */ export declare function getDefaultTileConfig(configName?: keyof typeof TILE_CONFIGS): TileConfig; /** * Default configuration for the map - Using Carto vector tiles */ export declare const DEFAULT_CONFIG: MapConfig; /** * Default coordinates (centered on world) */ export declare const DEFAULT_COORDINATE: Coordinate; /** * Default map region */ export declare const DEFAULT_REGION: MapRegion; /** * Nominatim Search Types */ export interface NominatimSearchResult { place_id: string; licence: string; osm_type: string; osm_id: string; boundingbox: [string, string, string, string]; lat: string; lon: string; display_name: string; class: string; type: string; importance: number; icon?: string; address?: NominatimAddress; } export interface NominatimAddress { house_number?: string; road?: string; neighbourhood?: string; suburb?: string; city?: string; state?: string; postcode?: string; country?: string; country_code?: string; } export interface NominatimSearchOptions { limit?: number; countrycodes?: string; bounded?: boolean; viewbox?: [number, number, number, number]; addressdetails?: boolean; extratags?: boolean; namedetails?: boolean; } export interface NominatimReverseOptions { zoom?: number; addressdetails?: boolean; extratags?: boolean; namedetails?: boolean; } export interface SearchLocation { coordinate: Coordinate; displayName: string; address?: NominatimAddress; boundingBox?: [number, number, number, number]; importance?: number; placeId: string; category?: string; type?: string; } /** * Search hook return type */ export interface UseNominatimSearchReturn { search: (query: string, options?: NominatimSearchOptions) => Promise<SearchLocation[]>; reverseGeocode: (coordinate: Coordinate, options?: NominatimReverseOptions) => Promise<SearchLocation | null>; isLoading: boolean; error: string | null; lastResults: SearchLocation[]; clearResults: () => void; } /** * Search UI component props */ export interface SearchBoxProps { onLocationSelected?: (location: SearchLocation) => void; onResultsChanged?: (results: SearchLocation[]) => void; onClear?: () => void; placeholder?: string; placeholderTextColor?: string; value?: string; editable?: boolean; style?: any; containerStyle?: any; maxResults?: number; showCurrentLocation?: boolean; autoComplete?: boolean; debounceMs?: number; } export interface SearchResultsProps { results: SearchLocation[]; onLocationSelected?: (location: SearchLocation) => void; style?: any; maxVisible?: number; showDistance?: boolean; userLocation?: Coordinate; } /** * LocationButton UI component props */ export interface LocationButtonProps { onLocationFound?: (location: { latitude: number; longitude: number; }) => void; onLocationError?: (error: string) => void; style?: any; size?: number; color?: string; getCurrentLocation?: () => Promise<{ latitude: number; longitude: number; }>; } /** * NavigationControls UI component props */ export interface NavigationControlsProps { onZoomIn?: () => void; onZoomOut?: () => void; onResetBearing?: () => void; onResetPitch?: () => void; bearing?: number; pitch?: number; style?: any; size?: number; color?: string; showPitchControl?: boolean; showCompassControl?: boolean; getBearing?: () => Promise<number>; getPitch?: () => Promise<number>; } /** * MapContainer component props */ export interface MapContainerProps extends OSMViewProps { fallbackComponent?: React.ComponentType<{ error: string; }>; showDebugInfo?: boolean; onError?: (error: Error) => void; } /** * Polyline component props */ export interface PolylineProps extends Omit<PolylineConfig, 'id'> { children?: React.ReactNode; } /** * Polygon component props */ export interface PolygonProps extends Omit<PolygonConfig, 'id'> { children?: React.ReactNode; } /** * Circle component props */ export interface CircleProps extends Omit<CircleConfig, 'id'> { children?: React.ReactNode; } /** * CustomOverlay component props */ export interface CustomOverlayProps extends Omit<OverlayConfig, 'id' | 'component'> { children: React.ReactNode; } /** * Geofence shape types */ export type GeofenceShape = 'circle' | 'polygon'; /** * Geofence event types */ export type GeofenceEventType = 'enter' | 'exit' | 'dwell'; /** * Base geofence configuration */ export interface GeofenceBase { id: string; name?: string; metadata?: Record<string, any>; } /** * Circle geofence (defined by center point and radius) */ export interface CircleGeofence extends GeofenceBase { type: 'circle'; center: Coordinate; radius: number; } /** * Polygon geofence (defined by array of coordinates) */ export interface PolygonGeofence extends GeofenceBase { type: 'polygon'; coordinates: Coordinate[]; } /** * Union type for all geofence types */ export type Geofence = CircleGeofence | PolygonGeofence; /** * Geofence event data */ export interface GeofenceEvent { geofenceId: string; geofenceName?: string | undefined; type: GeofenceEventType; coordinate: Coordinate; timestamp: number; distance?: number; metadata?: Record<string, any> | undefined; } /** * Geofence state (which geofences the user is currently inside) */ export interface GeofenceState { geofenceId: string; enteredAt: number; lastUpdate: number; dwellTime: number; } /** * Geofencing hook options */ export interface UseGeofencingOptions { /** * How often to check geofence boundaries (milliseconds) * @default 5000 (5 seconds) */ checkInterval?: number; /** * How long user must be inside before triggering 'dwell' event (milliseconds) * @default 60000 (1 minute) */ dwellThreshold?: number; /** * Enable high accuracy location tracking * @default true */ enableHighAccuracy?: boolean; /** * Callback for geofence enter events */ onEnter?: (event: GeofenceEvent) => void; /** * Callback for geofence exit events */ onExit?: (event: GeofenceEvent) => void; /** * Callback for geofence dwell events (user stayed inside for dwellThreshold duration) */ onDwell?: (event: GeofenceEvent) => void; /** * Callback for any geofence event */ onEvent?: (event: GeofenceEvent) => void; } /** * Return type for useGeofencing hook */ export interface UseGeofencingReturn { /** * Array of geofence IDs user is currently inside */ activeGeofences: string[]; /** * Map of geofence states (entry time, dwell time, etc.) */ geofenceStates: Map<string, GeofenceState>; /** * Check if user is inside a specific geofence */ isInGeofence: (geofenceId: string) => boolean; /** * Get dwell time for a specific geofence (milliseconds) */ getDwellTime: (geofenceId: string) => number; /** * Manually trigger a geofence check */ checkGeofences: () => void; /** * Current user location */ currentLocation: Coordinate | null; /** * Whether location tracking is active */ isTracking: boolean; /** * Array of all geofence events that occurred */ events: GeofenceEvent[]; } //# sourceMappingURL=index.d.ts.map