Class MapData

MapData is the core data container for all map information, providing access to spaces, floors, points of interest, and navigation capabilities. It serves as the foundation for building interactive indoor mapping applications.

  • Access to all map elements (spaces, floors, doors, etc.)
  • Built-in search functionality with suggestions
  • Navigation and wayfinding capabilities
  • Multi-language support
  • Analytics tracking
  • Data export and serialization

Best Practice: Use getByType() to retrieve collections of map elements, and getById() for specific elements. Enable search functionality when you need location discovery features.

// Get all spaces on the map
const spaces = mapData.getByType('space');

// Find a specific space by ID
const space = mapData.getById('space', 'space-123');

// Get directions between two locations
const directions = mapData.getDirections(space1, space2);

// Enable and use search
await mapData.Search.enable();
const results = await mapData.Search.query('Coffee Shop');

// Change language
await mapData.changeLanguage('es');
  • Collections: Use getByType() for all elements of a type
  • Specific Elements: Use getById() for individual elements
  • External IDs: Use getByExternalId() for custom identifiers
  • GeoJSON: Use getGeoJSON() for geometric data
  • getDirections(): Route between two locations
  • getDirectionsMultiDestination(): Route with multiple destinations
  • getDistance(): Calculate distance between locations

Represents the data for a map, providing access to map elements like spaces, floors, and points of interest.

Properties

Analytics: Analytics
Query: Query

Query API for advanced data filtering and retrieval.

Provides powerful querying capabilities to filter and find map elements based on various criteria.

// Find all spaces with specific properties
const results = mapData.Query.spaces()
.where('category', 'retail')
.where('floor', floor)
.execute();
Search: Search

Search API for MapData

Provides full-text search capabilities across all map locations, with support for suggestions, filtering, and result ranking.

// Enable search
const mapData = await getMapData({ search: { enabled: true } });
// or
await mapData.Search.enable();

// Perform a search query
const results = await mapData.Search.query('Coffee Shop');
console.log(results.locations);
// Get search suggestions
const suggestions = await mapData.Search.suggest('Coff');
console.log(suggestions);
const results = await mapData.Search.query('Shop', {
categories: ['retail'],
floor: mapData.getByType('floor')[0]
});

Accessors

  • get currentLanguage(): undefined | Language

    Gets the current language of the map data.

    Returns undefined | Language

    The current language code and name.

    const language = mapData.currentLanguage;
    console.log(`Current language: ${language.name} (${language.code})`);
  • get mapCenter(): Coordinate

    The approximate center coordinate (Coordinate) of the map.

    Returns Coordinate

    The center coordinate of the map.

    const center = mapData.mapCenter;
    console.log(`Map center: ${center.latitude}, ${center.longitude}`);
  • get mapId(): undefined | string

    The unique identifier for the map.

    Returns undefined | string

    The map ID.

    console.log(mapData.mapId); // "map-12345"
    
  • get mapName(): string

    The name of the map.

    Returns string

    The name of the map.

    console.log(mapData.mapName); // "Downtown Mall"
    
  • get naturalBearing(): number

    Gets the natural bearing of the map.

    The natural bearing represents the orientation of the map relative to true north. This is useful for aligning the map with compass directions or external mapping systems.

    Returns number

    The natural bearing in degrees.

    const bearing = mapData.naturalBearing;
    console.log(`Map is oriented ${bearing} degrees from true north`);
  • get organizationId(): string

    The organization ID of the map.

    Returns string

    The organization ID of the map.

    console.log(mapData.organizationId); // "org-12345"
    
  • get outdoorViewToken(): undefined | string

    The token used to fetch outdoor tiles for outdoor map integration.

    Returns undefined | string

    The outdoor view token.

    const outdoorToken = mapData.outdoorViewToken;
    if (outdoorToken) {
    // Configure outdoor map with token
    }

Methods

  • Changes the language of the map data.

    Updates all text content (names, descriptions, etc.) to the specified language. The map will emit a 'language-change' event when the language is updated.

    Parameters

    • localeCode: string

      The ISO 639-1 language code to change to (e.g., 'en' for English, 'fr' for French). Check (EnterpriseVenue.languages) for available languages

    Returns Promise<void>

    A promise that resolves when the language change is complete.

    await mapData.changeLanguage('es');
    console.log('Map language changed to Spanish');
    await mapData.changeLanguage('fr');
    console.log('Map language changed to French');
    mapData.on('language-change', ({ code, name }) => {
    console.log(`Language changed to ${name} (${code})`);
    });
  • Get an access token for use with Mappedin's API.

    Returns the current access token that can be used for authenticated API requests.

    Returns undefined | string

    The current access token

    const token = mapData.getAccessToken();
    // Use token for API requests
  • Retrieves map elements by their external ID.

    External IDs are custom identifiers that can be assigned to map elements. This is useful for integrating with external systems or databases.

    Type Parameters

    • T extends
          | "space"
          | "area"
          | "object"
          | "floor"
          | "door"
          | "floor-stack"
          | "connection"
          | "point-of-interest"
          | "enterprise-location"
          | "enterprise-category"
          | "location-profile"
          | "node"
          | "enterprise-venue"
          | "location-category"

    Parameters

    • type: T

      The type of element to retrieve.

    • externalId: string

      The external identifier to search for.

    Returns TMapDataObjectTypes[T][]

    An array of elements with the matching external ID.

    const spaces = mapData.getByExternalId('space', 'STORE-001');
    spaces.forEach(space => console.log(`Found space: ${space.name}`));
    const locations = mapData.getByExternalId('enterprise-location', 'RESTAURANT-ABC');
    locations.forEach(location => console.log(`Found location: ${location.name}`));
  • Retrieves a specific map feature by its type and ID.

    Use this method to find individual map elements when you know their exact ID. This is more efficient than filtering collections for specific elements.

    Type Parameters

    • T extends
          | "space"
          | "area"
          | "object"
          | "floor"
          | "door"
          | "facade"
          | "floor-stack"
          | "connection"
          | "annotation"
          | "point-of-interest"
          | "enterprise-location"
          | "enterprise-category"
          | "location-profile"
          | "node"
          | "location-category"
          | "unknown"

    Parameters

    • type: T

      The type of element to retrieve.

    • id: string

      The unique identifier of the element.

    Returns
        | undefined
        | (
            T extends keyof TMapDataObjectTypes
                ? TMapDataObjectTypes[T<T>]
                :
                    | Space
                    | Area
                    | MapObject
                    | Floor
                    | Door
                    | Facade
                    | FloorStack
                    | Connection
                    | Annotation
                    | PointOfInterest
                    | EnterpriseLocation
                    | EnterpriseCategory
                    | LocationProfile
                    | Node
                    | EnterpriseVenue
                    | LocationCategory
        )

    The map element if found, undefined otherwise.

    const space = mapData.getById('space', 'space-123');
    if (space) {
    console.log(`Found space: ${space.name}`);
    }
    const floor = mapData.getById('floor', 'floor-1');
    if (floor) {
    console.log(`Floor level: ${floor.level}`);
    }
    const door = mapData.getById('door', 'door-main-entrance');
    if (door) {
    console.log(`Door type: ${door.type}`);
    }

    In general, it is better to specify the type if you know it, since you get better type safety.

    const element = mapData.getById('unknown', 'element-123');
    if (!element) {
    console.log(`Element not found`);
    } else if (Space.is(element)) {
    console.log(`Found space: ${element.name}`);
    } else if (Door.is(element)) ...
  • Retrieves a specific map feature by its type and ID.

    Use this method to find individual map elements when you know their exact ID. This is more efficient than filtering collections for specific elements.

    Type Parameters

    Parameters

    • type: T

      The type of element to retrieve.

    • id: string

      The unique identifier of the element.

    Returns undefined | TMapDataObjectTypes[T]

    The map element if found, undefined otherwise.

    const space = mapData.getById('space', 'space-123');
    if (space) {
    console.log(`Found space: ${space.name}`);
    }
    const floor = mapData.getById('floor', 'floor-1');
    if (floor) {
    console.log(`Floor level: ${floor.level}`);
    }
    const door = mapData.getById('door', 'door-main-entrance');
    if (door) {
    console.log(`Door type: ${door.type}`);
    }

    In general, it is better to specify the type if you know it, since you get better type safety.

    const element = mapData.getById('unknown', 'element-123');
    if (!element) {
    console.log(`Element not found`);
    } else if (Space.is(element)) {
    console.log(`Found space: ${element.name}`);
    } else if (Door.is(element)) ...
  • Retrieves a specific map feature by its type and ID.

    Use this method to find individual map elements when you know their exact ID. This is more efficient than filtering collections for specific elements.

    Type Parameters

    • T extends "unknown"

    Parameters

    • type: T

      The type of element to retrieve.

    • id: string

      The unique identifier of the element.

    Returns
        | undefined
        | Space
        | Area
        | MapObject
        | Floor
        | Door
        | Facade
        | FloorStack
        | Connection
        | Annotation
        | PointOfInterest
        | EnterpriseLocation
        | EnterpriseCategory
        | LocationProfile
        | Node
        | EnterpriseVenue
        | LocationCategory

    The map element if found, undefined otherwise.

    const space = mapData.getById('space', 'space-123');
    if (space) {
    console.log(`Found space: ${space.name}`);
    }
    const floor = mapData.getById('floor', 'floor-1');
    if (floor) {
    console.log(`Floor level: ${floor.level}`);
    }
    const door = mapData.getById('door', 'door-main-entrance');
    if (door) {
    console.log(`Door type: ${door.type}`);
    }

    In general, it is better to specify the type if you know it, since you get better type safety.

    const element = mapData.getById('unknown', 'element-123');
    if (!element) {
    console.log(`Element not found`);
    } else if (Space.is(element)) {
    console.log(`Found space: ${element.name}`);
    } else if (Door.is(element)) ...
  • Retrieves all map elements of a specific type.

    This is the primary method for accessing collections of map elements. Use the typed overloads for better TypeScript support.

    Parameters

    • type: string

      The type of elements to retrieve.

    Returns MapDataElements[]

    An array of elements of the given type.

    const spaces = mapData.getByType('space');
    console.log(`Found ${spaces.length} spaces`);
    const floors = mapData.getByType('floor');
    floors.forEach(floor => console.log(floor.name));
    const doors = mapData.getByType('door');
    const entranceDoors = doors.filter(door => door.type === 'entrance');
  • Parameters

    • type: "space"

    Returns Space[]

    The spaces (Space) on the map.

    const spaces = mapData.getByType('space');
    const retailSpaces = spaces.filter(space => space.category === 'retail');
  • Parameters

    • type: "door"

    Returns Door[]

    The doors (Door) on the map.

    const doors = mapData.getByType('door');
    const entranceDoors = doors.filter(door => door.type === 'entrance');
  • Parameters

    • type: "floor"

    Returns Floor[]

    The floors (Floor) on the map.

    const floors = mapData.getByType('floor');
    const groundFloor = floors.find(floor => floor.level === 0);
  • Parameters

    • type: "floor-stack"

    Returns FloorStack[]

    The stacks of floors (FloorStack) within the map.

    const floorStacks = mapData.getByType('floor-stack');
    const mainBuilding = floorStacks.find(stack => stack.name === 'Main Building');
  • Parameters

    • type: "facade"

    Returns Facade[]

    The facades (Facade) within the map.

    const facades = mapData.getByType('facade');
    const northFacade = facades.find(facade => facade.name === 'North');
  • Parameters

    • type: "connection"

    Returns Connection[]

    The connections (Connection) on the map.

    const connections = mapData.getByType('connection');
    const elevators = connections.filter(conn => conn.type === 'elevator');
  • Parameters

    • type: "object"

    Returns MapObject[]

    The objects (MapObject) on the map.

    const objects = mapData.getByType('object');
    const furniture = objects.filter(obj => obj.category === 'furniture');
  • Parameters

    • type: "point-of-interest"

    Returns PointOfInterest[]

    The points of interest (PointOfInterest) on the map.

    const pois = mapData.getByType('point-of-interest');
    const restrooms = pois.filter(poi => poi.category === 'restroom');
  • Parameters

    • type: "annotation"

    Returns Annotation[]

    The annotations (Annotation) on the map.

    const annotations = mapData.getByType('annotation');
    const infoAnnotations = annotations.filter(ann => ann.type === 'info');
  • Parameters

    • type: "node"

    Returns Node[]

    The nodes (Node) on the map.

    const nodes = mapData.getByType('node');
    const navigationNodes = nodes.filter(node => node.type === 'navigation');
  • Parameters

    • type: "area"

    Returns Area[]

    The areas (Area) on the map.

    const areas = mapData.getByType('area');
    const parkingAreas = areas.filter(area => area.category === 'parking');
  • Parameters

    • type: "enterprise-location"

    Returns EnterpriseLocation[]

    The enterprise locations (EnterpriseLocation) on the map.

    const locations = mapData.getByType('enterprise-location');
    const stores = locations.filter(loc => loc.category === 'store');
  • Parameters

    • type: "enterprise-category"

    Returns EnterpriseCategory[]

    The enterprise categories (EnterpriseCategory) on the map.

    const categories = mapData.getByType('enterprise-category');
    const retailCategories = categories.filter(cat => cat.type === 'retail');
  • Parameters

    • type: "enterprise-venue"

    Returns undefined | EnterpriseVenue

    The enterprise venues (EnterpriseVenue) on the map.

    const venues = mapData.getByType('enterprise-venue');
    const malls = venues.filter(venue => venue.type === 'mall');
  • Parameters

    • type: "location-profile"

    Returns LocationProfile[]

    The location profiles (LocationProfile) on the map.

    const profiles = mapData.getByType('location-profile');
    const featuredProfiles = profiles.filter(profile => profile.featured);
  • Parameters

    • type: "location-category"

    Returns LocationCategory[]

    The location categories (LocationCategory) on the map.

    const categories = mapData.getByType('location-category');
    const mainCategories = categories.filter(cat => cat.parent === null);
  • Calculates directions between two or more locations.

    Provides turn-by-turn navigation instructions and a path between the specified locations. The path avoids obstacles and follows walkable routes.

    Parameters

    Returns Promise<undefined | Directions>

    A Directions object containing the route, or undefined if no route is found.

    const space1 = mapData.getById('space', 'space-123');
    const space2 = mapData.getById('space', 'space-456');

    if (space1 && space2) {
    const directions = await mapData.getDirections(space1, space2);
    if (directions) {
    console.log(`Distance: ${directions.distance}m`);
    console.log(`Duration: ${directions.duration}s`);
    directions.instructions.forEach(instruction => {
    console.log(instruction.action.type);
    });
    }
    }
    const directions = await mapData.getDirections(space1, space2, {
    accessible: true,
    smoothing: { radius: 3 }
    });
    const directions = await mapData.getDirections([space1, space2], destination);
    
  • Calculates directions to multiple destinations.

    Provides routes from a single starting point to multiple destinations. Useful for finding the best route when visiting multiple locations.

    Parameters

    Returns Promise<undefined | Directions[]>

    An array of Directions objects, one for each destination.

    const start = mapData.getById('space', 'entrance');
    const destinations = [
    mapData.getById('space', 'store-1'),
    mapData.getById('space', 'store-2'),
    mapData.getById('space', 'restaurant')
    ].filter(Boolean);

    const allDirections = await mapData.getDirectionsMultiDestination(start, destinations);
    allDirections.forEach((directions, index) => {
    console.log(`Route ${index + 1}: ${directions.distance}m`);
    });
    const directions = await mapData.getDirectionsMultiDestination(start, [
    [destination1, destination2], // First route option
    [destination3, destination4] // Second route option
    ]);
  • Calculates the straight-line distance between two locations.

    Returns the direct distance between two points, not following walkable paths. For navigation distances, use getDirections.

    Parameters

    Returns number

    The distance in meters.

    const space1 = mapData.getById('space', 'space-123');
    const space2 = mapData.getById('space', 'space-456');

    if (space1 && space2) {
    const distance = mapData.getDistance(space1, space2);
    console.log(`Direct distance: ${distance}m`);
    }
    const coordinate = mapData.mapCenter;
    const space = mapData.getByType('space')[0];
    const distance = mapData.getDistance(coordinate, space);
    console.log(`Distance from center: ${distance}m`);
  • Get the current environment configuration.

    Returns the environment settings including API endpoints and configuration.

    Returns {
        get analyticsBaseUri(): string;
        get baseAuthUri(): string;
        get baseUri(): string;
        get tileServerUri(): string;
    }

    Environment configuration object

    const env = mapData.getEnv();
    console.log(env.baseUri); // Get the API URL for the current environment
  • Retrieves the GeoJSON representation of a map element.

    Returns the geometric data for a map element in GeoJSON format, which can be used for custom rendering, analysis, or integration with mapping libraries.

    Type Parameters

    Parameters

    • mapDataObject: T

      The map element to get GeoJSON for.

    Returns T["geoJSON"]

    The GeoJSON representation of the element.

    const space = mapData.getById('space', 'space-123');
    if (space) {
    const geoJSON = mapData.getGeoJSON(space);
    console.log('Space geometry:', geoJSON.geometry);
    console.log('Space properties:', geoJSON.properties);
    }
    const floor = mapData.getByType('floor')[0];
    const geoJSON = mapData.getGeoJSON(floor);
    console.log('Floor bounds:', geoJSON.geometry.coordinates);
  • Unsubscribe from MapData events.

    Type Parameters

    • EventName extends "language-change"

    Parameters

    • eventName: EventName

      The name of the event to unsubscribe from.

    • fn: (
          payload: TMapDataEvents[EventName] extends { data: null }
              ? any[any]["data"]
              : TMapDataEvents[EventName],
      ) => void

      The callback function that was previously registered with on().

    Returns void

    const handleLanguageChange = ({ code, name }) => {
    console.log(`Language changed to ${name}`);
    };

    // Add listener
    mapData.on('language-change', handleLanguageChange);

    // Later, remove the listener
    mapData.off('language-change', handleLanguageChange);
  • Subscribe to MapData events.

    Listen for events emitted by the MapData instance such as language changes.

    Type Parameters

    • EventName extends "language-change"

    Parameters

    Returns void

    mapData.on('language-change', ({ code, name }) => {
    console.log(`Language changed to ${name} (${code})`);

    // Update UI to reflect new language
    updateInterfaceLanguage(code);
    });
  • Exports the map data as a JSON bundle.

    Creates a JSON representation of the map data that can be easily parsed and manipulated. Useful for data analysis, debugging, or integration with other systems.

    Parameters

    • options: { downloadLanguagePacks?: boolean } = {}

      Configuration options for the export.

      • OptionaldownloadLanguagePacks?: boolean

        Whether to include language packs in the export.

    Returns Promise<THydrateMapDataBundle>

    A JSON bundle containing the map data.

    const jsonBundle = mapData.toJSONBundle({ downloadLanguagePacks: true });
    console.log('Map data exported:', jsonBundle);
    const jsonBundle = mapData.toJSONBundle({ downloadLanguagePacks: false });
    // Use JSON data for analysis or processing