Tobias Weyer
Tobias Weyer

Reputation: 43

How to change map tile types on ui controls

When we are initializing the map, we set the baselayer to "reduced.day".
We are currently facing a problem, when the user changes the map type from "map-view" to "satellite" and back to "map-view", the tile changed to the standard and not "reduced.day".
I have looked up the docs, but can´t find any hint on how to prevent that problem.

So my question is, how to set with the UI controls the map-view tiles to reduced day.

Thanks a lot.

Upvotes: 0

Views: 149

Answers (2)

Tobias Weyer
Tobias Weyer

Reputation: 43

I finally could achieve the solution for my problem.

The solution was to pass a custom object with the requested map style for each map type.
See below the complete code for editing the map controls.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Here Custom Controlls</title>
    <script src="http://js.api.here.com/v3/3.0/mapsjs-core.js" type="text/javascript" charset="utf-8"
    ></script>
    <script src="http://js.api.here.com/v3/3.0/mapsjs-service.js" type="text/javascript" charset="utf-8"
    ></script>
    <script src="http://js.api.here.com/v3/3.0/mapsjs-ui.js" type="text/javascript" charset="utf-8"
    ></script>
    <link rel="stylesheet" type="text/css" href="http://js.api.here.com/v3/3.0/mapsjs-ui.css"
    />
  </head>
  <body>
    <div id="map" style="height: 800px; width: 800px;"></div>

    <script type="text/javascript" charset="utf-8">
      //Initialize the Platform object:
      const platform = new H.service.Platform({
        app_id: {YOUR_APP_ID},
        app_code: {YOUR_APP_CODE}
      });

      // Get the default map types from the Platform object:
      const defaultLayers = platform.createDefaultLayers();

      // Instantiate the map:
      const map = new H.Map(
        document.getElementById("map"),
        defaultLayers.normal.map,
        {
          zoom: 10,
          center: { lng: 13.4, lat: 52.51 }
        }
      );

      const mapTileService = platform.getMapTileService({ type: "base" });

      var reduce = mapTileService.createTileLayer(
        "maptile",
        "reduced.day",
        256,
        "png8"
      );

      map.setBaseLayer(reduce);

      // Create the custom UI:
      const ui = H.ui.UI.createDefault(
        map,
        {
          ...defaultLayers,
          normal: {
            map: reduce
          }
        },
        "de-DE"
      );
    </script>
  </body>
</html>

Upvotes: 1

user3505695
user3505695

Reputation:

Please see two javascript functions codes.

SatelliteLayer will work with type : 'aerial'.

ReducedLayer will work with type : 'base'.

/**
 *
 * @param  {H.Map}
 * @param   {H.service.Platform}
 */
function setAerialSatelliteLayer(map, platform){
  var mapTileService = platform.getMapTileService({
      type: 'aerial'
    });
  var parameters = {};
  var tileLayer = mapTileService.createTileLayer(
      'maptile',
      'satellite.day',
      256,
      'png8',
      parameters
    );
  map.setBaseLayer(tileLayer);
}

/**
 *
 * @param  {H.Map}
 * @param   {H.service.Platform}
 */
function setBaseReducedLayer(map, platform){
  var mapTileService = platform.getMapTileService({
      type: 'base'
    });
  var parameters = {};
  var tileLayer = mapTileService.createTileLayer(
      'maptile',
      'reduced.day',
      256,
      'png8',
      parameters
    );
  map.setBaseLayer(tileLayer);
}

Upvotes: 0

Related Questions