Exercise 1: Creating a custom data entry form for a Parcel layer
Creating a custom data entry form with a symbology chooser and automated data entry for an AXF layer
In previous projects, you learned the basic techniques for creating custom forms. In this project, you will create a data entry form for a Parcel layer and write scripts to update the data, then display it on the form.
In this exercise, you will need to create an ArcPad Exchange File (AXF) in ArcMap.
Creating an AXF file using ArcPad Data Manager in ArcMap
You will start by checking out data from a geodatabase. For full guidance on how to check out data, refer to the ArcPad Help. The following demonstrates the minimum steps:
- Start ArcMap and open C:\Documents and Settings\All Users\ Shared Documents\ArcPad\Samples\Riverside\Riverside.mxd (on computers running Windows Vista or Windows 7, the sample data folder is installed under Public Documents). See the following screen shot:
- Click the Get Data for ArcPad button on the ArcPad Data Manager toolbar. The Get Data For ArcPad - Select Data dialog box appears. Under the Action column, check out the Parcel layer for editing and copy the Streets layer as background data. Click Next. See the following screen shot:
- On the Get Data For ArcPad - Select Picture Options dialog box, click Next.
- On the Get Data For ArcPad - Select Output Options dialog box, type Parcel as the folder (and subsequently, AXF) name. Save it to a designated folder. Click Next.
- On the Get Data For ArcPad - Deployment Options dialog box, click Finish. A new AXF file is created.
If no AXF file is visible in the output folder, follow the Get Data for ArcPad wizard again and ensure that you do Check Out for disconnected editing in ArcPad the Parcel layer. Also confirm no errors are reported in summary dialog at the end of the wizard.
- View the contents of the Parcel folder. The folder should contain the Riverside_mdb.axf file and Streets shapefiles. See the following screen shot:
Creating an edit form for the Parcel layer
The checkout tool automatically creates an Edit form for each layer inside an AXF file during the checkout process. The following steps will show you how to create an Edit form from scratch. Normally it is easiest to start with the Edit forms created during the checkout process and modify them to suit your needs.This section will demonstrate how you can create a brand new Edit form.
- Start ArcPad Studio and open the Riverside_mdb.axf file.
- Right-click the Parcel feature layer and click Edit Layer Definition. The Layer Definition window appears.
- Click the Forms button on the toolbar. The Forms dialog box appears. Forms created during checkout are listed.
- Before creating a new Edit form, you must first delete the exiting Edit form. Select the Edit form from the list and click Delete
- To create a new Edit form for the Parcel layer, click the EDITFORM button on the Form dialog box. An Edit Form dialog box appears with the Controls and Fields palette. The Fields palette is a collection of "smart controls" for all the Parcel layer fields. See the following screen shots:
- Click the Form menu and click Form Properties. The Form Properties dialog box appears.
- Clear the Symbology Page and Attributes Page check boxes. Type Parcel in the Caption text box. Click OK. Notice, the caption changes to Parcel. See the following screen shot:
- Click the Label control on the Controls palette and drag it to the edit form.
- Type lblAPN in the Name text box and APN in the Caption text box. See the following screen shot:
- Type 30 in the Width text box and 12 in the Height text box. For the X and Y placement options, you will manually align the controls with the existing controls on the page.
- Click OK to close the Control Properties dialog box.
- Click and drag the APN edit control from the Fields palette to the page of your edit form.
- Double-click the control. The Controls Properties dialog box appears. Type edbAPN in the Name text box.
- Type 80 in the Width text box and 12 in the Height text box. Notice, this edit control is already associated to the APN field. See the following screen shot:
- Click OK to close the Control Properties dialog box.
- Click and drag the ZONECODE control on the Fields palette onto the edit form.
- Type lblZONE in the Name text box and ZONE in the Caption text box.
- Type 80 in the Width text box and 12 in the Height text box. See the following screen shot:
- Click OK to close the Control Properties dialog box.
- In ArcMap, ZoneCode is selected as the field used for the symbology for the Parcel layer. See the following screen shot:
You can use a SymbologyField control for the ZONECODE field in ArcPad to show the list of symbols as defined in the layer's symbology as a drop-down list. The SymbologyField control was introduced in ArcPad 7.1. If a layer was symbolized by a field in the original .mxd file that was checked out to ArcPad, this control automatically shows the layer's symbology definition (that is, the legend) as a choice on a custom form. See the following screen shot:
- Drag and drop the SymbologyField control onto the edit form. The Control Properties dialog box appears.
- Type sfZone in the Name text box. Type 80 in the Width text box and 14 in the Height text box. You will manually align the position of the control on the form; therefore, leave the X and Y positions as is. See the following screen shot:
- Click OK to close the Control Properties dialog box.
- The last field to add to the edit form is a SHAPE_AREA field. Drag and drop an Edit box control from the Controls palette onto the edit form.
- Type edbShapeArea in the Name text box, 80 in the Width text box, and 12 in the Height text box.
- Click the Field drop-down list and select SHAPE_AREA to associate the SHAPE_AREA to this edit control. See the following screen shot:
- Click OK to close the dialog box, then manually align the controls on the page. The following screen shot shows the resulting edit form:
- Click OK to close the edit form.
- Click the Save button on the toolbar to save the layer definition file (leave the file open for now).
Adding scripts to the Riverside_mbd.axf file store
To display the area of a new polygon added to the Parcel layer, add some scripts to update the area of the new polygon in the edit box associated to the Shape_Area field on the edit form. In ArcPad Studio, you will add JavaScript source code to the layer definition file.
- Click Tools > Options. The Preferences dialog box appears.
- Click the Scripting tab and select JScript from the Default Scripting Language drop-down list. See the following screen shot:
- Click OK to close the dialog box.
- Click the Edit Script button on the toolbar to create a JScript source code file with the name Layer1.js.
- Copy and paste the following script into the script editor. If you have formatting issues, paste the script into a text editor, such as Notepad, then copy and paste the script into the JScript source code file.
JScript
/** GeometryUpdates.js This script can be used to update the area of polygons, and the length of lines and polygons in an AXF file. To use: 1. Import this file to the file store of your .axf file. 2. Create an edit form for your line or polygon layer. 3. Add a control to display the value of the Shape_Length or Shape_Area. Name it GeomControl. 4. Add to the onSetActive event of the page of your edit form. ThisEvent.Object.Controls("GeomControl").Value = GetArea() //or GetLength 5. Ensure the field you are trying to update (for example, Shape_Area) is not read-only. The script updates the length or area when the form is opened. Note, it only works once the feature has been successfully added to the database. This means you will not see the area until you reopen the edit form for that feature. */ //Function to get the area of the currently selected polygon. function GetArea() { var area //Use the selection bookmark property to ensure the edit is to an existing feature. if( Map.SelectionBookmark == -1) { //If Map.SelectionBookmark = -1 implies a new feature, set to 0. area = 0 } else { //Get a reference to the polygon layer and its records. var lyr = Map.EditLayer(3) var myRecords = lyr.Records //Point the record set to the currently selected feature. myRecords.Bookmark = Map.SelectionBookmark //Return area of current feature. area = myRecords.Fields.Shape.Area } return area.toFixed(2) } //Function to get the length of the currently selected line. function GetLength() { var length //Use the selection bookmark property to ensure the edit is to existing features. if( Map.SelectionBookmark == -1) { //If Map.SelectionBookmark = -1 implies a new feature, set to 0. length = 0 } else { //Get a reference to the polygon layer and its records. var lyr = Map.EditLayer(2) var myRecords = lyr.Records //Point the record set to the currently selected feature. myRecords.Bookmark = Map.SelectionBookmark //Return the area of current feature. length = myRecords.Fields.Shape.Length } return length.toFixed(2) }
- After you type or paste the script, click the Verify Syntax button on the toolbar to perform a syntax check. If the compilation succeeds, you'll hear an audible beep. If you receive an error, review the script. Click Save to save your script. If the compilation fails, compare the script you typed to the previously shown script example and correct any errors.
- Click the Save button. The Layer1.jp file is saved in the AXF file store. See the following screen shot:
Attaching the script to the Edit form
- Double-click <EDITFORM>Parcel in the Parcel layer definition window to reactivate the Edit form.
- Select Page Properties on the Page menu. The Page Properties dialog box appears.
- Click the Events tab on the Page Properties dialog box. A list of events the Page object is capable of responding to displays.
- Click onsetactive under the Event column and type the following in the Event Script text box.
JScript
ThisEvent.Object.Controls("edbShapeArea").Value = GetArea()
- Click OK on the Page Properties dialog box.
- Click OK on the Edit Form dialog box. The <SCRIPT> element is added to the layer definition. See the following screen shot:
- Click Save to save all edits on the the layer definition.