Exercise 1: Creating a custom data entry form for a Parcel layer

Exercise 2: Adding a new feature layer to an existing 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:

Steps:
  1. 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:
    Screen shot showing ArcPad Data Manager toolbar in ArcMap.
  2. 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:
    Screen shot of the Get Data For ArcPad - Select Data dialog box.
  3. On the Get Data For ArcPad - Select Picture Options dialog box, click Next.
  4. 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.
    Screen shot specifying the folder name that is created to store the data.
  5. 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.

  6. View the contents of the Parcel folder. The folder should contain the Riverside_mdb.axf file and Streets shapefiles. See the following screen shot:
    Screen shot showing the Riverside_mdb.axf file and Streets shapefiles.

Creating an edit form for the Parcel layer

NoteNote:

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.

Steps:
  1. Start ArcPad Studio and open the Riverside_mdb.axf file.
  2. Right-click the Parcel feature layer and click Edit Layer Definition. The Layer Definition window appears.
  3. Click the Forms Forms button button on the toolbar. The Forms dialog box appears. Forms created during checkout are listed.
  4. Before creating a new Edit form, you must first delete the exiting Edit form. Select the Edit form from the list and click Delete
  5. 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:
    Screen shot showing the Controls palette.Screen shot showing the Fields palette.
  6. Click the Form menu and click Form Properties. The Form Properties dialog box appears.
  7. 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:
    Screen shot showing the Form Properties dialog box.
  8. Click the Label control Label control on the Controls palette on the Controls palette and drag it to the edit form.
  9. Type lblAPN in the Name text box and APN in the Caption text box. See the following screen shot:
    Screen shot showing the Controls Properties dialog box.
  10. 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.
  11. Click OK to close the Control Properties dialog box.
  12. Click and drag the APN edit control from the Fields palette to the page of your edit form.
  13. Double-click the control. The Controls Properties dialog box appears. Type edbAPN in the Name text box.
  14. 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:
    Screen shot showing the Control Properties dialog box.
  15. Click OK to close the Control Properties dialog box.
  16. Click and drag the ZONECODE control on the Fields palette onto the edit form.
  17. Type lblZONE in the Name text box and ZONE in the Caption text box.
  18. Type 80 in the Width text box and 12 in the Height text box. See the following screen shot:
    Screen shot showing the Control Properties dialog box.
  19. Click OK to close the Control Properties dialog box.
  20. In ArcMap, ZoneCode is selected as the field used for the symbology for the Parcel layer. See the following screen shot:
    Screen shot showing ZoneCode as the symbology for the Parcel layer.

    You can use a SymbologyField SymbologyField control 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:

    Screen shot showing the SymbologyField control.

  21. Drag and drop the SymbologyField control onto the edit form. The Control Properties dialog box appears.
  22. 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:
    Screen shot showing the Control Properties dialog box.
  23. Click OK to close the Control Properties dialog box.
  24. The last field to add to the edit form is a SHAPE_AREA field. Drag and drop an Edit box Edit box control control from the Controls palette onto the edit form.
  25. Type edbShapeArea in the Name text box, 80 in the Width text box, and 12 in the Height text box.
  26. Click the Field drop-down list and select SHAPE_AREA to associate the SHAPE_AREA to this edit control. See the following screen shot:
    Screen shot showing the SHAPE_AREA field on the Control Properties dialog box.
  27. Click OK to close the dialog box, then manually align the controls on the page. The following screen shot shows the resulting edit form:
    Screen shot showing the resulting edit form.
  28. Click OK to close the edit form.
  29. 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.

Steps:
  1. Click Tools > Options. The Preferences dialog box appears.
  2. Click the Scripting tab and select JScript from the Default Scripting Language drop-down list. See the following screen shot:
    Screen shot showing the Preferences dialog box.
  3. Click OK to close the dialog box.
  4. Click the Edit Script Edit Script button button on the toolbar to create a JScript source code file with the name Layer1.js.
  5. 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)
    }
  6. After you type or paste the script, click the Verify Syntax Verify Syntax button 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.
  7. Click the Save Save button button. The Layer1.jp file is saved in the AXF file store. See the following screen shot:
    Screen shot showing the Layer1.js file in the updated file store.

Attaching the script to the Edit form

Steps:
  1. Double-click <EDITFORM>Parcel in the Parcel layer definition window to reactivate the Edit form.
  2. Select Page Properties on the Page menu. The Page Properties dialog box appears.
  3. Click the Events tab on the Page Properties dialog box. A list of events the Page object is capable of responding to displays.
  4. Click onsetactive under the Event column and type the following in the Event Script text box.

    JScript

    ThisEvent.Object.Controls("edbShapeArea").Value = GetArea()
  5. Click OK on the Page Properties dialog box.
  6. Click OK on the Edit Form dialog box. The <SCRIPT> element is added to the layer definition. See the following screen shot:
    Screen shot showing the Page Properties dialog box.
  7. Click Save to save all edits on the the layer definition.

2/7/2013