Skip to main content

Map Context

The React HERE Maps library uses React Context to share the map instance and HERE Maps objects across components.

Overview

The HereMap component creates a context that provides access to:
  • map - The HERE Maps instance (H.Map)
  • platform - HERE Platform service (H.service.Platform)
  • ui - HERE Maps UI object (H.ui.UI)
  • behavior - Map behavior object (H.mapevents.Behavior)

Using the Context

Built-in Components

All library components automatically consume the context:

Custom Components

Access the context in your custom components using useMapContext:

Context Values

map (RefObject)

A React ref containing the HERE Maps instance:

platform (RefObject)

Reference to the HERE Platform service for geocoding, routing, etc.:

ui (RefObject)

Reference to the HERE Maps UI for controls and popups:

behavior (RefObject)

Reference to map behavior for interaction handling:

Advanced Examples

Map Event Listeners

Geocoding Service

Info Bubbles

Custom Controls

Best Practices

Since context values are refs, always check if they’re loaded before using:
Always remove event listeners in useEffect cleanup:
Use HERE Maps TypeScript definitions for type safety:

See Also

Hooks System

Custom hooks for map functionality

TypeScript

Type-safe development

Components

Available components