forked from SharpMap/SharpMap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClipLabelPosition.cs
More file actions
39 lines (36 loc) · 1.36 KB
/
ClipLabelPosition.cs
File metadata and controls
39 lines (36 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
namespace ExampleCodeSnippets
{
/// <summary>
/// A clipping utility that ensures every geometry is labeled within the current map viewport
/// </summary>
public class ClipLabelPosition
{
private GeoAPI.Geometries.IGeometry _clip;
private GeoAPI.Geometries.Prepared.IPreparedGeometry _prepClip;
/// <summary>
/// Creates an instance of this class
/// </summary>
/// <param name="map">A map</param>
public ClipLabelPosition(SharpMap.Map map)
{
map.MapViewOnChange += () =>
{
_clip = map.Factory.ToGeometry(map.Envelope);
_prepClip = NetTopologySuite.Geometries.Prepared.PreparedGeometryFactory.Prepare(_clip);
};
}
/// <summary>
/// A <see cref="SharpMap.Layers.LabelLayer.GetLocationMethod"/> implementation that clips
/// a feature's geometry to the current viewport of the map
/// </summary>
/// <param name="row">A feature</param>
/// <returns>A label position</returns>
public GeoAPI.Geometries.Coordinate GetClippedPosition(SharpMap.Data.FeatureDataRow row)
{
var g = _prepClip.Contains(row.Geometry)
? row.Geometry
: _clip.Intersection(row.Geometry);
return g.InteriorPoint.Coordinate;
}
}
}