Select to view content in your preferred language

Close Basemap Gallery On Selection

1894
9
Jump to solution
11-07-2016 07:47 AM
LloydBronn
Occasional Contributor II

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. 

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Lloyd,


   I normally use tp.toggle(); I would have to see more of your code.

View solution in original post

9 Replies
RobertScheitlin__GISP
MVP Emeritus

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.

0 Kudos
LloydBronn
Occasional Contributor II

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

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Lloyd,


   I normally use tp.toggle(); I would have to see more of your code.

LloydBronn
Occasional Contributor II

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():
 });

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Lloyd.

   Are you sure that basemapGallery and/or tp are not null that those vars are in scope?

0 Kudos
LloydBronn
Occasional Contributor II

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();
        }     
      });
0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Lloyd,

   Is "basemapGallery" the TitlePane or the basemap gallery widget? You need to get the titlepane not the basemap gallery widget.

0 Kudos
LloydBronn
Occasional Contributor II

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();
        }     
      });‍‍‍‍‍‍‍‍
0 Kudos
LloydBronn
Occasional Contributor II

Just needed an else{tp.toggle();}

0 Kudos