Posted by: Jeff Germain | October 22, 2008

DynamicMapServiceLayer render complete event for ArcGIS JavaScript Extension for Google Maps API

I’ve got a DynamicMapServiceLayer with 1000’s of features. So it takes a while to draw the overlay. This extra draw time justifies displaying a “loading” indicator image in the UI so as not to give the impression that the application has hung. So I searched for an event I could hook into to to get notification when all layers have finished drawing on the map. I tried the events on GMap2 (dragstart, dragend, movestart, moveend, zoomstart, zoomend), and while these let me know when to display my loading icon, they didn’t tell me when all layers had finished drawing. No luck. After pulling my hair out I got feedback from Praveenkumar Ponnusamy at ESRI.

ArcGIS JS Extension for Google Maps API v1.2

v1.2 will include a new event for the DynamicMapServiceLayer that you can wire up to get notification when the layer has finished drawing.

v1.2 is expected to be released around the end of October.

Update: v1.2 has been released and delivers with it Dojo v1.2. You may now listen and respond to the update event that has been added to DynamicMapServiceLayer, ImageServiceLayer, and TiledMapServiceLayer.

ArcGIS JS Extension for Google Maps API v1.1

In the meantime, here is a hack for v1.1. Note, this is NOT officially supported by ESRI and WILL NOT work at v1.2.

Download page sample

Code

<script type="text/javascript">
var gmap, dynamicMapServicelayer;

function initialize() {
  //Load Google Maps
  gmap = new GMap2(document.getElementById("map_canvas"));
  gmap.addControl(new GLargeMapControl());
  gmap.enableScrollWheelZoom();
  gmap.setCenter(
    new GLatLng(36.62513340485903, -112.32421875), 3);

  addUpdateEventWorkaround();

  //create dynamic map service layer
  dynamicMapServicelayer =
    new esri.arcgis.gmaps.DynamicMapServiceLayer(
    "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/" +
    "Specialty/ESRI_StatesCitiesRivers_USA/MapServer",
    null, 0.75, dynamicMapServiceLoaded);
}

function dynamicMapServiceLoaded(mapService) {
  gmap.addOverlay(dynamicMapServicelayer);
}

function addUpdateEventWorkaround() {
  /************************************************/
  // !!!!!!!! ALERT: IMPORTANT NOTE !!!!!!!!
  // This workaround is NOT officially supported and WILL NOT work
  // at version 1.2 So, PLEASE include a FIXME note in your code to
  // remove this workaround once you start using version 1.2
  /************************************************/
  // save the original redraw handler
  var _redrawHandler =
    esri.arcgis.gmaps.DynamicMapServiceLayer.prototype._redrawHandler;
  // create a new method to handle layer redraw
  esri.arcgis.gmaps.DynamicMapServiceLayer.prototype._redrawHandler =
    function() {
        // setup listener for image load event
        var listener = GEvent.addDomListener(this._img_loading, "load",
            function() {
              GEvent.removeListener(listener);
              listener = null;
              GLog.write("Map image has been loaded");
              // include code here to remove your "image loading" message
            });
        // call the actual redraw handler
        _redrawHandler.apply(this, arguments);
  }
}

</script>

Thanks Praveenkumar!


Responses

  1. Hi,
    I’m working on my master’s thesis using GIS and Google maps api. Basically I’m creating a website that will enable users to find the quickest routes as pedestrians, bicyclists, and wheelchair users throughout campus. In a nutshell, I’m using Network analyst to create the routes and then exporting them as kml data. I was wondering if you knew how to create a query to search the kml data using a drop down menu like say for the starting building and then a second drop down menu for the ending building finally clicking submit and then the route pops up. I’m think ajax might be the only way to do this but even then I’m having difficulty researching it. So far I’ve only been able to overlay the “line” data on google maps and embed it on my sight. I might be able to get access to ArcGIS server 9.3 through my school. So I was considering using the new javascripts google maps api extension that comes with it.
    I came across your blog through my research and I was wondering if you had any suggestions on the programming aspects. I attached the prototype of the website that I have so far. I have the projection in WGS 1984 I still need to change the datum to 1927 to line up with google maps (*just noting that there is a slight datum shift) and that you need to zoom in to Nacogdoches North st and E Starr ave to see the line data. Thank you for taking the time to read this.
    -Allison

  2. Sorry I made a mistake on my projection I have it set to “NAD_1983_StatePlane_Texas_Central_FIPS_4203_Feet”
    But I think my research says that google maps uses NAD 1927…

  3. Now that 1.2 is out and your great work around no longer works, what did you do as you current 1.2 loading feature. I noticed the dojo version they have as an example for loading. Did you try to integate that for your google map? Thanks again.


Leave a comment

Categories