Skip to main content

VectorBasemapStyle

The VectorBasemapStyle class provides easy access to Esri's professionally designed vector basemap styles through the ArcGIS Basemaps API.

Interactive Demo

Switch between different Esri vector basemap styles with your API key

Quick Start

import { VectorBasemapStyle } from 'esri-gl';

// Simple way - using the applyStyle wrapper
VectorBasemapStyle.applyStyle(map, 'arcgis/streets', { apiKey: 'YOUR_API_KEY' });

// Advanced way - create instance and manage manually
const basemapStyle = new VectorBasemapStyle('arcgis/streets', { apiKey: 'YOUR_API_KEY' });
map.setStyle(basemapStyle.styleUrl);

Available Styles

Style IDDescriptionUse Cases
ArcGIS:StreetsStandard street mapGeneral purpose, navigation
ArcGIS:TopographicTopographic map with terrainOutdoor recreation, analysis
ArcGIS:NavigationHigh-contrast navigation styleTurn-by-turn navigation
ArcGIS:Streets:ReliefStreets with hillshade reliefContext with terrain awareness
ArcGIS:LightGrayLight gray reference mapData visualization overlay
ArcGIS:DarkGrayDark gray reference mapDark theme applications
ArcGIS:OceansBathymetric ocean mappingMarine applications

Usage Examples

Basic Implementation

// Initialize with default Streets style
const vectorStyle = new VectorBasemapStyle('ArcGIS:Streets', apiKey);
const response = await fetch(vectorStyle.styleUrl);
const style = await response.json();
map.setStyle(style);

Dynamic Style Switching

async function switchBasemap(styleId) {
const vectorStyle = new VectorBasemapStyle(styleId, apiKey);
const response = await fetch(vectorStyle.styleUrl);
const style = await response.json();
map.setStyle(style);
}

// Switch to topographic style
await switchBasemap('ArcGIS:Topographic');

With Error Handling

async function loadBasemap(styleId, apiKey) {
try {
const vectorStyle = new VectorBasemapStyle(styleId, apiKey);
const response = await fetch(vectorStyle.styleUrl);

if (!response.ok) {
throw new Error('Failed to load basemap style');
}

const style = await response.json();
map.setStyle(style);
} catch (error) {
console.error('Error loading basemap:', error);
}
}

Key Features

  • Professional Design - Cartographically optimized styles from Esri
  • Global Coverage - Consistent styling worldwide with localized labels
  • High Performance - Optimized vector tiles with efficient rendering
  • API Key Required - Requires valid Esri API key for access
  • Style URL Generation - Automatically constructs proper style URLs

API Reference

Available Style Names

The service supports full TypeScript type safety with these available styles:

type EsriBasemapStyleName = 
| 'arcgis/streets'
| 'arcgis/topographic'
| 'arcgis/navigation'
| 'arcgis/streets-relief'
| 'arcgis/dark-gray'
| 'arcgis/light-gray'
| 'arcgis/oceans'
| 'arcgis/imagery'
| 'arcgis/streets-night'
// Legacy colon form (for backwards compatibility)
| 'arcgis:streets'
| 'arcgis:topographic'
| 'arcgis:navigation'
| 'arcgis:streetsrelief'
| 'arcgis:darkgray'
| 'arcgis:lightgray'
| 'arcgis:oceans'
| 'arcgis:imagery'
| 'arcgis:streetsnight'
// Custom enterprise styles also supported
| string

Advanced Examples

// Basic usage with API key
VectorBasemapStyle.applyStyle(map, 'arcgis/streets', { apiKey: 'YOUR_API_KEY' });

// With language and worldview options
VectorBasemapStyle.applyStyle(map, 'arcgis/navigation', {
apiKey: 'YOUR_API_KEY',
language: 'es',
worldview: 'FRA'
});

// Using token authentication
VectorBasemapStyle.applyStyle(map, 'arcgis/dark-gray', { token: 'YOUR_TOKEN' });

// Using legacy colon format (backwards compatibility)
VectorBasemapStyle.applyStyle(map, 'arcgis:streets', { apiKey: 'YOUR_API_KEY' });

Using the Full Service API

// Create service instance
const basemap = new VectorBasemapStyle('arcgis/streets', { apiKey: 'YOUR_API_KEY' });

// Apply to map
map.setStyle(basemap.styleUrl);

// Change style later
basemap.setStyle('arcgis/dark-gray-canvas');
map.setStyle(basemap.styleUrl);

Dynamic Style Switching

const styles = ['arcgis/streets', 'arcgis/imagery', 'arcgis/topographic', 'arcgis/dark-gray'];
let currentIndex = 0;

function switchStyle() {
VectorBasemapStyle.applyStyle(map, styles[currentIndex], { apiKey: 'YOUR_API_KEY' });
currentIndex = (currentIndex + 1) % styles.length;
}

For detailed API documentation, see VectorBasemapStyle API Reference.