This section shows how to start using the HERE Maps API for JavaScript with the Japan specific data and map style. Access to this data is determined by the contract of the user. If you would like to get access to this layer, please contact your sales representative or contact us.
Use Case
Sections below follow the steps of the Get Started chapter but additionally describe how to:
Configure the JavaScript API to call the "core" layer of the Vector Tile API
Fetch the map style that works best with the Japan data.
Display a route within Japan.
Load the API Code Libraries
There are no changes in how the JavaScript API is included on the page, here is the complete <head> element that loads the core and service modules and ensures optimum performance on mobile devices.
Initialize the Platform object normally by passing it the API Key:
var platform =newH.service.Platform({'apikey':'{YOUR_API_KEY}'});
Initialize the Map
Create an instance of the Vector Tile Service object that is pre-configured to use the coreendpoint that provides the Japan data.
Create a layer that uses the map style optimised for the display of the Japan data. The style can be adjusted with the help of Map Customization Tool.
Instantiate an H.Map object, specifying:
the map container element
the layer created in the previous step
the zoom level at which to display the map
the geographic coordinates of the point on which to center the map
// configure an OMV service to use the `core` enpointvar omvService = platform.getOMVService({path:'v2/vectortiles/core/mc'});var baseUrl ='https://js.api.here.com/v3/3.1/styles/omv/oslo/japan/';// create a Japan specific stylevar style =newH.map.Style(`${baseUrl}normal.day.yaml`, baseUrl);// instantiate provider and layer for the basemapvar omvProvider =newH.service.omv.Provider(omvService, style);var omvlayer =newH.map.layer.TileLayer(omvProvider,{max:22});// instantiate (and display) a map:var map =newH.Map(
document.getElementById('mapContainer'),
omvlayer,{
zoom:17,
center:{lat:35.68026, lng:139.76744}});
The implementation displays the following map image:
The following example demonstrates how to geocode two points in the Tokyo area and calculate the route between them. The snippet below:
geocodes start and finish point of the route.
defines the routing parameters and the routing callback that parses the response and displays the route polyline.
instantiates the routing service and calculates the route
let origin;let destination;letonError=(error)=>{alert(error.message);}// create an instance of the routing service and make a requestlet router = platform.getRoutingService(null,8);// Define a callback function to process the routing response:letonResult=function(result){// ensure that at least one route was foundif(result.routes.length){
result.routes[0].sections.forEach((section)=>{// Create a linestring to use as a point source for the route linelet linestring =H.geo.LineString.fromFlexiblePolyline(section.polyline);// Create a polyline to display the route:let routeLine =newH.map.Polyline(linestring,{
style:{ strokeColor:'blue', lineWidth:3}});// Create a marker for the start point:let startMarker =newH.map.Marker(section.departure.place.location);// Create a marker for the end point:let endMarker =newH.map.Marker(section.arrival.place.location);// Add the route polyline and the two markers to the map:
map.addObjects([routeLine, startMarker, endMarker]);// Set the map's viewport to make the whole route visible:
map.getViewModel().setLookAtData({bounds: routeLine.getBoundingBox()});});}};let routingParameters ={'transportMode':'car',// Include the route shape in the response'return':'polyline'};// Define a callback that calculates the routeletcalculateRoute=()=>{// Make sure that both destination and origin are presentif(!origin ||!destination)return;// Add origin and destination to the routing parameters
routingParameters.origin = origin;
routingParameters.destination = destination;
router.calculateRoute(routingParameters, onResult, onError);}// get the instance of the Search servicevar service = platform.getSearchService();// geocode origin point
service.geocode({
q:'東京都中央区佃1‐11‐8'},(result)=>{
origin = result.items[0].position.lat +','+ result.items[0].position.lng;calculateRoute();}, onError);// geocode a destination point
service.geocode({
q:'東京都千代田区丸の内1‐9'},(result)=>{
destination = result.items[0].position.lat +','+ result.items[0].position.lng;calculateRoute();}, onError)
The picture below demonstrates the result of the routing request from the code above.