日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > C# >内容正文

C#

C# SharpMap 学习总结

發(fā)布時(shí)間:2025/4/14 C# 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 C# SharpMap 学习总结 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

SharpMap V1.1 For Web教程系列之——地圖展示



SharpMap V1.1 For Web教程系列之——地圖展示 開篇先說本次的開發(fā)環(huán)境吧。采用Vs2010,.Net?


Framework 4.0。
為了更好的調(diào)試程序,建議在IIS中進(jìn)行調(diào)試及運(yùn)行,個(gè)人非常不喜歡利用VS自己提供的WebServer去調(diào)


試程序,而且很多在Web.config中的設(shè)置也需要在IIS中才能起到效果!
開發(fā)環(huán)境我就不要介紹了,先來說說SharpMap的組件要求吧。由于SharpMap的架構(gòu)一直在變化和改進(jìn)過


程中,因此參考網(wǎng)絡(luò)上別人的事例代碼,你會(huì)發(fā)現(xiàn)都運(yùn)行不起來,不是接口沒了,就是命名空間變了,


這點(diǎn)我也希望SharpMap早日穩(wěn)定下來。
這次使用的SharpMap的版本是V1.1版本,官方意見提供最新穩(wěn)定版的下載了,官方網(wǎng)址為:


http://sharpmap.codeplex.com/
SharpMap 1.1版本的下載地址為:http://sharpmap.codeplex.com/downloads/get/792797?,發(fā)布時(shí)間


為2014年12月11日;該版本只是SharpMap的核心庫(Core+UI),下載完后,為了Web開發(fā)還必須下載一個(gè)


Web端的庫,本人做完因?yàn)檫@一步走了好多彎路,網(wǎng)絡(luò)上的教程也沒有人寫上著一點(diǎn)。在官網(wǎng)的


DOWNLOADS節(jié)點(diǎn)下有個(gè)下載界面,需要下載SharpMap.Web這個(gè)組件。
OK!所需庫完成后,下面進(jìn)行Asp.Net的網(wǎng)站開發(fā)!你也可以不看下面的代碼,直接下載整個(gè)網(wǎng)站。解決


方案下載地址:http://pan.baidu.com/s/1i3vdUcd
打開VS2010,新建一個(gè)網(wǎng)站,?新建一個(gè)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測(cè)試</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下配置文件,紅色部分表示這個(gè)地方和SharpMap官網(wǎng)以及互聯(lián)網(wǎng)


上很多教程里面的區(qū)別。


<?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);


? ? ? ? //設(shè)置太原市區(qū)域圖層
? ? ? ? SharpMap.Layers.VectorLayer layTy = new SharpMap.Layers.VectorLayer("ty");
? ? ? ? layTy.DataSource = new SharpMap.Data.Providers.ShapeFile


(HttpContext.Current.Server.MapPath(@"~\App_data\Taiyuan\區(qū)縣級(jí)行政區(qū)劃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;


? ? ? ? //設(shè)置鎮(zhèn)的圖層
? ? ? ? SharpMap.Layers.VectorLayer layZ = new SharpMap.Layers.VectorLayer("z");
? ? ? ? layZ.DataSource = new SharpMap.Data.Providers.ShapeFile


(HttpContext.Current.Server.MapPath(@"~\App_data\Taiyuan\鎮(zhèn).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;


? ? ? ? //設(shè)置河流的圖層
? ? ? ? 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;


? ? ? ? //設(shè)置國道的圖層
? ? ? ? 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\基礎(chǔ)地標(biāo).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 鎮(zhèn) 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創(chuàng)建應(yīng)用程序教程



首先,下載SharpMap,下載地址:http://sharpmap.codeplex.com/releases/view/116326
下載完成后解壓。再下載演示程序所用的地圖文件,下載地址:
http://115.com/lb/5lbdeevtkasp
115網(wǎng)盤禮包碼:5lbdeevtkasp
下載完解壓,得到文件states_ugl.dbf,states_ugl.shp,states_ugl.shx。


一、創(chuàng)建一個(gè)包括MapControl的窗體
1、啟動(dòng)vs并且創(chuàng)建一個(gè)窗體應(yīng)用程序。
2、切換至.net4 full framewark。
右擊項(xiàng)目,點(diǎn)擊屬性,在應(yīng)用程序標(biāo)簽內(nèi)容內(nèi)的目標(biāo)框架處選擇.NET Framework 4。
SharpMap創(chuàng)建應(yīng)用程序教程
3、打開窗口設(shè)計(jì)
4、在工具箱“常規(guī)”下方的空白處右擊,然后點(diǎn)擊“選擇項(xiàng)”。
SharpMap創(chuàng)建應(yīng)用程序教程
5、在彈出的窗口中,點(diǎn)擊“瀏覽”,選擇SharpMap解壓出來的文件中的SharpMap.UI.dll,再點(diǎn)擊確定



完成之后會(huì)看到“常規(guī)”下面多了幾項(xiàng),其中包括MapBox。
SharpMap創(chuàng)建應(yīng)用程序教程
6、拖動(dòng)MapBox控件至剛才新建的窗全中,將會(huì)在窗體上增加一個(gè)地圖。
這時(shí)候,一般會(huì)自動(dòng)添加對(duì)SharpMap.dll的引用。
7、選擇這個(gè)地圖,在右側(cè)背景色屬性中改為白色以區(qū)別窗體本身的顏色。
SharpMap創(chuàng)建應(yīng)用程序教程


二、在地圖上增加一個(gè)層
在這一步,將會(huì)增加一個(gè)層到上一步創(chuàng)建的地圖中。
1、如果在上一步中沒有自動(dòng)添加對(duì)SharpMap.dll的引用,請(qǐng)右擊項(xiàng)目下的“引用”,添加引用。選擇


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();
? ? ? ? }
? ? }
然后,把第一步中下載的三個(gè)地圖文件,復(fù)制到程序的Debug文件夾中供程序使用。
4、啟動(dòng)調(diào)試,就可以看到一個(gè)疑似地圖的圖形了。
5、添加功能工具。


mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.Pan;
把這行代碼加到上面代碼的后面。
6、再調(diào)試程序,將會(huì)看到可以鼠標(biāo)的中輪滾動(dòng)來放大或縮小地圖。SharpMap創(chuàng)建應(yīng)用程序教程


三、用UniqueValueRenderer改變層的風(fēng)格樣式。
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);


? ? ? ? ? ? //創(chuàng)建大陸的樣式
? ? ? ? ? ? VectorStyle landStyle = new VectorStyle();
? ? ? ? ? ? landStyle.Fill = new SolidBrush(Color.FromArgb(232, 232, 232));




? ? ? ? ? ? //創(chuàng)建水域的樣式。
? ? ? ? ? ? VectorStyle waterStyle = new VectorStyle();
? ? ? ? ? ? waterStyle.Fill = new SolidBrush(Color.FromArgb(198, 198, 255));


? ? ? ? ? ? //創(chuàng)建樣式組
? ? ? ? ? ? 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;
? ? ? ? }
? ? }
再次調(diào)試運(yùn)行,將會(huì)看到已經(jīng)上色了。
SharpMap創(chuàng)建應(yīng)用程序教程


四、上數(shù)據(jù)層
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");
? ? ? ? ? ? //設(shè)定圖標(biāo)格式
? ? ? ? ? ? wmsL.SetImageFormat("image/png");
? ? ? ? ? ? //設(shè)定版本號(hào)
? ? ? ? ? ? wmsL.Version = "1.1.1";
? ? ? ? ? ? //為wms添加一個(gè)名字為2的層
? ? ? ? ? ? wmsL.AddLayer("2");
? ? ? ? ? ? //設(shè)定空間參考識(shí)別碼,這個(gè)東西是什么意思,自己去百度吧。
? ? ? ? ? ? wmsL.SRID = 4326;
? ? ? ? ? ? mapBox1.Map.Layers.Add(wmsL);
再調(diào)試運(yùn)行,將全看到一個(gè)城市的分布圖。官網(wǎng)給的那地址打不開了,找了一個(gè)相關(guān)的。
SharpMap創(chuàng)建應(yīng)用程序教程
不翻了,累,后面就差一節(jié)講怎么加背景色的了。
========

Gis初學(xué)者之sharpmap



今天開始了解sharpmap,來做webgis的項(xiàng)目。為什么要用sharpmap呢?
第一,開源。開源代表著免費(fèi),對(duì)于那些商業(yè)版高達(dá)十幾萬甚至幾十萬的費(fèi)用來說,小弟只能選擇這個(gè)


。
第二,是.net 的,因?yàn)楸救艘恢笔褂梦④浵盗械臇|西進(jìn)行開發(fā),所以選擇了這個(gè)。


準(zhǔn)備工作,需要有vs2008 和 sharpmap 1.1的demo。
IIS 推薦大家提前安裝好IIS ,如果是 server的系統(tǒng) 那么會(huì)自動(dòng)安裝IIS,如果是xp 系統(tǒng)請(qǐng)使用系統(tǒng)


光盤進(jìn)行安裝。參考下面的地址
http://blog.sina.com.cn/s/blog_4eac972c0100c8zh.html


vs2008 的下載請(qǐng)大家到迅雷去下載。?
sharpmap 1.1 的下載地址是?
http://download.codeplex.com/Project/Download/SourceControlFileDownload.ashx?


ProjectName=SharpMap&changeSetId=64449


sharpmap現(xiàn)在的版本是 2.0 版本。但是2.0版本沒有提供web的例子,所以這里還是使用1.1 版本。很多


朋友能在網(wǎng)上找到的是0.9版本的中文,其實(shí)差不多。


首先可以直接雙擊Demo程序里面的 SharpMap.VS2008.sln 使用 vs2008 打開。
然后會(huì)有很多的項(xiàng)目被加載,請(qǐng)耐心等待。 加載完項(xiàng)目以后可以使用 ctrl + shift + b 進(jìn)行編譯。如


果下載的是 SharpMap-64449 那么會(huì)出現(xiàn)編譯錯(cuò)誤,提示 SharpMap.Data.Providers.0gr 未定義。這里


為了能正常運(yùn)行程序,請(qǐng)修改所有這樣的報(bào)錯(cuò)代碼 ?SharpMap.Data.Providers.0gr 為?


SharpMap.Data.Providers.ShapeFile
到此就可以正常運(yùn)行了。然后在Demowebsite 上右鍵選擇 “設(shè)為啟動(dòng)項(xiàng)目”,然后選擇Default.aspx?


然后右鍵選擇設(shè)為起始頁。然后按F5。 恭喜你現(xiàn)在已經(jīng)可以正常的使用 sharpmap 的demo程序了。


==========================================================================

Gis初學(xué)者之sharpmap(一)?

http://www.cnblogs.com/52x/archive/2010/05/19/1739433.html


創(chuàng)建一個(gè)類似于 sample 的那樣的程序。


1. 啟動(dòng)vs2008 點(diǎn)新建 -- 項(xiàng)目?


然后選擇 web -- asp.net 應(yīng)用程序。
選擇程序要防止的位置 、程序解決方案 和 名稱。然后確定。
可以看到程序會(huì)自動(dòng)為您創(chuàng)建很多東西。接下來我們來認(rèn)識(shí)這些東西。


2. default.aspx是默認(rèn)創(chuàng)建的頁面。也是我們今天要進(jìn)行操作的頁面。
首頁雙擊 default.aspx 然后會(huì)看到如下的代碼


<%@ 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>


然后我們?cè)谶@里的 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" />
然后點(diǎn)擊左下角的設(shè)計(jì)。這樣會(huì)變成設(shè)計(jì)視圖,我們可以看到有一個(gè)單選按鈕組和一個(gè)圖片按鈕。然后


雙擊圖片按鈕。


雙擊以后會(huì)進(jìn)入程序代碼界面。我把注釋寫在程序里面這樣不介紹自動(dòng)的生成代碼了。
會(huì)看到如下的代碼:


//程序需要使用的類的命名空間
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;


//網(wǎng)站的命名空間
namespace Web
{
? ? //網(wǎng)站的頁面對(duì)應(yīng)的管理類的名稱
? ? public partial class _Default : System.Web.UI.Page
? ? {


? ? ? ? /// <summary>
? ? ? ? /// 頁面加載方法,頁面加載的時(shí)候進(jìn)行的操作放在這個(gè)方法里面
? ? ? ? /// </summary>
? ? ? ? /// <param name="sender"></param>
? ? ? ? /// <param name="e"></param>
? ? ? ? protected void Page_Load(object sender, EventArgs e)
? ? ? ? {
? ? ? ? }


? ? ? ? /// <summary>
? ? ? ? /// 圖片按鈕點(diǎn)擊觸發(fā)的方法
? ? ? ? /// </summary>
? ? ? ? /// <param name="sender">觸發(fā)的對(duì)象</param>
? ? ? ? /// <param name="e">事件對(duì)象</param>
? ? ? ? protected void imgMap_Click(object sender, ImageClickEventArgs e)
? ? ? ? {
? ? ? ? }
? ? }
}


ok 現(xiàn)在開始我們的程序了。 在類里面生成私有變量
//定義地圖對(duì)象
?private SharpMap.Map myMap;


然后從官方給的 demo程序的sample.aspx.cs里面復(fù)制代碼
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上點(diǎn)擊右鍵,然后選擇添加現(xiàn)有項(xiàng)。然后在官方Demo程序里面的App_Data 里面的文件全選。然


后點(diǎn)擊確定。(這里是為了加載地圖,以后我們可能使用別的地圖。也使用同樣的方法添加就可以了。





ok 到這里我們已經(jīng)大功告成了。按F5 運(yùn)行。
這時(shí)會(huì)出現(xiàn)報(bào)錯(cuò)
錯(cuò)誤 ? ?1 ? ?當(dāng)前上下文中不存在名稱“MapHelper” ? ?F:\程序\net\SharpMap\Web


\Default.aspx.cs ? ?29 ? ?21 ? ?Web
這里提示我們沒有 MapHelper 類。
如何解決呢,我們?cè)谖覀冞@個(gè)圖的?
?
帶小地圖圖標(biāo)的web(這里的web是我創(chuàng)建的網(wǎng)站的名稱,如果大家使用別的名稱可以選擇你創(chuàng)建的網(wǎng)站


的名稱)上點(diǎn)擊右鍵選擇添加現(xiàn)有項(xiàng)。然后選擇官方Demo程序里面的MapHelper 文件。


這時(shí)候再F5 運(yùn)行程序。
這時(shí)候會(huì)出現(xiàn)一個(gè)頁面。就是我們的成果了,但是我們會(huì)發(fā)現(xiàn),為什么圖片是一個(gè)小叉叉,沒有出現(xiàn)我


們理想的地圖呢。。。。。


如何解決這個(gè)問題呢,很簡(jiǎn)單。雙擊web.config 然后從官方Demo程序里面可以看到有這樣的代碼
<httpHandlers>
? ? ? ? ? ? <add verb="*" path="GetMap.aspx" type="SharpMap.Web.HttpHandler,SharpMap"/>
? ? ? ? </httpHandlers>
我們復(fù)制 add 這行到我們網(wǎng)站的 web.config 的httphandlers 的里面。


現(xiàn)在我們F5 運(yùn)行,是不是已經(jīng)能看到地圖了?而且可以放大縮小,哈哈。今天我們的任務(wù)完成了。
========

開源地圖 SharpMap

http://www.cnblogs.com/hanwen/p/4067472.html
Step1 創(chuàng)建一個(gè)地圖控件
1、啟動(dòng)Visual Studio 2012 并創(chuàng)建一個(gè)新的Windows應(yīng)用程序


2、調(diào)整項(xiàng)目到.net Framework 4.0全框架


3、打開Form1的設(shè)計(jì)視圖


4、在工具箱底部,常規(guī)右擊點(diǎn)擊“選擇項(xiàng)”?


4、瀏覽SharpMap.UI.dll并添加


 SharpMap的dll和地圖文件網(wǎng)盤共享地址:http://pan.baidu.com/s/1hqzG0de (內(nèi)含Demo)


5、點(diǎn)擊確定如圖:


6、拖動(dòng)MapBox控件插入Form1窗體中


7、將mapBox1控件背景色設(shè)置為白色,Dock屬性設(shè)置為Fill
 
Step2 添加一個(gè)圖層到地圖控件
?
1、添加SharpMap.dll到項(xiàng)目


2、添加地圖文件到項(xiàng)目
  
3、修改窗體構(gòu)造函數(shù)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;//設(shè)置平移
? ? ? ? }


4、運(yùn)行地圖可以看到地圖,并操作放大、縮小、平移


?Step3 給圖層添加樣式


1、修改窗體構(gòu)造函數(shù)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);


? ? ? ? ? ? //構(gòu)造土地樣式
? ? ? ? ? ? VectorStyle landStyle = new VectorStyle();
? ? ? ? ? ? landStyle.Fill = new SolidBrush(Color.FromArgb(232, 232, 232));


? ? ? ? ? ? //構(gòu)造水樣式
? ? ? ? ? ? VectorStyle waterStyle = new VectorStyle();
? ? ? ? ? ? waterStyle.Fill = new SolidBrush(Color.FromArgb(198, 198, 255));


? ? ? ? ? ? //創(chuàng)建地圖
? ? ? ? ? ? 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、運(yùn)行程序,如圖


? Step4 添加WMS-層到地圖
1、修改From3構(gòu)造函數(shù)()


? ?調(diào)用


http://sampleserver1.arcgisonline.com/ArcGIS/services/Specialty/ESRI_StatesCitiesRivers_USA


/MapServer/WMSServer 服務(wù)器記載數(shù)據(jù)。


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);


? ? ? ? ? ? //構(gòu)造土地樣式
? ? ? ? ? ? VectorStyle landStyle = new VectorStyle();
? ? ? ? ? ? landStyle.Fill = new SolidBrush(Color.FromArgb(232, 232, 232));


? ? ? ? ? ? //構(gòu)造水樣式
? ? ? ? ? ? VectorStyle waterStyle = new VectorStyle();
? ? ? ? ? ? waterStyle.Fill = new SolidBrush(Color.FromArgb(198, 198, 255));


? ? ? ? ? ? //創(chuàng)建地圖
? ? ? ? ? ? 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");
? ? ? ? ? ? //轉(zhuǎn)換為PNG
? ? ? ? ? ? wmsL.SetImageFormat("image/png");
? ? ? ? ? ? //11.0版本
? ? ? ? ? ? wmsL.Version = "1.1.0";
? ? ? ? ? ? //添加城市圖層 服務(wù)名稱2
? ? ? ? ? ? wmsL.AddLayer("2");
? ? ? ? ? ? //設(shè)置 SRID
? ? ? ? ? ? wmsL.SRID = 4326;
? ? ? ? ? ? mapBox1.Map.Layers.Add(wmsL);
? ? ? ? }


?2、運(yùn)行程序如圖,顯示城鎮(zhèn)。


?Step5 添加一個(gè)平鋪層作為背景
?在這個(gè)步驟中,可以結(jié)合網(wǎng)上瓦片服務(wù)器數(shù)據(jù)連同本地?cái)?shù)據(jù)顯示。


?1、添加BruTile.dll、ProjNet.dll、GeoAPI.dll 到項(xiàng)目中


?2、添加輔助方法來創(chuàng)建google坐標(biāo)系


? 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、修改構(gòu)造函數(shù)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);


? ? ? ? ? ? //構(gòu)造土地樣式
? ? ? ? ? ? VectorStyle landStyle = new VectorStyle();
? ? ? ? ? ? landStyle.Fill = new SolidBrush(Color.FromArgb(232, 232, 232));


? ? ? ? ? ? //創(chuàng)造水樣式
? ? ? ? ? ? VectorStyle waterStyle = new VectorStyle();
? ? ? ? ? ? waterStyle.Fill = new SolidBrush(Color.FromArgb(198, 198, 255));


? ? ? ? ? ? //創(chuàng)造地圖
? ? ? ? ? ? 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、運(yùn)行程序,如圖:
========

總結(jié)

以上是生活随笔為你收集整理的C# SharpMap 学习总结的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 久久久久久久久久久久久久久久久久 | 男人插女人网站 | 日本精品人妻无码免费大全 | 91精彩视频在线观看 | 男男一级淫片免费播放 | 欧美一级视频免费 | 日韩色网 | 短篇山村男同肉耽h | 亚洲美女爱爱 | 欧美色淫| 香蕉污视频在线观看 | 欧美在线视频你懂的 | 波多野结衣办公室33分钟 | a三级黄色片| 亚洲高清无码久久久 | 国产一区在线视频 | 男人久久久 | 奇米网在线观看 | 欧美在线观看一区 | 亚洲午夜在线 | 国产电影免费观看高清完整版视频 | 中国黄色一级视频 | 国产黄色美女视频 | 台湾佬中文在线 | 亚洲一区二区三区播放 | 亚洲一区a | jizz国产在线 | 日本国产亚洲 | 男女做的视频 | 影音先锋中文在线 | 国产毛片久久久久久国产毛片 | www.色偷偷| 日本黄动漫 | 久久精品毛片 | 少妇又紧又深又湿又爽视频 | 69精品丰满人妻无码视频a片 | 一区二区手机在线 | 欧美日韩中 | 日韩一区二区三区久久 | 中文字幕精品一区二区精品 | 免费黄色看片 | 亚洲一区二区三区蜜桃 | 少妇2做爰bd在线意大利堕落 | 丰满大乳少妇在线观看网站 | 久久久久久久久久久影院 | 少妇xxxx | 好男人网站| 久久精品国产99精品国产亚洲性色 | 狠狠干成人| 久久六| 天天操天天操天天操天天操天天操 | 夜夜撸网站| 毛片毛片毛片毛片毛片毛片毛片毛片毛片毛片 | 亚洲第一免费播放区 | 激情五月在线 | 乱老熟女一区二区三区 | 久久精品这里只有精品 | 欧美日韩一区二区在线观看 | 亚洲黄色中文字幕 | 日韩欧美在线精品 | 麻豆剧场| 天堂va在线 | 欧美丰满熟妇xxxxx | 黄色精品视频在线观看 | 91九色论坛 | 亚洲色图校园春色 | 在线视频综合网 | 欧美爱爱免费视频 | 黄色一级黄色片 | 不卡一区二区在线 | 九色蝌蚪91 | 人人操日日干 | 欧美日韩视频一区二区 | 挪威xxxx性hd极品 | 欧美mv日韩mv国产网站 | 亚洲成人二区 | 国产精品v欧美精品v日韩精品 | 欧美一区二不卡视频 | 国产精品精品视频 | 激情伦成人综合小说 | 国产一区二区视频在线免费观看 | 国模大尺度自拍 | 2021天天操| 8090理论片午夜理伦片 | 日韩久久久精品 | 91快射 | 夜夜免费视频 | 精品成人一区 | 天天插夜夜爽 | 性色av浪潮av | 国产精品视频99 | 国产精品成人久久久久久久 | 欧美在线黄色 | 最新国产拍偷乱偷精品 | 超碰日韩| 无码精品人妻一二三区红粉影视 | 欧美人与性动交α欧美精品 | 特黄aaaaaa私密按摩 | 亚洲高清视频一区二区 |