このセクションでは、日本固有のデータおよびマップスタイルで HERE Maps API for Javascript を使用する方法について説明します。 このデータへのアクセス権は、ユーザーの契約によって決まります。 このレイヤーへのアクセス権を取得するに は、営業担当者に連絡するか、または弊社にお問い合わせください。
// 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}});
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)