PolygonFence Class |
Namespace: Telogis.GeoBase.GeoFence
The PolygonFence type exposes the following members.
Name | Description | |
---|---|---|
PolygonFence |
Construct a new, empty PolygonFence.
|
Name | Description | |
---|---|---|
BoundingBox |
Gets the minimum BoundingBox for this GeoFence.
| |
Count |
Gets the number of points that describe this GeoFence.
| |
IsFixedSize |
Gets whether the PolygonFence is a fixed size. Always returns false.
| |
IsReadOnly |
Gets whether the PolygonFence is read-only. Always returns false.
| |
IsSynchronized |
If true, then this array is synchronized (thread-safe).
| |
Item |
Enables the PolygonFence to be treated as an array of LatLons.
| |
Points |
Gets the LatLon points that make up this GeoFence.
| |
RenderBrush | Brush used to fill the internal area of this GeoFence,
use null for no fill.
| |
RenderPen | Pen used to draw the border around the GeoFence, use null for no border.
| |
RequiredRendermodes |
Gets the RenderMode required by this PolygonFence.
| |
SyncRoot |
Gets the SyncRoot to allow synchronized access to the array of points.
|
Name | Description | |
---|---|---|
Add |
Add the specified point to
this PolygonFence.
| |
Clear |
Clears all points stored in this PolygonFence and clears
the BoundingBox.
| |
Contains |
Determine whether the specified point falls inside this PolygonFence.
| |
CopyTo |
Copy the array of points (of which this GeoFence is comprised) to
a given array.
| |
CreateFromStreetLinks |
Creates a GeoFence collection containing the street links provided.
| |
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) | |
GetEnumerator |
Get an enumerator for iteration through the points describing the PolygonFence.
| |
GetHashCode | Serves as the default hash function. (Inherited from Object.) | |
GetObjectData |
For serialization of the PolygonFence.
| |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
IndexOf |
Searches the points that make up this GeoFence
and returns the index of the point.
| |
Insert |
Inserts a new point to the GeoFence, at the
specified index.
| |
RecalculateBoundingBox |
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.
| |
Remove |
Removes a point from the GeoFence.
| |
RemoveAt |
Removes a point from a given index of the GeoFence.
| |
Render |
Renders this PolygonFence on the given IMap.
| |
SnapToStreets |
Create a new PolygonFence that includes only those streets that
lie entirely within the area of this fence.
| |
ToString | Returns a string that represents the current object. (Inherited from Object.) |
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.
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.
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.
pf.Clear();
If you retain a reference to the PolygonFence you can add and remove it from a map as you wish.
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.
<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.PolygonFence fence = new PolygonFence();
myMapsRendererList.Add(fence);
private void myMap_MouseClick(object sender, MouseEventArgs e) { if (e.button == MouseButtons.Right) fence.Add(myMap.Map.XYtoLatLon(e.X, e.Y)); myMap.Refresh(); }
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 } }