0

我可以使用此代码创建一个切片图层并将其添加到地图中...

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);

这工作正常,图层覆盖在地图上,但我希望能够通过“选择视图”菜单打开/关闭它。

我不知道该怎么做......我试过这个......

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);

...但它不起作用。

以后有什么办法可以像这样通过菜单切换瓷砖吗?

4

1 回答 1

1

您的图层应从baseLayers数组移动到图层数组:

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);

有关更多信息,请参阅:https ://developer.here.com/documentation/maps/dev_guide/topics_api/h-ui-mapsettingscontrol-options.html#h-ui-mapsettingscontrol-options

于 2019-11-05T12:46:29.280 回答