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 mapconst map = new TomTomMap({ mapLibre: { container: 'map' } });
// Initialize Places module with default configurationconst 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 placeawait 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 placesawait placesModule.show([place1, place2, place3]);
const searchResults = await search({ query: 'restaurants', position: [4.9041, 52.3676], // Amsterdam limit: 10});
// Show search resultsawait placesModule.show(searchResults);
// Remove all places from the map:await placesModule.clear();Custom Styling
Text Styling
Customize labels for places using text configuration:
// Make POI names red and other places blueconst customTextConfig: PlaceTextConfig = { textColor: ['match', ['get', 'type'], 'POI', '#D32F2F', '#1976D2']};
// Initialize with custom text stylingconst placesModule = await PlacesModule.get(map, { text: customTextConfig,});
// Or apply after initializationplacesModule.applyTextConfig(customTextConfig);Icon Styling
Customize place icons and markers:
// Use circle markers instead of pinsconst customIconConfig: PlaceIconConfig = { iconStyle: 'circle'}
// Initialize with custom icon stylingconst placesModule = await PlacesModule.get(map, { icon: customIconConfig});
// Or apply after initializationplacesModule.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 eventsplacesModule.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 eventsplacesModule.events.on('hover', (feature, lngLat) => { console.log('Hovering over:', feature.properties.poi?.name);});
// Remove event listenersplacesModule.events.off('click', handler);Programmatic Event States
Manually control visual states of places:
// Highlight first place as if clickedplacesModule.putEventState({ index: 0, state: 'click', mode: 'put'});
// Remove event state from specific placeplacesModule.cleanEventState({ index: 0 });
// Remove all hover statesplacesModule.cleanEventStates({ states: ['hover'] });
// Remove all event statesplacesModule.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 purposesconst restaurantPlaces = await PlacesModule.get(map, { icon: { iconStyle: 'pin', iconColor: '#FF5733' }});
const hotelPlaces = await PlacesModule.get(map, { icon: { iconStyle: 'circle', iconColor: '#3498DB' }});
// Each instance manages its own places independentlyawait restaurantPlaces.show(restaurantResults);await hotelPlaces.show(hotelResults);API Reference
For complete documentation of all Places Module properties, methods, and types, see the BaseMapModule 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