Select to view content in your preferred language

Question about an ESRI's sample code for Cached Map

569
1
07-16-2011 08:05 AM
ShaningYu
Honored Contributor
This is regarding one of ESRI's sample code in ArcGIS Extension for Google Map API.  For How to Add ArcGIS Server Cached Map (at http://help.arcgis.com/en/webapi/javascript/gmaps/help/google_samplestart.htm, the topic is /Map/Add ArcGIS Server cached map), ESRI provides a smaple code at
http://help.arcgis.com/en/webapi/javascript/gmaps/samples/maps/map_cached.html.
On Lines 30 and 32 of this script, a variable  gTileLayer  is used.

      //create custom tile layer - Line 26
      var tiledmap = new esri.arcgis.gmaps.TiledMapServiceLayer("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Portland/ESRI_LandBase_WebMercator/MapSer...", mapOptions, addTiledMap);
    }

    function addTiledMap(gTileLayer) {   // Line 30 
    //Add tile layer as a GTileLayerOverlay using mapExtension
      gOverlays = mapExtension.addToMap(gTileLayer);  // Line 32    }

However, this variable is not defined before.  I wonder how a tiled layer can be added on the map.  I wish ESRI can provide an answer for it.  Thanks.
0 Kudos
1 Reply
derekswingley1
Deactivated User
By providing a variable name in the function declaration (line 30), you can refer to variables passed to the function as named variables (line 32). This is for readability and convenience. If you didn't do this, you would have to rely on the function's arguments array.

Since addTileMap is passed to TiledMapServiceLayer as a callback, addTileMap is called when the layer loads and the newly loaded layer is passed to addTileMap as an argument.
0 Kudos