基于.NET 2.0的GIS开源项目SharpMap分析手记(三):地图渲染分析

 
1 运行过程
我们通过实例来讲述SharpMap的运行过程和渲染(绘制)机制。首先打开Simple.aspx,可知此页面有一组单选框(3个,分别是放大、缩小和漫游)和一个图像按钮,用于显示地图。它的代码在Simple.aspx.cs中。
打开Simple.aspx.cs,在Page_Load函数中是页面初始化代码。可知地图生成分两步:
1.1 初始化地图
//Set up the map. We use the method in the App_Code folder for initializing the map
myMap = MapHelper.InitializeMap(new
 System.Drawing.Size((int)imgMap.Width.Value,(int)imgMap.Height.Value));
我们找到MapHelper.InitializeMap函数,发现地图的初始化分为以下几步:
(1)创建地图,创建图层
//Initialize a new map of size 'imagesize'
SharpMap.Map map = new SharpMap.Map(size);
                            
//Set up the countries layer
SharpMap.Layers.VectorLayer layCountries = new SharpMap.Layers.VectorLayer("Countries");
//Set the datasource to a shapefile in the App_data folder
layCountries.DataSource = new
SharpMap.Data.Providers.ShapeFile(HttpContext.Current.Server.MapPath(@"~/App_data/countries.shp"), true);
 
(2)基本的图层显示设置
//Set fill-style to green
layCountries.Style.Fill = new SolidBrush(Color.Green);
//Set the polygons to have a black outline
layCountries.Style.Outline = System.Drawing.Pens.Black;
layCountries.Style.EnableOutline = true;
layCountries.SRID = 4326;
 
(3)加入图层到地图
//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);
 
(4)地图放缩、背景、中心等设置
//limit the zoom to 360 degrees width
map.MaximumZoom = 360;
map.BackColor = Color.LightBlue;
 
map.Zoom = 360;
map.Center = new SharpMap.Geometries.Point(0,0);
 
1.2 绘制并生成地图
我们回到Simple.aspx.cs的Page_Load函数,发现下一步调用GenerateMap();
//This is the initial view of the map. Zoom to the
  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值