Places Module
The Places Module allows you to display and interact with places on your TomTom map. You can add search results, custom locations, and handle user interactions.
Initialization
import { TomTomMap, PlacesModule } from '@tomtom-org/maps-sdk/map';
// Initialize map
const map = new TomTomMap({ mapLibre: { container: 'map' } });
// Initialize Places module with default configuration
const placesModule = await PlacesModule.get(map);
Displaying Places
Display one or multiple places on the map:
import { search } from '@tomtom-org/maps-sdk/services';
// Show single place
await placesModule.show({
id: 'custom-place-1',
type: 'Feature',
geometry: { type: 'Point', coordinates: [4.9041, 52.3676] },
properties: {
type: 'POI',
address: { freeformAddress: 'Custom Place 1, Amsterdam' },
poi: { name: 'Custom Place' }
}
});
// Show multiple places
await placesModule.show([place1, place2, place3]);
const searchResults = await search({
query: 'restaurants',
position: [4.9041, 52.3676], // Amsterdam
limit: 10
});
// Show search results
await placesModule.show(searchResults);
// Remove all places from the map:
await placesModule.clear();
Custom Styling
Theme
Themes control the overall look of place markers. Choose one at initialization or swap at runtime:
pin(default): traditional teardrop pin markerscircle-icon: circular markers with a centered category iconbase-map: mimics the base map style's POI layer, combiningmain,selected, andmicrolayers so places blend in with the style's built-in POIs. To render exclusively through the lightweightPOI - Microlayer โ ideal for dense results where a full POI treatment would be too heavy โ hide themainlayer vialayers.main.layout.visibility = 'none'.
// Initialize with a specific theme
const placesModule = await PlacesModule.get(map, { theme: 'base-map' });
// Or swap at runtime
placesModule.applyTheme('circle-icon');
// Micro-only rendering: combine `base-map` with a hidden `main` layer
const placesModule = await PlacesModule.get(map, {
theme: 'base-map',
layers: { main: { layout: { visibility: 'none' } } },
});
Text Styling
Customize labels for places using text configuration:
// Make POI names red and other places blue
const customTextConfig: PlaceTextConfig = {
color: ['match', ['get', 'type'], 'POI', '#D32F2F', '#1976D2']
};
// Initialize with custom text styling
const placesModule = await PlacesModule.get(map, {
text: customTextConfig,
});
// Or apply after initialization
placesModule.applyTextConfig(customTextConfig);
Icon Styling
Customize place icons and markers. Custom icons work under every theme: when a category is mapped, features in that category use the provided sprite; otherwise the theme's default icon (the base-map style's category/group expression or the default pin) still renders.
// Per-category custom images โ layered on top of any theme
const customIconConfig: PlaceIconConfig = {
categoryIcons: [
{ id: 'RESTAURANT', image: '/icons/food.png', pixelRatio: 2 },
{ id: 'HOTEL_MOTEL', image: '/icons/hotel.png', pixelRatio: 2 }
]
};
// Initialize with custom icon styling
const placesModule = await PlacesModule.get(map, {
theme: 'pin',
icon: customIconConfig
});
// Or apply after initialization
placesModule.applyIconConfig(customIconConfig);
Extra Properties
Add custom properties to places for advanced styling or filtering:
placesModule.applyExtraFeatureProps({
category: (place) => place.properties.poi?.categories?.[0],
rating: (place) => place.properties.poi?.rating || 0,
isOpen: true
});
Events
User events
Handle user interactions with places:
// Click events
placesModule.events.on('click', (feature, lngLat) => {
console.log('Click coordinates:', lngLat);
console.log('Place title:', feature.properties.title);
console.log('Place coordinates:', feature.geometry.coordinates);
});
// Hover events
placesModule.events.on('hover', (feature, lngLat) => {
console.log('Hovering over:', feature.properties.poi?.name);
});
// Remove event listeners
placesModule.events.off('click', handler);
Programmatic Event States
Manually control visual states of places:
// Highlight first place as if clicked
placesModule.putEventState({
index: 0,
state: 'click',
mode: 'put'
});
// Remove event state from specific place
placesModule.cleanEventState({ index: 0 });
// Remove all hover states
placesModule.cleanEventStates({ states: ['hover'] });
// Remove all event states
placesModule.cleanEventStates();
Multiple Module Instances
You can create multiple independent instances of the Places module, each with its own configuration and data. This is useful for displaying different sets of places with distinct styling or behavior.
// Create separate instances for different purposes
const restaurantPlaces = await PlacesModule.get(map, {
theme: 'pin',
icon: {
categoryIcons: [{ id: 'RESTAURANT', image: '/icons/restaurant.png', pixelRatio: 2 }]
}
});
const hotelPlaces = await PlacesModule.get(map, {
theme: 'circle-icon',
icon: {
categoryIcons: [{ id: 'HOTEL_MOTEL', image: '/icons/hotel.png', pixelRatio: 2 }]
}
});
// Each instance manages its own places independently
await restaurantPlaces.show(restaurantResults);
await hotelPlaces.show(hotelResults);
Reading Shown Data
Use getShown() to retrieve the places currently displayed on the map. This returns the exact data previously passed to show():
const shown = placesModule.getShown();
console.log(`Showing ${shown.places.features.length} places`);
API Reference
For complete documentation of all Places Module properties, methods, and types, see the PlacesModule API Reference.
Related Guides and Examples
Services Integration
- Search Services - Find places and POIs to display using the Places Module with autocomplete, fuzzy search, and geometry search
- Geocoding - Convert addresses to coordinates for precise place positioning on the map
- Reverse Geocoding - Get address information for places and display them with rich location context
Related Examples
- Places Customize - Advanced place styling and customization techniques
- Places in Geometry - Display places within specific geographic boundaries
- Fuzzy Search Playground - Search for places and display results interactively
- Geometry Search with POI Categories - Category-filtered place discovery and visualization
- Pin Interaction - Interactive place markers with click events and popups
Related Map Modules
- POIs - Advanced point-of-interest filtering and categorization for places
- User Interaction Events - Handle user interactions with places on the map