Updates with rendering of labels · SharpMap/SharpMap.DeltaShell@b7898c7 · GitHub
Skip to content

Commit b7898c7

Browse files
committed
Updates with rendering of labels
1 parent 52ee665 commit b7898c7

7 files changed

Lines changed: 196 additions & 31 deletions

File tree

src/Common/SharpMap/Layers/LabelLayer.cs

Lines changed: 16 additions & 7 deletions

src/Common/SharpMap/Layers/Layer.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
using SharpMap.Rendering.Thematics;
4141
using SharpMap.Styles;
4242
using log4net;
43+
using SharpMap.Utilities;
4344

4445
namespace SharpMap.Layers
4546
{
@@ -455,7 +456,7 @@ private void BuildQuadTree()
455456
geometrys[i] = g;
456457
}
457458

458-
var rectangleF = new RectangleF((float)envelope.MinX, (float)envelope.MinY, (float)envelope.Width, (float)envelope.Height);
459+
var rectangleF = envelope.ToRectangleF(); //new RectangleF((float)envelope.MinX, (float)envelope.MinY, (float)envelope.Width, (float)envelope.Height);
459460

460461
tree = new QuadTree(rectangleF, maxLevels, isPoint);
461462

@@ -499,7 +500,8 @@ private void BuildQuadTree()
499500

500501
private RectangleF ToRectangleF(Envelope envelope)
501502
{
502-
return new RectangleF((float)envelope.MinX, (float)envelope.MinY, (float)envelope.Width, (float)envelope.Height);
503+
return envelope.ToRectangleF();
504+
//return new RectangleF((float)envelope.MinX, (float)envelope.MinY, (float)envelope.Width, (float)envelope.Height);
503505
}
504506

505507
#region debugging

src/Common/SharpMap/Rendering/Label.cs

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1717

1818
using System;
19+
using System.CodeDom;
1920
using System.Collections.Generic;
21+
using System.Drawing;
22+
using QuickGraph;
2023
using SharpMap.Api;
2124

2225

@@ -135,13 +138,11 @@ public bool Intersects(LabelBox box)
135138
/// <returns>0 if the intersect</returns>
136139
public int CompareTo(LabelBox other)
137140
{
138-
if (this.Intersects(other))
141+
if (Intersects(other))
139142
return 0;
140-
else if (other.Left > this.Left+this.Width ||
141-
other.Top - other.Height > this.Top)
143+
if (other.Left > Right || other.Bottom > Top)
142144
return 1;
143-
else
144-
return -1;
145+
return -1;
145146
}
146147

147148
#endregion
@@ -259,26 +260,49 @@ public int CompareTo(Label other)
259260
{
260261
if (this == other)
261262
return 0;
262-
else if (box == null)
263-
return -1;
264-
else if (other.Box == null)
265-
return 1;
266-
else
267-
return box.CompareTo(other.Box);
263+
if (box == null)
264+
return other.box == null
265+
? ComparePoints(labelPoint, other.LabelPoint)
266+
: ComparePointToBox(labelPoint, other.Box);
267+
if (other.Box == null)
268+
return ComparePointToBox(other.LabelPoint, Box);
269+
270+
return box.CompareTo(other.Box);
268271
}
269272

270273
#endregion
271274

272-
273-
#region IComparer<Label> Members
274-
275-
/// <summary>
276-
/// Checks if two labels intersect
277-
/// </summary>
278-
/// <param name="x"></param>
279-
/// <param name="y"></param>
280-
/// <returns></returns>
281-
public int Compare(Label x, Label y)
275+
private static int ComparePoints(PointF pt1, PointF pt2)
276+
{
277+
if (pt1 == pt2)
278+
return 0;
279+
280+
int res = pt1.X.CompareTo(pt2.X);
281+
if (res != 0) return res;
282+
return pt1.Y.CompareTo(pt2.Y);
283+
}
284+
private static int ComparePointToBox(PointF pt, LabelBox box)
285+
{
286+
//if (box.Left <= pt.X && pt.X <= box.Right &&
287+
// box.Bottom <= pt.Y && pt.Y <= box.Top) return 0;
288+
289+
if (pt.X < box.Left) return -1;
290+
if (pt.X > box.Right) return 1;
291+
if (pt.Y < box.Bottom) return -1;
292+
if (pt.Y > box.Top) return 1;
293+
294+
return 0;
295+
}
296+
297+
#region IComparer<Label> Members
298+
299+
/// <summary>
300+
/// Checks if two labels intersect
301+
/// </summary>
302+
/// <param name="x"></param>
303+
/// <param name="y"></param>
304+
/// <returns></returns>
305+
public int Compare(Label x, Label y)
282306
{
283307
return x.CompareTo(y);
284308
}

src/Common/SharpMap/Rendering/LabelCollisionDetection.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ public static void SimpleCollisionDetection(List<SharpMap.Rendering.Label> label
5555
/// <param name="labels"></param>
5656
public static void ThoroughCollisionDetection(List<SharpMap.Rendering.Label> labels)
5757
{
58-
labels.Sort(); // sort labels by intersectiontests of labelbox
58+
try {
59+
labels.Sort(); // sort labels by intersectiontests of labelbox
60+
}
61+
finally{}
5962
//remove labels that intersect other labels
6063
for (int i = labels.Count - 1; i > 0; i--)
6164
for (int j = i - 1; j > 0; j--)

src/Common/SharpMap/SharpMap.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@
272272
<Compile Include="Styles\Style.cs" />
273273
<Compile Include="Styles\VectorStyle.cs" />
274274
<Compile Include="Utilities\Algorithms.cs" />
275+
<Compile Include="Utilities\RectangleUtility.cs" />
275276
<Compile Include="Utilities\RegularGridGeoTransform.cs" />
276277
<Compile Include="Utilities\Indexing\BinaryTree.cs" />
277278
<Compile Include="Utilities\Indexing\SpatialIndexing.cs" />

src/Common/SharpMap/Styles/VectorStyle.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,8 @@ public override object Clone()
349349
vectorStyle.UpdateSymbols();
350350
}
351351

352+
vectorStyle.Enabled = Enabled;
353+
352354
return vectorStyle;
353355
}
354356

Lines changed: 124 additions & 0 deletions

0 commit comments

Comments
 (0)