如何在sharpMap地理信息系统的ajax网页里填色?
按照sharpMap的demo,ajax简单功能和填色分别是两个demo。但当我想用ajax功能的网页里填色的时候,却始终无法实现。
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using SharpMap.Rendering.Thematics;
using System.Drawing;
public partial class Ajax : System.Web.UI.Page
{
private SharpMap.Styles.VectorStyle GetCountryStyle(SharpMap.Data.FeatureDataRow row)
{
SharpMap.Styles.VectorStyle style = new SharpMap.Styles.VectorStyle();
switch (row["RANK"].ToString().ToLower())
{
case "1": //1为绿色
style.Fill = Brushes.Green;
return style;
case "2": //2为蓝色
style.Fill = Brushes.Blue;
return style;
case "3": //3为黄色
style.Fill = Brushes.Yellow;
return style;
case "4"://4为橙色
style.Fill = Brushes.Orange;
return style;
case "5"://5为红色
style.Fill = Brushes.Red;
return style;
default:
style.Fill = Brushes.White;
return style;
}
}
protected void Page_Load(object sender, EventArgs e)
{
//ajaxMap.Map = MapHelper.InitializeMap(new System.Drawing.Size(10, 10));
ajaxMap.Map = MapHelper.InitializeMap(new System.Drawing.Size(10, 10));
SharpMap.Rendering.Thematics.CustomTheme iTheme = new SharpMap.Rendering.Thematics.CustomTheme(GetCountryStyle) ;
SharpMap.Styles.VectorStyle defaultstyle = new SharpMap.Styles.VectorStyle();
defaultstyle.Fill = Brushes.White;
iTheme.DefaultStyle = defaultstyle;
(ajaxMap.Map.Layers[0] as SharpMap.Layers.VectorLayer).Theme = iTheme;
if (!Page.IsPostBack && !Page.IsCallback)
{
//Set up the map. We use the method in the App_Code folder for initializing the map
ajaxMap.Map.Center = new SharpMap.Geometries.Point(116.0, 27.0);
ajaxMap.FadeSpeed = 10;
ajaxMap.ZoomSpeed = 10;
ajaxMap.Map.Zoom = 5.2;
GenerateMap();
}
ajaxMap.ResponseFormat = "maphandler.ashx?MAP=SimpleWorld&Width=[WIDTH]&Height=[HEIGHT]&Zoom=[ZOOM]&X=[X]&Y=[Y]";
}
private void GenerateMap()
{
//Save the current mapcenter and zoom in the viewstate
ViewState.Add("mapCenter", ajaxMap.Map.Center);
ViewState.Add("mapZoom", ajaxMap.Map .Zoom);
System.Drawing.Image img = ajaxMap.Map .GetMap();
string imgID = SharpMap.Web.Caching.InsertIntoCache(1, img);
ajaxMap.Map.ImageUrl = "getmap.aspx?ID=" + HttpUtility.UrlEncode(imgID);
}
}
关键是最后一行代码,ajaxMap.Map是没有ImageUrl方法的,原demo的这个位置是“imgMap.ImageUrl”,是一个imagelabel控件。既然sharpMap的ajaxMapControl控件没有提供ImageUrl控件,那到底应该如何去给ajax控件里填色呢?