Geometry Module
The Geometry Module in the TomTom Maps SDK enables displaying and visualizing geographic shapes and polygons on maps. This module provides comprehensive functionality for rendering complex geometries, administrative boundaries, and custom geographic data with customizable styling.
Purpose and Functionality
The Geometry Module serves as the primary interface for:
- Displaying polygon geometries from TomTom services and custom data
- Visualizing administrative boundaries such as countries, states, and cities
- Rendering custom geographic shapes with configurable styling options
- Managing geometry layers with visibility controls and interaction handling
- Integrating geometry data from search results and external sources
Core Concepts
Geometry Data Types
The module supports various types of geographic geometries:
Supported Geometry Types:
- Polygons: Closed shapes representing areas like administrative boundaries
- MultiPolygons: Complex shapes with multiple disconnected areas
- Administrative boundaries: Country, state, city, and district boundaries
- Custom shapes: User-defined geographic areas and regions
Data Sources
Geometries can come from multiple sources:
- TomTom Geometry Data Service: Official administrative boundaries and places
- Search results: Geographic data from place searches
- Custom GeoJSON: User-provided geometric data
- External APIs: Third-party geographic data sources
Basic Geometry Display
Initializing Geometry Module
import { TomTomConfig } from '@tomtom-org/maps-sdk/core';import { TomTomMap, GeometriesModule } from '@tomtom-org/maps-sdk/map';
// Configure SDK and create mapTomTomConfig.instance.put({ apiKey: 'YOUR_API_KEY' });const map = new TomTomMap({ mapLibre: { container: 'map' } });
// Initialize geometry module with default stylingconst geometryModule = await GeometriesModule.get(map);Displaying Administrative Boundaries
import { geocode, geometryData } from '@tomtom-org/maps-sdk/services';
// Get geometry for a specific placeconst place = (await geocode({ query: 'Amsterdam, Netherlands' })).features[0];const geometryResponse = await geometryData({ geometries: [place] });
// Display the geometry on the mapgeometryModule.show(geometryResponse);Custom Styling Configuration
// Initialize with custom stylingconst geometryModule = await GeometriesModule.get(map, { colorConfig: { fillColor: '#007cbf', // Fill color for polygons fillOpacity: 0.3 // Fill transparency }, lineConfig: { lineColor: '#005a8b', // Border color lineWidth: 2, // Border width lineOpacity: 0.8 // Border transparency }, beforeLayerConfig: 'road-labels' // Layer positioning});Advanced Geometry Features
Multiple Geometry Layers
// Create multiple geometry modules for different data setsconst countryGeometryModule = await GeometriesModule.get(map, { colorConfig: { fillColor: '#ff6b6b', fillOpacity: 0.2 }, lineConfig: { lineColor: '#ff0000', lineWidth: 3 }});
const cityGeometryModule = await GeometriesModule.get(map, { colorConfig: { fillColor: '#4ecdc4', fillOpacity: 0.4 }, lineConfig: { lineColor: '#00a896', lineWidth: 2 }});
// Display different geometry typescountryGeometryModule.show(countryBoundaries);cityGeometryModule.show(cityBoundaries);Dynamic Geometry Management
// Add and remove geometries dynamicallyconst geometryModule = await GeometriesModule.get(map);
// Show new geometry datafunction displayGeometry(newGeometryData) { geometryModule.clear(); // Clear existing geometries geometryModule.show(newGeometryData);}
// Toggle geometry visibilitylet geometryVisible = true;function toggleGeometry() { if (geometryVisible) { geometryModule.clear(); } else { geometryModule.show(currentGeometryData); } geometryVisible = !geometryVisible;}Layer Positioning and Styling
// Advanced styling with layer controlconst geometryModule = await GeometriesModule.get(map, { beforeLayerConfig: 'road-labels', // Position below road labels colorConfig: { fillColor: '#87CEEB', fillOpacity: 0.5 }, lineConfig: { lineColor: '#4682B4', lineWidth: 1.5, lineOpacity: 1 }});Multiple Module Instances
You can create multiple independent instances of the Geometry module, each with its own configuration and styling. This is useful for displaying different geometry layers with distinct visual styles.
// Create separate instances for different geometry typesconst countryBorders = await GeometriesModule.get(map, { colorConfig: { fillColor: '#E74C3C', fillOpacity: 0.2 }, lineConfig: { lineColor: '#C0392B', lineWidth: 3 }});
const cityBounds = await GeometriesModule.get(map, { colorConfig: { fillColor: '#3498DB', fillOpacity: 0.3 }, lineConfig: { lineColor: '#2980B9', lineWidth: 2 }});
// Each instance manages its own geometries independentlycountryBorders.show(countryData);cityBounds.show(cityData);Related Guides and Examples
Services Integration
- Geometry Data Service - Fetch detailed boundary and shape data for administrative areas and places
- Search Services - Find places and administrative areas that have associated geometry data
Related Examples
- Basic Geometry - Simple geometry display and styling examples
- Multiple Geometries - Working with multiple geometry layers and data sets
- Multiple Geometry Modules - Advanced geometry module management and organization
- Places in Geometry - Combining geometry boundaries with place markers
- Geometry Search Playground - Interactive geometry-based search and discovery
Related Map Modules
- Places Module - Display places and POIs within or related to geometric boundaries
- Routing Module - Show routes that intersect or travel through geometric areas
- User Interaction Events - Handle user interactions with geometric shapes and boundaries