show message if map service unavailable

700
1
05-08-2012 12:26 PM
ChadWilcomb
New Contributor III
It seems like this should be fairly straight forward but I haven't found a great solution yet. I would like to show my users a message, and possibly alter the way our interface looks, if and when there is a problem with one of our map services. In my application I have a basemap (ArcGISTiledMapServiceLayer), a dynamic layer (ArcGISDynamicMapServiceLayer) and a couple feature layers (FeatureLayer). For the basemap and dynamic layer, I am just doing a straightforward constructor and then map.addLayer to add them to the map. For the feature layers, I am doing a constructor, applying a setDefinitionExpression and then using map.addLayer to add to the map.

If any of the services are down I want to be able to tell the user, at minimum with an alert or message.

I thought I could use onLayerAddResult(layer, error) but it doesn't seem to be getting called if the layer based on a stopped/bad service is added to the map.

I see similar examples using esri.request but it doesn't seem like I should have to do an extra call to the service since in the console I see these types of calls to each service:

http: //myserver/ArcGIS/rest/services/Streets/Mask/MapServer?f=json&dpi=96&transparent=true&format=png8&layers=show%3A-1&callback=dojo.io.script.jsonp_dojoIoScript2._jsonpCallback

With a response of either:

dojo.io.script.jsonp_dojoIoScript2._jsonpCallback({"serviceDescription" : null,"mapName":"Layers","description":"","copyrightText":"","layers":[{"id":0,"name":"LMBCO_Mask","parentLayerId":-1,"defaultVisibility":true,"subLayerIds":null}],"tables":[],"spatialReference":{"wkid":2263},"singleFusedMapCache":false,"initialExtent":{"xmin":806353.163236593,"ymin":139639.306949227,"xmax":1165380.94101437,"ymax":327833.751393672,"spatialReference":{"wkid":2263}},"fullExtent":{"xmin":824755.941014371,"ymin":38597.6402825604,"xmax":1146978.16323659,"ymax":323319.862504783,"spatialReference":{"wkid":2263}},"units":"esriFeet","supportedImageFormatTypes":"PNG32,PNG24,PNG,JPG,DIB,TIFF,EMF,PS,PDF,GIF,SVG,SVGZ,BMP","documentInfo":{"Title":"","Author":"","Comments":"","Subject":"","Category":"","Keywords":"","AntialiasingMode":"Normal","TextAntialiasingMode":"Force"},"capabilities":"Map,Query,Data"});

if the service is up and running, or:

dojo.io.script.jsonp_dojoIoScript2._jsonpCallback({"error":{"code":400,"message":"Unable to complete  operation.","details":["Service 'NYCStreets/LMBCO_Mask' of type 'MapServer' does not exist or is inaccessible."]}});

if the service is not available.

Is there a way to handle this reponse that comes back?

Thanks for your help!

Chad Wilcomb
0 Kudos
1 Reply
StephenLead
Regular Contributor III
I see similar examples using esri.request but it doesn't seem like I should have to do an extra call to the service


FWIW, I'd suggest that esri.request is a good approach to take here.

Good luck,
Steve
0 Kudos