0

I'm able to create a tile layer and add it to the map with this code...

var tileProvider = new H.map.provider.ImageTileProvider({
        opacity: 0.8,
        getURL:  function (column, row, zoom) {
            return 'https://1.base.maps.api.here.com/maptile/2.1/truckonlytile/newest/reduced.day/' + zoom + '/' + column + '/' + row + '/256/png8?app_id=...&app_code=...'
        }
    });
    overlayLayer = new H.map.layer.TileLayer(tileProvider, {
        // Let's make it semi-transparent
        opacity: 0.8
    });
    map.addLayer(overlayLayer);

This works fine and the layer overlays on the map, but I want to be able to toggle it on/off via the "Choose View" menu.

I can't figure out how to do it... I've tried this ...

var defaultLayers = platform.createDefaultLayers();
    ui.removeControl('mapsettings');
    var ms = new H.ui.MapSettingsControl( {
    baseLayers : [ {
            label: 'Map View',layer: defaultLayers.raster.normal.map
        },{
            label: 'Satellite',layer: defaultLayers.raster.satellite.map
        }, {
            label: 'Terrain',layer: defaultLayers.raster.terrain.map
        },{
            label: 'overlay', layer: overlayLayer
        }
        ],
        layers: [{
            label: 'layer.traffic', layer: defaultLayers.vector.normal.traffic
        },
        {
            label: 'layer.incidents', layer: defaultLayers.vector.normal.trafficincidents
        }            
        ]
    });
    ui.addControl('customized',ms);

... but it doesn't work.

Is there any way to make a tile later like this toggle via the menu?

Michel
  • 26,600
  • 6
  • 64
  • 69
  • Hi, would you please see this question. https://stackoverflow.com/questions/58316602/here-maps-adding-layer-dynamically-in-mapsettingscontrol –  Nov 01 '19 at 04:49

1 Answers1

1

Your layer should be moved from baseLayers array to layers array:

var defaultLayers = platform.createDefaultLayers();
ui.removeControl('mapsettings');
var ms = new H.ui.MapSettingsControl({
    baseLayers: [{
        label: 'Map View', layer: defaultLayers.raster.normal.map
    }, {
        label: 'Satellite', layer: defaultLayers.raster.satellite.map
    }, {
        label: 'Terrain', layer: defaultLayers.raster.terrain.map
    }],
    layers: [{
        label: 'layer.traffic', layer: defaultLayers.vector.normal.traffic
    },
    {
        label: 'layer.incidents', layer: defaultLayers.vector.normal.trafficincidents
    },
    {
        label: 'overlay', layer: overlayLayer
    }]
});
ui.addControl('customized', ms);

For more information see: https://developer.here.com/documentation/maps/dev_guide/topics_api/h-ui-mapsettingscontrol-options.html#h-ui-mapsettingscontrol-options

Michel
  • 26,600
  • 6
  • 64
  • 69
Tomas
  • 1,849
  • 1
  • 13
  • 13
  • This works... the "overlay" is available and toggles on/off, however the base layers "Map View" Satellite" and "Terrain" don't work. Clicking on them does nothing on the map and gives a javascript error "Cannot read property 'cg' of null - not helpful as it's in a minified js file. Any ideas on how I can get the baseLayers working? – user12260850 Nov 06 '19 at 05:20
  • This looks like an issue on API side. – Tomas Nov 07 '19 at 13:55
  • It looks like the team fixed it and the issue is not happening anymore, @user12260850 can you try it again? – Tomas Nov 27 '19 at 16:17