カスタムのドメイン名とサービスパスを設定する
この記事では、プロキシ経由でAPIにアクセスする場合や、カスタム設定でプラットフォームをインストールする場合に、デフォルトのプラットフォームURLを変更する方法について説明します。
ドメイン名を設定する
デフォルトでは、MAPs API for JavaScriptはHEREプラットフォームAPIを使用するように設定されています。独自のインストール環境でベクターマップタイル、検索、ルーティングのこの設定を変更するには、アプリケーションスクリプトを使用して実行時にAPIを設定する必要があります。
以下のコードスニペットは、個別のサービスのリクエストドメインの変更方法を示しています。
// configuration object, is passed to the H.service.Platform
const domainConfig = {};
const getoptions = {
apikey: '<API_KEY>'
};
// HERE Vector Tile API v2
domainConfig[H.service.omv.Service.CONFIG_KEY] = {
baseUrl: new H.service.Url(
'https', 'custom.domain', 'v2/vectortiles/core/mc', getoptions
),
subdomain: 'subdomain' // optional, if subdomain is not needed, null must be passed
};
// HERE Geocoding and Search API v7
domainConfig[H.service.SearchService.CONFIG_KEY] = {
baseUrl: new H.service.Url(
'https', 'custom.domain', 'v1', getoptions
)
};
// HERE Interactive Map Layer Data API
domainConfig[H.service.iml.Service.CONFIG_KEY] = {
baseUrl: new H.service.Url(
'https', 'custom.domain', 'interactive/v1/catalogs', getoptions
)
};
// HERE Public Transit API v8
domainConfig[H.service.publicTransit.Service.CONFIG_KEY] = {
baseUrl: new H.service.Url(
'https', 'custom.domain', 'v8', getoptions
)
};
// HERE Routing API v8
domainConfig[H.service.RoutingService8.CONFIG_KEY] = {
baseUrl: new H.service.Url(
'https', 'custom.domain', 'v8/routes', getoptions
)
};
// HERE Raster Tile API v3
domainConfig[H.service.rasterTile.Service.CONFIG_KEY] = {
baseUrl: new H.service.Url(
'https', 'custom.domain', 'v3', getoptions
)
};
// HERE Traffic API v7
domainConfig[H.service.traffic.Service7.CONFIG_KEY] = {
baseUrl: new H.service.Url(
'https', 'custom.domain', 'v7', getoptions
)
};
// HERE Traffic Vector Tile API v2
domainConfig[H.service.trafficVectorTile.Service.CONFIG_KEY] = {
baseUrl: new H.service.Url(
'https', 'custom.domain', 'v2', getoptions
)
};
// HERE Waypoints Sequence API v8
domainConfig[H.service.WaypointsSequenceService.CONFIG_KEY] = {
baseUrl: new H.service.Url(
'https', 'custom.domain', 'v8', getoptions
)
};
// HERE Geofencing API v8
domainConfig[H.service.GeofencingService.CONFIG_KEY] = {
baseUrl: new H.service.Url(
'https', 'custom.domain', 'v8', getoptions
)
};
// Create an instance of the platform
var platform = new H.service.Platform({
apikey: '<API_KEY>',
servicesConfig: domainConfig
});
/**
* The rest of the application remains unchanged
*/ サービスパスを変更する
ドメイン設定を変更せずに、個々のサービスが異なるパスを使用するように設定できます。このアプローチは、国固有のエンドポイントなど、同様の機能を持つ追加のエンドポイントを提供するRESTfulサービスがある場合に役立ちます。
次のコードスニペットは、このユースケースを示しています。
// Create an instance of the platform
var platform = new H.service.Platform({
apikey: '<API_KEY>'
});
// create a service that calls the custom endpoint
var omvService = platform.getOMVService({path: 'custom/vector/endpoint'});
// create a provider and a layer that use the custom service
var omvProvider = new H.service.omv.Provider(omvService,
new H.map.render.harp.Style('https://js.api.here.com/v3/3.2/styles/harp/oslo/normal.day.json'));
var omvLayer = new H.map.layer.TileLayer(omvProvider, {max: 22});
/**
* The application can use the preceding layer configuration as normal
*/上記のコードは、H.service.Platformオブジェクトを作成し、pathオプションをファクトリメソッドgetOMVServiceに渡すことによって、カスタムのベクタータイルサービスインスタンスを作成します。services作成の詳細については、「APIリファレンス」を参照してください。
14 日前の更新