Select to view content in your preferred language

Points inside Polygons using the DrawTool and display of number of points

776
3
Jump to solution
07-18-2012 06:31 AM
ionarawilson1
Deactivated User
Hi,

I am developing a website that when you use the multipoint draw tool you click on one county or many counties, and it shows the companies in that county. There is a text area that displays how many icompanies have been selected. However this text area is just showing the records of the last selection. For example, let's say I select two counties, one with one company and another county with 5 companies. The text area will display "There is 1 matching record" but it should display "There are 6 matching records" as there are 6 companies displayed on the map. I believe it has something to do with the code on the onResult2 function but I haven't been able to find a solution. Thank you for any help!

   private function onDrawEnd(event:DrawEvent):void    {     drawToolbar.deactivate();      myGraphicsLayer.clear();     freehandbutton.selectedIndex = -1;     multipointbutton.selectedIndex = -1;     myMap.panEnabled = false;          if (event.graphic.geometry is Polygon)     {      var drawPolygon : Graphic = new Graphic();                   drawPolygon.geometry = event.graphic.geometry;      drawPolygon.autoMoveToTop = false; //keep graphics from moving to top               myPolygonGraphicsLayer.add(drawPolygon);       runQueryTask(event.graphic.geometry);     // If using point draw tool then run querytask3     } else{      //Must be multipoint      runQueryTask3(event.graphic.geometry);}                          }           [Bindable] private var queryTask3:QueryTask = new QueryTask();    [Bindable] private var query3:Query = new Query();       [Bindable] private var queryTask4:QueryTask = new QueryTask();    [Bindable] private var query4:Query = new Query();             private function runQueryTask3(geometry:Geometry):void    {     queryTask3.url = "http://tfs-24279/ArcGIS/rest/services/ForestProducts/county_forest_products/MapServer/0";     queryTask3.showBusyCursor = true;     queryTask3.useAMF = false;          query3.geometry = geometry;      //geometry from the drawToolbar     query3.returnGeometry = true;    //set to true because we want to place points on the map     query3.spatialRelationship = "esriSpatialRelIntersects";     query3.outSpatialReference = myMap.spatialReference;     query3.outFields = ['*'];         //run the query task     queryTask3.execute(query3, new AsyncResponder(onResult, onFault));          function onResult(featureSet:FeatureSet, token:Object = null):void     {             myGraphicslayer.clear()       myGraphicslayer.visible = true;       for each(var graphic : Graphic in featureSet.features)       {        graphic.symbol = fillSymbolmultipoint;         myGraphicslayer.add(graphic);                //Now run this query        //Of course this url needs to be to the layer that has your companies        queryTask4.url = "http://tfs-24279/ArcGIS/rest/services/ForestProducts/dynamic_layer_forest_products/MapServer/0";        queryTask4.showBusyCursor = true;        queryTask4.useAMF = false;                query4.geometry = graphic.geometry;      //geometry from the first query        query4.returnGeometry = true;    //set to true because we want to place points on the map        query4.spatialRelationship = "esriSpatialRelIntersects";        query4.outSpatialReference = myMap.spatialReference;        query4.outFields = ['*'];            //run the query task        queryTask4.execute(query4, new AsyncResponder(onResult2, onFault));       }                          }          function onResult2(featureSet:FeatureSet, token:Object = null):void     {                   //myGraphicslayer.clear()       myGraphicslayer.visible = true;       for each(var graphic : Graphic in featureSet.features){        graphic.symbol = resultsSymbol;         myGraphicslayer.add(graphic);              }            if (featureSet.features.length == 0) {        info.text = "There are no  records";       }       if (featureSet.features.length > 1) {        info.text = "There are " + featureSet.features.length + " matching records";       }       if (featureSet.features.length == 1) {        info.text = "There is " + featureSet.features.length + " matching record";       }          }                    function onFault(info:Object, token:Object = null):void     {      Alert.show(info.toString(), "Query Problem");     }    }      
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
ionarawilson1
Deactivated User
I found a solution! Instead of using the same graphic layer for queryTask4 I created another graphics layer (called myGraphicsLayer) and then changed the onResult2 to:

  function onResult2(featureSet:FeatureSet, token:Object = null):void
    {
    
    
      //myGraphicslayer.clear()
      myGraphicslayer.visible = true;
      for each(var graphic : Graphic in featureSet.features){
       graphic.symbol = resultsSymbol;
       myGraphicsLayer.add(graphic);
      
     }
   
        if (myGraphicsLayer.numGraphics  == 0) {
       info.text = "There are no  records";
      }
      if (myGraphicsLayer.numGraphics > 1) {
       info.text = " There are" + myGraphicsLayer.numGraphics  + " matching records";
      }
      if (myGraphicsLayer.numGraphics == 1) {
       info.text = " There is" + myGraphicsLayer.numGraphics  + " matching record";
      } 
    
    }

View solution in original post

0 Kudos
3 Replies
ionarawilson1
Deactivated User
By the way, it seems that it has to do with the number of selected records. I selected 3 counties (one county with 1 company, the other county with 4 companies and the third county with 3 companies) , and no matter the sequence I select it always shows "There is 1 matching record" instead of "There are 8 matching records". How can I sum the total number of records selected? Is there a method I can use for that?

Thank you!!!
0 Kudos
ionarawilson1
Deactivated User
Trying a solution I added to the onResult2 function this

info.text = " There are" + myGraphicslayer.numGraphics  + " matching records"


But the problem is that it adds the polygon graphics but I only want the points. Any ideas? Thanks
0 Kudos
ionarawilson1
Deactivated User
I found a solution! Instead of using the same graphic layer for queryTask4 I created another graphics layer (called myGraphicsLayer) and then changed the onResult2 to:

  function onResult2(featureSet:FeatureSet, token:Object = null):void
    {
    
    
      //myGraphicslayer.clear()
      myGraphicslayer.visible = true;
      for each(var graphic : Graphic in featureSet.features){
       graphic.symbol = resultsSymbol;
       myGraphicsLayer.add(graphic);
      
     }
   
        if (myGraphicsLayer.numGraphics  == 0) {
       info.text = "There are no  records";
      }
      if (myGraphicsLayer.numGraphics > 1) {
       info.text = " There are" + myGraphicsLayer.numGraphics  + " matching records";
      }
      if (myGraphicsLayer.numGraphics == 1) {
       info.text = " There is" + myGraphicsLayer.numGraphics  + " matching record";
      } 
    
    }
0 Kudos