C# SharpMap 学习总结
生活随笔
收集整理的這篇文章主要介紹了
C# SharpMap 学习总结
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
SharpMap V1.1 For Web教程系列之——地圖展示
SharpMap V1.1 For Web教程系列之——地圖展示 開篇先說本次的開發環境吧。采用Vs2010,.Net?
Framework 4.0。
為了更好的調試程序,建議在IIS中進行調試及運行,個人非常不喜歡利用VS自己提供的WebServer去調
試程序,而且很多在Web.config中的設置也需要在IIS中才能起到效果!
開發環境我就不要介紹了,先來說說SharpMap的組件要求吧。由于SharpMap的架構一直在變化和改進過
程中,因此參考網絡上別人的事例代碼,你會發現都運行不起來,不是接口沒了,就是命名空間變了,
這點我也希望SharpMap早日穩定下來。
這次使用的SharpMap的版本是V1.1版本,官方意見提供最新穩定版的下載了,官方網址為:
http://sharpmap.codeplex.com/
SharpMap 1.1版本的下載地址為:http://sharpmap.codeplex.com/downloads/get/792797?,發布時間
為2014年12月11日;該版本只是SharpMap的核心庫(Core+UI),下載完后,為了Web開發還必須下載一個
Web端的庫,本人做完因為這一步走了好多彎路,網絡上的教程也沒有人寫上著一點。在官網的
DOWNLOADS節點下有個下載界面,需要下載SharpMap.Web這個組件。
OK!所需庫完成后,下面進行Asp.Net的網站開發!你也可以不看下面的代碼,直接下載整個網站。解決
方案下載地址:http://pan.baidu.com/s/1i3vdUcd
打開VS2010,新建一個網站,?新建一個WebForm,我這里命名為“Map.aspx”,下面貼代碼:
Map.aspx:地圖展示頁面
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Map.aspx.cs" Inherits="Map" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"?
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
? ? <title>SharpMap測試</title>
</head>
<body>
? ? <form id="form1" runat="server">
? ? <div>
? ? ? ? <asp:RadioButtonList ID="rblMapTools" runat="server" RepeatDirection="Horizontal">
? ? ? ? ? ? <asp:ListItem Value="0">Zoom in</asp:ListItem>
? ? ? ? ? ? <asp:ListItem Value="1">Zoom out</asp:ListItem>
? ? ? ? ? ? <asp:ListItem Value="2" Selected="True">Pan</asp:ListItem>
? ? ? ? </asp:RadioButtonList>
? ? ? ? <asp:ImageButton runat="server" Width="700" Height="400" ID="imgMap"?
? ? ? ? ? ? οnclick="imgMap_Click" />
? ? </div>
? ? </form>
</body>
</html>
View Code
Map.aspx.cx:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Map : System.Web.UI.Page
{
? ? private SharpMap.Map myMap;
? ? protected void Page_Load(object sender, EventArgs e)
? ? {
? ? ? ? myMap = MapHelper.InitializeMap(new System.Drawing.Size((int)imgMap.Width.Value,?
(int)imgMap.Height.Value));
? ? ? ? //SharpMap.Map
? ? ? ? if (this.IsPostBack)
? ? ? ? {
? ? ? ? ? ? myMap.Center = (GeoAPI.Geometries.Coordinate)ViewState["mapCenter"];
? ? ? ? ? ? myMap.Zoom = (double)ViewState["mapZoom"];
? ? ? ? }
? ? ? ? else
? ? ? ? {
? ? ? ? ? ? this.generateMap();
? ? ? ? }
? ? }
? ? protected void imgMap_Click(object sender, ImageClickEventArgs e)
? ? {
? ? ? ? myMap.Center = myMap.ImageToWorld(new System.Drawing.Point(e.X, e.Y));
? ? ? ? //Set zoom value if any of the zoom tools were selected
? ? ? ? if (rblMapTools.SelectedValue == "0") //Zoom in
? ? ? ? ? ? myMap.Zoom = myMap.Zoom * 0.5;
? ? ? ? else if (rblMapTools.SelectedValue == "1") //Zoom out
? ? ? ? ? ? myMap.Zoom = myMap.Zoom * 2;
? ? ? ? //Create the map
? ? ? ? this.generateMap();
? ? }
? ? private void generateMap()
? ? {
? ? ? ? ViewState.Add("mapCenter", myMap.Center);
? ? ? ? ViewState.Add("mapZoom", myMap.Zoom);
? ? ? ? //myMap = MapHelper.InitializeMap(new System.Drawing.Size(256, 256));
? ? ? ? System.Drawing.Image img = myMap.GetMap();
? ? ? ? string imgID = SharpMap.Web.Caching.InsertIntoCache(1, img);
? ? ? ??
? ? ? ? imgMap.ImageUrl = "getmap.aspx?ID=" + HttpUtility.UrlEncode(imgID);
? ? }
}
Web.Config配置文件,在.Net 4.0下配置文件,紅色部分表示這個地方和SharpMap官網以及互聯網
上很多教程里面的區別。
<?xml version="1.0"?>
<configuration>
? <system.web>
? ? <compilation debug="true" targetFramework="4.0" />
? </system.web>
? <system.webServer>
? ? ?<modules runAllManagedModulesForAllRequests="true"/>
? ? ? <handlers>
? ? ? ? ? <add verb="*" name="test" path="GetMap.aspx" type="SharpMap.Web.HttpHandler"?
preCondition="integratedMode"/>
? ? ? </handlers>
? ? ? <validation validateIntegratedModeConfiguration="false" />
? </system.webServer>
</configuration>
MapHelper.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SharpMap;
using System.Drawing;
using SharpMap.Layers;
using SharpMap.Data.Providers;
using SharpMap.Styles;
using System.Drawing.Text;
using SharpMap.Rendering;
using ColorBlend=SharpMap.Rendering.Thematics.ColorBlend;
using Point=GeoAPI.Geometries.Coordinate;
using System.Drawing.Drawing2D;
/// <summary>
/// Summary description for MapHelper
/// </summary>
public class MapHelper
{
? ? public MapHelper()
? ? {
? ? }
? ? public static Map InitializeMap(Size size)
? ? {
? ? ? ? HttpContext.Current.Trace.Write("Initializing map...");
? ? ? ? //Initialize a new map of size 'imagesize'
? ? ? ? Map map = new Map(size);
? ? ? ? //Set up the countries layer
? ? ? ? VectorLayer layCountries = new VectorLayer("Countries");
? ? ? ? //Set the datasource to a shapefile in the App_data folder
? ? ? ? layCountries.DataSource = new ShapeFile(HttpContext.Current.Server.MapPath(@"~
\App_data\countries.shp"), true);
? ? ? ? //Set fill-style to green
? ? ? ? layCountries.Style.Fill = new SolidBrush(Color.Green);
? ? ? ? //Set the polygons to have a black outline
? ? ? ? layCountries.Style.Outline = Pens.Black;
? ? ? ? layCountries.Style.EnableOutline = true;
? ? ? ? layCountries.SRID = 4326;
? ? ? ? //Set up a river layer
? ? ? ? VectorLayer layRivers = new VectorLayer("Rivers");
? ? ? ? //Set the datasource to a shapefile in the App_data folder
? ? ? ? layRivers.DataSource = new ShapeFile(HttpContext.Current.Server.MapPath(@"~
\App_data\rivers.shp"), true);
? ? ? ? //Define a blue 1px wide pen
? ? ? ? layRivers.Style.Line = new Pen(Color.Blue, 1);
? ? ? ? layRivers.SRID = 4326;
? ? ? ? //Set up a river layer
? ? ? ? VectorLayer layCities = new VectorLayer("Cities");
? ? ? ? //Set the datasource to a shapefile in the App_data folder
? ? ? ? layCities.DataSource = new ShapeFile(HttpContext.Current.Server.MapPath(@"~
\App_data\cities.shp"), true);
? ? ? ? //Define a blue 1px wide pen
? ? ? ? //layCities.Style.Symbol = new Bitmap(HttpContext.Current.Server.MapPath(@"~
\App_data\Taiyuan\icon.png"));
? ? ? ? layCities.Style.SymbolScale = 0.8f;
? ? ? ? layCities.MaxVisible = 40;
? ? ? ? layCities.SRID = 4326;
? ? ? ? //Set up a country label layer
? ? ? ? LabelLayer layLabel = new LabelLayer("Country labels");
? ? ? ? layLabel.DataSource = layCountries.DataSource;
? ? ? ? layLabel.Enabled = true;
? ? ? ? layLabel.LabelColumn = "Name";
? ? ? ? layLabel.Style = new LabelStyle();
? ? ? ? layLabel.Style.ForeColor = Color.White;
? ? ? ? layLabel.Style.Font = new Font(FontFamily.GenericSerif, 12);
? ? ? ? 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;
? ? ? ? //Set up a city label layer
? ? ? ? LabelLayer layCityLabel = new LabelLayer("City labels");
? ? ? ? layCityLabel.DataSource = layCities.DataSource;
? ? ? ? layCityLabel.Enabled = true;
? ? ? ? layCityLabel.LabelColumn = "Name";
? ? ? ? layCityLabel.Style = new LabelStyle();
? ? ? ? layCityLabel.Style.ForeColor = Color.Black;
? ? ? ? layCityLabel.Style.Font = new Font(FontFamily.GenericSerif, 11);
? ? ? ? layCityLabel.MaxVisible = layLabel.MinVisible;
? ? ? ? layCityLabel.Style.HorizontalAlignment = LabelStyle.HorizontalAlignmentEnum.Left;
? ? ? ? layCityLabel.Style.VerticalAlignment = LabelStyle.VerticalAlignmentEnum.Bottom;
? ? ? ? layCityLabel.Style.Offset = new PointF(3, 3);
? ? ? ? layCityLabel.Style.Halo = new Pen(Color.Yellow, 2);
? ? ? ? layCityLabel.TextRenderingHint = TextRenderingHint.AntiAlias;
? ? ? ? layCityLabel.SmoothingMode = SmoothingMode.AntiAlias;
? ? ? ? layCityLabel.SRID = 4326;
? ? ? ? layCityLabel.LabelFilter = LabelCollisionDetection.ThoroughCollisionDetection;
? ? ? ? layCityLabel.Style.CollisionDetection = true;
? ? ? ? //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(layLabel);
? ? ? ? map.Layers.Add(layCityLabel);
? ? ? ? //limit the zoom to 360 degrees width
? ? ? ? map.MaximumZoom = 360;
? ? ? ? map.BackColor = Color.LightBlue;
? ? ? ? map.Zoom = 360;
? ? ? ? map.Center = new Point(0, 0);
? ? ? ? HttpContext.Current.Trace.Write("Map initialized");
? ? ? ? return map;
? ? }
? ? public static Map InitializeTaiyuanMap(Size size)
? ? {
? ? ? ? HttpContext.Current.Trace.Write("Initializing map...");
? ? ? ? //Initialize a new map of size 'imagesize'
? ? ? ? SharpMap.Map map = new SharpMap.Map(size);
? ? ? ? //設置太原市區域圖層
? ? ? ? SharpMap.Layers.VectorLayer layTy = new SharpMap.Layers.VectorLayer("ty");
? ? ? ? layTy.DataSource = new SharpMap.Data.Providers.ShapeFile
(HttpContext.Current.Server.MapPath(@"~\App_data\Taiyuan\區縣級行政區劃R.shp"), true);
? ? ? ? layTy.Style.Fill = new SolidBrush(Color.FromArgb(242, 239, 233));
? ? ? ? layTy.Style.Outline = System.Drawing.Pens.Black;
? ? ? ? layTy.Style.EnableOutline = true;
? ? ? ? layTy.SRID = 4326;
? ? ? ? //設置鎮的圖層
? ? ? ? SharpMap.Layers.VectorLayer layZ = new SharpMap.Layers.VectorLayer("z");
? ? ? ? layZ.DataSource = new SharpMap.Data.Providers.ShapeFile
(HttpContext.Current.Server.MapPath(@"~\App_data\Taiyuan\鎮.shp"), true);
? ? ? ? layZ.Style.Fill = new SolidBrush(Color.FromArgb(191, 237, 245));
? ? ? ? layZ.Style.Outline = System.Drawing.Pens.Black;
? ? ? ? layZ.Style.EnableOutline = true;
? ? ? ? layZ.SRID = 4326;
? ? ? ? //設置河流的圖層
? ? ? ? SharpMap.Layers.VectorLayer layHl = new SharpMap.Layers.VectorLayer("Hl");
? ? ? ? layHl.DataSource = new SharpMap.Data.Providers.ShapeFile
(HttpContext.Current.Server.MapPath(@"~\App_data\Taiyuan\河流湖泊R.shp"), true);
? ? ? ? layHl.Style.Fill = new SolidBrush(Color.FromArgb(151, 219, 242));
? ? ? ? layHl.Style.Outline = System.Drawing.Pens.Black;
? ? ? ? layHl.Style.EnableOutline = true;
? ? ? ? layHl.SRID = 4326;
? ? ? ? //設置國道的圖層
? ? ? ? SharpMap.Layers.VectorLayer layGd = new SharpMap.Layers.VectorLayer("gd");
? ? ? ? layGd.DataSource = new SharpMap.Data.Providers.ShapeFile
(HttpContext.Current.Server.MapPath(@"~\App_data\Taiyuan\國道L.shp"), true);
? ? ? ? layGd.Style.Fill = new SolidBrush(Color.FromArgb(255, 254, 169));
? ? ? ? layZ.Style.Outline = System.Drawing.Pens.Black;
? ? ? ? layZ.Style.EnableOutline = true;
? ? ? ? layGd.Style.Line = new Pen(Color.FromArgb(130, 130, 130), 1);
? ? ? ? layGd.SRID = 4326;
? ? ? ? //Set up the countries layer
? ? ? ? SharpMap.Layers.VectorLayer laySd = new SharpMap.Layers.VectorLayer("sd");
? ? ? ? //Set the datasource to a shapefile in the App_data folder
? ? ? ? laySd.DataSource = new SharpMap.Data.Providers.ShapeFile
(HttpContext.Current.Server.MapPath(@"~\App_data\Taiyuan\省道L.shp"), true);
? ? ? ? //Set fill-style to green
? ? ? ? laySd.Style.Fill = new SolidBrush(Color.FromArgb(255, 254, 169));
? ? ? ? //Set the polygons to have a black outline
? ? ? ? laySd.Style.Line = new Pen(Color.FromArgb(130, 130, 130), 1);
? ? ? ? layZ.Style.Outline = System.Drawing.Pens.Gainsboro;
? ? ? ? layZ.Style.EnableOutline = true;
? ? ? ? laySd.SRID = 4326;
? ? ? ? //Set up a river layer
? ? ? ? SharpMap.Layers.VectorLayer layRivers = new SharpMap.Layers.VectorLayer("Rivers");
? ? ? ? //Set the datasource to a shapefile in the App_data folder
? ? ? ? layRivers.DataSource = new SharpMap.Data.Providers.ShapeFile
(HttpContext.Current.Server.MapPath(@"~\App_data\Taiyuan\城市主干道L.shp"), true);
? ? ? ? layRivers.Style.Fill = new SolidBrush(Color.FromArgb(255, 254, 169));
? ? ? ? //Define a blue 1px wide pen
? ? ? ? layRivers.Style.Line = new Pen(Color.FromArgb(130, 130, 130), 1);
? ? ? ? layRivers.SRID = 4326;
? ? ? ? //Set up a river layer
? ? ? ? SharpMap.Layers.VectorLayer layCities = new SharpMap.Layers.VectorLayer("Cities");
? ? ? ? //Set the datasource to a shapefile in the App_data folder
? ? ? ? layCities.DataSource = new SharpMap.Data.Providers.ShapeFile
(HttpContext.Current.Server.MapPath(@"~\App_data\Taiyuan\城市次干道L.shp"), true);
? ? ? ? //Define a blue 1px wide pen
? ? ? ? //layCities.Style.Symbol = new Bitmap(HttpContext.Current.Server.MapPath(@"~
\App_data\Taiyuan\icon.png"));
? ? ? ? layCities.Style.SymbolScale = 0.8f;
? ? ? ? layCities.MaxVisible = 0.2;
? ? ? ? layCities.SRID = 4326;
? ? ? ? //Set up a river layer
? ? ? ? SharpMap.Layers.VectorLayer layDb = new SharpMap.Layers.VectorLayer("db");
? ? ? ? //Set the datasource to a shapefile in the App_data folder
? ? ? ? layDb.DataSource = new SharpMap.Data.Providers.ShapeFile
(HttpContext.Current.Server.MapPath(@"~\App_data\Taiyuan\基礎地標.shp"), true);
? ? ? ? //Define a blue 1px wide pen
? ? ? ? //layCities.Style.Symbol = new Bitmap(HttpContext.Current.Server.MapPath(@"~
\App_data\Taiyuan\icon.png"));
? ? ? ? layDb.Style.SymbolScale = 0.8f;
? ? ? ? layDb.MaxVisible = 0.05;
? ? ? ? layDb.SRID = 4326;
? ? ? ? //Set up a 鎮 label layer
? ? ? ? SharpMap.Layers.LabelLayer layZLabel = new SharpMap.Layers.LabelLayer("tyz?
labels");
? ? ? ? layZLabel.DataSource = layZ.DataSource;
? ? ? ? layZLabel.Enabled = true;
? ? ? ? layZLabel.LabelColumn = "Name";
? ? ? ? layZLabel.Style = new SharpMap.Styles.LabelStyle();
? ? ? ? layZLabel.Style.ForeColor = Color.White;
? ? ? ? layZLabel.Style.Font = new Font(FontFamily.GenericSerif, 12);
? ? ? ? layZLabel.Style.BackColor = new System.Drawing.SolidBrush(Color.Black);
? ? ? ? layZLabel.MaxVisible = 0.1;
? ? ? ? layZLabel.MinVisible = 0.05;
? ? ? ? layZLabel.Style.HorizontalAlignment =?
SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Center;
? ? ? ? layZLabel.SRID = 4326;
? ? ? ? layZLabel.MultipartGeometryBehaviour =?
SharpMap.Layers.LabelLayer.MultipartGeometryBehaviourEnum.Largest;
? ? ? ? //Set up a city label layer
? ? ? ? SharpMap.Layers.LabelLayer layCityLabel = new SharpMap.Layers.LabelLayer("City?
labels");
? ? ? ? layCityLabel.DataSource = layCities.DataSource;
? ? ? ? layCityLabel.Enabled = true;
? ? ? ? layCityLabel.LabelColumn = "Name";
? ? ? ? layCityLabel.Style = new SharpMap.Styles.LabelStyle();
? ? ? ? layCityLabel.Style.ForeColor = Color.Black;
? ? ? ? layCityLabel.Style.Font = new Font(FontFamily.GenericSerif, 11);
? ? ? ? layCityLabel.MaxVisible = layZLabel.MinVisible;
? ? ? ? layCityLabel.Style.HorizontalAlignment =?
SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Left;
? ? ? ? layCityLabel.Style.VerticalAlignment =?
SharpMap.Styles.LabelStyle.VerticalAlignmentEnum.Bottom;
? ? ? ? layCityLabel.Style.Offset = new PointF(3, 3);
? ? ? ? layCityLabel.Style.Halo = new Pen(Color.Yellow, 2);
? ? ? ? layCityLabel.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
? ? ? ? layCityLabel.SmoothingMode = SmoothingMode.AntiAlias;
? ? ? ? layCityLabel.SRID = 4326;
? ? ? ? layCityLabel.LabelFilter =?
SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection;
? ? ? ? layCityLabel.Style.CollisionDetection = true;
? ? ? ? //Set up a city label layer
? ? ? ? SharpMap.Layers.LabelLayer layDbLabel = new SharpMap.Layers.LabelLayer("Db?
labels");
? ? ? ? layDbLabel.DataSource = layDb.DataSource;
? ? ? ? layDbLabel.Enabled = true;
? ? ? ? layDbLabel.LabelColumn = "Name";
? ? ? ? layDbLabel.Style = new SharpMap.Styles.LabelStyle();
? ? ? ? layDbLabel.Style.ForeColor = Color.Black;
? ? ? ? layDbLabel.Style.Font = new Font(FontFamily.GenericSerif, 11);
? ? ? ? layDbLabel.MaxVisible = layCityLabel.MinVisible;
? ? ? ? layDbLabel.Style.HorizontalAlignment =?
SharpMap.Styles.LabelStyle.HorizontalAlignmentEnum.Left;
? ? ? ? layDbLabel.Style.VerticalAlignment =?
SharpMap.Styles.LabelStyle.VerticalAlignmentEnum.Bottom;
? ? ? ? layDbLabel.Style.Offset = new PointF(3, 3);
? ? ? ? layDbLabel.Style.Halo = new Pen(Color.Yellow, 2);
? ? ? ? layDbLabel.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
? ? ? ? layDbLabel.SmoothingMode = SmoothingMode.AntiAlias;
? ? ? ? layDbLabel.SRID = 4326;
? ? ? ? layDbLabel.LabelFilter =?
SharpMap.Rendering.LabelCollisionDetection.ThoroughCollisionDetection;
? ? ? ? layCityLabel.Style.CollisionDetection = true;
? ? ? ? //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(layTy);
? ? ? ? map.Layers.Add(layHl);
? ? ? ? map.Layers.Add(layGd);
? ? ? ? map.Layers.Add(laySd);
? ? ? ? map.Layers.Add(layRivers);
? ? ? ? map.Layers.Add(layCities);
? ? ? ? map.Layers.Add(layDb);
? ? ? ? map.Layers.Add(layZLabel);
? ? ? ? map.Layers.Add(layCityLabel);
? ? ? ? map.Layers.Add(layDbLabel);
? ? ? ? //limit the zoom to 360 degrees width
? ? ? ? map.MaximumZoom = 4;
? ? ? ? map.BackColor = Color.White;
? ? ? ? map.Zoom = 4;
? ? ? ? //map.Center = new SharpMap.Geometries.Point(0, 0);
? ? ? ? map.Center = new Point(112.48, 37.86);
? ? ? ? HttpContext.Current.Trace.Write("Map initialized");
? ? ? ? return map;
? ? }
}
========
SharpMap創建應用程序教程
首先,下載SharpMap,下載地址:http://sharpmap.codeplex.com/releases/view/116326
下載完成后解壓。再下載演示程序所用的地圖文件,下載地址:
http://115.com/lb/5lbdeevtkasp
115網盤禮包碼:5lbdeevtkasp
下載完解壓,得到文件states_ugl.dbf,states_ugl.shp,states_ugl.shx。
一、創建一個包括MapControl的窗體
1、啟動vs并且創建一個窗體應用程序。
2、切換至.net4 full framewark。
右擊項目,點擊屬性,在應用程序標簽內容內的目標框架處選擇.NET Framework 4。
SharpMap創建應用程序教程
3、打開窗口設計
4、在工具箱“常規”下方的空白處右擊,然后點擊“選擇項”。
SharpMap創建應用程序教程
5、在彈出的窗口中,點擊“瀏覽”,選擇SharpMap解壓出來的文件中的SharpMap.UI.dll,再點擊確定
。
完成之后會看到“常規”下面多了幾項,其中包括MapBox。
SharpMap創建應用程序教程
6、拖動MapBox控件至剛才新建的窗全中,將會在窗體上增加一個地圖。
這時候,一般會自動添加對SharpMap.dll的引用。
7、選擇這個地圖,在右側背景色屬性中改為白色以區別窗體本身的顏色。
SharpMap創建應用程序教程
二、在地圖上增加一個層
在這一步,將會增加一個層到上一步創建的地圖中。
1、如果在上一步中沒有自動添加對SharpMap.dll的引用,請右擊項目下的“引用”,添加引用。選擇
SharpMap.dll。
2、查看窗體的代碼,打開代碼頁。
3、添加以下代碼至除始化方法中。
public partial class Form1 : Form
? ? {
? ? ? ? public Form1()
? ? ? ? {
? ? ? ? ? ? InitializeComponent();
? ? ? ? ? ? SharpMap.Layers.VectorLayer vlay = new SharpMap.Layers.VectorLayer("States");
? ? ? ? ? ? vlay.DataSource = new SharpMap.Data.Providers.ShapeFile("states_ugl.shp",?
true);
? ? ? ? ? ? mapBox1.Map.Layers.Add(vlay);
? ? ? ? ? ? mapBox1.Map.ZoomToExtents();
? ? ? ? ?mapBox1.Refresh();
? ? ? ? }
? ? }
然后,把第一步中下載的三個地圖文件,復制到程序的Debug文件夾中供程序使用。
4、啟動調試,就可以看到一個疑似地圖的圖形了。
5、添加功能工具。
mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.Pan;
把這行代碼加到上面代碼的后面。
6、再調試程序,將會看到可以鼠標的中輪滾動來放大或縮小地圖。SharpMap創建應用程序教程
三、用UniqueValueRenderer改變層的風格樣式。
public partial class Form1 : Form
? ? {
? ? ? ? public Form1()
? ? ? ? {
? ? ? ? ? ? InitializeComponent();
? ? ? ? ? ? SharpMap.Layers.VectorLayer vlay = new SharpMap.Layers.VectorLayer("States");
? ? ? ? ? ? vlay.DataSource = new SharpMap.Data.Providers.ShapeFile("states_ugl.shp",?
true);
? ? ? ? ? ? //創建大陸的樣式
? ? ? ? ? ? VectorStyle landStyle = new VectorStyle();
? ? ? ? ? ? landStyle.Fill = new SolidBrush(Color.FromArgb(232, 232, 232));
? ? ? ? ? ? //創建水域的樣式。
? ? ? ? ? ? VectorStyle waterStyle = new VectorStyle();
? ? ? ? ? ? waterStyle.Fill = new SolidBrush(Color.FromArgb(198, 198, 255));
? ? ? ? ? ? //創建樣式組
? ? ? ? ? ? Dictionary styles = new Dictionary();
? ? ? ? ? ? styles.Add("land", landStyle);
? ? ? ? ? ? styles.Add("water", waterStyle);
? ? ? ? ? ? //添加樣式至層
? ? ? ? ? ? vlay.Theme = new SharpMap.Rendering.Thematics.UniqueValuesTheme("class",?
styles, landStyle);
? ? ? ? ? ? mapBox1.Map.Layers.Add(vlay);
? ? ? ? ? ? mapBox1.Map.ZoomToExtents();
? ? ? ? ? ? mapBox1.Refresh();
? ? ? ? ? ? mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.Pan;
? ? ? ? }
? ? }
再次調試運行,將會看到已經上色了。
SharpMap創建應用程序教程
四、上數據層
SharpMap.Layers.WmsLayer wmsL =
? ? ? ? ? ? ? ? new SharpMap.Layers.WmsLayer("US?
Cities","http://sampleserver1.arcgisonline.com/ArcGIS/services/Specialty/ESRI_StatesCitiesR
ivers_USA/MapServer/WMSServer?request=GetCapabilities&service=WMS");
? ? ? ? ? ? //設定圖標格式
? ? ? ? ? ? wmsL.SetImageFormat("image/png");
? ? ? ? ? ? //設定版本號
? ? ? ? ? ? wmsL.Version = "1.1.1";
? ? ? ? ? ? //為wms添加一個名字為2的層
? ? ? ? ? ? wmsL.AddLayer("2");
? ? ? ? ? ? //設定空間參考識別碼,這個東西是什么意思,自己去百度吧。
? ? ? ? ? ? wmsL.SRID = 4326;
? ? ? ? ? ? mapBox1.Map.Layers.Add(wmsL);
再調試運行,將全看到一個城市的分布圖。官網給的那地址打不開了,找了一個相關的。
SharpMap創建應用程序教程
不翻了,累,后面就差一節講怎么加背景色的了。
========
Gis初學者之sharpmap
今天開始了解sharpmap,來做webgis的項目。為什么要用sharpmap呢?
第一,開源。開源代表著免費,對于那些商業版高達十幾萬甚至幾十萬的費用來說,小弟只能選擇這個
。
第二,是.net 的,因為本人一直使用微軟系列的東西進行開發,所以選擇了這個。
準備工作,需要有vs2008 和 sharpmap 1.1的demo。
IIS 推薦大家提前安裝好IIS ,如果是 server的系統 那么會自動安裝IIS,如果是xp 系統請使用系統
光盤進行安裝。參考下面的地址
http://blog.sina.com.cn/s/blog_4eac972c0100c8zh.html
vs2008 的下載請大家到迅雷去下載。?
sharpmap 1.1 的下載地址是?
http://download.codeplex.com/Project/Download/SourceControlFileDownload.ashx?
ProjectName=SharpMap&changeSetId=64449
sharpmap現在的版本是 2.0 版本。但是2.0版本沒有提供web的例子,所以這里還是使用1.1 版本。很多
朋友能在網上找到的是0.9版本的中文,其實差不多。
首先可以直接雙擊Demo程序里面的 SharpMap.VS2008.sln 使用 vs2008 打開。
然后會有很多的項目被加載,請耐心等待。 加載完項目以后可以使用 ctrl + shift + b 進行編譯。如
果下載的是 SharpMap-64449 那么會出現編譯錯誤,提示 SharpMap.Data.Providers.0gr 未定義。這里
為了能正常運行程序,請修改所有這樣的報錯代碼 ?SharpMap.Data.Providers.0gr 為?
SharpMap.Data.Providers.ShapeFile
到此就可以正常運行了。然后在Demowebsite 上右鍵選擇 “設為啟動項目”,然后選擇Default.aspx?
然后右鍵選擇設為起始頁。然后按F5。 恭喜你現在已經可以正常的使用 sharpmap 的demo程序了。
==========================================================================
Gis初學者之sharpmap(一)?
http://www.cnblogs.com/52x/archive/2010/05/19/1739433.html創建一個類似于 sample 的那樣的程序。
1. 啟動vs2008 點新建 -- 項目?
然后選擇 web -- asp.net 應用程序。
選擇程序要防止的位置 、程序解決方案 和 名稱。然后確定。
可以看到程序會自動為您創建很多東西。接下來我們來認識這些東西。
2. default.aspx是默認創建的頁面。也是我們今天要進行操作的頁面。
首頁雙擊 default.aspx 然后會看到如下的代碼
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"?
Inherits="Web._Default" %>
<%@ Register assembly="SharpMap.UI" namespace="SharpMap.Web.UI.Ajax" tagprefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"?
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
? ? <title></title>
</head>
<body>
? ? <form id="form1" runat="server">
? ? <div>
? ??
? ? </div>
? ? </form>
</body>
</html>
然后我們在這里的 div 中間添加代碼?
<asp:RadioButtonList ID="rblMapTools" runat="server" RepeatDirection="Horizontal">
? ? ? ? ? ? <asp:ListItem Value="0">Zoom in</asp:ListItem>
? ? ? ? ? ? <asp:ListItem Value="1">Zoom out</asp:ListItem>
? ? ? ? ? ? <asp:ListItem Value="2" Selected="True">Pan</asp:ListItem>
? ? ? ? </asp:RadioButtonList>
? ? ? ? <asp:ImageButton runat="server" Width="700" Height="400" ID="imgMap"?
OnClick="imgMap_Click" />
然后點擊左下角的設計。這樣會變成設計視圖,我們可以看到有一個單選按鈕組和一個圖片按鈕。然后
雙擊圖片按鈕。
雙擊以后會進入程序代碼界面。我把注釋寫在程序里面這樣不介紹自動的生成代碼了。
會看到如下的代碼:
//程序需要使用的類的命名空間
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
//使用sharp的類需要引入的命名空間
using SharpMap.Geometries;
using SharpMap.Converters.WellKnownBinary;
//網站的命名空間
namespace Web
{
? ? //網站的頁面對應的管理類的名稱
? ? public partial class _Default : System.Web.UI.Page
? ? {
? ? ? ? /// <summary>
? ? ? ? /// 頁面加載方法,頁面加載的時候進行的操作放在這個方法里面
? ? ? ? /// </summary>
? ? ? ? /// <param name="sender"></param>
? ? ? ? /// <param name="e"></param>
? ? ? ? protected void Page_Load(object sender, EventArgs e)
? ? ? ? {
? ? ? ? }
? ? ? ? /// <summary>
? ? ? ? /// 圖片按鈕點擊觸發的方法
? ? ? ? /// </summary>
? ? ? ? /// <param name="sender">觸發的對象</param>
? ? ? ? /// <param name="e">事件對象</param>
? ? ? ? protected void imgMap_Click(object sender, ImageClickEventArgs e)
? ? ? ? {
? ? ? ? }
? ? }
}
ok 現在開始我們的程序了。 在類里面生成私有變量
//定義地圖對象
?private SharpMap.Map myMap;
然后從官方給的 demo程序的sample.aspx.cs里面復制代碼
private void GenerateMap()
? ? ? ? {
? ? ? ? ? ? //Save the current mapcenter and zoom in the viewstate
? ? ? ? ? ? ViewState.Add("mapCenter", myMap.Center);
? ? ? ? ? ? ViewState.Add("mapZoom", myMap.Zoom);
? ? ? ? ? ? //Render map
? ? ? ? ? ? this.Label1.Text = myMap.Layers[0].LayerName;
? ? ? ? ? ? System.Drawing.Image img = myMap.GetMap();
? ? ? ? ? ? string imgID = SharpMap.Web.Caching.InsertIntoCache(1, img);
? ? ? ? ? ? imgMap.ImageUrl = "getmap.aspx?ID=" + HttpUtility.UrlEncode(imgID);
? ? ? ? }
到程序里面。
然后在Page_load 方法里面添加代碼
myMap = MapHelper.InitializeGradientMap(new System.Drawing.Size((int)imgMap.Width.Value,?
(int)imgMap.Height.Value));
? ? ? ? ? ? if (Page.IsPostBack)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? //Page is post back. Restore center and zoom-values from viewstate
? ? ? ? ? ? ? ? myMap.Center = (SharpMap.Geometries.Point)ViewState["mapCenter"];
? ? ? ? ? ? ? ? myMap.Zoom = (double)ViewState["mapZoom"];
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? GenerateMap();
? ? ? ? ? ? }
在imgMap_Click 方法里面添加
//Set center of the map to where the client clicked
? ? ? ? ? ? myMap.Center = myMap.ImageToWorld(new System.Drawing.Point(e.X, e.Y));
? ? ? ? ? ? //Set zoom value if any of the zoom tools were selected
? ? ? ? ? ? if (rblMapTools.SelectedValue == "0") //Zoom in
? ? ? ? ? ? ? ? myMap.Zoom = myMap.Zoom * 0.5;
? ? ? ? ? ? else if (rblMapTools.SelectedValue == "1") //Zoom out
? ? ? ? ? ? ? ? myMap.Zoom = myMap.Zoom * 2;
? ? ? ? ? ? //Create the map
? ? ? ? ? ? GenerateMap();
接下來,在程序的
?
App_Data上點擊右鍵,然后選擇添加現有項。然后在官方Demo程序里面的App_Data 里面的文件全選。然
后點擊確定。(這里是為了加載地圖,以后我們可能使用別的地圖。也使用同樣的方法添加就可以了。
)
ok 到這里我們已經大功告成了。按F5 運行。
這時會出現報錯
錯誤 ? ?1 ? ?當前上下文中不存在名稱“MapHelper” ? ?F:\程序\net\SharpMap\Web
\Default.aspx.cs ? ?29 ? ?21 ? ?Web
這里提示我們沒有 MapHelper 類。
如何解決呢,我們在我們這個圖的?
?
帶小地圖圖標的web(這里的web是我創建的網站的名稱,如果大家使用別的名稱可以選擇你創建的網站
的名稱)上點擊右鍵選擇添加現有項。然后選擇官方Demo程序里面的MapHelper 文件。
這時候再F5 運行程序。
這時候會出現一個頁面。就是我們的成果了,但是我們會發現,為什么圖片是一個小叉叉,沒有出現我
們理想的地圖呢。。。。。
如何解決這個問題呢,很簡單。雙擊web.config 然后從官方Demo程序里面可以看到有這樣的代碼
<httpHandlers>
? ? ? ? ? ? <add verb="*" path="GetMap.aspx" type="SharpMap.Web.HttpHandler,SharpMap"/>
? ? ? ? </httpHandlers>
我們復制 add 這行到我們網站的 web.config 的httphandlers 的里面。
現在我們F5 運行,是不是已經能看到地圖了?而且可以放大縮小,哈哈。今天我們的任務完成了。
========
開源地圖 SharpMap
http://www.cnblogs.com/hanwen/p/4067472.htmlStep1 創建一個地圖控件
1、啟動Visual Studio 2012 并創建一個新的Windows應用程序
2、調整項目到.net Framework 4.0全框架
3、打開Form1的設計視圖
4、在工具箱底部,常規右擊點擊“選擇項”?
4、瀏覽SharpMap.UI.dll并添加
SharpMap的dll和地圖文件網盤共享地址:http://pan.baidu.com/s/1hqzG0de (內含Demo)
5、點擊確定如圖:
6、拖動MapBox控件插入Form1窗體中
7、將mapBox1控件背景色設置為白色,Dock屬性設置為Fill
Step2 添加一個圖層到地圖控件
?
1、添加SharpMap.dll到項目
2、添加地圖文件到項目
3、修改窗體構造函數Fomr1()
public Form1()
? ? ? ? {
? ? ? ? ? ? InitializeComponent();
? ? ? ? ? ? VectorLayer vlay = new VectorLayer("States")
? ? ? ? ? ? {
? ? ? ? ? ? ? ? DataSource = new ShapeFile(@"path_to_data\states_ugl.shp", true)
? ? ? ? ? ? };
? ? ? ? ? ? mapBox1.Map.Layers.Add(vlay);
? ? ? ? ? ? mapBox1.Map.ZoomToExtents();
? ? ? ? ? ? mapBox1.Refresh();
? ? ? ? ? ? mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.Pan;//設置平移
? ? ? ? }
4、運行地圖可以看到地圖,并操作放大、縮小、平移
?Step3 給圖層添加樣式
1、修改窗體構造函數Fomr2() 參見Dome
public Form2()
? ? ? ? {
? ? ? ? ? ? InitializeComponent();
? ? ? ? ? ? SharpMap.Layers.VectorLayer vlay = new SharpMap.Layers.VectorLayer("States");
? ? ? ? ? ? vlay.DataSource = new SharpMap.Data.Providers.ShapeFile(@"path_to_data
\states_ugl.shp", true);
? ? ? ? ? ? //構造土地樣式
? ? ? ? ? ? VectorStyle landStyle = new VectorStyle();
? ? ? ? ? ? landStyle.Fill = new SolidBrush(Color.FromArgb(232, 232, 232));
? ? ? ? ? ? //構造水樣式
? ? ? ? ? ? VectorStyle waterStyle = new VectorStyle();
? ? ? ? ? ? waterStyle.Fill = new SolidBrush(Color.FromArgb(198, 198, 255));
? ? ? ? ? ? //創建地圖
? ? ? ? ? ? Dictionary<string, SharpMap.Styles.IStyle> styles = new Dictionary<string,?
IStyle>();
? ? ? ? ? ? styles.Add("land", landStyle);
? ? ? ? ? ? styles.Add("water", waterStyle);
? ? ? ? ? ? //分配主題
? ? ? ? ? ? vlay.Theme = new SharpMap.Rendering.Thematics.UniqueValuesTheme<string>
("class", styles, landStyle);
? ? ? ? ? ? mapBox1.Map.Layers.Add(vlay);
? ? ? ? ? ? mapBox1.Map.ZoomToExtents();
? ? ? ? ? ? mapBox1.Refresh();
? ? ? ? ? ? mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.Pan;
? ? ? ? }
2、運行程序,如圖
? Step4 添加WMS-層到地圖
1、修改From3構造函數()
? ?調用
http://sampleserver1.arcgisonline.com/ArcGIS/services/Specialty/ESRI_StatesCitiesRivers_USA
/MapServer/WMSServer 服務器記載數據。
public Form3()
? ? ? ? {
? ? ? ? ? ? InitializeComponent();
? ? ? ? ? ? SharpMap.Layers.VectorLayer vlay = new SharpMap.Layers.VectorLayer("States");
? ? ? ? ? ? vlay.DataSource = new SharpMap.Data.Providers.ShapeFile(@"path_to_data
\states_ugl.shp", true);
? ? ? ? ? ? //構造土地樣式
? ? ? ? ? ? VectorStyle landStyle = new VectorStyle();
? ? ? ? ? ? landStyle.Fill = new SolidBrush(Color.FromArgb(232, 232, 232));
? ? ? ? ? ? //構造水樣式
? ? ? ? ? ? VectorStyle waterStyle = new VectorStyle();
? ? ? ? ? ? waterStyle.Fill = new SolidBrush(Color.FromArgb(198, 198, 255));
? ? ? ? ? ? //創建地圖
? ? ? ? ? ? Dictionary<string, SharpMap.Styles.IStyle> styles = new Dictionary<string,?
IStyle>();
? ? ? ? ? ? styles.Add("land", landStyle);
? ? ? ? ? ? styles.Add("water", waterStyle);
? ? ? ? ? ? //分配主題
? ? ? ? ? ? vlay.Theme = new SharpMap.Rendering.Thematics.UniqueValuesTheme<string>
("class", styles, landStyle);
? ? ? ? ? ? mapBox1.Map.Layers.Add(vlay);
? ? ? ? ? ? mapBox1.Map.ZoomToExtents();
? ? ? ? ? ? mapBox1.Refresh();
? ? ? ? ? ? mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.Pan;
? ? ? ? ? ? SharpMap.Layers.WmsLayer wmsL =new SharpMap.Layers.WmsLayer("US?
Cities","http://sampleserver1.arcgisonline.com/ArcGIS/services/Specialty/ESRI_StatesCitiesR
ivers_USA/MapServer/WMSServer");
? ? ? ? ? ? //轉換為PNG
? ? ? ? ? ? wmsL.SetImageFormat("image/png");
? ? ? ? ? ? //11.0版本
? ? ? ? ? ? wmsL.Version = "1.1.0";
? ? ? ? ? ? //添加城市圖層 服務名稱2
? ? ? ? ? ? wmsL.AddLayer("2");
? ? ? ? ? ? //設置 SRID
? ? ? ? ? ? wmsL.SRID = 4326;
? ? ? ? ? ? mapBox1.Map.Layers.Add(wmsL);
? ? ? ? }
?2、運行程序如圖,顯示城鎮。
?Step5 添加一個平鋪層作為背景
?在這個步驟中,可以結合網上瓦片服務器數據連同本地數據顯示。
?1、添加BruTile.dll、ProjNet.dll、GeoAPI.dll 到項目中
?2、添加輔助方法來創建google坐標系
? private ?GeoAPI.CoordinateSystems.IProjectedCoordinateSystem GetEPSG900913
(ProjNet.CoordinateSystems.CoordinateSystemFactory csFact)
? ? ? ? {
? ? ? ? ? ? List<GeoAPI.CoordinateSystems.ProjectionParameter> parameters = new?
List<GeoAPI.CoordinateSystems.ProjectionParameter>();
? ? ? ? ? ? parameters.Add(new GeoAPI.CoordinateSystems.ProjectionParameter("semi_major",?
6378137.0));
? ? ? ? ? ? parameters.Add(new GeoAPI.CoordinateSystems.ProjectionParameter("semi_minor",?
6378137.0));
? ? ? ? ? ? parameters.Add(new GeoAPI.CoordinateSystems.ProjectionParameter
("latitude_of_origin", 0.0));
? ? ? ? ? ? parameters.Add(new GeoAPI.CoordinateSystems.ProjectionParameter
("central_meridian", 0.0));
? ? ? ? ? ? parameters.Add(new GeoAPI.CoordinateSystems.ProjectionParameter("scale_factor",?
1.0));
? ? ? ? ? ? parameters.Add(new GeoAPI.CoordinateSystems.ProjectionParameter
("false_easting", 0.0));
? ? ? ? ? ? parameters.Add(new GeoAPI.CoordinateSystems.ProjectionParameter
("false_northing", 0.0));
? ? ? ? ? ? GeoAPI.CoordinateSystems.IProjection projection = csFact.CreateProjection
("Google Mercator", "mercator_1sp", parameters);
? ? ? ? ? ? GeoAPI.CoordinateSystems.IGeographicCoordinateSystem wgs84 =?
csFact.CreateGeographicCoordinateSystem(
? ? ? ? ? ? ? ? "WGS 84", ProjNet.CoordinateSystems.AngularUnit.Degrees,?
ProjNet.CoordinateSystems.HorizontalDatum.WGS84,?
ProjNet.CoordinateSystems.PrimeMeridian.Greenwich,
? ? ? ? ? ? ? ? new GeoAPI.CoordinateSystems.AxisInfo("north",?
GeoAPI.CoordinateSystems.AxisOrientationEnum.North), new GeoAPI.CoordinateSystems.AxisInfo
("east", GeoAPI.CoordinateSystems.AxisOrientationEnum.East)
? ? ? ? ? ? );
? ? ? ? ? ? GeoAPI.CoordinateSystems.IProjectedCoordinateSystem epsg900913 =?
csFact.CreateProjectedCoordinateSystem("Google Mercator", wgs84, projection,?
ProjNet.CoordinateSystems.LinearUnit.Metre,
? ? ? ? ? ? ? new GeoAPI.CoordinateSystems.AxisInfo("East",?
GeoAPI.CoordinateSystems.AxisOrientationEnum.East), new GeoAPI.CoordinateSystems.AxisInfo
("North", GeoAPI.CoordinateSystems.AxisOrientationEnum.North));
? ? ? ? ? ? return epsg900913;
? ? ? ? }
?3、修改構造函數Form4()
? ? ? ? public Form4()
? ? ? ? {
? ? ? ? ? ? InitializeComponent();
? ? ? ? ? ? SharpMap.Layers.VectorLayer vlay = new SharpMap.Layers.VectorLayer("States");
? ? ? ? ? ? vlay.DataSource = new SharpMap.Data.Providers.ShapeFile(@"path_to_data
\states_ugl.shp", true);
? ? ? ? ? ? //構造土地樣式
? ? ? ? ? ? VectorStyle landStyle = new VectorStyle();
? ? ? ? ? ? landStyle.Fill = new SolidBrush(Color.FromArgb(232, 232, 232));
? ? ? ? ? ? //創造水樣式
? ? ? ? ? ? VectorStyle waterStyle = new VectorStyle();
? ? ? ? ? ? waterStyle.Fill = new SolidBrush(Color.FromArgb(198, 198, 255));
? ? ? ? ? ? //創造地圖
? ? ? ? ? ? Dictionary<string, SharpMap.Styles.IStyle> styles = new Dictionary<string,?
IStyle>();
? ? ? ? ? ? styles.Add("land", landStyle);
? ? ? ? ? ? styles.Add("water", waterStyle);
? ? ? ? ? ? //分配主題
? ? ? ? ? ? vlay.Theme = new SharpMap.Rendering.Thematics.UniqueValuesTheme<string>
("class", styles, landStyle);
? ? ? ? ? ? mapBox1.Map.Layers.Add(vlay);
? ? ? ? ? ? ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory?
ctFact = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory();
? ? ? ? ? ? ProjNet.CoordinateSystems.CoordinateSystemFactory csFact = new?
ProjNet.CoordinateSystems.CoordinateSystemFactory();
? ? ? ? ? ? vlay.CoordinateTransformation = ctFact.CreateFromCoordinateSystems
(ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84, GetEPSG900913(csFact));
? ? ? ? ? ? vlay.ReverseCoordinateTransformation = ctFact.CreateFromCoordinateSystems
(GetEPSG900913(csFact), ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84);
? ? ? ? ? ? mapBox1.Map.BackgroundLayer.Add(new SharpMap.Layers.TileAsyncLayer(
? ? ? ? ? ? ? ? new BruTile.Web.OsmTileSource(), "OSM"));
? ? ? ? ? ? mapBox1.Map.ZoomToExtents();
? ? ? ? ? ? mapBox1.Refresh();
? ? ? ? ? ? mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.Pan;
? ? ? ? }
?4、運行程序,如圖:
========
總結
以上是生活随笔為你收集整理的C# SharpMap 学习总结的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux进程地址空间学习总结
- 下一篇: 地图瓦片相关学习总结