QueryControl user control

Land Desktop Map 3D Samples

 
QueryControl user control
 
 
 

When the QueryControl control is first created, it performs the following actions in the constructor and in the OnLoad event:

  1. Create an instance of the Query class. Query provides a series of utility functions for QueryControl.
  2. Calls the Query.GetMapLayerNames function to get an array of all the layer names. The layer names are placed in the comboBoxLayer combo box.
  3. Triggers the OnLayerChange event.

The following are the actions taken by the QueryControl user control in response to user input:

  • comboBoxLayer_SelectedIndexChanged - Calls the function OnLayerChange function. OnLayerChange gets the string name of the layer from the comboBoxLayer control and uses the global instance of the Query object to get the properties of that layer. OnLayerChange then adds the property names to the comboBoxProperty and comboBoxOutputProperty controls. The event then calls OnPropertyChange. OnPropertyChange then gets the Property object for the property selected in the comboBoxProperty control, and depending on the type of property it fills the comboBoxOperator control with the various types of operators that can act on that property.
  • comboBoxProperty_SelectedIndexChanged - Calls OnPropertyChange. OnPropertyChange gets the Property object for the property selected in the comboBoxProperty control, and depending on the type of property it fills the comboBoxOperator control with the various types of operators that can act on that property.
  • checkBoxSpatialFilter_CheckedChanged - Calls the OnToggleSpatialFilter function which sets whether the spatial filter layer created by the buttonRectangle or buttonPolygon controls is visible or not. OnToggleSpatialFilter first locks the currently active document using the LockDocument method. It then gets a reference to the currently active document’s database, and then a reference to the database’s transaction manager property. It creates a new transaction by calling the StartTransaction method of the transaction manager. It then gets the AutoCAD Polyline entity that represents the spatial filter outline and sets its visibility.
  • buttonRectangle_Click - Calls the OnRectangleDigitized function to create a spatial filter layer. Using a utility property, OnRectangleDigitized gets a reference to the AutoCAD Editor object. It then creates a PromptPointOptions object which contains a prompt string. The prompt is passed to the GetPoint method of the Editor object, which returns a PromptPointResult object containing the point the user selected. It then creates an instance of RectangleJig, a local class overriding the AutoCAD EntityJig abstract class. The Drag method of the AutoCAD Editor object is called with the RectangleJig object as the parameter to obtain the opposite corner point of the rectangle. Next, the SetRectangle method of RectangleJig is called to compute all four corners of the rectangle, and the local AddEntityToMap function is called.

    AddEntityToMap first locks the currently active document using the LockDocument method. It then gets a reference to the currently active document’s database, and then a reference to the database’s transaction manager property. It creates a new transaction by calling the StartTransaction method of the transaction manager. AddEntityToMap then adds the rectangle entity to a block table from the document’s database.

  • buttonPolygon_Click - Calls the OnPolyonDigitized function to create a spatial filter layer. Using a utility property, OnRectangleDigitized gets a reference to the AutoCAD Editor object. It then creates a PromptPointOptions object which contains a prompt string. The prompt is passed to the GetPoint method of the Editor object, which returns a PromptPointResult object containing the point the user selected. It then creates an instance of PolygonJig, a local class overriding the AutoCAD EntityJig abstract class. Within a While loop the Drag method of the AutoCAD Editor object is called with the PolygonJig object as the parameter to obtain the remaining points of the polygon. Next, the local AddEntityToMap function is called.

    AddEntityToMap first locks the currently active document using the LockDocument method. It then gets a reference to the currently active document’s database, and then a reference to the database’s transaction manager property. It creates a new transaction by calling the StartTransaction method of the transaction manager. AddEntityToMap then adds the polyline entity to a block table from the document’s database.

  • buttonClear_Click - Calls the OnClear method to erase the selection entity created by the buttonRectangle or buttonPolygon controls and reset the spatial filter layer. OnClear first locks the currently active document using the LockDocument method. It then gets a reference to the currently active document’s database, and then a reference to the database’s transaction manager property. It creates a new transaction by calling the StartTransaction method of the transaction manager. It uses the transaction manager’s GetObject method to get a reference to the entity described by the global _boundaryEntityId property and erases it. Lastly, it causes the current document to refresh its display.
  • comboBoxOutputProperty_SelectedIndexChanged - Calls the OnOutputPropertyChange function which clears the listBoxResults control.
  • button1_Click - Loops through all layers to find the one that matches the selected text in the comboBoxLayer control, and then calls ZoomToLayer method of the layer that matches.
    NoteThis control is a button labeled “Zoom” near the comboBoxLayer control.
  • buttonExecute_Click - Calls the ExecuteQuery function. ExecuteQuery first creates an instance of the QueryCondition class. All of the QueryCondition properties as assigned to the selected values of the controls on the user control and to the Property object represented by the value of the comboBoxProperty control. The QueryCondition object is then passed to the Execute method of the global Query object to perform the database query. Execute returns an array of Features. A loop adds the value of each of the features to the listBoxResults list box.
  • buttonSelect_Click - Calls the SelectFeature function. SelectFeature first gets the Feature object represented by the selected item in the listBoxResults control. It then creates a hash table from the IdProperties property of the feature object. If any features are currently selected (that is, if the _selectionSet object contains any features), they are unselected by calling the AcMapFeatureEntityService.UnhighlightFeatures method. The feature is then selected by calling the GetHilightSelectionFeature method of the global Query object, which requires a layer name and the hash table of IdProperties as parameters.
  • buttonZoom_Click - Calls the ZoomToFeature function. ZoomToFeature first gets a reference to the currently displayed AcMapMap object. It then gets the Feature object named by the selected item in the listBoxResults control. It then gets a reference to the MgGeometry property of the feature, and creates an MgEnvelope object indicating the extents of the feature. It calls the AcMapMap object’s ZoomToExtent function to zoom the map to the specified envelope, and finally calls the SelectFeature method to select the specified feature.