giorginus80

Arcgis 2.3 div cleared

Discussion created by giorginus80 on May 19, 2011
Latest reply on May 19, 2011 by giorginus80
Hi everybody,
I'm using a Arcgis V2.3 with a web application (ajax based) It works good, the only problem is that sometimes the ajax engine do a clear to the div (with the map inside) so How can I get back the map? I tried to store the innerHTML of the div, so when I detect the map is cleared i put it into again, and do a map.resize() and map.reposition again, but the result isn't good (as I imagined)
is there any other way?

I give an example:

[HTML]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<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</title>
    <link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.3/js/dojo/dijit/themes/claro/claro.css">
    <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.3"></script>
    <script type="text/javascript">
      dojo.require("esri.map");
   var map;
      function init() {
        map = new esri.Map("map");

        var dynamicMapServiceLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Population_World/MapServer");
        map.addLayer(dynamicMapServiceLayer);
      }

      function clearMap(){
       var n = dojo.byId('map');
       n.innerHTML = '';
      }

      function destroyMap(){
  try{map.destroy();}catch(err){alert(err.description);}
      }

      dojo.addOnLoad(init);
    </script>
  </head>
  <body class="claro">
    <div id="map" style="width:900px; height:600px; border:1px solid #000;"></div>
    <input type="button" value="CLEAR" onclick="clearMap();"/>
    <input type="button" value="DESTROY" onclick="destroyMap();"/>
    <input type="button" value="RECREATE" onclick="init();"/>
  </body>
</html>
[/HTML]

I create map, for some reason the div got cleared (click CLEAR to simulate) then if you click DESTROY calling map.destroy() (working for firefox but not for IE) I got an error, and I can't RECREATE the map.
How can I do?
Thanks in advance

Outcomes