Skip to main content

HereMap

The HereMap component is the main container for HERE Maps. It provides the map context to all child components through React Context.

Props

apikey
string
required
Your HERE Maps API key. Get one at developer.here.com
options
object
Map initialization options
mapStyle
string
Map style/theme. Defaults to "vector.normal.map"Available styles:
  • vector.normal.map - Standard vector map
  • raster.satellite.map - Satellite imagery
  • raster.terrain.map - Terrain view
  • raster.normal.mapnight - Night mode
children
ReactNode
Child components (Markers, Polylines, Controls, etc.)

Basic Usage

import { HereMap } from '@rodrito/react-here-maps';

function App() {
  return (
    <div style={{ height: '500px', width: '100%' }}>
      <HereMap
        apikey="YOUR_API_KEY"
        options={{
          center: { lat: 52.52, lng: 13.405 },
          zoom: 12
        }}
      />
    </div>
  );
}
The container must have a defined height for the map to render properly.

Map Styles

<HereMap
  apikey={apiKey}
  mapStyle="vector.normal.map"
  options={{ center: { lat: 40.7128, lng: -74.0060 }, zoom: 12 }}
/>

With Child Components

import { HereMap, Marker, Polyline, ZoomControl, ScaleBar } from '@rodrito/react-here-maps';

function CompleteMap() {
  return (
    <div style={{ height: '600px', width: '100%' }}>
      <HereMap
        apikey="YOUR_API_KEY"
        options={{
          center: { lat: 52.52, lng: 13.405 },
          zoom: 12
        }}
      >
        <Marker position={{ lat: 52.52, lng: 13.405 }} label="Berlin" />

        <Polyline
          points={[
            { lat: 52.52, lng: 13.405 },
            { lat: 52.53, lng: 13.415 }
          ]}
          options={{ style: { strokeColor: 'blue', lineWidth: 4 } }}
        />

        <ZoomControl alignment="right-top" />
        <ScaleBar alignment="bottom-right" />
      </HereMap>
    </div>
  );
}

Context Provider

The HereMap component provides a context that can be accessed by child components:
import { useMapContext } from '@rodrito/react-here-maps';

function CustomComponent() {
  const { map, platform, ui, behavior } = useMapContext();

  // Access map instance and other HERE Maps objects
  // ...

  return null;
}

Engine Types

P2D (Default)

2D rendering engine. Better performance on older devices.

WEBGL

WebGL rendering engine. Better performance with complex visualizations.
// Use WebGL engine
<HereMap
  apikey={apiKey}
  options={{
    center: { lat: 40.7128, lng: -74.0060 },
    zoom: 12,
    engineType: 'WEBGL'
  }}
/>

See Also