Leaflet がサポートするマップ ( HERE ビジュアル化に最適化した地図 Plus を含む ) を配置する要素 <body> を次のセクションに追加します。
<divid="map"style="height: 100%"></div>
プラットフォームでの認証
プラットフォームで認証するには、アクセス トークンを返す関数を使用する必要があります。 UserAuth コンストラクタで、アプリ資格情報アクセスキーの ID 、シークレット、およびプロジェクトのスコープを指定します ( 任意 ) 。
// Get a function, that will provide a token to access HERE data.const token =newUserAuth({
env,credentials:{
accessKeyId,
accessKeySecret
},tokenRequester: requestToken,
scope
}).getToken();getToken=()=> token;
/**
* Fetch and process schema archive to prepare a Protobuf decoder.
*
* @param layer Instance of a layer client.
*/asyncfunctiongetDecoder(hrn, settings){// Get schema with protobuf filesconst artifactClient =newArtifactClient(settings);const detailsRequest =newSchemaDetailsRequest().withSchema(HRN.fromString(hrn));const details =await artifactClient.getSchemaDetails(detailsRequest);if(details ===undefined|| details.variants ===undefined){return;}const variant = details.variants.find(item=> item.id ==="ds");if(variant ===undefined){return;}const request =newSchemaRequest().withVariant(variant);const archive =await artifactClient.getSchema(request);// Load schema as a ZIP archiveconst zip =newJSZip();await zip.loadAsync(archive);// Read all .proto file and parse them by Protobufconst protobufRoot =newprotobuf.Root();
Object.keys(zip.files).forEach(asyncfileName=>{if(!fileName.endsWith(".proto")){return;}const file =await zip.file(fileName).async("text");
protobuf.parse(file, protobufRoot,{keepCase:true})});// Extract the manifest data.const manifestFile =await zip.file("META-INF/layer.manifest.json").async("text");const manifest =JSON.parse(manifestFile);return protobufRoot.lookupType(manifest.main.message);}
if(layerConfig.schema ===undefined|| layerConfig.schema.hrn ===undefined){thrownewError("Layer schema HRN is not defined");}// Get a decoder from the schema.const decoder =awaitgetDecoder(layerConfig.schema.hrn, settings);if(!decoder){thrownewError("Decoder was not found.");}
// Get tile data and add to Leaflet.
partitions.forEach(asyncpartition=>{const request =newDataRequest().withPartitionId(`${partition}`);const response =await layer.getData(request);const data =await response.json();L.geoJSON(data).bindPopup(item=> item.feature.properties.tooltip).addTo(map);});