Using IdentityManager, where can I get the token and where does it go?

2218
1
08-27-2014 01:18 PM
TracySchloss
Frequent Contributor

This is the first time I've needed to deal with the token when using IdentityManager.  I have an existing application that worked fine with open services that is failing in two places now that I've secured the services:  my custom created legend and my identifyTask.

I've check through the threads, but I don't understand what I've found on how to determine what token was generated from the IdentifyManager.  Even after I find the token, I'm not where where it goes in my code.

First place it needs a token - legend

I wanted a bit more control over my legend so I'm making a call to the legend, but parsing it as JSON and recreating the look of it.  The odd thing here is that the text string comes through OK, but not the image representing the symbol.  In this url is the path of a ArcGISDynamicServiceLayer

// create legend based on symbology in service

  function createLegendJSON(url){

    mapUrl = url;

    var divLegend = dom.byId("legendDiv");

   legendURL = url + "/legend";

    var requestHandle = esriRequest({

      "url": legendURL,

      "content": {

        "f": "json"

      },

      "callbackParamName": "callback"

    });

    requestHandle.then(requestSucceeded, requestFailed);

  }

  function requestFailed(error){

    console.log("request failed" + error);

  }

  function requestSucceeded(response, io){

    var lyr, visLayers;

    var htmlString = "<table class='legend'>";

    var divLegend = dom.byId("legendDiv");

    if (ncdmLayer.visible){

        mapURL = ncdmLayer.url;

      visLayers = ncdmLayer.visibleLayers;

      dom.byId('legendTitle').innerHTML = currentYear + " " + title + " Rates";

    }else{

      visLayers = [0];

      mapURL = p1950Layer.url;

      dom.byId('legendTitle').innerHTML = "Percent Pre-1950 Housing";

    }

   

    if (response != null && response.layers.length > 0) {

      //    for (var iCnt = 0; iCnt < response.layers.length; iCnt++) {//interface only allows one layer, so took out the loop

      lyr = response.layers[visLayers];

      if (lyr.legend.length > 1) {

// htmlString += "<tr><td colspan='2' style='font-weight:bold;'>" + currentYear + " " + title + " Rates </td></tr>";

        for (var jCnt = 0; jCnt < lyr.legend.length; jCnt++) {

          var src = mapURL + "/" + lyr.layerId + "/images/" + lyr.legend[jCnt].url;

          var strlbl = lyr.legend[jCnt].label.replace("<Null>", "Null");

          htmlString += "<tr><td align='left'><img src=\"" + src + "\" alt ='' /></td><td>" + strlbl + "</td></tr>";

        }

      }

      else {

        htmlString += "<tr><td colspan='2' style='font-weight:bold;'>" + lyr.layerName + "</td></tr>";

        var src = mapURL + "/" + lyr.layerId + "/images/" + lyr.legend[0].url;

        htmlString += "<tr><td colspan='2' ><img src=\"" + src + "\" alt ='' /></td></tr>";

      }

      //  }

      htmlString += "</table>";

      if (ncdmLayer.visible){

        htmlString += "<div class='legend'><i>" + rateNote + "</i></div>"

      }  

    }

    divLegend.innerHTML = htmlString;

  }

The 2nd place it looks to be failing is in my identifyTask.  I have this set up as a deferred call so it has time to drill down through whatever layers I have turned on.  The variable ncdmLayer.url is the URL for the ArcGISDynamicMapService (the same as for my legend).  Some of my idParams are set earlier in the code, in case you think something is missing.

function clickIdentify(event){

   idParams.geometry = event.mapPoint;     

    idParams.mapExtent = map.extent;

    idParams.layerOption = IdentifyParameters.LAYER_OPTION_VISIBLE;

   if (ncdmLayer.visible) {

   idTask = new IdentifyTask(ncdmLayer.url);

    var visLayers = ncdmLayer.visibleLayers;

    idParams.layerIds = ncdmLayer.visibleLayers;

    } else {

        idParams.layerIds = [0];

      idTask = new IdentifyTask(p1950Layer.url);//supplemental layer, generally not turned on.

    }

    var deferred = idTask.execute(idParams).addCallback(function(response){

      return arrayUtils.map(response, function(result){

        var feature = result.feature;

        layerSel = getLayer(result.layerName);

        infoTemplate.setContent(generateInfoContent);

        feature.setInfoTemplate(infoTemplate);

        feature.geometry.spatialReference = spatialReference;

        return feature;

      });

    });

    map.infoWindow.setFeatures([deferred]);

    map.infoWindow.show(event.mapPoint);

  }

0 Kudos
1 Reply
TracySchloss
Frequent Contributor

Never mind. I have learned since I created this custom legend how to control the legend widget, so I switched it out.  the IdentifyTask was operator error. 

0 Kudos