I have the basemaps gallery widget in my maps. I'd like the gallery to automatically close when a user chooses a basemap. I'm not sure if I need to specify this in basemapGallery.on "selection-change" event or in the TitlePane dijit itself. I looked at the API reference and I don't think the destroy() method is what I want.
Solved! Go to Solution.
Lloyd,
I normally use tp.toggle(); I would have to see more of your code.
Llyod,
Yes if you are opening a TtilePane from some event and you want to close that pane then you need to attach to the selection-change and then close the pane from that event handler.
I tried this, but it's not working.
basemapGallery.on("selection-change",function(){
var layer = map.getLayer(refLayerId);
if(layer){
map.removeLayer(layer);
}
dijit.byId("basemapGallery").set('open',false);
});
Lloyd,
I normally use tp.toggle(); I would have to see more of your code.
Tried this, but it didn't work.
var basemapGallery = new BasemapGallery({
showArcGISBasemaps: true,
map: map
}, "basemapGallery");
basemapGallery.startup();
basemapGallery.on("selection-change",function(){
var layer = map.getLayer(refLayerId);
if(layer){
map.removeLayer(layer);
}basemapGallery.toggle():
});
basemapGallery.on("error", function(msg) {
console.log("basemap gallery error: ", msg);
});
basemapGallery.on("load", function(msg) {
for (b=0;b<map.basemapLayerIds.length;b++){
var lyr = map.getLayer(map.basemapLayerIds[b]);
if(lyr._isRefLayer){
refLayerId = lyr.id;
}
}
Also this
var tp = dijit.byId("basemapGallery")
basemapGallery.on("selection-change",function(){
var layer = map.getLayer(refLayerId);
if(layer){
map.removeLayer(layer);
}tp.toggle():
});
Lloyd.
Are you sure that basemapGallery and/or tp are not null that those vars are in scope?
Gotcha. Something along these lines?
basemapGallery.on("selection-change",function(){
var tp = dijit.byId("basemapGallery");
var layer = map.getLayer(refLayerId);
if(layer && tp != null){
map.removeLayer(layer);
tp.toggle();
}
});
Lloyd,
Is "basemapGallery" the TitlePane or the basemap gallery widget? You need to get the titlepane not the basemap gallery widget.
Ah, OK. My titlepane did not have a div ID, so I added one. That works, but only the first time I choose a new basemap. If I change it again, the titlepane stays open.
basemapGallery.on("selection-change",function(){
var tp = dijit.byId("TitlePane");
var layer = map.getLayer(refLayerId);
if(layer && tp != null){
map.removeLayer(layer);
tp.toggle();
}
});
Just needed an else{tp.toggle();}