expo-osm-sdk
Version:
OpenStreetMap component for React Native with Expo
443 lines • 13.2 kB
TypeScript
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;
}
/**
* 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;
tileServerUrl?: string;
styleUrl?: string;
markers?: MarkerConfig[];
polylines?: PolylineConfig[];
polygons?: PolygonConfig[];
circles?: CircleConfig[];
overlays?: OverlayConfig[];
clustering?: ClusterConfig;
showUserLocation?: boolean;
followUserLocation?: boolean;
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>;
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;
placeholder?: string;
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;
}
//# sourceMappingURL=index.d.ts.map