AnsweredAssumed Answered

JS API - Identify a clicked feature

Question asked by jimmyrose on Oct 11, 2015
Latest reply on Oct 11, 2015 by jimmyrose

By default, when an item is clicked on a map created with arcgisUtils.createMap, it shows the basic popup. I'd like to catch this event and get the ID from the feature (to use AJAX to open up some info in an external database)

 

I couldn't find a way to catch the event, but instead found the IdentifyTask

 

Following an example I came up with the code below, but the initFunctionality function never gets called according to Firefox debug. I'm a total newbie to the ArcGIS JS API so please bear with me - I'm just trying to piece code samples together. Hoping there is something glaringly obvious here. Maybe map.on("load, ____") doesn't work with createMap?

 

require([

        "dojo/parser",

        "dojo/ready",

        "dojo/on",

        "dijit/layout/BorderContainer",

        "dijit/layout/ContentPane",

        "dojo/dom",

        "esri/map",

        "esri/urlUtils",

        "esri/arcgis/utils",

        "esri/dijit/Legend",

        "esri/dijit/Scalebar",

        "esri/tasks/IdentifyTask",

        "esri/tasks/IdentifyParameters",

        "dojo/domReady!"

    ], function(

            parser,

            ready,

            on,

            BorderContainer,

            ContentPane,

            dom,

            Map,

            urlUtils,

            arcgisUtils,

            IdentifyTask,

            IdentifyParameters,

            Legend,

            Scalebar

    ) {

        ready(function(){

            parser.parse();

            arcgisUtils.createMap("THE_MAP_ID","map").then(function(response){

                var map = response.map;

                map.on("load", initFunctionality);

                map.on("click", doIdentify);

 

                function initFunctionality () {

                    identifyTask = new IdentifyTask("http://OUR_ONLINE_PORTAL_URL/ArcGIS/rest/services/");

                    identifyParams = new IdentifyParameters();

                    identifyParams.tolerance = 3;

                    identifyParams.returnGeometry = true;

                    identifyParams.layerIds = [0, 2];

                    identifyParams.layerOption = IdentifyParameters.LAYER_OPTION_ALL;

                    identifyParams.width = map.width;

                    identifyParams.height = map.height;

 

                    map.infoWindow.resize(415, 200);

                    map.infoWindow.setContent(registry.byId("tabs").domNode);

                    map.infoWindow.setTitle("Identify Results");

 

                    symbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,

                            new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,

                                    new Color([255, 0, 0]), 2),

                            new Color([255, 255, 0, 0.25]));

                }

 

                function doIdentify (event) {

                    map.graphics.clear();

                    identifyParams.geometry = event.mapPoint;

                    identifyParams.mapExtent = map.extent;

                    identifyTask.execute(identifyParams, function (idResults) {

                        addToMap(idResults, event);

                    });

                }

            });

 

        });

    });

Outcomes