我可以使用此代码创建一个图块图层并将其添加到地图中...
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);
...但是它不起作用。
以后是否可以通过菜单进行切换来制作图块?
答案 0 :(得分:1)
您的图层应从 baseLayers 数组移动到 layers 数组:
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);