Custom configurations

This article describes how to change the default platform URLs in cases when there is a need to access APIs via proxy or when the custom installation of the platform exists.

Setting the domain name

By default, the Maps API for JavaScript is configured to use the HERE platform APIs. To change this configuration for the vector map tiles, search or routing to your own installation, the API must be configured at run-time, i.e., in the application scripts using the API.

The following snippet demonstrates how to change the request domain for the individual services.

// configuration object, will be passed to the H.service.Platform
const domainConfig = {};
const getoptions = {
  apikey: '<API_KEY>'
};

// Vectore Tile service
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
};

// Geocoding service
domainConfig[H.service.GeocodingService.CONFIG_KEY] = {
  baseUrl: new H.service.Url(
    'https', 'custom.domain', 'search/6.3', getoptions
  ),
  reverseSubDomain: 'customreverse'
};

// Routing service
domainConfig[H.service.RoutingService.CONFIG_KEY] = {
  baseUrl: new H.service.Url(
    'https', 'custom.domain', 'routing/6.2', getoptions
  )
};

// Map tile service
domainConfig[H.service.MapTileService.CONFIG_KEY] = {
  baseUrl: new H.service.Url(
    'https', 'custom.domain', 'maptile/2.1', getoptions
  ),
  // optional if respected subdomain should be omitted
  ignoreTypes: ['base', 'aerial', 'traffic'],
  // optional if sharding scheme is different from defualt
  // null when sharding is not available
  shards: ['a', 'b', 'c', 'd']
};

// Traffic service
domainConfig[H.service.traffic.Service.CONFIG_KEY] = {
  baseUrl: new H.service.Url(
    'https', 'custome.domain', 'traffic/6.0', getoptions
  )
};

// Create an instamce of the platform
var platform = new H.service.Platform({
  apikey: '<API_KEY>',
  servicesConfig: domainConfig
});

/**
 * The rest of the application remains unchanged
 */

Changing the service path

The individual services could also be configured to use different paths leaving the domain configuration unchanged. That might be useful when the RESTful service provides additional endpoints that expose similar functionality (eg. country-specific endpoints).

The code snippet below demonstrates such a use case:

// Create an instamce 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.Style('https://js.api.here.com/v3/3.1/styles/omv/normal.day.yaml'));
var omvlayer = new H.map.layer.TileLayer(omvProvider, {max: 22});

/**
 * The application can use  the layer above as normal
 */

The code above creates the H.service.Platform object as usual and the custom Vector Tile Service instance is created by passing the path option to the factory method getOMVService. For more options related to the creation of the services please refer to the API Reference of the guide.

results matching ""

    No results matching ""