Query Feature Layer: Highlight and Zoom to Features

422
0
04-24-2020 04:35 PM
DenisGlibanovic
New Contributor III

I'm trying to run multiple queries on a point feature layer. I use dojo dijit combobox to enter the filter criteria. Basically everything is ok, except that after entering the second criteria "deliveryPointName" the features are not selected and cannot be zoomed to. I don't understand why I don't get geometry when I run the query2.
My code:

       var fields = ["city", "deliveryPoint", "amount", "pay", "discount"];

       var featureLayer = new FeatureLayer("https://...arcgis/service/FeatureServer/0", {
           mode: FeatureLayer.MODE_ONDEMAND,
           supportsStatistics: true,
           outFields: ['*'],
           visible: true,
           id: "fLayer"
       });

       /************************************************************************************************/

       var selectionSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE, 12,
           new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([48, 178, 255, 0.8])));

       featureLayer.setSelectionSymbol(selectionSymbol);

       map.addLayers([featureLayer]);

       /************************************************************************************************/

       var getAmount = new StatisticDefinition();
       getAmount.statisticType = "sum";
       getAmount.onStatisticField = "amount";
       getAmount.outStatisticFieldName = "_amount";

       var getPay = new StatisticDefinition();
       getPay.statisticType = "sum";
       getPay.onStatisticField = "pay";
       getPay.outStatisticFieldName = "_pay";

       var getDiscount = new StatisticDefinition();
       getDiscount.statisticType = "sum";
       getDiscount.onStatisticField = "discount";
       getDiscount.outStatisticFieldName = "_discount";

       /************************************************************************************************/

       var queryParams = new Query();
       queryParams.outFields = fields;
       queryParams.returnGeometry = true;
       queryParams.outStatistics = [getAmount, getPay, getDiscount];

       /************************************************************************************************/

       var queryList = new Query();
       queryList.where = "1=1";
       queryList.returnGeometry = false;
       queryList.returnDistinctValues = true;

       featureLayer.queryFeatures(queryList, function(featureSet) {
           var cityList = [];

           dojo.map(featureSet.features, function(feature) {
               cityList.push(feature.attributes.city);
           });

           var uniqueArray = Array.from(new Set(cityList));
           uniqueArray.sort();

           arrayUtils.forEach(uniqueArray, function(feature) {
               registry.byId("stateName").get('store').add({
                   name: feature
               });
           })
       });

       /***********************************************************************************************/
       registry.byId("deliveryPointName").set('disabled', true);

       /***********************************************************************************************/

       registry.byId("cityName").on("change", function() {
           map.graphics.clear();
           registry.byId("deliveryPointName").set('disabled', false);
           var query = new Query();
           query.where = "city='" + registry.byId("cityName").get('value') + "'";
           console.info(query.where);
           query.returnGeometry = true;

           featureLayer.queryFeatures(query, function(featureSet) {
               var resultFeatures = featureSet.features;
               console.log(resultFeatures);
               for (var i = 0, il = resultFeatures.length; i < il; i++) {
                   var graphic = resultFeatures[i];
                   graphic.setSymbol(selectionSymbol);
                   map.graphics.add(graphic);
                   map.setExtent(graphic._extent);
               }
           });

           var query = new Query();
           query.where = "city='" + registry.byId("cityName").get('value') + "'";
           query.returnGeometry = true;
           featureLayer.queryFeatures(query, function(featureSet) {
               var deliveryPointList = [];

               dojo.map(featureSet.features, function(feature) {
                   deliveryPointList.push(feature.attributes.deliveryPoint);
               });
               var _uniqueArray = Array.from(new Set(deliveryPointList));
               _uniqueArray.sort();

               registry.byId("deliveryPointName").get('store').data = [];
               arrayUtils.forEach(_uniqueArray, function(feature) {
                   registry.byId("countyName").get('store').add({
                       name: feature
                   });
               })
           });
       });
       /***********************************************************************************************/

       registry.byId("countyName").on("change", function() {
           map.graphics.clear();

           var query2 = new Query();
           query2.outFields = fields;

           query2.outStatistics = [getAmount, getPay, getDiscount];
           query2.where = "city='" + registry.byId("cityName").get('value') + "' AND deliveryPoint='" + registry.byId("deliveryPointName").get('value') + "'";


           console.info(query2.where);
           query2.returnGeometry = true;

           featureLayer.queryFeatures(query2, function(featureSet) {
              
			// this part of the code doesn't work
			  var resultFeatures = featureSet.features;
               console.log(resultFeatures);
               for (var i = 0, il = resultFeatures.length; i < il; i++) {
                   var graphic = resultFeatures[i];
                   graphic.setSymbol(selectionSymbol);
                   map.graphics.add(graphic);
                   map.setExtent(graphic._extent);
               }

               featureLayer.queryFeatures(query2, getStats2, errback);
           })
       })

       /***********************************************************************************************/
       registry.byId("cityName").on("change", function() {
           var query = new Query();
           query.outFields = fields;
           query.outStatistics = [getAmount, getPay, getDiscount];
           query.where = "city='" + registry.byId("cityName").get('value') + "'";

           console.info(query.where);

           featureLayer.queryFeatures(query, function(featureSet) {
               featureLayer.queryFeatures(query, getStats2, errback);
           })
       })
0 Kudos
0 Replies