Error {code: 500, message: "Unable to generate legends: - breaking Nianwei Liu's TOC

1176
4
09-11-2013 03:06 AM
AdrianMarsden
Occasional Contributor III
Hi

I am using Nianwei Liu's TOC - however sometimes the expand tree graphic isn't appearing.

I have several dynamic map services and add them all into the TOC.  Mostly this is fine.

However when it fails I get

"Unable to generate legends: zzzzz?Unable to connect to Host: zzzzz Port: -1?Please verify the Service URL specified is correct :- http://zzzzz/arcgis/services/LIVEinternal/aerials/MapServer?"


This happens about 20% of startups.  The Dynamic Service is there and at other times it is fine.

I can see why it breaks the TOC, as without any legends it can't build up the child nodes in functon
_createRootLayerNode as there is a IF statement that relies on a renderer being present.

Cheers

ACM
0 Kudos
4 Replies
NianweiLiu
Occasional Contributor II
"Unable to generate legends: zzzzz?Unable to connect to Host: zzzzz Port: -1?Please verify the Service URL specified is correct :- http://zzzzz/arcgis/services/LIVEinternal/aerials/MapServer?"


Looks like the error is on REST API side. You might have some data source with inconsistent connection such as timeout easily etc. When server is trying to create legend it may run into a broken link and error out initially. Checking server log via ArcGIS manager may provide some clue. You can also write a small app that make a legend request at given interval and record the results to see if there is a pattern of failing.

You can also replace the TOC with esri.dijit.Legend and see if you got error too.
0 Kudos
AdrianMarsden
Occasional Contributor III
One thing I was about to post anyway, the dynamic services it fails on contain ONLY raster images.

I was also about to dig into the server logs too.   I'll post back if I find anything

Many thanks

ACM

Edit - in fact one of the services isn't all raster - so please ignore.  However the one service that is all NON-raster never fails this way.
0 Kudos
AdrianMarsden
Occasional Contributor III
OK - nothing in the logs and straight requests for legend work every time, so time for a classic hack/bodge (sorry)

In the TOC.js I've changed the error routine of _getLegendInfo to call itself again

error: dojo.hitch(this, this._getLegendInfo)


WRONG  on SO many levels I know, but as I have a captive user base with known map services  AND this issue happens less than 1 in 5 requests  then it seems to work without adding much overhead at all.

If it breaks later, I'll simply cry and curl up in a corner somewhere.

ACM
0 Kudos
DerekNalder
New Contributor III
Hello,

The problem is that the layer is not loaded before the TOC widget is loaded and therefore the TOC.js is hitting the ArcGIS legend service everytime because this.rootLayer.version is not yet populated. This widget will not work with internal only services not accessible to ArcGIS legend service. The proper solution is to check to see if the root layer is loaded before building the legend, if it is not loaded, then add and on("load") to the layer and call the _getLegendInfo. Here's the new code at around line 620 of TOC.js.

         // extenstion point called by framework
         postCreate: function () {
             if ((this.rootLayer instanceof (ArcGISDynamicMapServiceLayer) ||
            this.rootLayer instanceof (ArcGISTiledMapServiceLayer))) {
                 //check if the layer is loaded yet, if not, add a listener to wait
                 if (this.rootLayer.loaded) {
                     if (this._legendResponse) {
                         this._createRootLayerTOC();
                     } else {
                         this._getLegendInfo();
                     }
                 }
                 else {//layer not yet loaded, add listener
                     this.rootLayer.on("load", lang.hitch(this, this._getLegendInfo));
                 }
             } else { //not servicelayer
                 this._createRootLayerTOC();
             }
         },
0 Kudos