AnsweredAssumed Answered

Query layer and return only the graphics selected

Question asked by alex92190 on Jun 27, 2014
Latest reply on Jun 30, 2014 by schlot
Hi all,

I am trying to create an application that allows users to query a layer and return only the graphics based on their selection, not only highlight the selected graphics.

Form instance, In my case, I want to query by users. As shown below I have a blue hashed polygon that represents Calmap users, in red I have "unknown users". My goal here is therefore to create a simple query that only returns the blue hashed polygon or red hashed polygon.

I have used this example but first it returns an error and also it will not return the exact same symbology as the feature layer I am using (is there a way to do that?).

  var gp, map, toc, dynaLayer1, query, queryTask;    var geocoder;       var symbol, infoTemplate, extractMethod;       var AOI, graphic, clipFeatureSet, clipFeature;       require(["dojo/_base/connect",          "dojo/dom", "dojo/dom-style", "dojo/parser", "dojo/on", "dojo/_base/Color",          "esri/map", "esri/config",          "esri/dijit/HomeButton",          "esri/dijit/BasemapGallery",          "esri/dijit/Bookmarks",          "esri/dijit/Scalebar",          "esri/geometry/Extent",          "esri/tasks/query", "esri/tasks/QueryTask",          "esri/layers/FeatureLayer",          "esri/layers/ArcGISTiledMapServiceLayer",          "esri/layers/ArcGISDynamicMapServiceLayer",          "esri/symbols/SimpleFillSymbol",          "esri/symbols/SimpleLineSymbol",          "esri/InfoTemplate",    "esri/tasks/FeatureSet",    "esri/graphic",          "agsjs/dijit/TOC",          "dijit/registry",          "dijit/layout/BorderContainer",          "dijit/layout/ContentPane",          "dijit/layout/AccordionContainer",          "dijit/TitlePane",          "dijit/form/CheckBox",          "dijit/form/ComboBox",          "dojo/parser",          "dijit/Toolbar",          "dijit/form/DropDownButton",    "dijit/layout/TabContainer",          "dijit/form/TextBox",          "dijit/TooltipDialog",          "dijit/ToolbarSeparator",          "dojo/domReady!"       ], function (connect, dom, domStyle, parser, on, Color,          Map, esriConfig, HomeButton, BasemapGallery, Bookmarks, Scalebar, Extent, Query, QueryTask, FeatureLayer, ArcGISTiledMapServiceLayer, ArcGISDynamicMapServiceLayer,          SimpleFillSymbol, SimpleLineSymbol, InfoTemplate, FeatureSet, Graphic,          TOC, registry) {           // call the parser to create the dijit layout dijits          parser.parse(); // note djConfig.parseOnLoad = false;           // Specify where the location of the proxy to use to communicate with the extract GP service. = "/proxy";            // Keep a reference to the loading icon DOM node.          var loading = dom.byId("loading");                     map = new Map("map", {             logo: true,             sliderPosition: "top-right",             basemap: "topo",             center: [-121.469, 38.556],             zoom: 8          });           var home = new HomeButton({             map: map          }, "HomeButton");          home.startup();           var basemapGallery = new BasemapGallery({             showArcGISBasemaps: true,             map: map          }, "basemapGallery");          basemapGallery.startup();                  var bookmarks = new Bookmarks({             map: map,             bookmarks: [],             editable: true          }, dom.byId('bookmarks'));           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",             scalebarStyle: "ruler",             attachTo: "bottom-left"          });           dynaLayer1 = new ArcGISDynamicMapServiceLayer("http://webgisdevint1/arcgis/rest/services/Alex_Try/Archived/MapServer", {});           map.on('layers-add-result', function (evt) {             dynaLayer1.setVisibleLayers([1, 2, 4]);             toc = new TOC({                map: map,                layerInfos: [{                   layer: dynaLayer1,                   title: "Layers",                   slider: true                }]             }, 'tocdiv');             toc.startup();          });          map.addLayers([dynaLayer1]);            symbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,             new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([111, 0, 255]), 2), new Color([255, 255, 0, 0.25]));          infoTemplate = new InfoTemplate("${OBJECTID}", "${*}");           registry.byId("query").on("click", executeQuery);           function executeQuery(name) {                 var name = document.getElementById("user").value       var queryTask = new QueryTask("http://webgisdevint1/arcgis/rest/services/Alex_Try/Archived/MapServer/0");             queryTask.on("complete", showResults)    var query = new Query();             query.returnGeometry = true;             query.outFields = ["LAST_EDITED_USER"];             query.where = "LAST_EDITED_USER = '" + name + "'";             query.outSpatialReference = map.spatialReference;             queryTask.execute(query, showResults);    }           function showResults(featureSet) {          //remove all graphics on the maps graphics layer;           //Performance enhancer - assign featureSet array to a single variable.          var resultFeatures = featureSet.features;           //Loop through each feature returned          for (var i=0, il=resultFeatures.length; i<il; i++) {          //Get the current feature from the featureSet.          //Feature is a graphic          var graphic = resultFeatures[i];          graphic.setSymbol(symbol);           //Set the infoTemplate.          graphic.setInfoTemplate(infoTemplate);           //Add graphic to the map graphics layer.;         }        }

The error I get is:

"Cannot read property 'length' of undefined"

Thank you,