ArcPad Scripting Object Model
AddFeature Method
See Also  Example  Send comments on this topic.
pShape
Required. A variable declared as a Geometric object.
ShowForm
Optional. A Boolean that specifies whether to display the feature properties dialog box (or edit form) after adding the feature.
Map Object : AddFeature Method

Glossary Item Box

Description

Adds a shape to the appropriate editable layer of the current map.

Syntax

object.AddFeature ( pShape [,ShowForm] )

Parameters

pShape
Required. A variable declared as a Geometric object.
ShowForm
Optional. A Boolean that specifies whether to display the feature properties dialog box (or edit form) after adding the feature.

Return Type

Boolean

Remarks

ShowForm is a boolean specifying whether to display the feature properties dialog box (or edit form) after adding the feature. Default is true. [Optional].

Be sure to confirm there is an editable layer of type Shape in the current map before calling AddFeature. This can be accomplished via the EditLayer property of the Map object. Calling AddFeature when there is not an editable layer of type Shape will cause ArcPad to crash.

Snapping will not be applied to a feature added via this method. The feature will added at the location of the geometric object specified by the Shape argument.

Example

Adds a new point with the coordinates of the current GPS position to the layer GPSPoints.
AddFeature Example (VBScript)Copy Code
Sub AddGPSPoint
  Dim objNewPoint
  'Check if the layer can be made editable
  If Not Application.Map.Layers("GPSPoints").CanEdit Then
    MsgBox "GPSPoints cannot be edited.",vbExclamation,"Error"    
    Exit Sub
  End If
  'If the layer is not already editable, make it editable
  If Not Application.Map.Layers("GPSPoints").Editable Then
    Application.Map.Layers("GPSPoints").Editable = True
  End If
  'Create a new Point object
  Set objNewPoint = Application.CreateAppObject("point")
  'Populate the new point's X and Y with the current GPS X and Y
  objNewPoint.X = Application.GPS.X
  objNewPoint.Y = Application.GPS.Y
  'Attempt to add the new point to the currently editable point layer
  'Return an error message if the attempt fails
  If Not Application.Map.AddFeature (objNewPoint) Then
    MsgBox "Error adding GPS Point.",vbExclamation,"Error"
    Exit Sub
  End If
  Set objNewPoint = Nothing
End Sub
AddFeature Example (JScript)Copy Code
function AddGPSPoint()
{
  //Check if the layer can be made editable
  try
  {
    if (!Application.Map.Layers("GPSPoints").CanEdit)
    {
      Application.MessageBox("GPSPoints cannot be edited.",apExclamation,"Error");
      return;
    }
  }
  catch (e)
  {
    Application.MessageBox("Error accessing GPSPoints layer.\nError is: " + e)
    return;
  }   //If the layer is not already editable, make it editable
  if (!Application.Map.Layers("GPSPoints").Editable)
  Application.Map.Layers("GPSPoints").Editable = true;
  //Create a new Point object
  var objNewPoint = Application.CreateAppObject("Point");
  //Populate the new point's X and Y with the current GPS X and Y
  objNewPoint.X = Application.GPS.X;
  objNewPoint.Y = Application.GPS.Y;
  //Attempt to add the new point to the currently editable point layer
  //Return an error message if the attempt fails
  if (!Application.Map.AddFeature (objNewPoint))
    Application.MessageBox("Error adding GPS Point.", apExclamation, "Error");

  //Clean up
  objNewPoint = null;
}

See Also

© 2013 All Rights Reserved.