Select to view content in your preferred language

Point representing the buffer centroid

901
2
Jump to solution
08-24-2012 12:21 PM
ionarawilson1
Deactivated User
I have a tool that creates a buffer where you click and shows points inside the buffer.

Can anybody please tell me what I need to add to this code to have a point inside the buffer that represents the point where you clicked to get the buffer (the buffer centroid)?. The function works great, I just need to show a point representing the buffer centroid. Thanks!!!!

     private function buffergeometry(geometry:Geometry):void    {     var bufferParameters:BufferParameters = new BufferParameters();     // Note: As of version 2.0, the GeometryService input is geometries (instead of graphics).     bufferParameters.geometries = [ geometry ];     bufferParameters.distances = [ Number(bufferDistance.text)];     // Note: As of version 2.0, the buffer constants have been moved to GeometryService.     bufferParameters.bufferSpatialReference = new SpatialReference(26918);     bufferParameters.unit = GeometryService.UNIT_STATUTE_MILE // this can be mile or feet with this new spatial reference, just substitute the unit for feet     //or?     //bufferParameters.unit = BufferParameters.UNIT_FOOT;     //bufferParameters.bufferSpatialReference = new SpatialReference(102629);     //from http://forums.esri.com/Thread.asp?c=158&f=2421&t=290857        bufferParameters.outSpatialReference = myMap.spatialReference;          myGeometryService2.addEventListener(GeometryServiceEvent.BUFFER_COMPLETE, bufferCompleteHandler1);     myGeometryService2.buffer(bufferParameters);          function bufferCompleteHandler1(event:GeometryServiceEvent):void     {            for each (var polygon:Polygon in event.result)      {       var graphic:Graphic = new Graphic(polygon);          graphic.symbol = fillSymbolcounty;       graphic.autoMoveToTop = false; //keep graphics from moving to top             myGraphicslayerbuffer.add(graphic);       runQueryTaskbuffer(graphic.geometry);       //????myMap.centerAt(polygon.extent.center);       var graphicProvider:ArrayCollection = myGraphicslayerbuffer.graphicProvider as ArrayCollection;       var graphicsExtent:Extent = GraphicUtil.getGraphicsExtent(graphicProvider.toArray());              if (graphicsExtent)       {        myMap.extent = graphicsExtent;                // make sure the whole extent is visible        if (!myMap.extent.contains(graphicsExtent))        {         myMap.level--;        }       }       }           }    }            [Bindable] private var queryTaskbuffer:QueryTask = new QueryTask();    [Bindable] private var querybuffer:Query = new Query();                private function runQueryTaskbuffer(geometry:Geometry):void    {               queryTaskbuffer.url = "http://tfs-24279/ArcGIS/rest/services/ForestProducts/forest_products_concatenated3/MapServer/0";     queryTaskbuffer.showBusyCursor = true;     queryTaskbuffer.useAMF = false;               querybuffer.geometry = geometry;      //geometry from the drawToolbar     querybuffer.returnGeometry = true;    //set to true because we want to place points on the map     querybuffer.spatialRelationship = "esriSpatialRelIntersects";     querybuffer.outSpatialReference = myMap.spatialReference;     querybuffer.outFields = ["County", "Address", "Phone1", "Homepage", "Email", "prim_bus", "other_bus", "maj_prod", "other_pro", "maj_spec", "other_spec", "Company"]                         //run the query task                         queryTaskbuffer.execute(querybuffer, new AsyncResponder( onResult, onFault));          function onResult(featureSet:FeatureSet, token:Object = null):void     {      if (featureSet.features.length == 0){       //If I use an alert, there are many alerts for just one click sometimes       //var alert8:Alert = Alert.show("No matching records found. Please try again.");       //alert8.setStyle("buttonStyleName", "roundedAlertButtons");       resizableDraggableTitleWindowbuffer.visible = false;       resizableDraggableTitleWindowpolygon.visible = false;       resizableDraggableTitleWindowintersectingpolygon.visible = false;       resizableDraggableTitleWindow.visible = false;       resizableDraggableTitleWindowcompanyincounty.visible = false;       querydgbuffer.visible = false;       info.text = "No matching records found. Please try again.";             }else{       myGraphicslayer.clear()       querydgbuffer.visible = true;       resizableDraggableTitleWindowbuffer.visible = true;       myGraphicslayerbuffer.visible = true;       querydgbuffer.dataProvider = queryTaskbuffer.executeLastResult.attributes       resizableDraggableTitleWindowpolygon.visible = false;       resizableDraggableTitleWindowintersectingpolygon.visible = false;       resizableDraggableTitleWindow.visible = false;       resizableDraggableTitleWindowcompanyincounty.visible = false;              for each(var graphic : Graphic in featureSet.features)       {                graphic.symbol = resultsSymbol;        myGraphicslayerbuffer.add(graphic);                          graphic.addEventListener(MouseEvent.MOUSE_OVER, onMouseOverbuffer);        graphic.addEventListener(MouseEvent.MOUSE_OUT, onMouseOutbuffer);        if (graphic.attributes.Homepage !== " " || graphic.attributes.Email !==" ")        {         graphic.addEventListener(MouseEvent.CLICK, clickongraphic)         if   (graphic.attributes.Homepage !== " " && graphic.attributes.Email !==" ")                             {          graphic.toolTip = "Click for Website or Email link"                   }                  if   (graphic.attributes.Homepage == " " && graphic.attributes.Email !==" ")                             {          graphic.toolTip = "Click for Email link"                   }         if   (graphic.attributes.Homepage !== " " && graphic.attributes.Email ==" ")                             {          graphic.toolTip = "Click for Website link"                   }                 }                       }                                                  }            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 in the Buffer Search");     }    }      
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor
You've got the geometry of the point you clicked, so you can create a graphic from that and add it to the graphic layer

var clickGraphic:Graphic = new Graphic(geometry, clickPointSymbol) graphicsLayer.add(clickGraphic);  <fx:Declarations>     <esri:SimpleMarkerSymbol id="clickPointSymbol" style="x" color="0xFF0000" size="12"/> </fx:Declarations>

View solution in original post

0 Kudos
2 Replies
KenBuja
MVP Esteemed Contributor
You've got the geometry of the point you clicked, so you can create a graphic from that and add it to the graphic layer

var clickGraphic:Graphic = new Graphic(geometry, clickPointSymbol) graphicsLayer.add(clickGraphic);  <fx:Declarations>     <esri:SimpleMarkerSymbol id="clickPointSymbol" style="x" color="0xFF0000" size="12"/> </fx:Declarations>
0 Kudos
ionarawilson1
Deactivated User
Thank you so much Ken!!!

Here is code snippet with the graphic added:

    
    function bufferCompleteHandler1(event:GeometryServiceEvent):void
    {
     
     for each (var polygon:Polygon in event.result)
     {
      var graphic:Graphic = new Graphic(polygon);
         graphic.symbol = fillSymbolcounty;
      graphic.autoMoveToTop = false; //keep graphics from moving to top
      myGraphicslayerbuffer.clear();
      var clickGraphic:Graphic = new Graphic(geometry, clickPointSymbol)
      myGraphicslayerbuffer.add(clickGraphic);
      

      myGraphicslayerbuffer.add(graphic);
      runQueryTaskbuffer(graphic.geometry);
    
      var graphicProvider:ArrayCollection = myGraphicslayerbuffer.graphicProvider as ArrayCollection;
      var graphicsExtent:Extent = GraphicUtil.getGraphicsExtent(graphicProvider.toArray());
      
      if (graphicsExtent)
      {
       myMap.extent = graphicsExtent;
       
       // make sure the whole extent is visible
       if (!myMap.extent.contains(graphicsExtent))
       {
        myMap.level--;
       }
      }

     }
     
    }
   }
0 Kudos