AnsweredAssumed Answered

can't get legend to work w/ secured service....

Question asked by caseycupp on May 2, 2014
Latest reply on May 6, 2014 by caseycupp
I've been working in the javascript legend sandbox...

I've made a minor change to the sandbox code... my Unsecured Services show up in the map and the legend...

However, my secured services prompt me for the username and password, I manually enter them... then the service does show up in the map but not the legend...

http://developers.arcgis.com/javascript/sandbox/sandbox.html?sample=widget_legend



<!DOCTYPE html> <html> <head>   <meta http-equiv="Content-Type" content="text/html; charset=utf-8">   <!--The viewport meta tag is used to improve the presentation and behavior of the samples     on iOS devices-->   <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">   <title>Map with legend</title>    <link rel="stylesheet" href="http://js.arcgis.com/3.9/js/dojo/dijit/themes/claro/claro.css">   <link rel="stylesheet" href="http://js.arcgis.com/3.9/js/esri/css/esri.css">    <style>     html, body {       height: 97%;       width: 98%;       margin: 1%;     }      #rightPane {       width: 20%;     }        </style> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>   <script src="http://js.arcgis.com/3.9/"></script>   <script>     var map;     require([       "esri/map", "esri/layers/FeatureLayer", "esri/dijit/Legend",       "dojo/_base/array", "dojo/parser",       "dijit/layout/BorderContainer", "dijit/layout/ContentPane",        "dijit/layout/AccordionContainer", "dojo/domReady!"     ], function(       Map, FeatureLayer, Legend,       arrayUtils, parser     ) {       parser.parse();        map = new Map("map", {         basemap:"topo",         center: [-96.53, 38.374],         zoom: 13       });         //add the legend       map.on("layers-add-result", function (evt) {         var layerInfo = arrayUtils.map(evt.layers, function (layer, index) {           return {layer:layer.layer, title:layer.layer.name};         });         if (layerInfo.length > 0) {           var legendDijit = new Legend({             map: map,             layerInfos: layerInfo           }, "legendDiv");           legendDijit.startup();         }       });                           $.get("https://maps2.petroweb.com/MAPS2ArcGISServer/tokens?request=getToken&username=pwuser&password=Mauser$98K&expiration=1440&client=http%20referer&referer=localhost")                     .done(function (data) {                                               var imageParameters = new esri.layers.ImageParameters();                         imageParameters.format = "png";                                                    var mapServiceURL = "http://mymapserver.com/MAPS2ArcGISServer/rest/services/MySecureService/MapServer/?token=" + data;                         //var mapServiceURL = "http://mymapserver.com/MAPS2ArcGISServer/rest/services/MyUnsecureService/MapServer/?token=" + data;                                                  var usWellsLayer = new esri.layers.ArcGISDynamicMapServiceLayer(mapServiceURL, { "opacity": 1, "imageParameters": imageParameters });                         map.addLayers([usWellsLayer]);                                            })                     .fail(function (xhr, textStatus, errorThrown) {                         alert("Failed to get us wells map layer security token.");                     });                 //map.addLayers([colorado]);     });   </script> </head>  <body class="claro">    <div id="content"        data-dojo-type="dijit/layout/BorderContainer"        data-dojo-props="design:'headline', gutters:true"        style="width: 100%; height: 100%; margin: 0;">           <div id="rightPane"          data-dojo-type="dijit/layout/ContentPane"          data-dojo-props="region:'right'">           <div id="legendDiv"></div>         </div>        <div id="map"          data-dojo-type="dijit/layout/ContentPane"          data-dojo-props="region:'center'"          style="overflow:hidden;">     </div>   </div> </body>  </html>

Outcomes