UNPKG

expo-osm-sdk

Version:

OpenStreetMap component for React Native with Expo

108 lines 3.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DEFAULT_REGION = exports.DEFAULT_COORDINATE = exports.DEFAULT_CONFIG = exports.TILE_CONFIGS = void 0; exports.isVectorTileUrl = isVectorTileUrl; exports.validateStyleUrl = validateStyleUrl; exports.getDefaultTileConfig = getDefaultTileConfig; /** * Alternative tile configurations for different use cases */ exports.TILE_CONFIGS = { openMapTiles: { name: 'Carto Voyager', description: 'High-quality production vector tiles with professional styling and global coverage. Uses MapLibre GL for hardware acceleration.', isVector: true, styleUrl: 'https://basemaps.cartocdn.com/gl/voyager-gl-style/style.json', attribution: '© OpenStreetMap contributors, © CARTO' }, openStreetMap: { name: 'OpenStreetMap Raster', description: 'Standard OpenStreetMap raster tiles - reliable and free.', isVector: false, tileUrl: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png', attribution: '© OpenStreetMap contributors' }, openTopoMap: { name: 'OpenTopoMap', description: 'Topographic map based on OpenStreetMap data with contour lines and elevation.', isVector: false, tileUrl: 'https://tile.opentopomap.org/{z}/{x}/{y}.png', attribution: '© OpenStreetMap contributors, SRTM | Style: © OpenTopoMap' }, humanitarian: { name: 'Humanitarian', description: 'Humanitarian OpenStreetMap style optimized for crisis response.', isVector: false, tileUrl: 'https://tile-{s}.openstreetmap.fr/hot/{z}/{x}/{y}.png', attribution: '© OpenStreetMap contributors, Tiles courtesy of Humanitarian OpenStreetMap Team' } }; /** * Utility function to detect if a URL is a vector tile style URL */ function isVectorTileUrl(url) { if (!url || typeof url !== 'string') { return false; } // Check for common vector style URL patterns return (url.includes('.json') || url.includes('style.json') || url.includes('/styles/') || (url.includes('api.') && url.includes('style'))); } /** * Validates a vector tile style URL */ function validateStyleUrl(url) { if (!url) { throw new Error('Style URL cannot be empty'); } try { const parsedUrl = new URL(url); if (parsedUrl.protocol !== 'https:') { throw new Error('Style URL must use HTTPS'); } } catch (error) { throw new Error('Invalid URL format'); } } /** * Gets a default tile configuration by name */ function getDefaultTileConfig(configName) { if (configName && exports.TILE_CONFIGS[configName]) { return exports.TILE_CONFIGS[configName]; } return exports.TILE_CONFIGS.openStreetMap; } /** * Default configuration for the map - Using Carto vector tiles */ exports.DEFAULT_CONFIG = { tileServerUrl: exports.TILE_CONFIGS.openMapTiles.styleUrl, // For backward compatibility styleUrl: exports.TILE_CONFIGS.openMapTiles.styleUrl, // Vector style maxZoom: 22, minZoom: 1, attribution: exports.TILE_CONFIGS.openMapTiles.attribution, isVectorTiles: true, initialCenter: { latitude: 0, longitude: 0 }, initialZoom: 10 }; /** * Default coordinates (centered on world) */ exports.DEFAULT_COORDINATE = { latitude: 0, longitude: 0 }; /** * Default map region */ exports.DEFAULT_REGION = { latitude: 0, longitude: 0, latitudeDelta: 90, longitudeDelta: 180 }; //# sourceMappingURL=index.js.map