2015-07-22 107 views
0

正如我们所知silverlight5有能力获取pageElement的视觉效果,因此我们可以将其打印或保存为pictrue.but如果您的MapTilesSource uri与Silverlight应用程序主机站点位于不同的域中,则可以没有得到BingMapControl的视觉效果,因为“跨域问题”,clr会抛出一个System.Security.SecurityException异常。 为避免此问题,我在silverlight主机站点中添加了一个Proxy aspx页面,该页面可以将bingMap TileImage请求发送到远程MapTilesService。 这里是TileSource我的客户类继承:Silverlight bingMapContril使用LocalProxyPage下载MapTiles极其缓慢

public class GoogleTileSource : TileSource 
     { 
      public GoogleTileSource() 
       : base("http://mt{0}.google.cn/vt/lyrs={1}@180000000&hl=zh-CN&gl=cn&z={2}&x={3}&y={4}") 
      { 
       this.Type = GoogleTileType.Hybrid; 
      } 

public override Uri GetUri(int x, int y, int zoomLevel) 
     { 
      string TargetUrl = string.Format(this.UriFormat, this.Server, (char)this.Type, zoomLevel, x, y); 
      return new Uri(string.Format(http://localhost:52879/MapTilesServerProxy.aspx + "?sourceUrl={0}", TargetUrl)); 
      //return new Uri(string.Format(this.UriFormat, this.Server, (char)this.Type, zoomLevel, x, y)); 
     } 

public int Server 
    { 
     get; 
     set; 
    } 

public GoogleTileType Type 
    { 
     get; 
     set; 
    } 

} 

这里是我的代理页面代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MapTilesServerProxy.aspx.cs" Inherits="AeroZH.Web.MapTilesServerProxy" %> 
<%@ Import Namespace=System.Net %> 
<%@ Import Namespace=System.IO %> 
<%@ Import Namespace=System.Diagnostics %> 
<script runat="server"> 
    protected override void OnLoad(EventArgs e) 
    { 
     base.OnLoad(e); 
     ProxyRequest(); 
    } 

    private void ProxyRequest() 
    { 
     try 
     { 
     string url = ""; 
     url = this.Page.Request.Url.AbsoluteUri.Split(new string[] { "?sourceUrl=" }, StringSplitOptions.RemoveEmptyEntries)[1]; 
     Debug.WriteLine("url:" + url); 

      Debug.WriteLine(url + "——requestTime:" + System.DateTime.Now); 
      HttpWebRequest loHttp = (HttpWebRequest)WebRequest.Create(url); 
      loHttp.Timeout = 10000;  // 10 secs 
      loHttp.UserAgent = "Web Client"; 
      HttpWebResponse loWebResponse = (HttpWebResponse)loHttp.GetResponse(); 
      Debug.WriteLine(url + "——responseTime:" + System.DateTime.Now); 
      using (Stream inputStream = loWebResponse.GetResponseStream()) 
      { 
       byte[] buffer = new byte[4096 * 100]; 
       int bytesRead; 
       do 
       { 
        bytesRead = inputStream.Read(buffer, 0, buffer.Length); 

       } while (bytesRead != 0); 
       Response.BinaryWrite(buffer); 
       Response.End(); 

      } 
      loWebResponse.Close(); 
      if (loHttp != null) 
       loHttp.Abort(); 
     } 
     catch (Exception e) 
     { 
      Debug.WriteLine(e.Message); 
     } 
    } 

这项工作后,bingMapcontrol成功使其图像请求以为代理页面,以及ProxyPage的要求得到响应表单的远程服务器也是成功的,但只有少数mapTiles显示在地图上。 我使用debug.write跟踪响应状态,几乎每个请求都有正确的响应,我不知道为什么只有少数mapTiles显示在地图中。

回答

0

首先,在Bing地图中使用Google地图磁贴违反Bing地图和Google地图使用条款的使用条款。其次,Bing地图Silverlight控件即将结束生命。文档已经离线,并且在控制被禁用之前不久。没有新的发展应该与它一起。此外,几年前,Silverlight的生命周期结束了。