AnsweredAssumed Answered

Clear ArcGISDynamicMapServiceLayer layer def before displaying a different definition

Question asked by monzay on Mar 20, 2013
Latest reply on Mar 25, 2013 by monzay
I've modified this sample to see if there is a way to change the display of an ArcGISDynamicMapService layer that uses layer definitions. I'm changing the definition through a drop down menu. The previous state boundary does not clear before drawing a new state. I've looked through the forums and the API and tried different ideas. Nothing seems to work. Of course, it could just be that my advanced novice skills are not just advanced enough and I am missing something obvious. :)

I know that I could use feature layers but in my own project some of my features are just too big and will actually crash the browser. Using a dynamic service is much faster.

I tried to create a jsfiddle instead of posting the code but I could not figure out how to make the drop down menu work. So, I've posted both.

<!DOCTYPE html> <html>   <head>     <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>     <meta http-equiv="X-UA-Compatible" content="IE=7,IE=9">     <!--The viewport meta tag is used to improve the presentation and behavior of the samples        on iOS devices-->     <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">     <title>Create Map with Custom ArcGISDynamicMapServiceLayer Layer Definitions</title>      <link rel="stylesheet" href="">     <link rel="stylesheet" href="">      <script src=""></script>     <script>       dojo.require("");        var map, layer, state = 'Iowa';        function init() {         map = new esri.Map("map", {           basemap: "streets",           center: [-98.258, 38.236],           zoom: 4         });  }    function changeLayerVisibility(){   console.log('inside clv');   var layerIdsArr = map.layerIds;   layer = map.getLayer(layerIdsArr["census"]);   layer.hide();  }    function addMap(state){           var imageParameters = new esri.layers.ImageParameters();          var layerDefs = [];         layerDefs[5] = "STATE_NAME='" + state + "'";         imageParameters.layerDefinitions = layerDefs;          imageParameters.layerIds = [5];         imageParameters.layerOption = esri.layers.ImageParameters.LAYER_OPTION_SHOW;         imageParameters.transparent = true;          var dynamicMapServiceLayer = new esri.layers.ArcGISDynamicMapServiceLayer("", {"imageParameters":imageParameters, id:"census"});          map.addLayer(dynamicMapServiceLayer);;       }        dojo.ready(init);     </script>   </head>   <body class="claro">     <div id="map" style="width:900px; height:600px;"></div>  <div style="position:absolute;top:10px;right:250px;z-index:999;">         <form><select id="ddbox"  onClick="changeLayerVisibility()" onChange="addMap(this.value)" data-dojo-type="dijit.form.Select">             <option value = "" selected="selected">Select...</option>             <option value="Oregon" id = "1">Oregon</option>             <option value="Colorado"  id = "2">Colorado</option>    <option value="Iowa"  id = "3">Iowa</option>    <option value="Alabama"  id = "4">Alabama</option>    <option value="Maine"  id = "5">Maine</option>   </select></form>     </div>    </body> </html>