Namespace Summary
This is a summary of the main namespaces of the API.
| Namespace | Description |
|---|---|
| H.map | Contains interfaces and implementation of core map-related functionality for rendering base map, map objects, basic operations with the data model and view model. |
| H.service | Contains implementations of service stubs and helper functionality to integrate with various HERE REST APIs like Map Tile API, Geocoding and Search API, Routing API, and so on. |
| H.mapevents | Contains functionality for supporting various map events as well as default handling of various mouse, stylus and touch input for panning, zooming, tilt, etc. |
| H.data | Contains functionality for data visualization like heatmaps, KML or GeoJSON data rendering. |
| H.clustering | Contains functionality for marker clustering. |
| H.ui | Contains UI controls for interacting with the map. |
Initialize Communication with Back-end Services
An essential part of creating a working application is to establish communication with the back-end services.
To make this possible, initialize a Platform object with the apikey you received on registration (see the Identity & Access Management Developer Guide):
const platform = new H.service.Platform({
'apikey': '{YOUR_APIKEY}'
});
Initialize the Map
To get things started, create a Map instance like this:
// Obtain the default map types from the platform
const maptypes = platform.createDefaultLayers();
// Instantiate and display a map
const map = new H.Map(document.getElementById('mapdiv'), maptypes.vector.normal.map, {
center: {lat: 0, lng: 51},
zoom: 8
});
Enable Default Map Behavior
The Maps API mapevents module provides full support for map interactions, such as pan, zoom and pinch-to-zoom. The implementation resides in the class H.mapevents.Behavior and makes use of the event system abstraction.
To enable map interactions, add the following line of code:
// Enable the event system on the map instance:
var mapEvents = new H.mapevents.MapEvents(map);
// Instantiate the default behavior, providing the mapEvents object:
new H.mapevents.Behavior(mapEvents);
The above code ensures that the map reacts to mouse, stylus and touch input.