Deep understanding of the most powerful desktop map control GMAP. NET-initial use

Source: Internet
Author: User

The previous article introduced the basic concepts of GMAP. NET and some demos. This chapter mainly introduces how to use GMAP. NET in our code.

1. Download


2. Compile the GMAP. NET project

3. Reference in the project

My project uses WPF, so we need to reference GMAP. NET Core and GMap. NET. WindowsPresentation.

4. GMapControl

1) create a UserControl in UserControl. xaml and reference it in UserControl.GMapControlI have set MaxZoom and MinZoom, which are also the maximum scaling scales supported by GMAP. NET, as shown below:

<UserControl x:Class="UICommon.View.Map.GMapTrack"    xmlns=""    xmlns:x=""    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 event

Set the Event code, including entering the event MouseEnter, right-clicking the event MouseRightButtonDown, and double-clicking the event MouseDoubleClick.

The OnTileLoadStart and OnTileLoadComplete events are as follows: All maps are downloaded and spliced as an image,The image here is called Tile.. So

OnTileLoadStart is the event triggered when each image starts loading. OnTileLoadComplete is the event triggered after each image is loaded. Then it can be displayed at OnTileLoadStart.

Loading or progress bars won't make the user feel dead. OnTileLoadComplete can close the progress bar.

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 Initialization

PositionIt is the center location where the map is started by default. I read it from the configuration file here.

AreaIndicates the region of the entire map. You can leave it empty.

ModeThere are three types: CacheOnly (obtained from the cache only), ServerAndCache (Network + cache), and ServerOnly (read from the network only)

MapProviderIt is the source of the map. The default value is OpenStreetMap. Of course, BingMap, GoogleMap, and support for domestic maps such as Baidu and SoSo will be introduced in the following sections.

DragButtonIndicates whether to use the left mouse or right mouse button to drag a map.

ZoomIs the level of the current Map Display (1 ~ 24)

MinZoomIs the minimum level supported by maps,MaxZoomIs the maximum level supported by a map.

                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;


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.