问题
Is there a way for us to remove options from the "Choose View" menu?
Based on what I see online, it might have something to do with the layers, but I'm having trouble finding a simple example and getting it to properly populate the options menu.
For example, if we never want to show the 3 options at the bottom and don't need the "terrain" map?
Update: I tried a solution below provided by HERE Developer support (manually removing some of the options), but I end up with a line underneath it (and also it doesn't describe how to remove Terrain map, so any additional help would be appreciated!
Alternatively, if there's a way to not just remove the options from the UI menu and just completely get rid of the layers and map types from the map altogether, that would be even better. Thanks!
回答1:
You can try this example:
//get map settings
var mapSettings= ui.getControl('mapsettings');
//remove incidents options
mapSettings.setIncidentsLayer(false);
// remove traffic and public transit option
var traffic=mapSettings.getChildren()[1].getChildren()[1];
var publicTransit=mapSettings.getChildren()[1].getChildren()[2];
mapSettings.getChildren()[1].removeChild(traffic);
mapSettings.getChildren()[1].removeChild(publicTransit);
回答2:
It is possible to create a custom MapSettingsControl with the desired list of layers and show it in the UI. Layers can be specified to the constructor of the class. They are split into 2 groups:
baseLayers
Clicking on those will change the base map (works like a "radio button").
layers
Clicking on those will add the specified layer to the map in addition to other layers and existing base map layers (works like a "checkbox")
ui.addControl('custom_settings_control', new H.ui.MapSettingsControl({
baseLayers: [{
label: 'Normal Map',
layer: maptypes.vector.normal.map
}, {
label: 'Satellite',
layer: maptypes.raster.satellite.map
}],
layers: []
}))
When "layers" are not specified, the divider is not drawn automatically.
If you don't want to create default layers remove the platform.createDefaultLayers(...) method call from your code.
Note that the above mentioned will work with the HERE Maps API for JavaScript version 3.1. If you are using version 3.0 please find the migration guide here.
回答3:
I found another solution here, which also removes the "line":
Disable traffic map views with HERE JavaScript API
let mapsettings = ui.getControl('mapsettings');
let menuEntries = mapsettings.getChildren()[1].getChildren();
menuEntries[0].getElement().style.borderBottom = 'none';
for (let i=1; i<menuEntries.length; i++)
menuEntries[i].setVisibility(false);
And to get rid of one of the map view options (like terrain or satellite), I just did:
delete maptypes.terrain;
after the creation of the default layers.
It's not 100% my ideal (since I wanted to prevent the layers from getting created at all), but from what I've seen, it may be a lot more trouble and for not much more gain if we tried to create the layers from scratch.
来源:https://stackoverflow.com/questions/56799751/here-maps-choose-view-can-we-remove-options