Viewport Places Plugin
The Viewport Places plugin enables dynamic display of places on the map viewport, automatically updating as the map moves. It wires the SDK search service to the SDK PlacesModule and provides a small, composable API to manage multiple viewport-driven place layers.
Use cases
- Customize your map POIs — control which POI categories are shown at which zoom levels and with which visual theme.
- Search this area — keep search results (fuzzy/geometry) limited to the current viewport and refresh them automatically when the user pans or zooms.
- Layered overlays — stack multiple place modules (base-map POIs, brand search results, availability overlays) and control their priority.
How it works
Each time the map moves, the plugins queries the search service for places within the current viewport bounding box and displays them using a dedicated PlacesModule.
This can be done for multiple place modules, each with its own search options (query string, POI categories, limits) and visual configuration (theme, clustering, etc).
API Reference:
Viewport Places Plugin API Reference
Guides to the underlying components
- Search service: Search (autocomplete / fuzzy / geometry)
- Display places on the map: Places module
- Map motion and events: About MapLibre
Installation
-
Follow the SDK Project Setup to create a working SDK project and initialize a
TomTomMapinstance. -
Import and initialize the plugin (plugin-specific steps only):
// assume `map` is your initialized TomTomMap instance// import the plugin in your application code:// import { ViewportPlaces } from '@tomtom-org/maps-sdk-plugin-viewport-places';
const viewportPlaces = new ViewportPlaces(map);- Try it: add a simple viewport-driven place module:
await viewportPlaces.addBaseMapPOICategories({ id: 'restaurants', categories: ['RESTAURANT'], minZoom: 10});The plugin will keep the restaurants place module in sync with the visible map bounds.
For a complete working example, see the viewport-places-plugin example in the SDK repository (live coding example above).
Usage examples
Add base-map POI categories (styled like the base map)
Use when you want to surface additional base map categories or override visibility at specific zooms:
await viewportPlaces.addBaseMapPOICategories({ id: 'base-pois', categories: ['PARKING_GARAGE', 'ELECTRIC_VEHICLE_STATION'], minZoom: 10});Add a branded search place module (custom theme)
Use placesModuleConfig to apply a visual theme (for example pin vs base-map):
await viewportPlaces.add({ id: 'brand-search', searchOptions: { query: 'Lidl', poiCategories: ['SUPERMARKETS_HYPERMARKETS'], limit: 20 }, minZoom: 8, placesModuleConfig: { theme: 'pin' }});Update an existing place module
Change query, categories, limits or visual config for an existing place module:
await viewportPlaces.update({ id: 'brand-search', searchOptions: { query: 'Aldi', limit: 30 }, placesModuleConfig: { theme: 'base-map' }});Remove a place module
viewportPlaces.remove('brand-search');Remove all place modules
viewportPlaces.removeAll();