Problems Using BasemapGallery

585
0
09-25-2012 05:09 AM
AlexDeVine
New Contributor III
Morning,

I am trying to utilize BasemapGallery is perhaps an unorthodox fashion. I am initializing the gallery with 4 basemaps that are broad categories of data and then, on selection, emptying the gallery and refilling it with more specific basemaps containing subsets of data in the chosen category. Ultimately, when the user gets three levels in, the gallery is replaced with a TOC. The trouble I am running into is "refreshing" the BasemapGallery on selection change. Here is my code:

//On basemap selection change, run basemapHandler
        dojo.connect(basemapGallery, "onSelectionChange", basemapHandlerExtent);
        function basemapHandlerExtent() {
            var basemap = basemapGallery.getSelected();
            if (basemap.id === "main") {
                basemaps.length = 0;
                basemaps.push(main_Basemap);
                basemaps.push(main_water);
                basemaps.push(main_fire);
                basemaps.push(main_earth);
                basemaps.push(main_air);
                //basemapGallery.startup();
                var mainExtent = new esri.geometry.Extent({ "xmin": 2532400, "ymin": 1436400, "xmax": 2540900, "ymax": 1442900, "spatialReference": { "wkid": 102667} });
                map.setExtent(mainExtent);
            } else if (basemap.id === "water") {
                basemaps.length = 0;
                basemaps.push(main_Basemap);
                basemaps.push(water_lakes);
                basemaps.push(water_rivers);
                basemaps.push(water_ponds);
                basemaps.push(water_swamps);
                //basemapGallery.startup();
                var secondExtent = new esri.geometry.Extent({ "xmin": 2463600, "ymin": 1392560, "xmax": 2609000, "ymax": 1468600, "spatialReference": { "wkid": 102667} });
                map.setExtent(secondExtent);
            } else if (basemap.id === "fire") {
                basemaps.length = 0;
                basemaps.push(main_Basemap);
                basemaps.push(fire_torch);
                basemaps.push(fire_bonfire);
                basemaps.push(fire_fireplace);
                basemaps.push(fire_explosion);
                //basemapGallery.startup();
                var secondExtent = new esri.geometry.Extent({ "xmin": 2532400, "ymin": 1436400, "xmax": 2540900, "ymax": 1442900, "spatialReference": { "wkid": 102667} });
                map.setExtent(secondExtent);
            } else if (basemap.id === "earth") {
                basemaps.length = 0;
                basemaps.push(main_Basemap);
                basemaps.push(earth_rock);
                basemaps.push(earth_stone);
                basemaps.push(earth_dirt);
                basemaps.push(earth_landslide);
                //basemapGallery.startup();
                var secondExtent = new esri.geometry.Extent({ "xmin": 2463600, "ymin": 1392560, "xmax": 2609000, "ymax": 1468600, "spatialReference": { "wkid": 102667} });
                map.setExtent(secondExtent);
            } else if (basemap.id === "air") {
                basemaps.length = 0;
                basemaps.push(main_Basemap);
                basemaps.push(air_breeze);
                basemaps.push(air_wind);
                basemaps.push(air_gust);
                basemaps.push(air_tornado);
                //basemapGallery.startup();
                var secondExtent = new esri.geometry.Extent({ "xmin": 2532400, "ymin": 1436400, "xmax": 2540900, "ymax": 1442900, "spatialReference": { "wkid": 102667} });
                map.setExtent(secondExtent);
            }
        }


As you can see, basemapGallery.startup() has been commented out. I know it is only really intended to be called when you first initialize the widget, but it does cause the tiles and titles of the basemaps in the gallery to update. It also throws an error that prevents my setExtents from firing. When basemapGallery.startup() is commented out, the code works fine (including the array updating), but the basemap image and Title appearance in the Gallery do not update.

Anyone have any suggestions on how to get the basemapGallery to "refresh" in my if...else statements?

Alex DeVine
University of Georgia
0 Kudos
0 Replies