How to refresh map

2767
3
06-20-2011 07:56 AM
JamilNawaz
New Contributor II
Hi,
I have a task to where we have a dropdown with possible scale values. I have task that when user select a scale we need to refresh map to that scale.

//Add the topographic layer to the map. Use the ArcGIS Online site for services
            basemap = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer");
            map.addLayer(basemap);

            //Use a dynamic layer to display initially the set of map features
            displayLayer = new esri.layers.ArcGISDynamicMapServiceLayer("service_url", { "opacity": 0.6 });
            var layerDefs = [];
            layerDefs[0] = "ESCALA = 100000";  //CHANGE QUERY FILTER ON USER SELECTION IN COMBO BOX OF SCALES VALUES
            displayLayer.setLayerDefinitions(layerDefs);
            map.addLayer(displayLayer);

            var template = new esri.InfoTemplate();
            template.setContent(getTextContent);

            //Use a feature service layer for queries and as basis for map graphics 
            featureLayer = new esri.layers.FeatureLayer("service_url", {
                mode: esri.layers.FeatureLayer.MODE_SELECTION,
                outFields: ["INT_ORIG", "CD_CORRELA", "ESCALA ", "SOURCE_TIT"],
                infoTemplate: template
            });

            //CHANGE QUERY FILTER ON USER SELECTION IN COMBO BOX OF SCALES VALUES
            featureLayer.setDefinitionExpression("ESCALA = 100000");


In this sample code, if you notice I have mention two places which I need to change based on dropdown selection. On select change I did this code

function OnSelectionChangeClick() {
         map.removeAllLayers();
   
   var layerDefs = [];
         layerDefs[0] = "ESCALA = 500000";  //CHANGE QUERY FILTER ON USER SELECTION IN COMBO BOX OF SCALES VALUES
         displayLayer.setLayerDefinitions(layerDefs);
   //displayLayer.layerDefinitions[0] = 'ESCALA = 500000'
         featureLayer.setDefinitionExpression("ESCALA = 500000");

         map.addLayer(basemap);
         map.addLayer(displayLayer);
         map.addLayer(featureLayer);
         console.log('testing');
         //featureLayer.refresh();
        }


Basically, I remove all layers and update the values of Display Layer and Feature Layer and add those again. Now problem is, Display Layer and Feature Layer works fine according to new value but base map stays on the same extent. Any idea how can i update base map as well?

Thanks!
JAMIL
0 Kudos
3 Replies
deleted-user-VeZur_n9o0OZ
New Contributor III
Hi Jamil,

were you able to resolve this? I have the same problem of my basemap not refreshing once I've changed the extent or scale.

Thanks,
James
0 Kudos
JamilNawaz
New Contributor II
Hi James,

Not really. Later client decided, not to use basemap. So right now we are not using basemap.

JAMIL

Hi Jamil,

were you able to resolve this? I have the same problem of my basemap not refreshing once I've changed the extent or scale.

Thanks,
James
0 Kudos
deleted-user-VeZur_n9o0OZ
New Contributor III
I just cracked my problem. I was using adding the same basemap object to both maps. If i create seperate basemap objects per map then they behave as expected. Let me know if that works for you too.

Thanks,
James
0 Kudos