本文整理汇总了C#中Map.WorldToImage方法的典型用法代码示例。如果您正苦于以下问题:C# Map.WorldToImage方法的具体用法?C# Map.WorldToImage怎么用?C# Map.WorldToImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Map
的用法示例。
在下文中一共展示了Map.WorldToImage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateLabel
protected override SharpMap.Rendering.Label CreateLabel(SharpMap.Geometries.Geometry feature, string text, float rotation, SharpMap.Styles.LabelStyle style, Map map, System.Drawing.Graphics g)
{
//System.Drawing.SizeF size = g.MeasureString(text, style.Font);
System.Drawing.PointF position = map.WorldToImage(feature.GetBoundingBox().GetCentroid());
//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(SharpMap.Geometries.LineString))
{
SharpMap.Geometries.LineString line = feature as SharpMap.Geometries.LineString;
if (line.Length / map.PixelSize > 40/*size.Width*/) //Only label feature if it is long enough
CalculateLabelOnLinestring(line, ref lbl, map);
else
return null;
}
return lbl;
}
}
示例2: WorldToMap_DefaultMap_ReturnValue
public void WorldToMap_DefaultMap_ReturnValue()
{
var map = new Map(new Size(500, 200));
map.Center = GeometryFactory.CreateCoordinate(23, 34);
map.Zoom = 1000;
PointF p = map.WorldToImage(GeometryFactory.CreateCoordinate(8, 50));
Assert.AreEqual(new PointF(242f, 92), p);
}
示例3: WorldToImage
public void WorldToImage()
{
var map = new Map(new Size(1000, 500)) {Zoom = 360, Center = GeometryFactory.CreateCoordinate(0, 0)};
Assert.AreEqual(new PointF(500, 250), map.WorldToImage(GeometryFactory.CreateCoordinate(0, 0)));
Assert.AreEqual(new PointF(0, 0), map.WorldToImage(GeometryFactory.CreateCoordinate(-180, 90)));
Assert.AreEqual(new PointF(0, 500), map.WorldToImage(GeometryFactory.CreateCoordinate(-180, -90)));
Assert.AreEqual(new PointF(1000, 0), map.WorldToImage(GeometryFactory.CreateCoordinate(180, 90)));
Assert.AreEqual(new PointF(1000, 500), map.WorldToImage(GeometryFactory.CreateCoordinate(180, -90)));
}
示例4: GetPreview
protected virtual void GetPreview(Dataset dataset, Size size, Graphics g,
Envelope displayBbox, ProjectionInfo mapProjection, Map map)
#endif
{
DateTime drawStart = DateTime.Now;
double totalReadDataTime = 0;
double totalTimeSetPixel = 0;
if (!NeedRotation(dataset))
{
GetNonRotatedPreview(dataset, size, g, displayBbox, mapProjection);
return;
}
var geoTransform = new GeoTransform(dataset);
Bitmap bitmap = null;
var bitmapTl = new Point();
var bitmapSize = new Size();
const int pixelSize = 3; //Format24bppRgb = byte[b,g,r]
if (dataset != null)
{
//check if image is in bounding box
if ((displayBbox.MinX > _envelope.MaxX) || (displayBbox.MaxX < _envelope.MinX)
|| (displayBbox.MaxY < _envelope.MinY) || (displayBbox.MinY > _envelope.MaxY))
return;
// init histo
Histogram = new List<int[]>();
for (int i = 0; i < Bands + 1; i++)
Histogram.Add(new int[256]);
var trueImageBbox = displayBbox.Intersection(_envelope);
// put display bounds into current projection
Envelope shownImageBbox = trueImageBbox;
#if !DotSpatialProjections
if (ReverseCoordinateTransformation != null)
{
shownImageBbox = GeometryTransform.TransformBox(trueImageBbox, ReverseCoordinateTransformation.MathTransform);
}
#else
if (CoordinateTransformation != null)
{
shownImageBbox = GeometryTransform.TransformBox(trueImageBbox,
CoordinateTransformation.Target, CoordinateTransformation.Source);
}
#endif
// find min/max x and y pixels needed from image
var g2I = geoTransform.GroundToImage(shownImageBbox).Intersection(new Envelope(0, _imageSize.Width, 0, _imageSize.Height));
var gdalImageRect = ToRectangle(g2I);
var displayImageSize = gdalImageRect.Size;
// convert ground coordinates to map coordinates to figure out where to place the bitmap
var bitmapBr = new Point((int)map.WorldToImage(trueImageBbox.BottomRight()).X + 1,
(int)map.WorldToImage(trueImageBbox.BottomRight()).Y + 1);
bitmapTl = new Point((int)map.WorldToImage(trueImageBbox.TopLeft()).X,
(int)map.WorldToImage(trueImageBbox.TopLeft()).Y);
bitmapSize.Width = bitmapBr.X - bitmapTl.X;
bitmapSize.Height = bitmapBr.Y - bitmapTl.Y;
// check to see if image is on its side
if (bitmapSize.Width > bitmapSize.Height && displayImageSize.Width < displayImageSize.Height)
{
displayImageSize.Width = bitmapSize.Height;
displayImageSize.Height = bitmapSize.Width;
}
else
{
displayImageSize.Width = bitmapSize.Width;
displayImageSize.Height = bitmapSize.Height;
}
// scale
var bitScalar = GetBitScalar();
// 0 pixels in length or height, nothing to display
if (bitmapSize.Width < 1 || bitmapSize.Height < 1)
return;
//initialize bitmap
BitmapData bitmapData;
bitmap = InitializeBitmap(bitmapSize, PixelFormat.Format24bppRgb, out bitmapData);
try
{
unsafe
{
var cr = _noDataInitColor.R;
var cg = _noDataInitColor.G;
var cb = _noDataInitColor.B;
// create 3 dimensional buffer [band][x pixel][y pixel]
var buffer = new double[Bands][][];
for (int i = 0; i < Bands; i++)
//.........这里部分代码省略.........
示例5: DrawPoints
private void DrawPoints(Map map, IEnumerable<IFeature> features, Bitmap dot, Bitmap image)
{
var size = new Size(dot.Width, dot.Height);
foreach (var row in features)
{
var heatValue = HeatValueComputer(row);
if (heatValue <= 0) continue;
if (heatValue >= 1f) heatValue = 1;
var c = row.Geometry.PointOnSurface.Coordinate;
if (CoordinateTransformation != null)
{
#if !DotSpatialProjection
c = GeometryTransform.TransformCoordinate(c, CoordinateTransformation.MathTransform);
#else
c = GeometryTransform.TransformCoordinate(c, CoordinateTransformation.Source, CoordinateTransformation.Target);
#endif
}
var posF = map.WorldToImage(c);
var pos = Point.Round(posF);
//var pos = Point.Round(PointF.Subtract(posF, halfSize));
using (var tmpDot = ApplyHeatValueToImage(dot, heatValue))
{
ImageBlender.BlendImages(image, pos.X, pos.Y, size.Width, size.Height,
tmpDot, 0, 0, BlendOperation.BlendMultiply);
}
}
}
示例6: HandleMapNewTileAvaliable
static void HandleMapNewTileAvaliable(Map map, IGraphics g, Envelope box, Bitmap bm, int sourceWidth, int sourceHeight, ImageAttributes imageAttributes)
{
try
{
PointF min_f = map.WorldToImage(box.Min());
PointF max_f = map.WorldToImage(box.Max());
double minx = Math.Round(min_f.X);
double miny = Math.Round(min_f.Y);
double maxx = Math.Round(max_f.X);
double maxy = Math.Round(max_f.Y);
Point min = new Point(
Convert.ToInt32(minx),
Convert.ToInt32(miny));
Point max = new Point(
Convert.ToInt32(maxx),
Convert.ToInt32(maxy));
g.DrawImage(bm,
min.X, max.Y, max.X - min.X, min.Y - max.Y,
0, 0, sourceWidth, sourceHeight,
GraphicsUnitType.Pixel,
imageAttributes);
// g.Dispose();
}
catch (Exception ex)
{
Logger.Warn(ex.Message, ex);
//this can be a GDI+ Hell Exception...
}
}
示例7: GetPreview
protected virtual void GetPreview(Dataset dataset, Size size, Graphics g,
Envelope displayBbox, ProjectionInfo mapProjection, Map map)
#endif
{
if (!NeedRotation(dataset))
{
GetNonRotatedPreview(dataset, size, g, displayBbox, mapProjection);
return;
}
var geoTransform = new GeoTransform(dataset);
Bitmap bitmap = null;
var bitmapTL = new Point();
//Coordinate imageTL = new Coordinate(), imageBR = new Coordinate();
//int bitmapWidth, bitmapHeight;
var bitmapSize = new Size();
const int pixelSize = 3; //Format24bppRgb = byte[b,g,r]
if (dataset != null)
{
//check if image is in bounding box
if ((displayBbox.MinX > _envelope.MaxX) || (displayBbox.MaxX < _envelope.MinX)
|| (displayBbox.MaxY < _envelope.MinY) || (displayBbox.MinY > _envelope.MaxY))
return;
// init histo
Histogram = new List<int[]>();
for (int i = 0; i < Bands + 1; i++)
Histogram.Add(new int[256]);
// bounds of section of image to be displayed
//var left = Math.Max(displayBbox.MinX, _envelope.MinX);
//var top = Math.Min(displayBbox.MaxY, _envelope.MaxY);
//var right = Math.Min(displayBbox.MaxX, _envelope.MaxX);
//var bottom = Math.Max(displayBbox.MinY, _envelope.MinY);
var trueImageBbox = displayBbox.Intersection(_envelope);
// put display bounds into current projection
Envelope shownImageBbox;
if (Transform != null)
{
#if !DotSpatialProjections
Transform.MathTransform.Invert();
shownImageBbox = GeometryTransform.TransformBox(trueImageBbox, Transform.MathTransform);
Transform.MathTransform.Invert();
#else
shownImageBbox = GeometryTransform.TransformBox(trueImageBbox, _transform.Source, _transform.Target);
#endif
}
else
{
shownImageBbox = trueImageBbox;
}
// find min/max x and y pixels needed from image
var g2i = geoTransform.GroundToImage(shownImageBbox).Intersection(new Envelope(0, _imageSize.Width, 0, _imageSize.Height));
var gdalImageRect = ToRectangle(g2i);
var displayImageSize = gdalImageRect.Size;
//// find ground coordinates of image pixels
//var groundBR = geoTransform.ImageToGround(imageBR);
//var groundTL = geoTransform.ImageToGround(imageTL);
// convert ground coordinates to map coordinates to figure out where to place the bitmap
var bitmapBR = new Point((int)map.WorldToImage(trueImageBbox.BottomRight()).X + 1,
(int)map.WorldToImage(trueImageBbox.BottomRight()).Y + 1);
bitmapTL = new Point((int)map.WorldToImage(trueImageBbox.TopLeft()).X,
(int)map.WorldToImage(trueImageBbox.TopLeft()).Y);
bitmapSize.Width = bitmapBR.X - bitmapTL.X;
bitmapSize.Height = bitmapBR.Y - bitmapTL.Y;
// check to see if image is on its side
if (bitmapSize.Width > bitmapSize.Height && displayImageSize.Width < displayImageSize.Height)
{
displayImageSize.Width = bitmapSize.Height;
displayImageSize.Height = bitmapSize.Width;
}
else
{
displayImageSize.Width = bitmapSize.Width;
displayImageSize.Height = bitmapSize.Height;
}
// scale
var bitScalar = GetBitScalar();
// 0 pixels in length or height, nothing to display
if (bitmapSize.Width < 1 || bitmapSize.Height < 1)
return;
//initialize bitmap
BitmapData bitmapData;
bitmap = InitializeBitmap(bitmapSize, PixelFormat.Format24bppRgb, out bitmapData);
//.........这里部分代码省略.........
示例8: Render
/// <summary>
/// Renders the layer
/// </summary>
/// <param name="graphics">Graphics object reference</param>
/// <param name="map">Map which is rendered</param>
public override void Render(Graphics graphics, Map map)
{
if (!map.Size.IsEmpty && map.Size.Width > 0 && map.Size.Height > 0)
{
var bmp = new Bitmap(map.Size.Width, map.Size.Height, PixelFormat.Format32bppArgb);
using (var g = Graphics.FromImage(bmp))
{
g.InterpolationMode = InterpolationMode;
g.Transform = graphics.Transform.Clone();
var extent = new Extent(map.Envelope.MinX, map.Envelope.MinY,
map.Envelope.MaxX, map.Envelope.MaxY);
var level = BruTile.Utilities.GetNearestLevel(_source.Schema.Resolutions, map.PixelSize);
var tiles = new List<TileInfo>(_source.Schema.GetTilesInView(extent, level));
var tileWidth = _source.Schema.GetTileWidth(level);
var tileHeight = _source.Schema.GetTileWidth(level);
IList<WaitHandle> waitHandles = new List<WaitHandle>();
var toRender = new Dictionary<TileIndex, Bitmap>();
var takenFromCache = new Dictionary<TileIndex,bool>();
foreach (TileInfo info in tiles)
{
var image = _bitmaps.Find(info.Index);
if (image != null)
{
toRender.Add(info.Index, image);
takenFromCache.Add(info.Index,true);
continue;
}
if (_fileCache != null && _fileCache.Exists(info.Index))
{
_bitmaps.Add(info.Index, GetImageFromFileCache(info) as Bitmap);
toRender.Add(info.Index, _bitmaps.Find(info.Index));
takenFromCache.Add(info.Index,true);
continue;
}
var waitHandle = new AutoResetEvent(false);
waitHandles.Add(waitHandle);
ThreadPool.QueueUserWorkItem(GetTileOnThread,
new object[] { _source.Provider, info, toRender, waitHandle, true });
}
foreach (var handle in waitHandles)
handle.WaitOne();
using (var ia = new ImageAttributes())
{
if (!_transparentColor.IsEmpty)
ia.SetColorKey(_transparentColor, _transparentColor);
#if !PocketPC
ia.SetWrapMode(WrapMode.TileFlipXY);
#endif
foreach (var info in tiles)
{
if (!toRender.ContainsKey(info.Index))
continue;
var bitmap = toRender[info.Index];//_bitmaps.Find(info.Index);
if (bitmap == null) continue;
var min = map.WorldToImage(new Coordinate(info.Extent.MinX, info.Extent.MinY));
var max = map.WorldToImage(new Coordinate(info.Extent.MaxX, info.Extent.MaxY));
min = new PointF((float) Math.Round(min.X), (float) Math.Round(min.Y));
max = new PointF((float) Math.Round(max.X), (float) Math.Round(max.Y));
try
{
g.DrawImage(bitmap,
new Rectangle((int) min.X, (int) max.Y, (int) (max.X - min.X),
(int) (min.Y - max.Y)),
0, 0, tileWidth, tileHeight,
GraphicsUnit.Pixel,
ia);
}
catch (Exception ee)
{
Logger.Error(ee.Message);
}
}
}
//Add rendered tiles to cache
foreach (var kvp in toRender)
{
if (takenFromCache.ContainsKey(kvp.Key) && !takenFromCache[kvp.Key])
{
_bitmaps.Add(kvp.Key, kvp.Value);
}
}
//.........这里部分代码省略.........
示例9: CreateLabel
private static BaseLabel CreateLabel(FeatureDataRow fdr, Geometry feature, string text, float rotation, int priority, LabelStyle style, Map map, Graphics g, GetLocationMethod _getLocationMethod)
{
BaseLabel lbl = null;
SizeF size = VectorRenderer.SizeOfString(g, text, style.Font);
if (feature is ILineal)
{
var line = feature as LineString;
if (line != null)
{
if (style.IsTextOnPath == false)
{
if (size.Width < 0.95 * line.Length / map.PixelWidth || style.IgnoreLength)
{
var positiveLineString = PositiveLineString(line, false);
var lineStringPath = LineStringToPath(positiveLineString, map /*, false*/);
var rect = lineStringPath.GetBounds();
if (style.CollisionDetection && !style.CollisionBuffer.IsEmpty)
{
var cbx = style.CollisionBuffer.Width;
var cby = style.CollisionBuffer.Height;
rect.Inflate(2 * cbx, 2 * cby);
rect.Offset(-cbx, -cby);
}
var labelBox = new LabelBox(rect);
lbl = new PathLabel(text, lineStringPath, 0, priority, labelBox, style);
}
}
else
{
//get centriod
System.Drawing.PointF position2 = map.WorldToImage(feature.GetBoundingBox().GetCentroid());
lbl = new Label(text, position2, rotation, priority, style);
if (size.Width < 0.95 * line.Length / map.PixelWidth || !style.IgnoreLength)
{
CalculateLabelAroundOnLineString(line, ref lbl, map, g, size);
}
}
}
return lbl;
}
PointF position = Transform.WorldtoMap(feature.GetBoundingBox().GetCentroid(), map);
if (_getLocationMethod != null)
{
Point p = _getLocationMethod(fdr);
if (p !=null)
position = Transform.WorldtoMap(p, map);
}
position.X = position.X - size.Width*(short) style.HorizontalAlignment*0.5f;
position.Y = position.Y - size.Height*(short) (2-(int)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;
if (!style.CollisionDetection)
lbl = new Label(text, position, rotation, priority, null, style);
else
{
//Collision detection is enabled so we need to measure the size of the string
lbl = new Label(text, position, rotation, priority,
new 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 is LineString)
{
var line = feature as LineString;
//Only label feature if it is long enough, or it is definately wanted
if (line.Length / map.PixelSize > size.Width || style.IgnoreLength)
{
CalculateLabelOnLinestring(line, ref lbl, map);
}
else
return null;
}
*/
return lbl;
}
示例10: GetPreview
// add image pixels to the map
protected virtual void GetPreview(Dataset dataset, System.Drawing.Size size, System.Drawing.Graphics g,
BoundingBox displayBbox, ICoordinateSystem mapProjection, Map map)
{
double[] geoTrans = new double[6];
_GdalDataset.GetGeoTransform(geoTrans);
// not rotated, use faster display method
if ((!_useRotation || (geoTrans[1] == 1 && geoTrans[2] == 0 && geoTrans[4] == 0 && Math.Abs(geoTrans[5]) == 1))
&& !_haveSpot && _transform == null)
{
GetNonRotatedPreview(dataset, size, g, displayBbox, mapProjection);
return;
}
// not rotated, but has spot...need default rotation
else if ((geoTrans[0] == 0 && geoTrans[3] == 0) && _haveSpot)
geoTrans = new double[] { 999.5, 1, 0, 1000.5, 0, -1 };
GT = new GeoTransform(geoTrans);
double DsWidth = _imagesize.Width;
double DsHeight = _imagesize.Height;
double left, top, right, bottom;
double GndX = 0, GndY = 0, ImgX = 0, ImgY = 0, PixX, PixY;
double[] intVal = new double[Bands];
double imageVal = 0, SpotVal = 0;
double bitScalar = 1.0;
Bitmap bitmap = null;
GdiPoint bitmapTL = new GdiPoint(), bitmapBR = new GdiPoint();
SMPoint imageTL = new SMPoint(), imageBR = new SMPoint();
BoundingBox shownImageBbox, trueImageBbox;
int bitmapLength, bitmapHeight;
int displayImageLength, displayImageHeight;
int iPixelSize = 3; //Format24bppRgb = byte[b,g,r]
if (dataset != null)
{
//check if image is in bounding box
if ((displayBbox.Left > _Envelope.Right) || (displayBbox.Right < _Envelope.Left)
|| (displayBbox.Top < _Envelope.Bottom) || (displayBbox.Bottom > _Envelope.Top))
return;
// init histo
_histogram = new List<int[]>();
for (int i = 0; i < _lbands + 1; i++)
_histogram.Add(new int[256]);
// bounds of section of image to be displayed
left = Math.Max(displayBbox.Left, _Envelope.Left);
top = Math.Min(displayBbox.Top, _Envelope.Top);
right = Math.Min(displayBbox.Right, _Envelope.Right);
bottom = Math.Max(displayBbox.Bottom, _Envelope.Bottom);
trueImageBbox = new BoundingBox(left, bottom, right, top);
// put display bounds into current projection
if (_transform != null)
shownImageBbox = GeometryTransform.TransformBox(trueImageBbox, _transform.MathTransform.Inverse());
else
shownImageBbox = trueImageBbox;
// find min/max x and y pixels needed from image
imageBR.X = (int)(Math.Max(GT.GroundToImage(shownImageBbox.TopLeft).X, Math.Max(GT.GroundToImage(shownImageBbox.TopRight).X,
Math.Max(GT.GroundToImage(shownImageBbox.BottomLeft).X, GT.GroundToImage(shownImageBbox.BottomRight).X))) + 1);
imageBR.Y = (int)(Math.Max(GT.GroundToImage(shownImageBbox.TopLeft).Y, Math.Max(GT.GroundToImage(shownImageBbox.TopRight).Y,
Math.Max(GT.GroundToImage(shownImageBbox.BottomLeft).Y, GT.GroundToImage(shownImageBbox.BottomRight).Y))) + 1);
imageTL.X = (int)Math.Min(GT.GroundToImage(shownImageBbox.TopLeft).X, Math.Min(GT.GroundToImage(shownImageBbox.TopRight).X,
Math.Min(GT.GroundToImage(shownImageBbox.BottomLeft).X, GT.GroundToImage(shownImageBbox.BottomRight).X)));
imageTL.Y = (int)Math.Min(GT.GroundToImage(shownImageBbox.TopLeft).Y, Math.Min(GT.GroundToImage(shownImageBbox.TopRight).Y,
Math.Min(GT.GroundToImage(shownImageBbox.BottomLeft).Y, GT.GroundToImage(shownImageBbox.BottomRight).Y)));
// stay within image
if (imageBR.X > _imagesize.Width)
imageBR.X = _imagesize.Width;
if (imageBR.Y > _imagesize.Height)
imageBR.Y = _imagesize.Height;
if (imageTL.Y < 0)
imageTL.Y = 0;
if (imageTL.X < 0)
imageTL.X = 0;
displayImageLength = (int)(imageBR.X - imageTL.X);
displayImageHeight = (int)(imageBR.Y - imageTL.Y);
// find ground coordinates of image pixels
SMPoint groundBR = GT.ImageToGround(imageBR);
SMPoint groundTL = GT.ImageToGround(imageTL);
// convert ground coordinates to map coordinates to figure out where to place the bitmap
bitmapBR = new GdiPoint((int)map.WorldToImage(trueImageBbox.BottomRight).X + 1, (int)map.WorldToImage(trueImageBbox.BottomRight).Y + 1);
bitmapTL = new GdiPoint((int)map.WorldToImage(trueImageBbox.TopLeft).X, (int)map.WorldToImage(trueImageBbox.TopLeft).Y);
bitmapLength = bitmapBR.X - bitmapTL.X;
bitmapHeight = bitmapBR.Y - bitmapTL.Y;
// check to see if image is on its side
if (bitmapLength > bitmapHeight && displayImageLength < displayImageHeight)
{
displayImageLength = bitmapHeight;
displayImageHeight = bitmapLength;
//.........这里部分代码省略.........
示例11: HandleMapNewTileAvaliable
static void HandleMapNewTileAvaliable(Map map, Graphics g, Envelope box, Bitmap bm, int sourceWidth, int sourceHeight, ImageAttributes imageAttributes)
{
try
{
var min = map.WorldToImage(box.Min());
var max = map.WorldToImage(box.Max());
min = new PointF((float)Math.Round(min.X), (float)Math.Round(min.Y));
max = new PointF((float)Math.Round(max.X), (float)Math.Round(max.Y));
g.DrawImage(bm,
new Rectangle((int)min.X, (int)max.Y, (int)(max.X - min.X), (int)(min.Y - max.Y)),
0, 0,
sourceWidth, sourceHeight,
GraphicsUnit.Pixel,
imageAttributes);
// g.Dispose();
}
catch (Exception ex)
{
Logger.Warn(ex.Message, ex);
//this can be a GDI+ Hell Exception...
}
}
示例12: Render
/// <summary>
/// Method to render the layer
/// </summary>
/// <param name="g">The graphics object</param>
/// <param name="map">The map</param>
public override void Render(Graphics g, Map map)
{
if (!Enabled)
{
DisplayPictureBoxes(false);
return;
}
var env = this.ToSource(map.Envelope);
_provider.Open();
var points = _provider.GetObjectIDsInView(env);
var validBoxes = new HashSet<uint>();
Monitor.Enter(_renderLock);
if (points != null && points.Count > 0)
{
_mapBox.Invoke(new MethodInvoker(() => _mapBox.SuspendLayout()));
var gif = (Bitmap)_animatedGif.Clone();
var gifSize = gif.Size;
gif.SelectActiveFrame(FrameDimension.Page, 0);
foreach (var oid in points)
{
if (!_pictureBoxes.ContainsKey(oid))
{
//var pic = new PictureBox {Image = _animatedGif, AutoSize = true, Name = string.Format("smpic{0}", oid)};
//new MethodInvoker(() =>_mapBox.Controls.Add(pic)).Invoke();
var oid1 = oid;
var ctname = string.Format("smpic{0}", oid1);
_mapBox.Invoke(
new MethodInvoker(delegate
{
var pic = new TransparentPicBox
{
Image = (Image) _animatedGif.Clone(),
AutoSize = true,
Name = ctname
, Size = _animatedGif.Size
, BackColor = Color.Transparent
};
//((Bitmap)pic).MakeTransparent(Color.Black);
_mapBox.Controls.Add(pic);
}));
//Thread.Sleep(5);
_pictureBoxes.Add(oid, (PictureBox) _mapBox.Controls[ctname]);
}
var point = this.ToTarget(_provider.GetGeometryByID(oid), map.Factory).Coordinate;
var np = Point.Subtract(Point.Truncate(map.WorldToImage(point)), gifSize);
// Draw on the map
g.DrawImageUnscaled(gif, new Rectangle(np, gifSize));
var picbox = _pictureBoxes[oid];
_mapBox.Invoke(new MethodInvoker(delegate
{
picbox.Location = np;
picbox.Visible = true;
}
));
validBoxes.Add(oid);
}
}
// Close the connection
_provider.Close();
// Disable pictureboxes that are not in viewport
foreach (var picbox in _pictureBoxes)
{
if (!validBoxes.Contains(picbox.Key))
{
var p = picbox.Value;
_mapBox.Invoke(new MethodInvoker(() => p.Visible = false));
}
}
_mapBox.Invoke(new MethodInvoker(() => _mapBox.ResumeLayout()));
Monitor.Exit(_renderLock);
base.Render(g, map);
}
示例13: CalculateLabelOnLinestring
//private static LineString ReverseLineString(LineString clippedLineString)
//{
// var coords = new Stack<Point>(clippedLineString.Vertices);
// return new LineString(coords.ToArray());
//}
///// <summary>
///// Function to transform a linestring to a graphics path for further processing
///// </summary>
///// <param name="multiLineString">The Linestring</param>
///// <param name="map">The map</param>
///// <param name="useClipping">A value indicating whether clipping should be applied or not</param>
///// <returns>A GraphicsPath</returns>
//public static GraphicsPath MultiLineStringToPath(MultiLineString multiLineString, Map map, bool useClipping)
//{
// var gp = new GraphicsPath(FillMode.Alternate);
// foreach (var lineString in multiLineString.LineStrings)
// gp.AddPath(LineStringToPath(lineString, map, useClipping), false);
// return gp;
//}
//private static GraphicsPath LineToGraphicsPath(LineString line, Map map)
//{
// GraphicsPath path = new GraphicsPath();
// path.AddLines(line.TransformToImage(map));
// return path;
//}
private static void CalculateLabelOnLinestring(ILineString line, ref BaseLabel baseLabel, Map map)
{
double dx, dy;
var label = baseLabel as Label;
// first find the middle segment of the line
var vertices = line.Coordinates;
int midPoint = (vertices.Length - 1)/2;
if (vertices.Length > 2)
{
dx = vertices[midPoint + 1].X - vertices[midPoint].X;
dy = vertices[midPoint + 1].Y - vertices[midPoint].Y;
}
else
{
midPoint = 0;
dx = vertices[1].X - vertices[0].X;
dy = vertices[1].Y - vertices[0].Y;
}
if (dy == 0)
label.Rotation = 0;
else if (dx == 0)
label.Rotation = 90;
else
{
// calculate angle of line
double 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
}
var tmpx = vertices[midPoint].X + (dx*0.5);
var tmpy = vertices[midPoint].Y + (dy*0.5);
label.Location = map.WorldToImage(new Coordinate(tmpx, tmpy));
}
示例14: Render
/// <summary>
/// Renders the layer
/// </summary>
/// <param name="g">Graphics object reference</param>
/// <param name="map">Map which is rendered</param>
public override void Render(Graphics g, Map map)
{
if (map.Center == null)
throw (new ApplicationException("Cannot render map. View center not specified"));
if (_image == null)
throw new Exception("Image not set");
// Style enabled?
var doRender = Style.Enabled;
// Valid for this zoom
if (map.Zoom < Style.MinVisible || Style.MaxVisible < map.Zoom)
doRender = false;
// View to render
var mapView = map.Envelope;
// Layer view
var lyrView = _envelope;
// Get the view intersection
var vi = mapView.Intersection(lyrView);
if (doRender && !vi.IsNull)
{
// Image part
// ReSharper disable InconsistentNaming
var imgLT = Clip(_worldFile.ToRaster(new Coordinate(vi.MinX, vi.MaxY)));
var imgRB = Clip(_worldFile.ToRaster(new Coordinate(vi.MaxX, vi.MinY)));
var imgRect = new Rectangle(imgLT, PointDiff(imgLT, imgRB, 1));
// Map Part
var mapLT = Point.Truncate(map.WorldToImage(new Coordinate(vi.MinX, vi.MaxY)));
var mapRB = Point.Ceiling(map.WorldToImage(new Coordinate(vi.MaxX, vi.MinY)));
var mapRect = new Rectangle(mapLT, PointDiff(mapLT, mapRB, 1));
// ReSharper restore InconsistentNaming
// Set the interpolation mode
var tmpInterpolationMode = g.InterpolationMode;
g.InterpolationMode = InterpolationMode;
// Render the image
using (var ia = new ImageAttributes())
{
ia.SetColorMatrix(new ColorMatrix { Matrix44 = 1 - Transparency },
ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
g.DrawImage(_image, mapRect, imgRect.X, imgRect.Y, imgRect.Width, imgRect.Height,
GraphicsUnit.Pixel, ia);
}
// reset the interpolation mode
g.InterpolationMode = tmpInterpolationMode;
}
base.Render(g, map);
}
示例15: CalculateLabelAroundOnLineString
private static void CalculateLabelAroundOnLineString(SharpMap.Geometries.LineString line, ref BaseLabel label, Map map, System.Drawing.Graphics g, System.Drawing.SizeF textSize)
{
IList<SharpMap.Geometries.Point> sPoints = line.Vertices;
// only get point in enverlop of map
Collection<System.Drawing.PointF> colPoint = new Collection<System.Drawing.PointF>();
bool bCheckStarted = false;
for (int j = 0; j < sPoints.Count; j++)
{
if (map.Envelope.Grow(map.PixelSize * 10).Contains(sPoints[j]))
{
//points[j] = map.WorldToImage(sPoints[j]);
colPoint.Add(map.WorldToImage(sPoints[j]));
bCheckStarted = true;
}
else if (bCheckStarted == true)
{
// fix bug curved line out of map in center segment of line
break;
}
}
if (colPoint.Count > 1)
{
label.TextOnPathLabel = new SharpMap.Rendering.TextOnPath();
switch (label.Style.HorizontalAlignment)
{
case SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Left:
label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Left;
break;
case SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Right:
label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Right;
break;
case SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Center:
label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Center;
break;
default:
label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Center;
break;
}
switch (label.Style.VerticalAlignment)
{
case SharpMap.Styles.LabelStyle.VerticalAlignmentEnum.Bottom:
label.TextOnPathLabel.TextPathPathPosition = SharpMap.Rendering.TextPathPosition.UnderPath;
break;
case SharpMap.Styles.LabelStyle.VerticalAlignmentEnum.Top:
label.TextOnPathLabel.TextPathPathPosition = SharpMap.Rendering.TextPathPosition.OverPath;
break;
case SharpMap.Styles.LabelStyle.VerticalAlignmentEnum.Middle:
label.TextOnPathLabel.TextPathPathPosition = SharpMap.Rendering.TextPathPosition.CenterPath;
break;
default:
label.TextOnPathLabel.TextPathPathPosition = SharpMap.Rendering.TextPathPosition.CenterPath;
break;
}
int idxStartPath = 0;
int numberPoint = colPoint.Count;
// start Optimzes Path points
int step = 100;
if (colPoint.Count >= step * 2)
{
numberPoint = step * 2; ;
switch (label.Style.HorizontalAlignment)
{
case SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Left:
//label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Left;
idxStartPath = 0;
break;
case SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Right:
//label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Right;
idxStartPath = colPoint.Count - step;
break;
case SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Center:
//label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Center;
idxStartPath = (int)colPoint.Count / 2 - step;
break;
default:
//label.TextOnPathLabel.TextPathAlignTop = SharpMap.Rendering.TextPathAlign.Center;
idxStartPath = (int)colPoint.Count / 2 - step;
break;
}
}
// end optimize path point
System.Drawing.PointF[] points = new System.Drawing.PointF[numberPoint];
int count = 0;
if (colPoint[0].X <= colPoint[colPoint.Count - 1].X)
{
for (int l = idxStartPath; l < numberPoint + idxStartPath; l++)
{
points[count] = colPoint[l];
count++;
}
}
else
{
//reverse the path
for (int k = numberPoint - 1 + idxStartPath; k >= idxStartPath; k--)
{
points[count] = colPoint[k];
count++;
//.........这里部分代码省略.........