The ArcPad Team Blog

Unofficial stuff from the team behind the World's leading mobile GIS platform

Friday, September 01, 2006

Event Driven Scripting #1

The Tree Height Applet

If you are comfortable with using ArcPad Application Builder to build simple forms like the ArcPad generated Quickform, but are not quite sure how to progress to the next level , this article is for you…

For those of you that have ArcPad Application Builder 7.0 installed there is a sample in the Samples\Applets\Rangefinder folder that measures tree heights from incoming rangefinder events. This article will describe how this applet works.

<APPLET name="TreeHeight">
<RANGEFINDER onmeasurement="MeasurementReceived();"/>
<SCRIPT language="jscript" src="treeheight.js"/>

The applet file (.APA) is very basic! There are two main nodes, the APPLET node, and the SCRIPT node. The APPLET node contains the rangefinder system object node. The rangefinder node is used to define the onmeasurement system event. What this means is when the applet is loaded at startup, the code specified in the onmeasurement event is called by the ArcPad system core when an incoming rangefinder range measurement event is fired.

The SCRIPT node contains the scripting information like the script language and the script file name. The script file name (src attribute) is the file which ArcPad opens and the internal range finder event uses to call the function which you have defined in the RANGEFINDER element, onmeasurement event.

So, we have the Applet file and we have the script file that is referenced in the applet. This still doesn’t handle to data capture. We will now look at the sample data supplied with the applet which is a point layer containing the tree positions and their attributes.

Of interest to us is the second page of the form. This is where the information from incoming rangefinder events gets placed from the Applet event. Pretty cool! The applet updates controls in the form that is open.

How does this happen you ask? Well if you open the applet treeheight.js file you will see the function which is called in the onmeasurement event.

What happens in the function?
1. We have to get the maps layers and place it in a variable.
2. We search for a specific layer in the set of layers
3. If the layer is not found, then we display a debug message to console. (See Elvin’s article below on using the ArcPad Console window).
4. Get the form which is associated with our selected layer
5. Based on the value of a forms control, populate others controls.

This brief script shows how the forms controls values can change based on other control values.

The full sequence of events that occur from start to finish are as follows:

1. The rangefinder is configured in ArcPad
2. The tree layer is loaded into ArcPad
3. You start editing the tree layer
4. Create a new tree feature, or update an existing one
5. Now that the form is display go to second page on form
6. Make a selection in the laser measurement combo
7. Make a laser measurement to base of tree (send to ArcPad if it isn't automatically done). Applet onmeasurement event is called by ArcPad
8. Note the fields get populated on the form
9. Make a selection in the laser measurement combo
10. Make a laser measurement to top of tree (send to ArcPad if it isn't automatically done) Applet onmeasurement event is called by ArcPad
11. Note the fields get populated on the form
12. If your rangefinder doesn't support angle, measure angle from base to top of tree with clinometer
13. If you now click the calculate button on form, the height will be set in the height text control. The onclick button event of the forms page is called by ArcPad
14. Approve your edits on command bar. Edits are saved