本文整理汇总了C#中IMap.WorldToImage方法的典型用法代码示例。如果您正苦于以下问题:C# IMap.WorldToImage方法的具体用法?C# IMap.WorldToImage怎么用?C# IMap.WorldToImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMap
的用法示例。
在下文中一共展示了IMap.WorldToImage方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CalculateLabelOnLinestring
private void CalculateLabelOnLinestring(ILineString line, ref SharpMap.Rendering.Label label, IMap map)
{
double dx, dy;
double tmpx, tmpy;
double angle = 0.0;
// first find the middle segment of the line
int midPoint = (line.Coordinates.Length - 1) / 2;
if (line.Coordinates.Length > 2)
{
dx = line.Coordinates[midPoint + 1].X - line.Coordinates[midPoint].X;
dy = line.Coordinates[midPoint + 1].Y - line.Coordinates[midPoint].Y;
}
else
{
midPoint = 0;
dx = line.Coordinates[1].X - line.Coordinates[0].X;
dy = line.Coordinates[1].Y - line.Coordinates[0].Y;
}
if (dy == 0)
label.Rotation = 0;
else if (dx == 0)
label.Rotation = 90;
else
{
// calculate angle of line
angle = -Math.Atan(dy / dx) + Math.PI * 0.5;
angle *= (180d / Math.PI); // convert radians to degrees
label.Rotation = (float)angle - 90; // -90 text orientation
}
tmpx = line.Coordinates[midPoint].X + (dx * 0.5);
tmpy = line.Coordinates[midPoint].Y + (dy * 0.5);
label.LabelPoint = map.WorldToImage(SharpMap.Converters.Geometries.GeometryFactory.CreateCoordinate(tmpx, tmpy));
}
示例2: CreateLabel
private SharpMap.Rendering.Label CreateLabel(IGeometry feature,string text, float rotation, ILabelStyle style, IMap map, System.Drawing.Graphics g)
{
System.Drawing.SizeF size = g.MeasureString(text, style.Font);
System.Drawing.PointF position = map.WorldToImage(feature.EnvelopeInternal.Centre);
position.X = position.X - size.Width * (short)style.HorizontalAlignment * 0.5f;
position.Y = position.Y - size.Height * (short)style.VerticalAlignment * 0.5f;
if (position.X-size.Width > map.Size.Width || position.X+size.Width < 0 ||
position.Y-size.Height > map.Size.Height || position.Y+size.Height < 0)
return null;
else
{
SharpMap.Rendering.Label lbl;
if (!style.CollisionDetection)
lbl = new SharpMap.Rendering.Label(text, position, rotation, this.Priority, null, style);
else
{
//Collision detection is enabled so we need to measure the size of the string
lbl = new SharpMap.Rendering.Label(text, position, rotation, this.Priority,
new SharpMap.Rendering.LabelBox(position.X - size.Width * 0.5f - style.CollisionBuffer.Width, position.Y + size.Height * 0.5f + style.CollisionBuffer.Height,
size.Width + 2f * style.CollisionBuffer.Width, size.Height + style.CollisionBuffer.Height * 2f), style);
}
if (feature.GetType() == typeof(ILineString))
{
ILineString line = feature as ILineString;
if (line.Length / map.PixelSize > size.Width) //Only label feature if it is long enough
CalculateLabelOnLinestring(line, ref lbl, map);
else
return null;
}
return lbl;
}
}