Skip to Content
ExamplesData Loading

Data Loading, Configuration, and Cache

Data loading demo: API calls with cache timing

This guide covers the SDK methods used to load places, subplaces, configuration, and cached data in real applications.

Load available places

import { initializeSDK, type MVXPlace } from "@mapvx/web-js" const sdk = initializeSDK("<YOUR_API_KEY>", { lang: "es", cache: { persistent: true, maxStorageBytes: 5 * 1024 * 1024, }, }) const places: MVXPlace[] = await sdk.getAvailablePlaces()

Each returned MVXPlace includes geometry and indoor metadata:

places.forEach((place) => { console.log({ id: place.mapvxId, title: place.title, coordinate: place.position, firstFloor: place.inFloors?.[0] ?? "outdoor", indoorLevels: place.innerFloors.length, }) })

Load subplaces of a parent place

const subplaces = await sdk.getSubPlaces("<PARENT_PLACE_ID>") subplaces.forEach((subplace) => { console.log({ id: subplace.mapvxId, title: subplace.title, firstFloor: subplace.inFloors?.[0] ?? "outdoor", categories: [subplace.localizedCategory, subplace.generalCategory].filter(Boolean), }) })

Use inFloors when you need the floor key of a place. Use innerFloors when the place itself is a parent place that owns several floors.

Fetch remote configuration

const configuration = await sdk.getConfiguration("<PARENT_PLACE_ID>", "directory") console.log(configuration)

Search places on demand

const institutions = await sdk.getInstitutions() const institutionId = institutions[0].mapvxId const searchResults = await sdk.getPlacesByInput( "coffee", institutionId, "<OPTIONAL_PARENT_PLACE_ID>" )

Read from cache without a network request

const cachedPlaces = sdk.getCachedPlaces(["place-id-1", "place-id-2", "place-id-3"]) console.log(`Found ${cachedPlaces.length} places in cache`)

Clear cached routes when needed

sdk.cleanRoutesCache()

Example: load data for an indoor map

async function loadIndoorContext(parentPlaceId: string): Promise<void> { const [parentPlace, subplaces, configuration] = await Promise.all([ sdk.getPlaceDetail(parentPlaceId), sdk.getSubPlaces(parentPlaceId), sdk.getConfiguration(parentPlaceId, "directory"), ]) console.log("Parent place floors", parentPlace.innerFloors) console.log("Subplaces", subplaces.length) console.log("Configuration loaded", configuration) }
const sdk = initializeSDK("<YOUR_API_KEY>", { cache: { persistent: true, maxStorageBytes: 10 * 1024 * 1024, configs: { places: { maxItems: 1500, ttlMs: 30 * 60 * 1000 }, subPlaces: { maxItems: 3000, ttlMs: 15 * 60 * 1000 }, configurations: { maxItems: 20, ttlMs: 2 * 60 * 60 * 1000 }, routes: { maxItems: 300, ttlMs: 5 * 60 * 1000 }, }, }, })
Last updated on