AnsweredAssumed Answered

Problem with Identify tool

Question asked by pramodharithsa on May 31, 2012
Latest reply on Jun 4, 2012 by pramodharithsa
This is my code., wherein i want attributes of a layer to pop up on click..

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>      <meta http-equiv="X-UA-Compatible" content="IE=7,IE=9" />      <!--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>Navigation toolbar</title>      <style type="text/css">        @import "http://serverapi.arcgisonline.com/jsapi/arcgis/2.8/js/dojo/dijit/themes/claro/claro.css";        .zoominIcon { background-image:url(images/nav_zoomin.png); width:16px; height:16px; }        .zoomoutIcon { background-image:url(images/nav_zoomout.png); width:16px; height:16px; }        .zoomfullextIcon { background-image:url(images/nav_fullextent.png); width:16px; height:16px; }        .zoomprevIcon { background-image:url(images/nav_previous.png); width:16px; height:16px; }        .zoomnextIcon { background-image:url(images/nav_next.png); width:16px; height:16px; }        .panIcon { background-image:url(images/nav_pan.png); width:16px; height:16px; }        .deactivateIcon { background-image:url(images/nav_decline.png); width:16px; height:16px; }          .style2         {             font-size:xx-large;             position:relative;         }     </style>            <script type="text/javascript">        dojoConfig = { parseOnLoad: true }</script>            <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.8"></script>        <script type="text/javascript">          dojo.require("esri.map");         dojo.require("esri.toolbars.navigation");         dojo.require("dijit.form.Button");         dojo.require("dijit.Toolbar");         dojo.require("esri.dijit.Popup");         dojo.require("dijit.layout.ContentPane");           var map, navToolbar;         var resizeTimer;         var identifyTask, identifyParams;          function init() {             esri.config.defaults.map.sliderLabel = null;             var startExtent = new esri.geometry.Extent({ "xmin": -10858450, "ymin": 3300000, "xmax": -10858500, "ymax": 3365000, "spatialReference": { "wkid": 102100} });             map = new esri.Map("map", { infoWindow: popup, extent: startExtent });              //setup the popup window               var popup = new esri.dijit.Popup({                 fillSymbol: new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255, 0, 0]), 2), new dojo.Color([255, 255, 0, 0.25]))             }, dojo.create("div"));              dojo.connect(map, "onLoad", mapReady);              map.addLayer(new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer"));             // var mymxdURL = "http://xxxxx258069d:x399/arcgis/rest/services/txx34/MapServer";            var mymxdURL= "http://xxxxx258069d:x399/arcgis/rest/services/txx34/MapServer"             var mymxd = new esri.layers.ArcGISDynamicMapServiceLayer(mymxdURL);             map.addLayer(mymxd);             navToolbar = new esri.toolbars.Navigation(map);             dojo.connect(navToolbar, "onExtentHistoryChange", extentHistoryChangeHandler);          }          function mapReady(map) {              dojo.connect(map, "onClick", executeIdentifyTask);              //create identify tasks and setup parameters               identifyTask = new esri.tasks.IdentifyTask("http://xxxxx258069d:x399/arcgis/rest/services/txx34/MapServer");              identifyParams = new esri.tasks.IdentifyParameters();             identifyParams.tolerance = 3;             identifyParams.returnGeometry = true;             identifyParams.layerIds = [0, 1];             identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_ALL;             identifyParams.width = map.width;             identifyParams.height = map.height;               //resize the map when the browser resizes              dojo.connect(dijit.byId('map'), 'resize', map, map.resize);          }         function executeIdentifyTask(evt) {             identifyParams.geometry = evt.mapPoint;             identifyParams.mapExtent = map.extent;              var deferred = identifyTask.execute(identifyParams);              deferred.addCallback(function (response) {                 // response is an array of identify result objects                      // Let's return an array of features.                  return dojo.map(response, function (result) {                     var feature = result.feature;                     feature.attributes.layerName = result.layerName;                     if (result.layerName === 'TX__GOLIAD__PIPELINES') {                         //console.log(feature.attributes.OBJECTID);                         var template = new esri.InfoTemplate("", "${STATE} <br/> Risk Score: ${Risk_Score}");                         feature.setInfoTemplate(template);                     }                     else {                         var template = new esri.InfoTemplate("","No element found");                                              feature.setInfoTemplate(template);                     }                     //                    else if (result.layerName === 'Building Footprints') {                     //                        var template = new esri.InfoTemplate("", "Parcel ID: ${PARCELID}");                     //                        feature.setInfoTemplate(template);                     //                    }                     return feature;                 });             });               // InfoWindow expects an array of features from each deferred              // object that you pass. If the response from the task execution               // above is not an array of features, then you need to add a callback              // like the one above to post-process the response and return an              // array of features.              map.infoWindow.setFeatures([deferred]); {Exception: Object doesn't support this property or method}                   map.infoWindow.show(evt.mapPoint);         }             function extentHistoryChangeHandler() {             dijit.byId("zoomprev").disabled = navToolbar.isFirstExtent();             dijit.byId("zoomnext").disabled = navToolbar.isLastExtent();         }          dojo.addOnLoad(init);      </script>    </head>    <body class="claro">    <table>   <tr><td class="style2" align="center" bgcolor="#8080FF" valign="baseline"            colspan="2">XXXX GIS Dashboard<hr />   </td></tr>   <tr>   <td class="style2">      </td>   <td>     <div id="navToolbar" data-dojo-type="dijit.Toolbar">        <div data-dojo-type="dijit.form.Button" id="zoomin"  data-dojo-props="iconClass:'zoominIcon', onClick:function(){navToolbar.activate(esri.toolbars.Navigation.ZOOM_IN);}">Zoom In</div>        <div data-dojo-type="dijit.form.Button" id="zoomout" data-dojo-props="iconClass:'zoomoutIcon', onClick:function(){navToolbar.activate(esri.toolbars.Navigation.ZOOM_OUT);}">Zoom Out</div>        <div data-dojo-type="dijit.form.Button" id="zoomfullext" data-dojo-props="iconClass:'zoomfullextIcon', onClick:function(){navToolbar.zoomToFullExtent();}">Full Extent</div>        <div data-dojo-type="dijit.form.Button" id="zoomprev" data-dojo-props="iconClass:'zoomprevIcon', onClick:function(){navToolbar.zoomToPrevExtent();}">Prev Extent</div>        <div data-dojo-type="dijit.form.Button" id="zoomnext" data-dojo-props="iconClass:'zoomnextIcon', onClick:function(){navToolbar.zoomToNextExtent();}">Next Extent</div>        <div data-dojo-type="dijit.form.Button" id="pan" data-dojo-props="iconClass:'panIcon', onClick:function(){navToolbar.activate(esri.toolbars.Navigation.PAN);}">Pan</div>        <div data-dojo-type="dijit.form.Button" id="deactivate" data-dojo-props="iconClass:'deactivateIcon' ,onClick:function(){navToolbar.deactivate();}">Deactivate</div>      </div>             <div id="map" style="width:1024px; height:512px; border:1px solid #000;"></div>      </td>     </tr>      </table>   </body>  </html>


None of the attributes are shown in the pop up..
What am i missing here.
Any help will be appreciated.

Outcomes