本文整理汇总了C#中SharpMap.Map.GetMap方法的典型用法代码示例。如果您正苦于以下问题:C# Map.GetMap方法的具体用法?C# Map.GetMap怎么用?C# Map.GetMap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SharpMap.Map
的用法示例。
在下文中一共展示了Map.GetMap方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MagnifierTool
/// <summary>
/// Creates an instance of this class
/// </summary>
public MagnifierTool(MapBox parentMapBox)
: base("Magnifier", "A tool to magnify the portion of the map below the cursor")
{
_parentMapBox = parentMapBox;
_parentMapBox.MapChanged += HandleMapChanged;
Map = _parentMapBox.Map;
MagnificationFactor = 1.10;
Offset = new Size(5,5);
_magnified = new PictureBox();
_magnified.Size = new Size(75, 75);
_magnified.BorderStyle = BorderStyle.FixedSingle;
_magnified.Visible = false;
_parentMapBox.Controls.Add(_magnified);
Map = _parentMapBox.Map;
_map = Map.Clone();
_map.Size = _magnified.Size;
_map.Zoom = _map.Size.Width*(Map.Envelope.Width/Map.Size.Width) / _magnification;
_map.Center = _map.Center;
_magnified.Image = _map.GetMap();
Enabled = true;
var ms = Assembly.GetExecutingAssembly().GetManifestResourceStream("WinFormSamples.Magnifier.cur");
if (ms != null)
Cursor = new Cursor(ms);
}
示例2: TestMaps
private static void TestMaps(string name, Map m, Map mD)
{
Assert.NotNull(mD);
Assert.AreEqual(m.Size, mD.Size);
Assert.AreEqual(m.Layers.Count, mD.Layers.Count);
var c = new LayerTest.VectorLayerEqualityComparer();
for (var i = 0; i < m.Layers.Count; i++)
{
Assert.IsTrue(c.Equals((VectorLayer)m.Layers[i],
(VectorLayer)mD.Layers[i]),
"Layer {0}, '{1}' Differs at {2}",
i, m.Layers[i].LayerName, string.Join(", ", c.DifferAt));
}
Assert.AreEqual(m.PixelAspectRatio, mD.PixelAspectRatio);
Assert.AreEqual(m.PixelHeight, mD.PixelHeight);
Assert.AreEqual(m.PixelWidth, mD.PixelWidth);
Assert.AreEqual(m.PixelSize, mD.PixelSize);
Assert.AreEqual(m.BackColor, mD.BackColor);
Assert.IsTrue(m.Center.Equals(mD.Center));
Assert.IsTrue(m.GetExtents().Equals(mD.GetExtents()));
Assert.IsTrue(m.Envelope.Equals(mD.Envelope));
Assert.AreEqual(m.Decorations.Count, mD.Decorations.Count);
Assert.AreEqual(m.SRID, mD.SRID);
Assert.AreEqual(m.Zoom, mD.Zoom);
Assert.DoesNotThrow(() => m.GetMap().Save(name + "-S.bmp"));
Assert.DoesNotThrow(() => mD.GetMap().Save(name + "-D.bmp"));
}
示例3: TestPlainPolygonSymbolizer
public void TestPlainPolygonSymbolizer()
{
ShapeFile provider = new ShapeFile(
"..\\..\\..\\WinFormSamples\\GeoData\\World\\countries.shp", true);
PolygonalVectorLayer l = new PolygonalVectorLayer("Countries", provider);
l.Symbolizer = new ModifiedBasicPolygonSymbolizer
{
Fill = new HatchBrush(
HatchStyle.WideDownwardDiagonal,
Color.Red /*,
System.Drawing.Color.LightPink*/),
UseClipping = false,
//Outline = System.Drawing.Pens.AliceBlue
};
Map m = new Map(new Size(1440, 1080)) { BackColor = Color.Cornsilk };
m.Layers.Add(l);
m.ZoomToExtents();
Stopwatch sw = new Stopwatch();
Image img = m.GetMap();
sw.Start();
img = m.GetMap();
img.Save("PolygonSymbolizer-1.bmp", ImageFormat.Bmp);
sw.Stop();
Console.WriteLine(string.Format("Rendering new method:{0}ms", sw.ElapsedMilliseconds));
l.Symbolizer = new BasicPolygonSymbolizer()
{
Fill = new HatchBrush(
HatchStyle.WideDownwardDiagonal,
Color.Red/*,
System.Drawing.Color.LightPink*/),
UseClipping = false,
//Outline = System.Drawing.Pens.AliceBlue
};
sw.Reset(); sw.Start();
img = m.GetMap();
img.Save("PolygonSymbolizer-2.bmp", ImageFormat.Bmp);
sw.Stop();
Console.WriteLine(string.Format("Rendering new method:{0}ms", sw.ElapsedMilliseconds));
}
示例4: TestMapDecorationTest
public void TestMapDecorationTest()
{
var m = new Map(new Size(780, 540)) {BackColor = Color.White};
var p = new GeometryProvider(new List<SharpMap.Geometries.Geometry>());
var pts = new [] {new GeoPoint(0, 0), new GeoPoint(779, 539)};
var ls = new SharpMap.Geometries.LineString(new List<GeoPoint>(pts));
p.Geometries.Add(ls);
m.Layers.Add(new VectorLayer("t",p));
m.ZoomToExtents();
m.Decorations.Add(new TestDecoration
{
Anchor = MapDecorationAnchor.LeftTop,
BorderColor = Color.Green,
BackgroundColor = Color.LightGreen,
BorderWidth = 2,
Location = new Point(10, 10),
BorderMargin = new Size(5, 5),
RoundedEdges = true,
Opacity = 0.6f
});
m.Decorations.Add(new TestDecoration
{
Anchor = MapDecorationAnchor.RightTop,
BorderColor = Color.Red,
BackgroundColor = Color.LightCoral,
BorderWidth = 2,
Location = new Point(10, 10),
BorderMargin = new Size(5, 5),
RoundedEdges = true,
Opacity = 0.2f
});
m.Decorations.Add(new ScaleBar
{
Anchor = MapDecorationAnchor.Default,
BorderColor = Color.Blue,
BackgroundColor = Color.CornflowerBlue,
BorderWidth = 2,
Location = new Point(10, 10),
BorderMargin = new Size(5, 5),
RoundedEdges = true,
BarWidth = 4,
ScaleText =ScaleBarLabelText.RepresentativeFraction,
NumTicks = 2,
Opacity = 1f
});
var bmp = m.GetMap();
bmp.Save("TestMapDecorationTest.bmp");
}
示例5: TestBasicLineSymbolizer
public void TestBasicLineSymbolizer()
{
ShapeFile p = new ShapeFile(@"d:\\daten\GeoFabrik\\roads.shp", false);
VectorLayer l = new VectorLayer("roads", p);
//l.Style.Outline = new System.Drawing.Pen(System.Drawing.Color.Firebrick, 5);
l.Style.Line = new Pen(Color.Gold, 1);
l.Style.EnableOutline = false;
Map m = new Map(new Size(1440, 1080)) { BackColor = Color.Cornsilk };
m.Layers.Add(l);
m.ZoomToExtents();
Stopwatch sw = new Stopwatch();
sw.Start();
m.GetMap();
sw.Stop();
Console.WriteLine(string.Format("Rendering old method: {0}ms", sw.ElapsedMilliseconds));
sw.Reset();
sw.Start();
Image bmp = m.GetMap();
sw.Stop();
Console.WriteLine(string.Format("Rendering old method: {0}ms", sw.ElapsedMilliseconds));
bmp.Save("NDSRoads1.bmp");
CachedLineSymbolizer cls = new CachedLineSymbolizer();
//cls.LineSymbolizeHandlers.Add(new SharpMap.Rendering.Symbolizer.PlainLineSymbolizeHandler { Line = new System.Drawing.Pen(System.Drawing.Color.Firebrick, 5) });
cls.LineSymbolizeHandlers.Add(new PlainLineSymbolizeHandler { Line = new Pen(Color.Gold, 1) });
l.Style.LineSymbolizer = cls;
sw.Reset(); sw.Start();
bmp = m.GetMap();
sw.Stop();
Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds));
bmp.Save("NDSRoads2.bmp");
}
示例6: TestMapDecorationTest
public void TestMapDecorationTest()
{
Map m = new Map(new Size(780, 540)) {BackColor = Color.White, SRID = 0};
GeoPoint[] pts = new [] {new GeoPoint(0, 0), new GeoPoint(779, 539)};
FeatureProvider p = new FeatureProvider(m.Factory.CreateLineString(pts));
m.Layers.Add(new VectorLayer("t",p));
m.ZoomToExtents();
m.Decorations.Add(new TestDecoration
{
Anchor = MapDecorationAnchor.LeftTop,
BorderColor = Color.Green,
BackgroundColor = Color.LightGreen,
BorderWidth = 2,
Location = new Point(10, 10),
BorderMargin = new Size(5, 5),
RoundedEdges = true,
Opacity = 0.6f
});
m.Decorations.Add(new TestDecoration
{
Anchor = MapDecorationAnchor.RightTop,
BorderColor = Color.Red,
BackgroundColor = Color.LightCoral,
BorderWidth = 2,
Location = new Point(10, 10),
BorderMargin = new Size(5, 5),
RoundedEdges = true,
Opacity = 0.2f
});
m.Decorations.Add(new ScaleBar
{
Anchor = MapDecorationAnchor.Default,
BorderColor = Color.Blue,
BackgroundColor = Color.CornflowerBlue,
BorderWidth = 2,
Location = new Point(10, 10),
BorderMargin = new Size(5, 5),
RoundedEdges = true,
BarWidth = 4,
ScaleText =ScaleBarLabelText.RepresentativeFraction,
NumTicks = 2,
Opacity = 1f
});
Image bmp = m.GetMap();
bmp.Save("TestMapDecorationTest.bmp");
}
示例7: TestGetMap
public void TestGetMap()
{
var m = new Map(new Size(500, 300));
m.BackColor = Color.White;
var p = KmlProvider.FromKml(@"TestData\KML_Samples.kml");
var l = new VectorLayer(p.ConnectionID, p);
l.Theme = p.GetKmlTheme();
m.Layers.Add(l);
m.ZoomToExtents();
m.Zoom *= 1.1;
var img = m.GetMap();
img.Save("KmlProviderImage.png", ImageFormat.Png);
}
示例8: TestRender
public void TestRender()
{
var style = new SharpMap.Styles.GroupStyle();
var vStyle = new SharpMap.Styles.VectorStyle()
{
Enabled = true,
PointColor = Brushes.Red,
PointSize = 6
};
style.AddStyle(vStyle);
vStyle = new SharpMap.Styles.VectorStyle()
{
Enabled = true,
PointColor = Brushes.White,
PointSize = 2
};
style.AddStyle(vStyle);
Assert.AreEqual(2, style.Count);
Assert.AreEqual(Color.Red, (style[0].PointColor as SolidBrush).Color);
VectorLayer vLay = new VectorLayer("test");
vLay.Style = style;
vLay.DataSource = new SharpMap.Data.Providers.GeometryProvider("POINT(0 0)");
Map m = new Map(new Size(11, 11));
m.BackColor = Color.White;
m.ZoomToBox(new GeoAPI.Geometries.Envelope(-5, 5, -5, 5));
m.Layers.Add(vLay);
var img = m.GetMap();
//img.Save(@"c:\\temp\ren.png");
Bitmap bmp = img as Bitmap;
Color c1 = bmp.GetPixel(5, 5);
Assert.AreEqual(Color.White.ToArgb(), c1.ToArgb());
c1 = bmp.GetPixel(3, 5);
Assert.AreEqual(Color.Red.ToArgb(), c1.ToArgb());
c1 = bmp.GetPixel(7, 5);
Assert.AreEqual(Color.Red.ToArgb(), c1.ToArgb());
c1 = bmp.GetPixel(5, 3);
Assert.AreEqual(Color.Red.ToArgb(), c1.ToArgb());
c1 = bmp.GetPixel(5, 7);
Assert.AreEqual(Color.Red.ToArgb(), c1.ToArgb());
}
示例9: TestTransparency
public void TestTransparency()
{
var tmpFile = GdiImageLayerTest.CreateImage(new Size(300, 300), new Point(10, 10));
using(var l = new GdiImageLayer(tmpFile))
using (var pl = new GdiImageLayerProxy<GdiImageLayer>(l, 0.3f))
using (var m = new Map(new Size(450, 450)))
{
m.Layers.Add(pl);
m.ZoomToExtents();
using (var img = (Bitmap)m.GetMap())
{
var color = img.GetPixel(225, 225);
Assert.LessOrEqual(Math.Abs((int)Math.Round(0.3f*255, MidpointRounding.AwayFromZero) - color.A),1);
}
}
GdiImageLayerTest.DeleteTmpFiles(tmpFile);
}
示例10: TestColorMap
public void TestColorMap()
{
var tmpFile = GdiImageLayerTest.CreateImage(new Size(300, 300), new Point(10, 10));
using (var l = new GdiImageLayer(tmpFile))
using (var pl = new GdiImageLayerProxy<GdiImageLayer>(l, new ColorMap{OldColor = Color.Red, NewColor = Color.MistyRose}))
using (var m = new Map(new Size(450, 450)))
{
m.Layers.Add(pl);
m.ZoomToExtents();
using (var img = (Bitmap)m.GetMap())
{
var color = img.GetPixel(225, 225);
Assert.AreEqual(Color.MistyRose.ToArgb(), color.ToArgb());
}
}
GdiImageLayerTest.DeleteTmpFiles(tmpFile);
}
示例11: GetMap_RenderLayerWithoutDatasource_ThrowException
public void GetMap_RenderLayerWithoutDatasource_ThrowException()
{
Map map = new Map();
map.Layers.Add(new VectorLayer("Layer 1"));
map.GetMap();
}
示例12: GetMap_RenderEmptyMap_ThrowInvalidOperationException
public void GetMap_RenderEmptyMap_ThrowInvalidOperationException()
{
Map map = new Map(new Size(2, 1));
map.GetMap();
}
示例13: GetMap_GeometryProvider_ReturnImage
public void GetMap_GeometryProvider_ReturnImage()
{
Map map = new Map(new Size(400, 200));
VectorLayer vLayer = new VectorLayer("Geom layer", CreateDatasource());
vLayer.Style.Outline = new Pen(Color.Red, 2f);
vLayer.Style.EnableOutline = true;
vLayer.Style.Line = new Pen(Color.Green, 2f);
vLayer.Style.Fill = Brushes.Yellow;
map.Layers.Add(vLayer);
VectorLayer vLayer2 = new VectorLayer("Geom layer 2", vLayer.DataSource);
vLayer2.Style.SymbolOffset = new PointF(3, 4);
vLayer2.Style.SymbolRotation = 45;
vLayer2.Style.SymbolScale = 0.4f;
map.Layers.Add(vLayer2);
VectorLayer vLayer3 = new VectorLayer("Geom layer 3", vLayer.DataSource);
vLayer3.Style.SymbolOffset = new PointF(3, 4);
vLayer3.Style.SymbolRotation = 45;
map.Layers.Add(vLayer3);
VectorLayer vLayer4 = new VectorLayer("Geom layer 4", vLayer.DataSource);
vLayer4.Style.SymbolOffset = new PointF(3, 4);
vLayer4.Style.SymbolScale = 0.4f;
vLayer4.ClippingEnabled = true;
map.Layers.Add(vLayer4);
map.ZoomToExtents();
Image img = map.GetMap();
Assert.IsNotNull(img);
map.Dispose();
img.Dispose();
}
示例14: ProcessRequest
public void ProcessRequest(HttpContext context)
{
// tile keys
int x, y, z;
//Parse request parameters
if (!int.TryParse(context.Request.Params["x"], out x))
throw (new ArgumentException("Invalid parameter"));
if (!int.TryParse(context.Request.Params["y"], out y))
throw (new ArgumentException("Invalid parameter"));
if (!int.TryParse(context.Request.Params["z"], out z))
throw (new ArgumentException("Invalid parameter"));
string layer = context.Request.Params["layer"]; // not used here
string style = context.Request.Params["style"]; // not used here
// set response type to png
context.Response.ContentType = "image/png";
// check if already rendered, rendered tiles are cached within HttpContext
string cacheKey = string.Format("Tile/{0}/{1}/{2}/{3}/{4}", layer, style, x, y, z);
byte[] buffer = context.Cache[cacheKey] as byte[];
if (buffer != null)
{
context.Response.OutputStream.Write(buffer, 0, buffer.Length);
return;
}
// create a transparent sharpmap map with a size of 256x256
using (var sharpMap = new Map(new Size(256, 256)) { BackColor = Color.Transparent })
{
// the map contains only one layer
var countries = new VectorLayer("WorldCountries")
{
// set tranform to WGS84->Spherical_Mercator
CoordinateTransformation = TransformToMercator(GeographicCoordinateSystem.WGS84),
// set the sharpmap provider for shape files as data source
DataSource = new ShapeFile(
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data") +
@"\world_countries_boundary_file_world_2002.shp"),
// use a dynamic style for thematic mapping
// the lambda also takes the map instance into account (to scale the border width)
Theme = new CustomTheme(row => GetPopDensStyle(sharpMap, row)),
};
// add the layer to the map
sharpMap.Layers.Add(countries);
// calculate the bbox for the tile key and zoom the map
sharpMap.ZoomToBox(TileToMercatorAtZoom(x, y, z));
// render the map image
using (var img = sharpMap.GetMap())
{
// stream the image to the client
using (var memoryStream = new MemoryStream())
{
// Saving a PNG image requires a seekable stream, first save to memory stream
// http://forums.asp.net/p/975883/3646110.aspx#1291641
img.Save(memoryStream, ImageFormat.Png);
buffer = memoryStream.ToArray();
// write response
context.Response.OutputStream.Write(buffer, 0, buffer.Length);
// add to cache
context.Cache[cacheKey] = buffer;
}
}
}
}
示例15: TestWarpedLineSymbolizer
public void TestWarpedLineSymbolizer()
{
ShapeFile p = new ShapeFile(@"d:\\daten\GeoFabrik\\Aurich\\roads.shp", false);
VectorLayer l = new VectorLayer("roads", p);
CachedLineSymbolizer cls = new CachedLineSymbolizer();
cls.LineSymbolizeHandlers.Add(new PlainLineSymbolizeHandler { Line = new Pen(Color.Gold, 2) });
WarpedLineSymbolizeHander wls = new WarpedLineSymbolizeHander
{
Pattern =
WarpedLineSymbolizer.
GetGreaterSeries(3, 3),
Line = new Pen(Color.Firebrick, 1)
,
Interval = 20
};
cls.LineSymbolizeHandlers.Add(wls);
l.Style.LineSymbolizer = cls;
Map m = new Map(new Size(720, 540)) { BackColor = Color.Cornsilk };
m.Layers.Add(l);
m.ZoomToExtents();
Stopwatch sw = new Stopwatch();
sw.Start();
Image bmp = m.GetMap();
sw.Stop();
Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds));
bmp.Save("AurichRoads1.bmp");
cls.LineSymbolizeHandlers[1] = new WarpedLineSymbolizeHander
{
Pattern =
WarpedLineSymbolizer.
GetTriangle(4, 0),
Line = new Pen(Color.Firebrick, 1),
Fill = new SolidBrush(Color.Firebrick)
,
Interval = 10
};
sw.Reset(); sw.Start();
bmp = m.GetMap();
sw.Stop();
Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds));
bmp.Save("AurichRoads2-0.bmp");
cls.LineSymbolizeHandlers[1] = new WarpedLineSymbolizeHander
{
Pattern =
WarpedLineSymbolizer.
GetTriangle(4, 1),
Line = new Pen(Color.Firebrick, 1),
Fill = new SolidBrush(Color.Firebrick)
,
Interval = 10
};
sw.Reset(); sw.Start();
bmp = m.GetMap();
sw.Stop();
Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds));
bmp.Save("AurichRoads2-1.bmp");
cls.LineSymbolizeHandlers[1] = new WarpedLineSymbolizeHander
{
Pattern =
WarpedLineSymbolizer.
GetTriangle(4, 2),
Line = new Pen(Color.Firebrick, 1),
Fill = new SolidBrush(Color.Firebrick)
,
Interval = 10
};
sw.Reset(); sw.Start();
bmp = m.GetMap();
sw.Stop();
Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds));
bmp.Save("AurichRoads2-2.bmp");
cls.LineSymbolizeHandlers[1] = new WarpedLineSymbolizeHander
{
Pattern =
WarpedLineSymbolizer.
GetTriangle(4, 3),
Line = new Pen(Color.Firebrick, 1),
Fill = new SolidBrush(Color.Firebrick)
,
Interval = 10
};
sw.Reset(); sw.Start();
bmp = m.GetMap();
sw.Stop();
Console.WriteLine(string.Format("Rendering new method: {0}ms", sw.ElapsedMilliseconds));
bmp.Save("AurichRoads2-3.bmp");
//cls.LineSymbolizeHandlers[0] = cls.LineSymbolizeHandlers[1];
cls.LineSymbolizeHandlers[1] = new WarpedLineSymbolizeHander
//.........这里部分代码省略.........