Click or drag to resize

PolygonFence Class

Verizon Connect Logo
Print this page
Learn more about Verizon Connect GeoBase.
Get information about the latest release
An irregularly shaped GeoFence connecting an arbitrary number of points.
Inheritance Hierarchy
SystemObject
  Telogis.GeoBase.GeoFencePolygonFence

Namespace:  Telogis.GeoBase.GeoFence
Assembly:  geobase.net (in geobase.net.dll) Version: 4.84.0.0
Syntax
public class PolygonFence : IMapRenderer, 
	IGeoFence, ICollection<LatLon>, IEnumerable<LatLon>, 
	IEnumerable

The PolygonFence type exposes the following members.

Constructors
  NameDescription
Public methodPolygonFence
Construct a new, empty PolygonFence.
Top
Properties
  NameDescription
Public propertyBoundingBox
Gets the minimum BoundingBox for this GeoFence.
Public propertyCount
Gets the number of points that describe this GeoFence.
Public propertyIsFixedSize
Gets whether the PolygonFence is a fixed size. Always returns false.
Public propertyIsReadOnly
Gets whether the PolygonFence is read-only. Always returns false.
Public propertyIsSynchronized
If true, then this array is synchronized (thread-safe).
Public propertyItem
Enables the PolygonFence to be treated as an array of LatLons.
Public propertyPoints
Gets the LatLon points that make up this GeoFence.
Public propertyRenderBrush
Brush used to fill the internal area of this GeoFence, use null for no fill.
Public propertyRenderPen
Pen used to draw the border around the GeoFence, use null for no border.
Public propertyRequiredRendermodes
Gets the RenderMode required by this PolygonFence.
Public propertySyncRoot
Gets the SyncRoot to allow synchronized access to the array of points.
Top
Methods
  NameDescription
Public methodAdd
Add the specified point to this PolygonFence.
Public methodClear
Clears all points stored in this PolygonFence and clears the BoundingBox.
Public methodContains
Determine whether the specified point falls inside this PolygonFence.
Public methodCopyTo
Copy the array of points (of which this GeoFence is comprised) to a given array.
Public methodStatic memberCreateFromStreetLinks
Creates a GeoFence collection containing the street links provided.
Public methodEquals (Inherited from Object.)
Public methodGetEnumerator
Get an enumerator for iteration through the points describing the PolygonFence.
Public methodGetHashCode (Inherited from Object.)
Public methodGetObjectData
For serialization of the PolygonFence.
Public methodGetType (Inherited from Object.)
Public methodIndexOf
Searches the points that make up this GeoFence and returns the index of the point.
Public methodInsert
Inserts a new point to the GeoFence, at the specified index.
Public methodRecalculateBoundingBox
After points have been removed from a PolygonFence, the Bounding Box may be larger than is required to encompass the remaining points. This function recalculates a minimal bounding box that encompasses all the remaining points.
Public methodRemove
Removes a point from the GeoFence.
Public methodRemoveAt
Removes a point from a given index of the GeoFence.
Public methodRender
Renders this PolygonFence on the given IMap.
Public methodSnapToStreets
Create a new PolygonFence that includes only those streets that lie entirely within the area of this fence.
Public methodToString (Inherited from Object.)
Top
Remarks

It is not necessary to specify the start and end points to the same co-ordinates to ensure that a closed polygon is drawn. The FillPolygon(Brush, PointF) method will automatically close an open polygon by drawing a line between the start and end points.

Related articles: Geofences Concept.

Examples

The following example creates a large blue PolygonFence. When you create a PolygonFence you will typically set the opacity so that the PolygonFence is translucent (i.e. opacity << 1). This ensures that the map below the PolygonFence is still visible.

C#
PolygonFence pf = new PolygonFence();

// define the vertices of the polygon
pf.Add(new LatLon(33.1, -117.6));
pf.Add(new LatLon(33.8, -117.8));
pf.Add(new LatLon(33.5, -117.0));

// set the color and opacity of the polygon
pf.Opacity = 0.5;
pf.Fill = new SolidColorBrush(Colors.Blue);

// draw the PolygonFence as an item on a map
myMap.Items.Add(pf);

You can clear all the points from a PolygonFence using the PolygonFence.Clear() method.

C#
pf.Clear();

If you retain a reference to the PolygonFence you can add and remove it from a map as you wish.

C#
myMap.Items.Remove(pf); // no longer shown on map
...
myMap.Items.Add(pf); // show it on the map again

The exact same effect can be achieved in XAML code by placing the following code snippet inside a Map object.

XAML
<GeoFence:PolygonFence 
    x:Name="pf"
    Points="33.581,-117.726 33.588,-117.728 33.585,-117.730"
/>

Note that the points are latitude,longitude coordinates delimited by whitespace.

After you create a PolygonFence you'll often want to add it to a MapCtrl's RendererList so that the PolygonFence will be drawn on the map.
C#
PolygonFence fence = new PolygonFence();
myMapsRendererList.Add(fence);
This code snippet could be used in conjunction with a MapCtrl's mouse-click event to add a new vertex to the PolygonFence. Note that we redraw the map to reflect the changes made to the geofence.
C#
private void myMap_MouseClick(object sender, MouseEventArgs e)
{
    if (e.button == MouseButtons.Right)
        fence.Add(myMap.Map.XYtoLatLon(e.X, e.Y));

    myMap.Refresh();
}
The following code snippet could be used in conjunction with a mouse-move event to determine whether the cursor is inside or outside the geofence.
C#
private void myMap_MouseMove(object sender, MouseEventArgs e)
{
    if (fence.Contains(myMap.Map.XYtoLatLon(e.X, e.Y)) {
        // the mouse cursor is inside the PolygonFence
    }
    else {
        // the mouse cursor is *not* inside the PolygonFence
    }
}
See Also