
Since Google Earth is so popular, I thought why not join in and have SharpMap serve maps for GE? It is quite simple to make you own GE Network Link, and here are a few pointers, and you can download a demo web application you can use as well.
因为google earth太火了,我想为什么不加入呢,让SharpMap为GoogleEarth提供地图?创建你自己的GE网络连接非常简单,这里是一些指点,你也可以自己下载一个demo。
The GE Network Link basically works by requesting an XML webpage (well Google calls it KML), telling GE where to get the image tiles and where they should be placed on the globe. GE also adds a 'BBOX=minx,miny,maxx,maxy' querystring to the request so you can return a custom KML response containing the most appropriate tile(s). A response could look like this:
GE网络连接的基本工作方式是请求一个XML网页(google叫它KML),告诉GE去哪里得到图形文件,还有它们应该被放在地球上的那里。GE也在请求中添加了一个'BBOX=minx,miny,maxx,maxy' querystring以便你返回一个包含最适当标题的定制KML回应。一个回应可能是这样:
<?xml version="1.0" encoding="UTF-8" ?>
<kml xmlns="http://earth.google.com/kml/2.0">
<Document>
<open>1</open>
<GroundOverlay>
<open>1</open>
<Icon>
<href>http://localhost/TileServer.ashx?BBOX=-180,-90,0,90&size=512</href>
</Icon>
<LatLonBox>
<north>90</north>
<south>-90</south>
<east>0</east>
<west>-180</west>
<rotation>0</rotation>
</LatLonBox>
</GroundOverlay>
</Document>
</kml>
You can add as many "GroundOverlays" as you like. For instance you can cover a requested BBOX with as many tiles as you like. That way you can increase the image size/resolution or cover a larger or smaller area than initially requested while getting quicker responses. You can read more about the KML format here.
你可以任你喜欢随便添加多少"GroundOverlays"。目前你可以随你喜欢用多少tiles去描述一个请求BBOX。在获得快速回复的时候,用这种方法你可以增加图片的大小、分辨率或者比最初的请求覆盖更大/更小的面积。点击了解更多KML format。
Creating the KML is pretty straight-forward in ASP.NET, so I wont cover that here (but download the example and see for yourself).
在ASP.NET中创建KML是非常简单的事,所以这里我就不涉及了(想看了就下载例子自己看)
Creating the image tile is easily done using SharpMap. Add an HttpHandler to you webpage, and create the following ProcessRequest method to render and return the map:
用SharpMap创建地图是非常容易的。在你的网页上添加一个HttpHandler,创建以下的ProcessRequest method 去渲染并返回地图:
public void ProcessRequest(HttpContext context)
{
//Get tilesize in request url
int tilesize = int.Parse(context.Request.QueryString["size"]);
//Get boundingbox requested
string[] strbox = context.Request.QueryString["BBOX"].Split(new char[] { ',' });
SharpMap.Geometries.BoundingBox box = new SharpMap.Geometries.BoundingBox
(double.Parse(strbox[0]), double.Parse(strbox[1]),
double.Parse(strbox[2]), double.Parse(strbox[3]));
//Call custom method that sets up the map with the requested tilesize
SharpMap.Map myMap = MapHelper.InitializeMap(new System.Drawing.Size(tilesize, tilesize));
//Center on requested tile and set the appropriate view width
myMap.Center = box.GetCentroid();
myMap.Zoom = box.Width;
//Render the map
System.Drawing.Bitmap b = (System.Drawing.Bitmap)myMap.GetMap();
//Create a PNG image which supports transparency
context.Response.Clear();
context.Response.Expires = 10000000;
context.Response.ContentType = "image/png";
System.IO.MemoryStream MS = new System.IO.MemoryStream();
//Set background to the transparent color which will be see-through in Google Earth
b.MakeTransparent(myMap.BackColor);
b.Save(MS, System.Drawing.Imaging.ImageFormat.Png);
byte[] buffer = MS.ToArray();
//Send image response
context.Response.OutputStream.Write(buffer, 0, buffer.Length);
// tidy up
b.Dispose();
context.Response.End();
}
The last thing we need to do is add the network link to GE. The easiest way to do this is to do this from within GE. From the menu Select Add –> Network link. Type a name for your network link and set the location to the URL of the XML service. Under “View-Based Refresh” , set the “When” parameter to “After camera stops”, and click OK, and you should be set to go !
最后要做的是向GE中添加网络连接。最方便的方法是从GE之内去做。在菜单选择Add –> Network link。为你的网络连接起一个名字然后设置XML服务的URL地址。在“View-Based Refresh”下面,把“When”参数设为“After camera stops”,点击OK,就行了。
Unfortunately GE doesn't provide you with the same smooth image transitions that it use for its own tiles, so you will have to do with the rather crude way of showing big red squares until the tiles have been loaded. Furthermore the BBOX GE requests isn't always very accurate, especially if you are looking south at an angle you will notice the BBOX is very much off.
不幸的是GE并没有向你提供用于它自己的tiles的平滑图像转换,所以你必须用更加原始的方法去显示big red squares 知道titles被加载。此外,BBOX GE的请求并不很准确,特别是如果你正从南方的一个角度,你就会发现BBOX非常的远(请教高人,终于知道是什么意思了
)
The small demo application you can download below shows a world map with each country’s population density shown on a colorscale from blue to red. Copy the files to a virtual directory (make sure it runs as its own web-application, at least the sub-folders are located at the root of the webapplication). Set the network-link to point to the URL of the default.aspx page.
下面这个小demo显示了一张世界地图,各个国家的人口密度以从蓝到红的色彩表示。把文件拷贝到virtual 目录 (保证它作为它自己的网络应用程序,至少子文件夹位于网络应用程序的根目录)。设置网络链接指向默认的.aspx页URL。
Download GoogleEarthServer.zip (270,65 KB)
GE also supports vectordata to be served as KML. It could be interesting to see who comes up with a "SharpMap KML Vector Server" first 
GE也支持矢量数据提供给KML。看谁先搞出"SharpMap KML Vector Server"不是很有趣吗?


