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.

import { bboxFromGeoJSON, TomTomConfig } from '@tomtom-org/maps-sdk/core';
import { PlacesModule, TomTomMap } from '@tomtom-org/maps-sdk/map';
import { geocode } from '@tomtom-org/maps-sdk/services';
import './style.css';
import { API_KEY } from './config';

// (Set your own API key when working in your own environment)
TomTomConfig.instance.put({ apiKey: API_KEY, language: 'en-US' });

(async () => {
    const [firstGroup, secondGroup, thirdGroup] = await Promise.all([
        geocode({ query: '1051', countries: ['NL'] }), // searching for locations by postcode
        geocode({ query: '1052', countries: ['NL'] }),
        geocode({ query: '1053', countries: ['NL'] }),
    ]);

    const map = new TomTomMap({
        mapLibre: {
            container: 'sdk-map',
            bounds: bboxFromGeoJSON([firstGroup, secondGroup]),
            fitBoundsOptions: { padding: 50 },
        },
    });

    const firstPlacesModule = await PlacesModule.get(map, {
        icon: { default: { style: { fillColor: '#FFBF00', outlineColor: '#113300', outlineOpacity: 0.25 } } },
    });
    await firstPlacesModule.show(firstGroup);

    const secondPlacesModule = await PlacesModule.get(map, {
        icon: { default: { style: { fillColor: 'lightblue', outlineColor: 'grey', outlineOpacity: 0.5 } } },
    });
    await secondPlacesModule.show(secondGroup);

    const thirdPlacesModule = await PlacesModule.get(map, {
        icon: { default: { style: { fillColor: '#FFBBCC', outlineColor: 'red', outlineOpacity: 0.25 } } },
    });
    await thirdPlacesModule.show(thirdGroup);
})();

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

Text Styling

Customize labels for places using text configuration:

// Make POI names red and other places blue
const customTextConfig: PlaceTextConfig = {
textColor: ['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:

// Use circle markers instead of pins
const customIconConfig: PlaceIconConfig = {
iconStyle: 'circle'
}
// Initialize with custom icon styling
const placesModule = await PlacesModule.get(map, {
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, {
icon: { iconStyle: 'pin', iconColor: '#FF5733' }
});
const hotelPlaces = await PlacesModule.get(map, {
icon: { iconStyle: 'circle', iconColor: '#3498DB' }
});
// Each instance manages its own places independently
await 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 .

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