Map requires a refresh to initialize

647
3
10-15-2012 10:50 AM
CraigMcDade
Occasional Contributor III
When I launch my application in a browser it shows the shell (header and other panes) but it does not show the map itself. When I refrefresh the browser everything draws...

Any idea what might be causing this. Happens in all browsers.

Here is my init function:

function init() {

 dojo.connect(dijit.byId("gridParcel"), "onRowClick", onRowClickHandler);
    
  //Slash Screen Message 
    var myMessage = "<snip>;
     dojo.byId('divLoadMessage').innerHTML = myMessage;
     dijit.byId('dialogLoadMessage').show();
   
    var initExtent = new esri.geometry.Extent({"xmin":-9199621.530456403,
    "ymin":3365235.5214724857,
    "xmax":-9077475.159256855,
    "ymax":3443965.6606061114,
    "spatialReference":{"wkid":102100}});  
    
  //setup the popup window 
        var popup = new esri.dijit.Popup({
          fillSymbol: new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255,0,0]), 2), new dojo.Color([255,255,0,0.25]))
        }, dojo.create("div"));
        
    map = new esri.Map("map", {
     infoWindow:popup,
     extent:initExtent, 
     logo:false
     });
    
   dojo.connect(map,"onLoad",mapReady);
   
    //Set The Initial Basemap
    var initBasemap = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/Canvas/World_Light_Gray_Base/MapServer");
        map.addLayer(initBasemap);
    
        createBasemapGallery();
    
    //Create Find Task using the URL of the map service to search
        findTaskParcel = new esri.tasks.FindTask("http://gisprod2/arcgis/rest/services/Dynamic/ParcelsTestSDE/MapServer");

        //Create the find parameters
        findParamsParcel = new esri.tasks.FindParameters();
        findParamsParcel.returnGeometry = true;
        findParamsParcel.layerIds = [0];
        findParamsParcel.searchFields = ["PARCELID", "SITEADDRESS"];
        findParamsParcel.outSpatialReference = map.spatialReference;

        //Create Find Task using the URL of the map service to search
        findTaskYear = new esri.tasks.FindTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/TaxParcel/TaxParcelQuery/MapServer/");

        //Create the find parameters
        findParamsYear = new esri.tasks.FindParameters();
        findParamsYear.returnGeometry = true;
        findParamsYear.layerIds = [0];
        findParamsYear.searchFields = ["RESYRBLT"];
        findParamsYear.outSpatialReference = map.spatialReference;
        
    //resize the map when the browser resizes
       dojo.connect(map, 'onLoad', function (theMap) {
          //resize the map when the browser resizes
          dojo.connect(dijit.byId('map'), 'resize', map, map.resize);
        });
      
    locator = new esri.tasks.Locator("http://tasks.arcgis.com/ArcGIS/rest/services/WorldLocator/GeocodeServer");
        dojo.connect(locator, "onAddressToLocationsComplete", showResults);
        
        map.infoWindow.resize(300,125);
    
    //parcellayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://gisprod2/arcgis/rest/services/Dynamic/ParcelsTestSDE/MapServer");
    layer = new esri.layers.ArcGISDynamicMapServiceLayer("http://gisprod2/arcgis/rest/services/Dynamic/Zoning/MapServer");
    
  
  //Add the Legend
    legendLayers.push({layer:layer,title:''});
    dojo.connect(map,'onLayersAddResult',function(results){
          var legend = new esri.dijit.Legend({
            map:map,
            layerInfos:legendLayers
          },"legendDiv");
          legend.startup();
        });
    map.addLayers([layer]);
  
        if (layer.loaded) {
          buildLayerList(layer);
        }
        else {
          dojo.connect(layer, "onLoad", buildLayerList);
        }
   }
0 Kudos
3 Replies
CraigMcDade
Occasional Contributor III
any idea on the best way to go about finding why I need to refresh?

Attached is a screenshot of the errors I get in firebug.
0 Kudos
JafarAl-Kofahi
New Contributor II
Hi mcdade31,

I recently developed a map control for my application and I had this same problem! In my case: ASP.Net application using Ajax controls and after researching it for too long, it seems its related to having the control within a control within an update panel, so I had to either move my map outside of the control and directly within the update panel. Or I had the user to click a button that would do partial refresh for the map contain (my custom control)! of course I went with the first and redesigned my GUI and now everything works fine 🙂

This might not be much help but hopefully it gives you an idea.

Jafar
0 Kudos
CraigMcDade
Occasional Contributor III
Rookie mistake. I had my external JS references in the wrong spot. Now the map loads all at once.

**EDIT**

Well. Looks like the issue is two pronged. When I moved the external JS files to their (what I think is) correct location, the map loads quickly and all at once... EXCEPT for one of the files (a series of 3 dojo.fx.Toggler functions) does not execute from the external files.

When I place the contents of the external file into the main default.html code file the toggler functions work... However, the map requires the additional refresh again...

Stumped

Here is my toggle code FWIW. Thanks for any heads up you all might be able to give.

//Toggles
function basemapToggle() {
     basemaptoggler = new dojo.fx.Toggler({
      node: "basemaptoggle",
      showFunc : dojo.fx.wipeIn,
      showDuration: 1000,
      hideDuration: 1000,
      hideFunc : dojo.fx.wipeOut
     })
    }
    dojo.addOnLoad(basemapToggle);

    function layerToggle() {
     layertoggler = new dojo.fx.Toggler({
      node: "layertoggle",
      showFunc : dojo.fx.wipeIn,
      showDuration: 750,
      hideDuration: 750,
      hideFunc : dojo.fx.wipeOut
     })
    }
    dojo.addOnLoad(layerToggle);

    function legendToggle() {
     legendtoggler = new dojo.fx.Toggler({
      node: "legendtoggle",
      showFunc : dojo.fx.wipeIn,
      hideFunc : dojo.fx.wipeOut
     })
    }
    dojo.addOnLoad(legendToggle);
0 Kudos