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