zoukankan      html  css  js  c++  java
  • GMAP.NET

    深入理解最强桌面地图控件GMAP.NET --- 初用

    上一篇介绍了GMAP.NET的基本概念和一些Demo的截图,这一章主要介绍我们的代码如何使用GMAP.NET。

    1.下载

    http://greatmaps.codeplex.com/releases/view/20235

    2.编译GMAP.NET工程

    3.在项目中引用

    我的项目是用的WPF,因此需要引用GMAP.NET Core和GMap.NET.WindowsPresentation两个dll。

    4.GMapControl

     1)UserControl.xaml 创建一个UserControl,并在UserControl中引用GMapControl,我设置了MaxZoom和MinZoom, 也是GMAP.NET支持的最大缩放比例尺,如下所示:

    复制代码
    <UserControl x:Class="UICommon.View.Map.GMapTrack"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:gmap="clr-namespace:GMap.NET.WindowsPresentation;assembly=GMap.NET.WindowsPresentation"
                 xmlns:Map="clr-namespace:UICommon.View.Map" x:Name="userControl"
        >
        <Grid>
          
            <GroupBox Name="mapgroup" Margin="0,0,50,0"  VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch">
                <gmap:GMapControl x:Name="MainMap"  MaxZoom="24" MinZoom="1">
                  
                </gmap:GMapControl>
            </GroupBox>   
            
        </Grid>
    </UserControl>
    复制代码

    5.GMapControl事件

    设置事件代码,包括鼠标进入事件MouseEnter, 鼠标右键事件MouseRightButtonDown,鼠标双击事件MouseDoubleClick。

    OnTileLoadStart和OnTileLoadComplete这两个事件是这样的:所有地图下载的时候都是讲一张一张图片下载下来拼接而成的,而这里的图片就叫做Tile。所以

    OnTileLoadStart就是指每次每张图片开始载入时触发的事件,OnTileLoadComplete就是每次每张图片载入完成后触发的事件。那么就可以在OnTileLoadStart的时候显示

    正在加载或进度条之类的,不会让用户感觉死在那儿;而OnTileLoadComplete可以关闭进度条。

    复制代码
    public GMapTrack()
            {
                InitializeComponent();
    
                this.MainMap.MouseEnter += MainMap_MouseEnter;
            this.MainMap.MouseRightButtonDown += new MouseButtonEventHandler(MainMap_MouseRightButtonDown);
                this.MainMap.MouseDoubleClick += new MouseButtonEventHandler(MainMap_MouseDoubleClick);
           this.MainMap.OnTileLoadStart += MainMap_OnTileLoadStart;
    this.MainMap.OnTileLoadComplete += MainMap_OnTileLoadComplete;
    this.MainMap.Loaded += new RoutedEventHandler(MainMap_Loaded);
    }
    复制代码

    6.GMapControl Loaded初始化

    Position是地图默认启动的中心位置,我这里是从配置文件里面读取的。

    Area是指整个地图的区域,可以不填

    Mode有三种, CacheOnly(只从缓存中取),ServerAndCache(网络+缓存), ServerOnly(只从网络读)

    MapProvider是地图的来源,默认是OpenStreetMap,当然也可以使BingMap, GoogleMap,关于百度,SoSo等国内地图的支持会在后面的章节介绍。

    DragButton是指拖动地图时是用鼠标左键还是右键

    Zoom是当前地图显示的层级 (1~24)

    MinZoom是地图支持最小的层级,MaxZoom是地图支持的最大层级。

    复制代码
                    this.MainMap.Position = new PointLatLng(double.Parse(ConfigurationManager.AppSettings["defaultLat"]), 
                                                            double.Parse(ConfigurationManager.AppSettings["defaultLng"]));
    
                    this.MainMap.MapProvider.Area = new RectLatLng(30.981178, 105.351914, 2.765142, 4.120995);
                    this.MainMap.BoundsOfMap = new RectLatLng(30.981178, 105.351914,  2.765142, 4.120995);
                    this.MainMap.Manager.Mode = AccessMode.CacheOnly;
                    this.MainMap.MapProvider = GMapProviders.OpenStreetMap;
                    this.MainMap.DragButton = MouseButton.Left;
                    this.MainMap.Zoom = 13;
                    this.MainMap.MinZoom = 8;
                    this.MainMap.MaxZoom = 24;
    复制代码
     
     
     
  • 相关阅读:
    说一下Mysql索引
    B树、B-树、B+树、B*树之间的关系
    Mybatis Plus 的优点
    JVM垃圾回收机制
    Java中的集合
    MQ 面试题
    Redis 双写一致性
    Redis 主从复制
    C#中Abstract和Virtual的区别
    C#设计模式(2)——简单工厂模式
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/2858818.html
Copyright © 2011-2022 走看看