0

in the default Here Map, there is a "Choose View" button in the bottom right corner. This can be seen in many maps, for example here: https://developer.here.com/api-explorer/maps-js/maps/map-at-specified-location

The user has the choice between "Map View" and "Satellite". How can I change the tile type of these two views? For example, how can I change the tile type of the "Map View" to "raster.terrain.xbase"?

Currently I can set the Tile Type to xbase when I init the map, but when the user switches views the tile type gets overriden with the default.

Nils Schlüter
  • 1,418
  • 1
  • 19
  • 30

1 Answers1

0

For anybody else who might have the same problem: I found a solution based on this answer and updated it for Here Maps 3.1.

You can remove the default mapSettings and create your own H.ui.MapSettingsControl:

// remove default mapsettings
ui.removeControl('mapsettings');

// store scalebar
const scalebar = ui.getControl('scalebar');
ui.removeControl('scalebar');

// Create custom mapSettings
const mapSettings = new H.ui.MapSettingsControl({
    baseLayers: [
        {
            label: 'Layer 1',
            layer: defaultLayers.vector.normal.map,
        },
        {
            label: 'Layer 2',
            layer: defaultLayers.raster.terrain.xbase,
        },
    ],
});

// Add Map Settings and scalebar
ui.addControl('custom-mapsettings', mapSettings);
ui.addControl('scalebar', scalebar);

The MapSettingsControl accepts an array of base layers and an array of layers, as you can see in the official documentation. These layers are then displayed in the choose view dialog.

Nils Schlüter
  • 1,418
  • 1
  • 19
  • 30
  • is it possible to change layers programatically? I have to remove all the control (zoom, mapsettings, scale) from the UI but I need to change the layer at runtime. – psclkhoury Feb 25 '22 at 14:26