Point Buffer Widget customization

670
14
Jump to solution
01-10-2012 01:03 PM
RachelS_
New Contributor III
I've adopted the Point Buffer code and wrote a function to calculate the radius distance I want to apply a buffer for, based on some user inputs via combo boxes. Instead of using the input text (textInputBuffer) I want the buffer distance to be defined by my function. Is there a way to switch it so that the ApplyBuffer function reads from my function and not the text input?
Thanks!!
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus
Rachel,

   Sure just put
cboBufferUnit.selectedIndex = 2;
at the end of the init function.

Don't forget to click the top arrow (promote) and to click the Mark as answer check as shown below:

View solution in original post

0 Kudos
14 Replies
RobertScheitlin__GISP
MVP Emeritus
Rachel,

  So right now the applyBuffer function takes the textInputBuffer.text and splits it into an array if the text is a comma separated list for a multi ring buffer operation. So I need to see your code and what you are wanting to use to have an idea of how to advise you from here.
0 Kudos
RachelS_
New Contributor III
Right, I am not interested in multi ringed operations. There are a few dropdowns plus a text input where users select wind turbine variables, and the inputs determine the calculated fall zone.
I've defined some variables under the functions 'public function getHeight()', 'public function getDiameter()', and 'public function calculateBtn_clickHandler.'  The actual calculation occurs in this last function.  Code is attached, still kinda rough.

many thanks - Rachel
0 Kudos
RachelS_
New Contributor III
code attached.....
0 Kudos
RachelS_
New Contributor III
seems I'm having an issue attaching code. so be it, below are the functions


   public function getHeight():void
   {
    if (surfaceLevRB.selected == true)
    {
     if (towerCombo.selectedItem == "65 m")
     {
      towerHeight = 65;
     }
     if (towerCombo.selectedItem == "80 m")
     {
      towerHeight = 80;
     }
     if (towerCombo.selectedItem == "100 m")
     {
      towerHeight = 80;
     }
    }
    else
    {
     towerHeight = parseInt(towerText.text);
    }
   }
  
   public function getDiameter():void
   {
    if (surfaceLevRB.selected == true)
    {
     if (rotorCombo.selectedItem == "70 m")
     {
      rotorDiam = 70;
     }
     if (rotorCombo.selectedItem == "77 m")
     {
      rotorDiam = 77;
     }
    }
    else
    {
     rotorDiam = parseInt(rotorText.text);
    }
   
   }
  
   //Calculate turbine fall zone
   public function calculateBtn_clickHandler(event:MouseEvent):void
   {
   
    if (surfaceLevRB.selected == true)
    {
     rotorDiam = parseInt(rotorCombo.selectedLabel);
     towerHeight = parseInt(towerCombo.selectedLabel);
    }
    if (allLevRB.selected == true)
    {
     rotorDiam = parseInt(rotorText.text);
     towerHeight = parseInt(towerText.text);
    }
    if (safetyMult.text == "")
    {
     safezone = 1
    }
    else
    {
     safezone = parseInt(safetyMult.text);
    }
   
    fallzone = Math.floor((towerHeight + (rotorDiam/2))* safezone);
    Alert.show("Radius (m): " + fallzone.toString());
   }
  
  
  ]]>
</fx:Script>
<viewer:WidgetTemplate id="wTemplate" width="400" height="310">
  <s:Scroller width="100%" height="100%">
   <s:VGroup width="100%" gap="6">
    <s:HGroup id="boxMessage"
        width="100%"
        includeInLayout="{msgVisible}"
        visible="{msgVisible}" horizontalAlign="center">
     <mx:Image id="swfMessage"
         source="assets/images/loader.swf"
         visible="false"/>
     <s:Label id="txtMessage"
        width="90%"
        text=""/>
    </s:HGroup>
    <s:Label text="Turbine specifications" textDecoration="underline" paddingLeft="5" fontWeight="bold"/>
    <!--Added from WEST-->
    <s:VGroup width="100%" >
     <!-- <s:Label fontWeight="bold" text="{step1Label}"/> -->   
     <s:HGroup height="100%"  paddingBottom="3" width="100%">
      <s:RadioButton 
       id="surfaceLevRB" label="Select from menus"
       selected="true" />
      <mx:Spacer width="5" height="100%"/>
      <s:RadioButton label="{allLevRBLabel}"
            id="allLevRB" />     
      <mx:Spacer height="100%" width="20"/>
     </s:HGroup>
    </s:VGroup>
   
    <s:VGroup >
     <s:HGroup>
      <mx:Spacer width="15" />
      <s:VGroup>
       <s:Label text="Hub height (m)" visible="{surfaceLevRB.selected}" />
       <mx:ComboBox
        id="towerCombo" prompt=" "
        visible="{surfaceLevRB.selected}" enabled="{surfaceLevRB.selected}"      
        dataProvider="{towerList}" width="75"  />
      </s:VGroup>
      <mx:Spacer width="15" />
      <s:VGroup>
       <s:Label text="Rotor diameter (m)" visible="{surfaceLevRB.selected}" />
       <mx:ComboBox
        id="rotorCombo" prompt=" "
        visible="{surfaceLevRB.selected}" enabled="{surfaceLevRB.selected}"      
        dataProvider="{rotorList}" width="75"  />
      </s:VGroup>
     
     </s:HGroup>
    </s:VGroup>
   
    <s:VGroup paddingTop="-50" >
     <s:HGroup visible="{allLevRB.selected}" >
      <s:Label text="Rotor diameter (m): " visible="{allLevRB.selected}" paddingTop="5" />
      <mx:TextInput id="rotorText" width="50" />
     </s:HGroup>
     <s:HGroup visible="{allLevRB.selected}"  >
      <s:Label text="Hub height (m): " visible="{allLevRB.selected}" paddingTop="5" />
      <mx:TextInput id="towerText" width="50" />
     </s:HGroup>
     <s:HGroup >
      <s:Label text="Safety factor: " paddingTop="5" paddingLeft="20" />
      <mx:TextInput id="safetyMult" width="40" restrict="1-5"    />
     </s:HGroup>
    </s:VGroup>
   
    <s:Label text="Locate turbine" fontWeight="bold" textDecoration="underline" paddingTop="10" />
    <s:HGroup id="imageGroup" horizontalAlign="left" width="100%" > <!--verticalAlign="middle"-->
     <mx:Image name="{DrawTool.MAPPOINT}"
         buttonMode="true"
         click="{activateDrawTool(event)}"
         rollOut="iconRollOutHandler(event)"
         rollOver="iconRollOverHandler(event)"
         source="assets/images/winds-25.png"
         toolTip="{pointLabel}"
         useHandCursor="true"/>
     <mx:Spacer width="10" />
    
     <mx:Spacer width="10" />
     <s:Label id="coordinatesRequiredFieldsLabel"
        buttonMode="true"
        click="clear()"
        fontWeight="bold"
        text="{clearLabel}"
        textDecoration="underline"
        verticalAlign="middle"/>
     <mx:Button id="calculateBtn"
          icon="@Embed(source='assets/images/Gear.png')"
          click="calculateBtn_clickHandler(event)" />
    </s:HGroup>
    <s:HGroup width="100%"
        horizontalAlign="right"
        paddingRight="10"
        paddingTop="2">
    
    </s:HGroup>
    <s:HGroup width="100%" height="29" horizontalAlign="left" >
     <s:TextInput id="textInputBuffer" text="5" width="100" />
     <s:DropDownList id="cboBufferUnit" x="130" width="175" prompt="{unitPrompt}" change="{(null);checkDrawNumGras(null);checkPntNumGras(null);clearMessage();}"/>
    </s:HGroup>
    <s:HGroup width="100%" horizontalAlign="left" verticalAlign="middle">
     <!--<s:CheckBox id="dischk" label="Dissolve" toolTip="{dissolveTooltip}" />-->
     <mx:Image id="ApplyBufferBtn"
         width="30" height="30"
         click="applyBuffer()"
         source="assets/images/i_target.png"/>
     <mx:Image id="ClearBufferBtn"
         width="40" height="40"
         click="clearBuffer()"
         source="assets/images/i_clear.png"
         toolTip="{clearLabel}"/>
    </s:HGroup>
   </s:VGroup>
  </s:Scroller>
</viewer:WidgetTemplate>
</viewer:BaseWidget>
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Rachel,

   So it would look like this then:

            //Calculate turbine fall zone
            public function calculateBtn_clickHandler(event:MouseEvent):void
            {
                if (surfaceLevRB.selected == true){
                    rotorDiam = parseInt(rotorCombo.selectedLabel);
                    towerHeight = parseInt(towerCombo.selectedLabel);
                }
                if (allLevRB.selected == true){
                    rotorDiam = parseInt(rotorText.text);
                    towerHeight = parseInt(towerText.text);
                }
                if (safetyMult.text == ""){
                    safezone = 1
                }else{
                    safezone = parseInt(safetyMult.text);
                }
                fallzone = Math.floor((towerHeight + (rotorDiam/2))* safezone);
                Alert.show("Radius (m): " + fallzone.toString());
                applyBuffer(fallzone);
            }

            private function applyBuffer(fallzone:Number):void
            {
                var graLayAC:ArrayCollection = graphicsLayer.graphicProvider as ArrayCollection;
                if (graLayAC.length > 0) 
                {
                    geomArr = [];
                    for each (var graphic:Graphic in graphicsLayer.graphicProvider)
                    {
                        geomArr.push(graphic.geometry);
                    }
                    var buffUnit:Number = GeometryService[configBufferUnits[cboBufferUnit.selectedIndex].name];
                    bufferGeometries(geomArr,sReff,[fallzone],buffUnit);
                } else {
                    showMessage("There is no result to buffer, please make a graphical or text search first.",false, true);
                }
            }
0 Kudos
RachelS_
New Contributor III
Great! I modified click="applyBuffer(fallzone)" and it worked.
Is there a way to set Meters as the automatic unit to create a buffer without providing a user input? Can one simply set configBufferUnits[cboBufferUnit.selectedIndex].name once in the script? Many Thanks.
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Rachel,

   Sure just put
cboBufferUnit.selectedIndex = 2;
at the end of the init function.

Don't forget to click the top arrow (promote) and to click the Mark as answer check as shown below:
0 Kudos
EricPollard2
New Contributor III
This seems to be a different topic than my specific question, but I too am trying to use the "Buffer Point" function. I am trying to use it in much the same way the sample works in the Javascript API samples area on the resource center (http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples/util_buffer.html). I am hoping to be able to have the user click on a newly created 'Buffer' button, then click on the map in any location, and the ring graphic will appear, having buffered the point by my specified distances (set in the array).

I have downloaded the 'basic viewer' web app from ArcGIS Online (javascript) and am tweaking it with my limited knowledge of programming. I have used the "print" button section of the code to convert to this function, changed the png/title/label etc for it and made it a "toggleButton" so that it can be toggled much the same way the 'Measure' tool is toggled. I have also changed the array to the three distances I want to buffer by. The button now looks right, and can be clicked on and off. From here I am lost. I need to somehow link the button to the buffering function and function to show the buffer graphics (from the sample). In the sample, it seems to call up a new map when it is initialized, but I need for the arcgis map that my app is based on to stay in the map frame, and be able to be panned/zoomed/etc before and after the buffer is created by the user. I am also hoping to have the 'toggleButton' essentially switch on and off the buffering "ability" of the application.

To make this more simple, if anyone can show me how to essentially add the 'buffer point' sample from the sample area in the Resource Center API help (link above) to a standard web app downloaded from ArcGIS Online (in javascript), then I can probably figure out how to insert it in my app specifically.

Thank you so much to anyone who can help!! Been struggling with this for many hours.
-Eric
0 Kudos
RobertScheitlin__GISP
MVP Emeritus
Eric,

   Your big issue is that you are posting a JavaScript question the the FLEX Viewer forum. Flex and JavaScript are two different languages. You will have better luck waiting for a response to the post you made in the JavaScript forum. Cross posting to a forum that is not specific to your language is frowned on.
0 Kudos