当前位置:编程学习 > wap >>

Windows Mobile引路蜂地图开发示例:第一个地图应用

打开Visual studio 创建一个新项目WM6GISEngineTutorial。把Form1改名为MainForm,添加对引路蜂类库的引用,并把guidebee.lic做为Content添加到项目中。

我们将使用MainForm来显示地图,下面的例子显示南京地图,缩放级别为13级,地图类型为Bing中国地图。

[csharp] 
using System; 
using System.Windows.Forms; 
using Mapdigit.Gis; 
using Mapdigit.Gis.Drawing; 
using Mapdigit.Gis.Geometry; 
using Mapdigit.Gis.Raster; 
using Mapdigit.Gis.Service; 
using Mapdigit.Licence; 
using WM6GISEngineTutorial.Drawing; 
using System.Drawing; 
  
namespace WM6GISEngineTutorial 

    public partial class Mainform : Form, IMapDrawingListener, IReaderListener, 
         IRoutingListener, IGeocodingListener 
    { 
        /// <summary>  
        /// map tile downloader manager  
        /// </summary>  
        private readonly MapTileDownloadManager _mapTileDownloadManager; 
        /// <summary>  
        /// raster map.  
        /// </summary>  
        private readonly RasterMap _rasterMap; 
        /// <summary>  
        /// map image.  
        /// </summary>  
        private readonly IImage _mapImage; 
        /// <summary>  
        /// map graphics object.  
        /// </summary>  
        private IGraphics _mapGraphics; 
        /// <summary>  
        /// map type.  
        /// </summary>  
        private int _mapType = MapType.MicrosoftChina; 
        private int _oldX; 
        private int _oldY; 
        private bool _isPanMode; 
        private delegate void UpdateInfo(string message); 
        public Mainform() 
        { 
            InitializeComponent(); 
            //set the licence info.  
            LicenceManager licenceManager = LicenceManager.GetInstance(); 
            long[] keys = { -0x150dc6a05f379456L, -0x703237078e243c4fL, 
      -0x104afc92926c5418L, -0x4af1782b11010f5dL, 
      -0x27d1f7ce354a3419L, 0x17ded67edd3a5281L, }; 
            licenceManager.AddLicence("GuidebeeMap_DotNet", keys); 
            //optional, get the tile url from server.  
            MapType.UpdateMapTileUrl(); 
            MapLayer.SetAbstractGraphicsFactory(NETGraphicsFactory.GetInstance()); 
            MapConfiguration.SetParameter(MapConfiguration.WorkerThreadNumber, 4); 
            _mapImage = MapLayer.GetAbstractGraphicsFactory() 
      .CreateImage(Width, Height); 
            _mapTileDownloadManager = new MapTileDownloadManager(this); 
            _rasterMap = new RasterMap(1024, 1024, _mapType, _mapTileDownloadManager); 
            _rasterMap.SetScreenSize(Width, Height); 
            _mapTileDownloadManager.Start(); 
            _rasterMap.SetMapDrawingListener(this); 
            _rasterMap.SetRoutingListener(this); 
            _rasterMap.SetGeocodingListener(this); 
             GeoLatLng center = new GeoLatLng(32.0616667, 118.7777778); 
            _rasterMap.SetCenter(center, 13, _mapType); 
        } 
  
        private void Mainform_Paint(object sender, PaintEventArgs e) 
        { 
            Graphics graphics = e.Graphics; 
            Bitmap image = (Bitmap)_mapImage.GetNativeImage(); 
            graphics.DrawImage(image, 0, 0); 
        } 
  
        private void PanMap(int x, int y) 
        { 
            int dx = x - _oldX; 
            int dy = y - _oldY; 
           _rasterMap.PanDirection(dx, dy); 
        } 
  
        private void UpdateStatus(string messsage) 
        { 
            if (InvokeRequired) 
            { 
                BeginInvoke(new UpdateInfo(UpdateStatus), messsage); 
  
            } 
            else 
            { 
                _mapGraphics = _mapImage.GetGraphics(); 
          

补充:移动开发 , Windows Phone ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,