Identify Tool (IdentifyTask)

2553
6
09-29-2015 05:38 AM
PriyaRanjanJena
New Contributor II

I am trying to popup an InfoWindow when user click on visible layer after selecting Identify Tool  from the menu as shown in the attached image.

I followed this example URL(Display identify results in popup | ArcGIS API for JavaScript )  from ESRI officail website and coded so far as below but not succeeded yet. It is showing "map.infoWindow.setFeatures" is not a function" error.

Please help me to solve this problem. Please find the code in the attachment.

<!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>Identify with Popup</title>


    <link rel="stylesheet" href="http://js.arcgis.com/3.14/esri/css/esri.css">
    <style>
      html, body, #map {height:100%;width:100%;margin:0;padding:0;}
    </style>
    <script src="http://js.arcgis.com/3.14/"></script>
    <script>
      var map;
      var identifyListener;


      require([
        "esri/map",
        "esri/layers/FeatureLayer",
  "esri/dijit/InfoWindow",
        "esri/InfoTemplate",
        "esri/layers/ArcGISDynamicMapServiceLayer",
        "esri/symbols/SimpleFillSymbol",
        "esri/symbols/SimpleLineSymbol",
        "esri/tasks/IdentifyTask",
        "esri/tasks/IdentifyParameters",
  "dojox/layout/FloatingPane",
        "esri/dijit/Popup",
        "dojo/_base/array",
        "esri/Color",
        "dojo/dom-construct",
        "dojo/dom",
        "dojo/on",
        "dojo/domReady!"
      ], function (
        Map, FeatureLayer, InfoWindow, InfoTemplate, ArcGISDynamicMapServiceLayer, SimpleFillSymbol,
        SimpleLineSymbol, IdentifyTask, IdentifyParameters, FloatingPane, Popup,
        arrayUtils, Color, domConstruct, dom, on
      ) {
        var identifyTask, identifyParams;
  var infoWindow = new InfoWindow({}, domConstruct.create("div"));
  infoWindow.startup();
        var popup = new Popup({
          fillSymbol: new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,
            new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,
              new Color([255, 0, 0]), 2), new Color([255, 255, 0, 0.25]))
        }, domConstruct.create("div"));


        map = new Map("map", {
          basemap: "satellite",
          center: [84.0000, 20.1500],
          zoom: 7,
   infoWindow: infoWindow
        });
        map.on("load", mapReady);
        var stateLayerURL = "http://10.172.10.152/odisha/rest/services/GisMain/FYEARPERMITS/MapServer/"; 
        map.addLayer(new ArcGISDynamicMapServiceLayer(stateLayerURL,
          { opacity: 0.55 }));
        function mapReady () {
          //map.on("click", executeIdentifyTask);
  on(dom.byId("identifyMe"), "click", function(evt){
  identifyListener = dojo.connect(map, "onClick", executeIdentifyTask);
  });  
  //create identify tasks and setup parameters
  identifyTask = new IdentifyTask(stateLayerURL);


  identifyParams = new IdentifyParameters();
  identifyParams.tolerance = 3;
  identifyParams.returnGeometry = true;
  identifyParams.layerIds = [6];
  identifyParams.layerOption = IdentifyParameters.LAYER_OPTION_TOP;
  identifyParams.width = map.width;
  identifyParams.height = map.height;
        }


        function executeIdentifyTask (event) {
          identifyParams.geometry = event.mapPoint;
          identifyParams.mapExtent = map.extent;
          var deferred = identifyTask
            .execute(identifyParams)
            .addCallback(function (response) {
              // response is an array of identify result objects
              // Let's return an array of features.
              return arrayUtils.map(response, function (result) {
                var feature = result.feature;
                var layerName = result.layerName;


                feature.attributes.layerName = layerName;

  var taxParcelTemplate = new InfoTemplate("${S_NAME}", "Tractors : ${TRACTORS_2012}");
  feature.setInfoTemplate(taxParcelTemplate);
                  
                return feature;
              });
            });
          map.infoWindow.setFeatures([deferred]);
          map.infoWindow.show(event.mapPoint);
        }
      });
    </script>
  </head>  
  <body>
    <button id="identifyMe">Identify</button>
    <div id="map">
  </div>
  </body>
</html>
Tags (2)
0 Kudos
6 Replies
RobertScheitlin__GISP
MVP Emeritus

PriyaRanjan,

  Your issue is that you are setting the maps infowindow to a infoWindow object and that does not have a setFeatures function. You will notice in the sample you began with they are setting the maps infoWindow to a Popup dijit and the popup dijit does have a setFeatures function.

So just change the map constructor to this:

      map = new Map("map", {
        basemap: "satellite",
        center: [84.0000, 20.1500],
        zoom: 7,
        infoWindow: popup
      });
0 Kudos
PriyaRanjanJena
New Contributor II

Thanks Robert fro your reply but actually I want to use InfoWindow instead of popup. So do you have any idea how to do that ?

0 Kudos
TimWitt2
MVP Alum

I think what you are trying to do is setContent InfoWindow | API Reference | ArcGIS API for JavaScript

PriyaRanjanJena
New Contributor II

When I am using setContent() its showing error.

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

PriyaRanjan,

  If you are wanting to use InfoWindow then you have to manually add your content to the InfoWindow and can not take advantage of the way the sample demos using a defered. You would have to use the infoWindows setContent method and manually show the infoWindow using the show method from the Identify Task result handler.

PriyaRanjanJena
New Contributor II

Can you give me any example code or demo app for reference.

I want exactly the same way how Identify tool is working in this video.

v1 - ArcGIS Javascript API, Identify, Hyperlink manager, Spatial Queries - YouTube

Thanks.

0 Kudos