How to explicity invoke the zoom/pan with out a event trigger

808
5
06-24-2012 10:26 AM
HarshanaDias
New Contributor
Hi All,

I have create a map on the fly by getting the rings of a selected zip codes, counties or states. But when the map loads for the first time I found the boundary areas (this is added by the NeilsenLayer) is not showing.

But this is not a problem with setting the nelson layer since even for the first time loading of the map, the nelson layer is already there in the map object as I check it by debugging it in firebug. But once I do a little zoom or move the map it shows the map successfully with boundaries as in below first image  

How can I explicitly call the zoom or move the map after loads just a couple of pixel using java script API , so that I can view the correct map with boundaries (borders) ?

The two attachment show how the map load first time with out the boundaries for zip codes added and how it shows the boundaries successfully when i do a little zoom or pan the map bit.

Also if some one can give me a hint why I missing those boundaries when first time map loads and zoom little bit will give me the correct map, then i dont need to explicity call the zoom or pan. But any way I would like to hear the answer for my initial question how to zoom or pan the map explicitly with out trigger a event.

Thank You.
0 Kudos
5 Replies
by Anonymous User
Not applicable
Original User: Harshana

I have found below flex API which can do the trick but can some one post the JS API for do the same trick please.
Map.initialExtent
0 Kudos
derekswingley1
Frequent Contributor
Is the layer that's not displaying an ONDEMAND mode feature layer? Try adding your layer after the map's onLoad event fires. This is shown in the "On Demand Mode" Feature Layer sample.
0 Kudos
by Anonymous User
Not applicable
Original User: Harshana

Is the layer that's not displaying an ONDEMAND mode feature layer? Try adding your layer after the map's onLoad event fires. This is shown in the "On Demand Mode" Feature Layer sample.


Actually the layer not display is the Neilsen Layer which added in the initialization method. any way i inspect that layer is still visible in maps onLoad event fire method and the layer is set and the property for visibility is set to true. I cant understand why that layer not show in first place and showing it once only i do a zoom/pan. I even explicitly call the show() method on that layer after when map extent call/ But had no luck. Below is the code for your reference to see if you can see any mistakes. please ignore the velocity variables in the code.  In the end of the mapOnLoad() method i have add  map.getLayer("layer1").show(); which is the nielson layer not showing to see whether i can view that missing layer. kind of similar solutionwhat you told me. But had no luck.

[HTML]function init() {
        // Specify the initial extent to display the Contiguous United States
        // Note the spatial reference must match that of the basemap to be added
        var startExtent = new esri.geometry.Extent({"xmin":-16715860,"ymin":1992010,"xmax":-4789238,"ymax":7177498,"spatialReference":{"wkid":102100}});
       
        // Logo: false to hide the Esri logo in the lower right corner       
        map = new esri.Map("map", {  extent: startExtent, logo:false });
        
        // +++++Listen for map onLoad event to finalize set-up+++++
        dojo.connect(map, "onLoad", onMapLoad);
        
        // Get the basemap layer from the relevant Map Service 
        // Light gray canvas
        var basemap = new esri.layers.ArcGISTiledMapServiceLayer("$lthUtil.getArcgisServiceCanvasMapServer()");
        map.addLayer(basemap);
        var nielsenRestEndpoint = "$lthUtil.getArcgisMapServerURL()";
        var imageParameters = new esri.layers.ImageParameters();
                  #if ($geography)
                       #if($!geography.getGeoType().toString() == "STATE")
                            imageParameters.layerIds = [0, 1, 2];
                       #elseif($!geography.getGeoType().toString() == "COUNTY")
                            imageParameters.layerIds = [0, 1];  
                       #elseif($!geography.getGeoType().toString() == "ZIPCODE")
                            imageParameters.layerIds = [0, 2];    
                       #end
                   #end
      
        imageParameters.layerOption = esri.layers.ImageParameters.LAYER_OPTION_SHOW;
        imageParameters.transparent = true;
       
        // Add the NeilsenLayer to the Base Map
        var nielsenLayer = new esri.layers.ArcGISDynamicMapServiceLayer(nielsenRestEndpoint, {"imageParameters":imageParameters});
        map.addLayer(nielsenLayer);


        var subgeographyRestEndpoint = "$subgeo_service_endpoint";
    
        // Get query task from the Sub-Geography Map Service
        subgeographyQueryTask = new esri.tasks.QueryTask(subgeographyRestEndpoint);       
      }



       /*
       * All set-up code to be executed upon the initial load of the map
       */             
      function onMapLoad(themap) {
        // Specify custom function to handle browser resize
        dojo.connect(dijit.byId('map'), 'resize', function() {
          resizeMap();
        });

        // Identify proxy page to use if the toJson payload to the geometry service is greater than 2000 characters.
        // If this null or not available the buffer operation will not work.  Otherwise it will do a http post to the proxy.
        esriConfig.defaults.io.proxyUrl = "$lthUtil.getArcgisJavaScriptProxy()";
        esriConfig.defaults.io.alwaysUseProxy = false;

        // Query
        query = new esri.tasks.Query();
        query.returnGeometry = true;
        query.outFields = ["NAME","ORDER_NUM"];
        query.outSpatialReference = {"wkid":102100};
       
        // Create info template for styling the result info window
        var infoTemplate = new esri.InfoTemplate("Sub-Geography: ${NAME}");
        map.infoWindow.resize(240,60);
       
        var subGeographyGraphic = null;
    
         var new_extent = null;
      
       #foreach( $feature in $featuresList)
      
          var count = 0;
          var geometry = $feature.getGeometry();
          var order_num = $feature.getAttributes().get("ORDER_NUM");     
          var symbol = symbols[order_num-1];
          var geometryObj = esri.geometry.fromJson(geometry);
                   
             var graphicObj = new esri.Graphic(geometryObj, symbol);
        
          graphicObj.setGeometry(geometryObj);
          graphicObj.setSymbol(symbol);
          graphicObj.setAttributes( {"ORDER_NUM":order_num});
       graphicObj.setInfoTemplate(infoTemplate);
             map.graphics.add(graphicObj);
             var old_extent = geometryObj.getExtent();
              if(count == 0)
              {
                 new_extent = old_extent;
              }
              else
              {
                 new_extent = new_extent.union(old_extent);
              }   
         
           count++;
   
        #end

      // Set the map extent to zoom into the returned geography
          map.setExtent(new_extent);
          dojo.byId('messages').innerHTML = "";
 
          //This is the nielsen layer which map already set to true. But i try to explicitly call show
   //whether to see the layer will show up when the map show for the first time
   map.getLayer("layer1").show();  
      } [/HTML]
0 Kudos
derekswingley1
Frequent Contributor
Good to know you're using a dynamic layer. You don't need to wait for the map to load to add the layer to your map.

Do you see a request for <Nielsen Layer URL>/export when your app loads? How long does that request take to complete? You can check this in Chrome or Firefox's dev tools. Or with a tool like fiddler.
0 Kudos
by Anonymous User
Not applicable
Original User: Harshana

Do you see a request for <Nielsen Layer URL>/export when your app loads? How long does that request take to complete? You can check this in Chrome or Firefox's dev tools. Or with a tool like fiddler.


Thank You Derek for your answer. Yes actually as i mentioned earlier I have inspect the map object just before map.setExtent(new_extent) with firebug and surprisingly the layers which added are successfully bind with the map object. (the base map layer and the nielsen layer).  I cant figure why that nielsen layer not show up in the initial load of the map. So thats why i decided to go for a kind of a tricky solution which i will explicitly zoom/pan the map just a couple of degrees so it will show the missing layer too. If you cant also figure why the nielson layer not show up even its attached to the map object, can you please  tell me how to zoom or pan the map little bit after loads?
0 Kudos