AnsweredAssumed Answered

TypeError: d.toJson is not a function on IdentifyTask

Question asked by mkoneya on Mar 9, 2017
Latest reply on Mar 13, 2017 by mkoneya

I am getting a TypeError: d.toJson is not a function on IdentifyTask.execute(identifyParams)

 

I am guessing that I am missing something obvious,  but the error is not pointing me in the right direction.

 

Thanks,

 

Mele

 

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
    <link rel="stylesheet" href="https://js.arcgis.com/3.19/dijit/themes/claro/claro.css">
    <link rel="stylesheet" href="https://js.arcgis.com/3.19/esri/css/esri.css">
    <script src="https://js.arcgis.com/3.19/"></script>
    <style>
    html,
    body,
    #search {
        display: block;
        cursor: pointer;
        margin: 5px;
    }
          </style>
          <script>
      require(["esri/map", "esri/geometry/Extent", "esri/tasks/GeometryService",
        "dojo/dom", "dojo/on",
        "esri/dijit/Search", "esri/layers/FeatureLayer", "esri/tasks/IdentifyTask", "esri/tasks/IdentifyParameters", "dojo/_base/array",  "dojo/_base/array", "dojo/domReady!"
      ], function (Map, Extent,GeometryService, dom, on, Search, FeatureLayer, IdentifyTask, IdentifyParameters, arrayUtils, array) {
           
                     
           var lyrFields;
           var URL = "http://maps/arcgis/rest/services/Address_Search_Test/MapServer/0";
           var swURL = "http://maps/arcgis/rest/services/My_Services/MapServer";
           var identifyTask = new IdentifyTask(swURL);
           var identifyParams = new IdentifyParameters(); 
           fl = new FeatureLayer(URL);
        esriConfig.defaults.geometryService = new GeometryService("https://maps/arcgis/rest/services/Utilities/Geometry/GeometryServer"); 
        var resultItems = [];
        dom.byId("info").innerHTML = "Enter Address";
        var map = new Map("Map", {
                  extent: new Extent({xmin:675912,ymin:886288,xmax:755209,ymax:1060473,spatialReference:{wkid:2223}}),
                  zoom: 0,
                  resize: false
                });
        map.addLayer(fl);
        var search = new Search({
        sources: [{
            featureLayer: fl,
            searchFields: ["site_address"],
            displayField: "site_address",
            exactMatch: false,
            outFields: ["site_address"],
            name: "Address",
            maxResults: 1,
            maxSuggestions: 20,
            enableSuggestions: true,
            minCharacters: 1,
           
      }],
       map: map,
       allPlaceholder: "Find Address",
       activeSourceIndex: "all"
      }, "search");
      search.startup();
      map.on("load", mapReady);
         function mapReady () {
           search.on("select-result", executeIdentifyTask);
           identifyParams.tolerance = 3;
           identifyParams.returnGeometry = true;
           identifyParams.layerIds = [0, 1, 2];
           //identifyParams.layerOption = IdentifyParameters.LAYER_OPTION_VISIBLE;
           identifyParams.spatialReference = 2223;
           identifyParams.width = map.width;
           identifyParams.height = map.height;
         } 
        function executeIdentifyTask (event) {
             search.set("value", search.selectedResult.name);
             resultItems = [];
             dom.byId("info").innerHTML = "";
             event.result.feature;
          identifyParams.geometry = event.result.feature.geometry;
          identifyParams.mapExtent = map.extent;
                 var featureAttributes = event.result.feature.attributes;
                       for (var attr in featureAttributes) {    
                            resultItems.push("<b>" + getFldAlias(attr) + ":</b>  " + featureAttributes[attr] + "<br>");
                       }
            
             var deferred = identifyTask
                       .execute(identifyParams)
                .addCallback(function (response){
                     return arrayUtils.map(response, function (result) {
                var feature = result.feature;
                var layerName = result.layerName;

                feature.attributes.layerName = layerName;
                if (layerName === 'Brush Collection') {
                     //alert(feature.attributes['Area']);
                     resultItems.push("<b>" + "Brush Area: " + "</b>  " + feature.attributes['Area'] + "<br>");
                }
                else if (layerName === 'Refuse Collection') {
                     //alert(feature.attributes['Collection Day']);
                     resultItems.push("<b>" +  "Refuse Collection Day: " + "</b> "  + feature.attributes['Collection Day'] + "<br>");
                }
                else if (layerName === 'Recycling Collection') {
                     //alert(feature.attributes['Collection Day']);
                     resultItems.push("<b>" + "Recycling Collection Day: " + "</b> " + feature.attributes['Collection Day'] + "<br>");
                }
                //return feature;
              
               dom.byId("info").innerHTML = resultItems.join("");    
              });
             });
          }
        function getFldAlias(fieldName) {
            var retVal = "";
            console.info(fl);
            array.some(fl.fields, function(item) {
                if (item.name === fieldName) {
                    retVal = item.alias;
                    return true;
                }
            });
            return retVal;
        }
       
      }
    );
    </script>
</head>
<p>Enter your address in the text box to get more details about your property for the form below:</p>
<div id="search" ></div>
<br />
</div>
<div id="Map"  style="display: none;"></div>
<div id="info" style="margin: 5px; padding: 5px; background-color: #eeeeee;"></div>
<br />


 

Outcomes