I add dynamic and feature layers when the application loads by iterating through an object literal like such:var config = { token: SOME_TOKEN, layers: [ { type: 'dynamic', url: 'http://MY_URL/ArcGIS/rest/services/Slope/MapServer', token: true, name: 'Slope', id: 'slope', visible: false, opacity: 0.5, imageFormat: 'png32', dpi: 96, legend: true, parcelLabelControl: false, subLayerControl: false, info: true, infoHtml: 'This layer displays slopes.' }, { type: 'feature', url: 'http://MY_URL/ArcGIS/rest/services/Fire_Hydrants/MapServer/0', token: true, name: 'Fire Hydrants', id: 'firehydrants', visible: false, opacity: 1, imageFormat: 'png32', dpi: 96, legend: true, itTitle: 'Fire Hydrant', itContentType: 'function', itContentText: '', itContentFunction: 'config.featureFunctions.hydrants.infoTemplate' } ] }
If a token is required it's added to the url when the layer object is created. Layers are pushed to the legend when legend is set to true. Through 2.8 this worked fine, but not in 3.0+. I did some digging and discovered that in 2.8 the legend widget makes calls to the map service's legend REST like so:http://MY_URL/ArcGIS/rest/services/Slope/MapServer/legend?token=SOME_TOKEN&f=json&callback=dojo.io.script.jsonp_dojoIoScript23._jsonpCallback
In 3.0+ the call is:http://MY_URL/ArcGIS/rest/services/Slope/MapServer/legend?token=SOME_TOKEN?token=SOME_TOKEN&f=json&callback=dojo.io.script.jsonp_dojoIoScript23._jsonpCallback
Notice the token query string is represented twice with two ?. AGS returns a 'invalid token' error. Seems to me there's an error forming the url for the legend REST call. Perhaps getting the service's base url from SOME_LAYER.url instead of SOME_LAYER._url.path.Any help would be appreciated as this is a roadblock as I migrate to 3.0+. Thanks.