WP7 ArcGIS 地图

ArcGIS Runtime SDK for Windows Phone是一套用于构建具有专业GIS功能、大众地图服务、LBS相关移动应用的类库。通过该类库可将地图嵌入到您的应用中,加载在线地图服务,Bing Maps或离线地图,以完成定位/搜索/空间查询/数据展示等常见功能;此外,它提供了一系列专业的GIS功能,允许您加载自己的地理数据,进行数据采集/编辑,执行复杂的地理分析任务,从而挖掘数据的潜在价值。

摘自:http://msdn.microsoft.com/zh-cn/windowsphone/partner

准备

SDK下载地址:http://resources.arcgis.com/zh-cn/content/arcgis-api-windows-phone-24-download

帮助文档http://help.arcgis.com/en/arcgismobile/10.0/apis/windowsphone/help/index.html

这个帮助文档不得不说一下,很好很强大~~~特别喜欢Sample那一栏

中国数据服务地址 :http://www.arcgisonline.cn/agsolcn/service/map/countrymap2.jsp

中国的地图数据服务很棒,有各种色调版本,很有爱,哈哈

再一个需要准备的资料是坐标纠偏了,这个~~~~不想多说了,最近看美谍战剧,一个美特务威胁果戈理说:你要不把东西给我,我就把你的人送到中国监狱,栽赃他危害国家总统~~~果戈里无语了~~,没有纠偏,阿果连监狱都找不到~~~

基本知识点

  • 基本的地图加载
<esri:Map x:Name="map" IsLogoVisible="False" Extent="12915510.1474625, 4827746.45379021, 12998675.8823845,4877354.08514722">
    <esri:Map.Layers>
        <local:OfflineArcGISTiledMapServiceLayer ID="StreetMapLayer" Url="http://www.arcgisonline.cn/ArcGIS/rest/services/ChinaOnlineStreetWarm/MapServer"/>
        <esri:GraphicsLayer ID="MyGraphicsLayer" />
    </esri:Map.Layers>
</esri:Map>
 

IsLogoVisible="False" 隐藏Logo,其实ArcGIS的LOGO还是蛮漂亮的,哈

    • 在地图上添加自定义图形
      private GraphicsLayer graphicsLayer { get { return mapFeet.Layers["MyGraphicsLayer"] as GraphicsLayer; } }
      private static WebMercator mercator = new WebMercator();
      var myPoint = mercator.FromGeographic(new MapPoint(point.X, point.Y, new SpatialReference(4326)));
      Graphic graphic = new Graphic()
      {
            Geometry = myPoint,
            Symbol = this.Resources["RedMarkerSymbol"] as Symbol
      };
      graphicsLayer.Graphics.Add(graphic);
       

//这个图形只能是园,方框等,如果其他,只能用图片

<esriSymbols:PictureMarkerSymbol x:Key="BlueMarkerSymbol" Source="/Images/fuck.png" />

<esriSymbols:SimpleMarkerSymbol x:Key="RedMarkerSymbol" Color="Red" Size="20" Style="Circle" />

用这个添加元素有个好处,效率高,比在图层上话UIElement效率要高的多,我搞了200多个fuck.png都很快

  • 地图缓存

OfflineArcGISTiledMapServiceLayer 是参考菩提老王的博客重写的一个缓存图片的Layer

代码如下:

 public class OfflineArcGISTiledMapServiceLayer : ArcGISTiledMapServiceLayer
    {
        private const string c_fileName = "MapTiles\\{0}_{1}_{2}.jpg";
 
        protected override void GetTileSource(int level, int row, int col, Action<ImageSource> onComplete)
        {
            string fileName = string.Format(c_fileName, level, row, col);
 
            FileStream fileStream = null;
            if (Isolated.FileExist(fileName) && Isolated.ReadFile(fileName, out fileStream))
            {
                BitmapImage image = new BitmapImage()
                {
                    CreateOptions = BitmapCreateOptions.DelayCreation
                };
                image.SetSource(fileStream);
                onComplete(image);
            }
            else
            {
                base.GetTileSource(level, row, col, onComplete);
            }
        }
 
        public override void Initialize()
        {
            base.Initialize();
            base.TileLoaded += new EventHandler<TileLoadEventArgs>(OfflineArcGISTiledMapServiceLayer_TileLoaded);
        }
 
        void OfflineArcGISTiledMapServiceLayer_TileLoaded(object sender, TiledLayer.TileLoadEventArgs e)
        {
            string fileName = string.Format(c_fileName, e.Level, e.Row, e.Column);
            if (e.ImageStream != null && Isolated.FileExist(fileName) == false)
            {
                Isolated.SaveFile(fileName, e.ImageStream);
            }
        }
    }

总的来说

之前一直用BingMap控件引Google的数据源,后来发现不能做缓存~~~就放弃了,其实BingMap的操控流畅比ArcGIS要好,不过缓存是硬伤,没办法,好处是ArcGis的效率还不错,特别是我需要在Map上加载很多东西的时候,BingMap就会变慢,可能是我处理的方式不太对~~~

哦,还有MapABC的大家也可以参考

总的来说:ArcGis的缓存还是很棒的,哈哈

posted @ 2012-05-17 18:38  Bryht  阅读(2064)  评论(8编辑  收藏  举报