I've been searching this forum and the stackoverflow for a while but I could not solve it. I found many examples show how to set and switch the default imagery when constructing a viewer, but not with customized ProviderViewModel. Please see my code below (I removed my access token). Thanks in advance!
2. A minimal code example. If you've found a bug, this helps us reproduce and repair it.
This is my HTML button: <button onclick="javascript:changeBaseLayer(1);">changeBaseLayer</button>
var imageryViewModels = [];
imageryViewModels.push(new Cesium.ProviderViewModel({
name: 'ArtilerySim Terrain',
iconUrl: Cesium.buildModuleUrl('Widgets/Images/ImageryProviders/mapboxSatellite.png'),
tooltip: 'Beautiful clear imagery',
creationFunction: function () {
return new Cesium.MapboxImageryProvider({
mapId: 'mapbox.satellite',
//Get your DigitalGlobe Maps API Access Token here: http://developer.digitalglobe.com/maps-api
accessToken: 'pk.',
credit: 'ArtilleryVision'
});
}
}));
imageryViewModels.push(new Cesium.ProviderViewModel({
name: 'ArtilerySim Street Maps',
iconUrl: Cesium.buildModuleUrl('Widgets/Images/ImageryProviders/mapboxStreets.png'),
tooltip: 'Beautiful clear imagery',
creationFunction: function () {
return new Cesium.MapboxImageryProvider({
mapId: 'mapbox.streets',
//Get your DigitalGlobe Maps API Access Token here: http://developer.digitalglobe.com/maps-api
accessToken: 'pk.',
credit: 'ArtilleryVision'
});
}
}));
var viewer = new Cesium.Viewer('cesiumContainer', {
baseLayerPicker: false,
terrainProvider: Cesium.createWorldTerrain(),
imageryProviderViewModels: imageryViewModels, //HQN: new with Mapbox
shouldAnimate: true,
homeButton: false,
animation: true,
timeline: true,
navigationHelpButton: false
});
var baseLayerPicker = new Cesium.BaseLayerPicker('baseLayerPickerContainer', {
globe: viewer.scene, // Yep, this is right
imageryProviderViewModels: imageryViewModels
});
// This is the javascript function that the button calls:
function changeBaseLayer(iIndex) {
console.log(imageryViewModels[1]);
baseLayerPicker.selectedImageryProviderViewModel = imageryViewModels[iIndex];
}
3. Context. Why do you need to do this? We might know a better way to accomplish your goal.
I want to switch my customized imageryViewModel on-the-fly using Javascript.
4. The Cesium version you're using, your operating system and browser.
I'm using version 1.55
--
You received this message because you are subscribed to a topic in the Google Groups "cesium-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cesium-dev/DhPGPhlPSC8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cesium-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cesium-dev/d14e36fb-8478-4136-a1d0-f9eac38cf15e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.