Silverlight Bing Maps 加载三维(假)地图

第一步.     在Sketch UP 中创建三维建筑物:

              创建三维建筑物可能大多数想到的都是强大的3DMax,但我在这推荐下简练的Sketch UP。下面这个就是创建好的三维模型,看上去有点灰不溜秋的(因为没做渲染处理)。

                                           

               模型创建好了以后,就可以把模型调到一个合适的角度,然后导出2D Graphic保存为jpg格式。

第二步.     使用MapCruncher进行地图切片

              在这我们使用微软提供的地图切片工具MapCruncher,下载地址:http://research.microsoft.com/en-us/um/redmond/projects/mapcruncher/

              里面也有具体的教材,在这我就做下简单切片步骤:

        1.     导入上一步我们导出的图片

                                               

         2.    然后我们就可以左视图中看到我们的三维地图了     

                                             

            

         3.     下一步就开始配准,也就是确定你所建的模型的实际地理位置。一般我们需要有三个点来配准

                                             添加三个配准坐标点(point1、point2、point3)

                                            

   

        4.      然后点击render进行切片(切片需要一段时间)。

        5.      最后我们就可以在保存的文件夹下看到所切的图了:

                                           

第三步.     接下来我们就开始在silverlight中读取这些切片了

              首先把上一步保存的切片文件夹放到C:\inetpub\wwwroot下,

              编写自定义Custom3DTileSource实现对我们自己部署的地图加载算法:      

public class Custom3DTileSource : LocationRectTileSource
{

private const string baseUrl = "http://localhost/3DMapLayer/{0}.png";
public Custom3DTileSource()
:
base(baseUrl, new LocationRect(new Location(60, 60), new Location(13, 140)),
new Range<double>(1, 17))
{ }


public override Uri GetUri(int x, int y, int zoomLevel)
{
return new Uri(string.Format(this.UriFormat, TileXYToQuadKey(x, y, zoomLevel)), UriKind.RelativeOrAbsolute);
}


private static string TileXYToQuadKey(int tileX, int tileY, int levelOfDetail)
{
StringBuilder quadKey
= new StringBuilder();
for (int i = levelOfDetail; i > 0; i--)
{
char digit = '0';
int mask = 1 << (i - 1);
if ((tileX & mask) != 0)
{
digit
++;
}
if ((tileY & mask) != 0)
{
digit
++;
digit
++;
}
quadKey.Append(digit);
}
return quadKey.ToString();
}
}

然后我们就可以用Custom3DTileSource来加载地图了

public partial class _3DMapViews : UserControl
{
MapTileLayer mapTileLayer
= new MapTileLayer();
public _3DMapViews()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(_3DMapViews_Loaded);
}

void _3DMapViews_Loaded(object sender, RoutedEventArgs e)
{
Custom3DTileSource cts
= new Custom3DTileSource();
mapTileLayer.TileSources.Add(cts);
my3DMap.Mode
= new MercatorMode();
my3DMap.Center
= new Location(25.18, 119.50);
my3DMap.Children.Add(mapTileLayer);
}
}

最终效果如下:

原文地址:https://www.cnblogs.com/shitao/p/2072563.html