本文整理匯總了C#中SharpMap.Map.ZoomToExtents方法的典型用法代碼示例。如果您正苦於以下問題:C# Map.ZoomToExtents方法的具體用法?C# Map.ZoomToExtents怎麽用?C# Map.ZoomToExtents使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類SharpMap.Map
的用法示例。
在下文中一共展示了Map.ZoomToExtents方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: InitializeMap
public static Map InitializeMap()
{
Map map = new Map();
//string url = "http://labs.metacarta.com/wms-c/tilecache.py?version=1.1.1&request=GetCapabilities&service=wms-c";
string url = "http://dev:8080/geoserver/gwc/service/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=getcapabilities&TILED=true";
//string url = "http://dev:8080/geoserver/ows?service=wms&version=1.3.0&request=GetCapabilities&tiled=true";
//TiledWmsLayer tiledWmsLayer = new TiledWmsLayer("Metacarta", url);
//tiledWmsLayer.TileSetsActive.Add(tiledWmsLayer.TileSets["avalon"].Name);
//map.Layers.Add(tiledWmsLayer);
//map.ZoomToBox(new BoundingBox(-180.0, -90.0, 180.0, 90.0));
//WmscRequest req;
//ITileSource tileSource;
TileAsyncLayer tileLayer;
//BruTile.Web.TmsTileSource source2 = new TmsTileSource(url);
var source = new List<ITileSource>(WmscTileSource.CreateFromWmscCapabilties(new System.Uri(url)));
// foreach (ITileSource src in source)
// {
tileLayer = new TileAsyncLayer(source[16], "tileLayer" + source[16]);
tileLayer.MapNewTileAvaliable += map.MapNewTileAvaliableHandler;
map.BackgroundLayer.Add(tileLayer);
// }
map.ZoomToExtents();
return map;
}
示例2: InitializeMap
public static Map InitializeMap(float angle)
{
string wmsUrl = "http://dev:8080/geoserver/ows?service=wms&version=1.1.1&request=GetCapabilities";
Map map = new Map();
WmsLayer layWms = new WmsLayer("Demis Map", wmsUrl);
layWms.AddLayer("sf:roads");
//layWms.AddLayer("Topography");
//layWms.AddLayer("Hillshading");
layWms.SetImageFormat(layWms.OutputFormats[0]);
layWms.ContinueOnError = true;
//Skip rendering the WMS Map if the server couldn't be requested (if set to false such an event would crash the app)
layWms.TimeOut = 5000; //Set timeout to 5 seconds
layWms.SRID = 4326;
map.Layers.Add(layWms);
//limit the zoom to 360 degrees width
map.MaximumZoom = 360;
map.BackColor = Color.LightBlue;
map.Zoom = 360;
map.Center = new Point(0, 0);
Matrix mat = new Matrix();
mat.RotateAt(angle, map.WorldToImage(map.Center));
map.MapTransform = mat;
map.ZoomToExtents();
return map;
}
示例3: InitializeDXF
private static Map InitializeDXF(float angle)
{
Map map = new Map();
//Set the datasource to a shapefile in the App_data folder
Ogr provider;
try
{
provider = new Ogr("GeoData/SampleDXF.dxf",0);
}
catch (TypeInitializationException ex)
{
if (ex.Message == "The type initializer for 'OSGeo.OGR.Ogr' threw an exception.")
{
throw new Exception(
String.Format(
"The application threw a PINVOKE exception. You probably need to copy the unmanaged dll's to your bin directory. They are a part of fwtools {0}. You can download it from: http://home.gdal.org/fwtools/",
GdalRasterLayer.FWToolsVersion));
}
throw;
}
VectorLayer lay = new VectorLayer("SampleDXF", provider);
map.Layers.Add(lay);
map.ZoomToExtents();
Matrix mat = new Matrix();
mat.RotateAt(angle, map.WorldToImage(map.Center));
map.MapTransform = mat;
_ogrSampleDataset = "SampleDXF";
return map;
}
示例4: InitializeMapOrig
public static Map InitializeMapOrig(float angle)
{
//Initialize a new map of size 'imagesize'
Map map = new Map();
//Set up the countries layer
VectorLayer layRoads = new VectorLayer("Roads");
//Set the datasource to a shapefile in the App_data folder
layRoads.DataSource = new ShapeFile("GeoData/World/shp_textonpath/DeMo_Quan5.shp", false);
(layRoads.DataSource as ShapeFile).Encoding = Encoding.UTF8;
//Set fill-style to green
layRoads.Style.Fill = new SolidBrush(Color.Yellow);
layRoads.Style.Line = new Pen(Color.Yellow, 4);
//Set the polygons to have a black outline
layRoads.Style.Outline = new Pen(Color.Black, 5); ;
layRoads.Style.EnableOutline = true;
layRoads.SRID = 4326;
//Set up a country label layer
LabelLayer layLabel = new LabelLayer("Roads labels");
layLabel.DataSource = layRoads.DataSource;
layLabel.Enabled = true;
layLabel.LabelColumn = "tenduong";
layLabel.LabelFilter = SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection;
layLabel.Style = new LabelStyle();
layLabel.Style.ForeColor = Color.White;
layLabel.Style.Font = new Font(FontFamily.GenericSerif, 9f, FontStyle.Bold);
layLabel.Style.Halo = new Pen(Color.Black, 2f);
layLabel.Style.IsTextOnPath = true;
layLabel.Style.CollisionDetection = true;
//layLabel.Style.BackColor = new SolidBrush(Color.FromArgb(128, 255, 0, 0));
//layLabel.MaxVisible = 90;
//layLabel.MinVisible = 30;
layLabel.Style.HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Center;
layLabel.SRID = 4326;
//layLabel.MultipartGeometryBehaviour = LabelLayer.MultipartGeometryBehaviourEnum.Largest;
//Add the layers to the map object.
//The order we add them in are the order they are drawn, so we add the rivers last to put them on top
map.Layers.Add(layRoads);
map.Layers.Add(layLabel);
//limit the zoom to 360 degrees width
//map.MaximumZoom = 360;
// map.BackColor = Color.LightBlue;
map.ZoomToExtents();
Matrix mat = new Matrix();
mat.RotateAt(angle, map.WorldToImage(map.Center));
map.MapTransform = mat;
return map;
}
示例5: InitializeMap
public static Map InitializeMap()
{
try
{
//Sample provided by Dan Brecht and Joel Wilson
Map map = new Map();
map.BackColor = Color.White;
string relativePath = "GeoData/GeoTiff/";
SharpMap.Layers.GdalRasterLayer layer;
if (!File.Exists(relativePath + "format01-image_a.tif"))
{
throw new Exception("Make sure the data is in the relative directory: " + relativePath);
}
layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffA", relativePath + "format01-image_a.tif");
map.Layers.Add(layer);
layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffB", relativePath + "format01-image_b.tif");
map.Layers.Add(layer);
layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffC", relativePath + "format01-image_c.tif");
map.Layers.Add(layer);
layer = new SharpMap.Layers.GdalRasterLayer("GeoTiffD", relativePath + "format01-image_d.tif");
map.Layers.Add(layer);
SharpMap.Layers.VectorLayer shapeLayer;
if (!File.Exists(relativePath + "outline.shp"))
{
throw new Exception("Make sure the data is in the relative directory: " + relativePath);
}
shapeLayer = new SharpMap.Layers.VectorLayer("outline", new SharpMap.Data.Providers.ShapeFile(relativePath + "outline.shp"));
shapeLayer.Style.Fill = Brushes.Transparent;
shapeLayer.Style.Outline = Pens.Black;
shapeLayer.Style.EnableOutline = true;
shapeLayer.Style.Enabled = true;
map.Layers.Add(shapeLayer);
map.ZoomToExtents();
return map;
}
catch (Exception ex)
{
if (ex.Message == "The type initializer for 'OSGeo.GDAL.GdalPINVOKE' threw an exception.")
{
throw new Exception(String.Format("The application threw a PINVOKE exception. You probably need to copy the unmanaged dll's to your bin directory. They are a part of fwtools {0}. You can download it from: http://home.gdal.org/fwtools/", SharpMap.Layers.GdalRasterLayer.FWToolsVersion));
}
throw;
}
}
示例6: TestMap1
public void TestMap1()
{
var m = new Map(_mapSize);
m.Layers.Add(new VectorLayer("tmp", new GeometryProvider(
new LineString(new [] {new Coordinate(0, 0), new Coordinate(10, 10), }))));
m.ZoomToExtents();
Map mD = null;
Assert.DoesNotThrow(()=>mD=SandD(m, GetFormatter()));
TestMaps("Test1", m, mD);
}
示例7: 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");
}
示例8: 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");
}
示例9: ShowMap
public void ShowMap(Map map)
{
MapControl.Map = map;
map.ZoomToExtents();
MapControl.MouseMove += delegate(object sender, MouseEventArgs e)
{
var point = map.ImageToWorld(new PointF(e.X, e.Y));
coordinateLabel.Text = string.Format("{0}:{1}", point.X, point.Y);
};
WindowsFormsTestHelper.ShowModal(this);
map.Dispose();
}
示例10: 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);
}
示例11: 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);
}
示例12: 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);
}
示例13: 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));
}
示例14: 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");
}
示例15: InitializeMap
//.........這裏部分代碼省略.........
layRivers.DataSource = new SpatiaLite(
DataSource, "rivers", "geom", "PK_UID");
//Define a blue 3px wide pen
layRivers.Style.Line = new Pen(Color.LightBlue, 2);
layRivers.Style.Line.CompoundArray = new[] { 0.2f, 0.8f };
layRivers.Style.Outline = new Pen(Color.DarkBlue, 3);
layRivers.Style.EnableOutline = true;
//Set up a cities layer
VectorLayer layCities = new VectorLayer("Cities");
//Set the datasource to the spatialite table
layCities.DataSource = new SpatiaLite(
DataSource, "cities", "geom", "PK_UID");
layCities.Style.SymbolScale = 0.8f;
layCities.MaxVisible = 40;
//Set up a country label layer
LabelLayer layLabel = new LabelLayer("Country labels")
{
DataSource = layCountries.DataSource,
LabelColumn = "NAME",
MultipartGeometryBehaviour = LabelLayer.MultipartGeometryBehaviourEnum.Largest,
LabelFilter = LabelCollisionDetection.ThoroughCollisionDetection,
PriorityColumn = "POPDENS",
Style = new LabelStyle
{
ForeColor = Color.White,
Font = new Font(FontFamily.GenericSerif, 12),
BackColor = new SolidBrush(Color.FromArgb(128, 255, 0, 0)),
HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Center,
MaxVisible = 90,
MinVisible = 30,
CollisionDetection = true
}
};
//Set up a city label layer
LabelLayer layCityLabel = new LabelLayer("City labels")
{
DataSource = layCities.DataSource,
LabelColumn = "name",
PriorityColumn = "population",
PriorityDelegate = delegate(IFeature fdr)
{
Int32 retVal = 10000000 * ( (String)fdr.Attributes["capital"] == "Y" ? 1 : 0 );
return retVal + Convert.ToInt32(fdr.Attributes["population"]);
},
TextRenderingHint = TextRendering.AntiAlias,
SmoothingMode = Smoothing.AntiAlias,
LabelFilter = LabelCollisionDetection.ThoroughCollisionDetection,
Style = new LabelStyle
{
ForeColor = Color.Black,
Font = new Font(FontFamily.GenericSerif, 11),
MaxVisible = layLabel.MinVisible,
HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Left,
VerticalAlignment = LabelStyle.VerticalAlignmentEnum.Bottom,
Offset = new PointF(3, 3),
Halo = new Pen(Color.Yellow, 2),
CollisionDetection = true
}
};
LabelLayer layRiverLabels = new LabelLayer("RiverLabels");
layRiverLabels.DataSource = layRivers.DataSource;
layRiverLabels.LabelColumn = "Name";
layRiverLabels.PriorityDelegate = GetRiverLength;
layRiverLabels.Style = new LabelStyle
{
Font = new Font("Arial", 10, FontStyle.Bold),
Halo = new Pen(Color.Azure, 2),
ForeColor = Color.DarkCyan,
IgnoreLength = true,
Enabled = true,
CollisionDetection = true,
};
layRiverLabels.LabelFilter = LabelCollisionDetection.ThoroughCollisionDetection;
//Add the layers to the map object.
//The order we add them in are the order they are drawn, so we add the rivers last to put them on top
map.Layers.Add(layCountries);
map.Layers.Add(layRivers);
map.Layers.Add(layCities);
map.Layers.Add(layRiverLabels);
map.Layers.Add(layLabel);
map.Layers.Add(layCityLabel);
//limit the zoom to 360 degrees width
map.MaximumZoom = 360;
map.BackColor = Color.LightBlue;
map.ZoomToExtents(); // = 360;
Matrix mat = new Matrix();
mat.RotateAt(angle, map.WorldToImage(map.Center));
map.MapTransform = mat;
return map;
}