AnsweredAssumed Answered

JS API 3.13 - IdentifyParameters undefined?

Question asked by cleotokos on Jun 11, 2015
Latest reply on Jun 12, 2015 by cleotokos

Hi All,

I've been struggling with this code, everything has been working until I tried to throw in the ability to identify. When I run the code, I get the error that identifyParams is undefined. Specifically, "Uncaught TypeError: Cannot set property 'geometry' of undefined"

 

Can anyone see what I've got wrong? Thanks in advance.

 

var map;

 

 

require([

    "esri/InfoTemplate",

    "esri/map",

    "esri/dijit/BasemapToggle",

    "esri/dijit/Popup",

    "esri/dijit/Scalebar",

    "esri/dijit/Search",

    "esri/Color",

    "esri/InfoTemplate",

    "esri/layers/ArcGISDynamicMapServiceLayer",

    "esri/layers/FeatureLayer",

    "esri/layers/ImageParameters",

    "esri/symbols/SimpleFillSymbol",

    "esri/symbols/SimpleLineSymbol",

    "esri/tasks/IdentifyTask",

    "esri/tasks/IdentifyParameters",

    "dojo/_base/array",

    "dojo/dom",

    "dojo/on",

    "dojo/query",

    "dojo/ready",

    "dijit/registry",

    "dojo/dom-construct",

    "dojo/parser",

    "dojo/domReady!"

    ],

    function(

  InfoTemplate,

  Map,

  BasemapToggle,

        Popup,

  Scalebar,

  Search,

        Color,

        InfoTemplate,

  ArcGISDynamicMapServiceLayer,

  FeatureLayer,

  ImageParameters,

        SimpleFillSymbol,

        SimpleLineSymbol,

        IdentifyTask,

        IdentifyParameters,

        arrayUtils,

  dom,

  on,

  query,

  ready,

  registry,

  domConstruct,

  parser

  ) {

 

          var layer, visibleLayerIds = [], identifyTask, identifyParams;

         

          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: "topo",

            center: [-123, 49.2],

            zoom:10,

            infoWindow: popup

            });

 

 

        //Use the ImageParameters to set the visibleLayerIds layers in the map service during ArcGISDynamicMapServiceLayer construction.

        var imageParameters = new ImageParameters();

  //VFPA Boundary line layers (confirmed and non-confirmed) visible on startup

        imageParameters.layerIds = [0,2];

        imageParameters.layerOption = ImageParameters.LAYER_OPTION_SHOW;

        //can also be: LAYER_OPTION_EXCLUDE, LAYER_OPTION_HIDE, LAYER_OPTION_INCLUDE

 

 

          var layerCadastral = new ArcGISDynamicMapServiceLayer("http://cop-gis4:6080/arcgis/rest/services/MOR/MOR_Cadastral_WGS1984/MapServer",

            {

            "imageParameters": imageParameters

            });

           

          map.addLayer(layerCadastral);

 

 

  //every time a layer is clicked, update the layer visibility

        on(dom.byId("chkVFPABoundary"), "change", updateLayerVisibility);

        on(dom.byId("chkMunicipalBoundaries"), "change", updateLayerVisibility);

  on(dom.byId("chkLots"), "change", updateLayerVisibility);

  

          function updateLayerVisibility () {

            var inputs = query(".list_item");

            var inputCount = inputs.length;

            //Dummy layer - is there a workaround? Setting this to an actual layer means that layer can't be turned off

            visibleLayerIds = [1001];

 

 

            for (var i = 0; i < inputCount; i++) {

              if (inputs[i].checked) {

                visibleLayerIds.push(inputs[i].value);

              }

            }

 

 

            if (visibleLayerIds.length === 0) {

              visibleLayerIds.push(-1);

            }

 

 

            layerCadastral.setVisibleLayers(visibleLayerIds);

          }

 

 

       

  //Basemap toggle

  var toggle = new BasemapToggle({

            map: map,

            basemap: "satellite"

            }, "BasemapToggle");

           

  toggle.startup();

 

  var scalebar = new Scalebar({

          map: map,

          // "dual" displays both miles and kilmometers

          // "english" is the default, which displays miles

          // use "metric" for kilometers

          scalebarUnit: "dual"

        });

 

  var s = new Search({

            enableButtonMode: false, //this enables the search widget to display as a single button

            enableLabel: false,

            enableInfoWindow: true,

            showInfoWindowOnSelect: true,

            map: map

         }, "search");

 

 

         var sources = s.get("sources");

 

 

         //Push the sources used to search, by default the ArcGIS Online World geocoder is included.

 

 

         sources.push({

            featureLayer: new FeatureLayer("http://cop-gis4:6080/arcgis/rest/services/MOR/MOR_Cadastral_WGS1984/MapServer/7"),

            searchFields: ["LOT_NO"],

            exactMatch: false,

            outFields: ["*"],

     displayField: "LOT_NO",

            name: "Lots - Lot Number",

            placeholder: "Lot Number",

            maxResults: 6,

            maxSuggestions: 6,

 

 

            //Create an InfoTemplate and include three fields

            infoTemplate: new InfoTemplate("Lot Number", "Lot #: ${LOT_NO}</br>Owner: ${OWNER}</br>Title Link: <a href =${TITLE_LINK}>Click to open</a>"),

            enableSuggestions: true,

            minCharacters: 0

         });

        

         sources.push({

            featureLayer: new FeatureLayer("http://cop-gis4:6080/arcgis/rest/services/MOR/MOR_Cadastral_WGS1984/MapServer/7"),

            searchFields: ["OWNER"],

            exactMatch: false,

            outFields: ["*"],

            displayField: "OWNER",

            name: "Lots - Owner",

            placeholder: "Owner",

            maxResults: 6,

            maxSuggestions: 6,

 

 

            //Create an InfoTemplate and include three fields

            infoTemplate: new InfoTemplate("Lot Number", "Lot #: ${LOT_NO}</br>Owner: ${OWNER}</br>Title Link: <a href =${TITLE_LINK}>Click to open</a>"),

            enableSuggestions: true,

            minCharacters: 0

         });

        

 

 

         //Set the sources above to the search widget

         s.set("sources", sources);

  

  s.startup();

                

        map.on("load", mapReady);

                

        function mapReady () {

          map.on("click", executeIdentifyTask);

          //create identify tasks and setup parameters

          identifyTask = new IdentifyTask(layerCadastral);

 

 

          identifyParams = new IdentifyParameters();

          identifyParams.tolerance = 3;

          identifyParams.returnGeometry = true;

          identifyParams.layerIds = [7];

          identifyParams.layerOption = IdentifyParameters.LAYER_OPTION_VISIBLE;

          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;

                if (layerName === 'Lots') {

                  var lotsTemplate = new InfoTemplate("",

                    "Lot #: ${LOT_NO} <br/> Owner: ${OWNER}");

                  feature.setInfoTemplate(lotsTemplate);

                }

                else if (layerName === 'Building Footprints') {

                  console.log(feature.attributes.PARCELID);

                  var buildingFootprintTemplate = new InfoTemplate("",

                    "Parcel ID: ${PARCELID}");

                  feature.setInfoTemplate(buildingFootprintTemplate);

                }

                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]);

          map.infoWindow.show(event.mapPoint);

        }

 

        });

Outcomes