By using the HERE Vector Tile API in conjunction with MapLibre, you can create a fully functional map with interactive features like zooming, panning, and markers. The MapLibre library handles the map rendering and user interactions, while the HERE Vector Tile API provides the underlying map data in the form of vector tiles, ensuring that you get accurate and up-to-date geographic information for your map to display.
Obtain an API Key: If you do not have one already, sign up for a HERE platform account and generate an API key. For more information, see Get started.
Open a text editor or Integrated Development Environment (IDE) to write HTML and JavaScript code.
Build a basic HTML file
Create a basic HTML page as a container for the JavaScript code rendering the map.
In the text editor or IDE of your choice, create a new HTML file.
In the HTML file, set up the basic HTML structure, as shown in the following example:
<!DOCTYPEhtml><html><head><title>HERE Vector Tile API with MapLibre</title><!-- Scripts and styles are included here --></head><body><!-- Map content is included here --></body></html>
In the <head> section, after the closing </title> tag, include MapLibre scripts and styles, as shown in the following example:
const map - Creates a new map object using the maplibregl.Map constructor.
container: 'map' - Specifies the HTML element to display the map. In this case, the map is placed inside an element with the id attribute set to map.
style - Defines the visual style and appearance of the map. In this example, the HERE Vector Tile API loads the map style. The URL provided points to the default berlin style and includes the apikey to authenticate the request. Replace the placeholder value in the URL with your actual HERE Vector Tile API key.
center - Sets the initial geographical coordinates to center the map when it first loads. In this example, the center is set to the latitude and longitude pair representing a location in New York City.
zoom - Sets the initial zoom level of the map.
Optional: Enhance the appearance and user experience of your map by displaying additional features. The following example adds a marker at the map center coordinates: