MapGuide API Extensions v5.0

 

Clip Polygon Control

The Clip Polygon Control is an ActiveX component that extends the capability of the MapGuide Viewer API by enabling the development of applications that require clipping of objects to a polygon and point-in-polygon analysis. The Control provides a set of public methods that enable the developer to:

  • establish a clipping polygon,
  • determine whether a point lies within the clipping polygon,
  • evaluate whether an object's extent crosses the clipping polygon's bounding box,
  • clip an object against the clipping polygon,
  • retrieve the clipped object's coordinates.

This control requires the MapGuide SDF Component Toolkit DLL (sdfcomtk.dll) to be registered on the client's computer. The client must download the Toolkit from the Autodesk website (www.mapguide.com), install the Toolkit, and register the DLL by entering the following command in the Windows Run menu:

 C:\Windows\System\Regsvr32.exe  C:\Program Files\Autodesk\SdfComTk4\Bin\sdfcomtk.dll

Alternatively, you could permit the user to download the DLL from your website. Ensure that the version of the control that you use matches the version of the SDF Component Toolkit.

The control appears as a clickable button:

HgisClipPoly

The button may be sized through the BoxWidth and BoxHeight parameters while the label is set through the ButtonLabel parameter. Clicking on the button pulls up the Clip Polygon About Dialog:

HgisClipPolyMenu

The control allows display of the coordinates of the clipping polygon and the last object that was clipped:

HgisClipPolyVerts

Loading the Control

Instructions for implementing the control on web pages are provided with the Toolkit documentation.

Parameters

Name Description>
AboutDlgStatus Toggles the ability to display the About Dialog Box by clicking on the Control. A value of "0" prevents the display of the Dialog, while a value of "1" enables display (Default: "1" )
ButtonLabel The label to appear on the button (Default: "Hgis Clip Poly" )
BoxWidth The width of the control in Twips (Default: 1500 Minimum: 200 )
BoxHeight The height of the control in Twips (Default: 500 Minimum: 50 )

Clipping Objects

The general sequence of steps for clipping objects against a clipping polygon are as follows:

  • ensure that the coordinates of objects on layers to be clipped can be accessed (validatePassword())
  • create a clipping polygon by submitting a collection of MGPoints (setClipPolygon())
  • determine whether the extents of an object to be clipped crosses the bounding box of the clipping polygon (extentIntersectsClipPolygon())
  • for a point object, determine whether it lies in the clipping polygon (pointInClipPolygon())
  • for polyline and polygon objects (including polypolylines and polypolygons):
    • use the getVertices method of the MGMapObject class to retrieve collections of the object's vertices and vertice counts
    • clip the collections (clipObjectInside())
    • retrieve the number of internal objects in the clipped object (getClippedNumObjects())
    • retrieve a collection of the vertice counts of the internal objects (getClippedNumVerts())
    • retrieve a collection of the vertices of the internal objects (getClippedVertices())
A polygon must meet these following conditions in order to be a valid clipping polygon:
  • simple polygon object (polypolygons are not currently supported)
  • must contain a minimum of 4 coordinate pairs
  • the last coordinate pair must precisely match the first coordinate pair
  • the polygon cannot self-intersect, that is, a segment in the polygon cannot intersect another segment within the polygon.
It is important to bear in mind the types of coordinates that are being sent to the Control's methods. Once a clipping polygon has been established, all coordinates submitted to the Control must be in the same units, otherwise the application must designate a transformation via the CoordConv parameter:
  • 0 - do not perform coordinate conversion. The coordinates that are sent to the control are in the same units as the clipping polygon.
     
  • 1 - convert from MCS to latitude/longitude (MCStoLL). MCS coordinates are sent to the Control and the clipping polygon has latitude/longitude.
     
  • 2 - convert from latitude/longitude to MCS (LLtoMCS). Latitude/longitude coordinates are sent to the Control and the clipping polygon has latitude/longitude.
The getVertices() method of the MGMapObject class of the MapGuide Viewer API returns coordinates in MCS units, while the getExtents() method and the digitizing methods, return coordinates in latitude/longitude. All coordiates passed to the Control must either be in MCS units or latitude/longitude.

Methods

A complete list of the public methods is provided with the Toolkit documentation.

 © 2002, Hunter GIS