資源簡介
1. 我們在使用鼠標拖拽地圖時,拖拽完成后,抬起鼠標GMap控件會觸發鼠標點擊事件,
如果我們在地圖上點擊鼠標添加Marker,如何利用鼠標移動已有的Maker.

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Linq;
using?System.Text;
using?System.Threading.Tasks;
using?System.Windows.Forms;
using?GMap.NET;
using?GMap.NET.MapProviders;
using?GMap.NET.WindowsForms;
using?GMap.NET.WindowsForms.Markers;
namespace?GMapTest1
{
????public?partial?class?Form1?:?Form
????{
????????public?GMapOverlay?overlay?=?new?GMapOverlay(“WPMarker“);?????????//用于繪制航點的Marker
????????private?DateTime?timemousedown;
????????private?int?timemillSecond?=?200;
????????private?int?mousedistance?=?30;
????????private?int?mousepress_x?=?0?mousepress_y?=?0;
????????bool?isMouseDrag?=?false;//false:鼠標單擊?true:鼠標拖拽
????????bool?isMouseDown?=?false;
????????bool?isMarkerEnter?=?false;
????????bool?isMarkerDrag?=?false;
????????GMapMarker?currentMarker;
????????public?Form1()
????????{
????????????InitializeComponent();
????????????this.gMapControl1.CacheLocation?=?System.Windows.Forms.Application.StartupPath?+?“\\GMapCache\\“;?//緩存位置
????????????this.gMapControl1.CacheLocation?=?System.Windows.Forms.Application.StartupPath;
????????????this.gMapControl1.MapProvider?=?GMapProviders.BingHybridMap;
????????????this.gMapControl1.Manager.Mode?=?AccessMode.ServerAndCache;
????????????this.gMapControl1.MinZoom?=?1;?????????????????????????????????????????????????????//最小比例
????????????this.gMapControl1.MaxZoom?=?23;????????????????????????????????????????????????????//最大比例
????????????this.gMapControl1.Zoom?=?15;???????????????????????????????????????????????????????//當前比例
????????????this.gMapControl1.ShowCenter?=?false;??????????????????????????????????????????????//不顯示中心十字點
????????????this.gMapControl1.DragButton?=?System.Windows.Forms.MouseButtons.Left;?????????????//左鍵拖拽地圖
????????????this.gMapControl1.Position?=?new?PointLatLng(23113);
????????????this.gMapControl1.Overlays.Add(overlay);
????????????this.gMapControl1.MouseClick?+=?gMapControl1_MouseClick;
????????????this.gMapControl1.MouseDown?+=?gMapControl1_MouseDown;
????????????this.gMapControl1.OnMarkerEnter?+=?gMapControl1_OnMarkerEnter;
????????????this.gMapControl1.OnMarkerLeave?+=?gMapControl1_OnMarkerLeave;
????????????this.gMapControl1.MouseMove?+=?gMapControl1_MouseMove;
????????????this.gMapControl1.MouseUp?+=?gMapControl1_MouseUp;
????????}
????????void?gMapControl1_MouseMove(object?sender?MouseEventArgs?e)
????????{
????????????PointLatLng?p?=?gMapControl1.FromLocalToLatLng(e.X?e.Y);
????????????if?(isMarkerEnter?&&?isMouseDown)?{
????????????????isMarkerDrag?=?true;
????????????}
????????????if?(!isMouseDown)?{
????????????????isMarkerDrag?=?false;
????????????}
????????????if?(isMarkerDrag)?{?
????????????????currentMarker.Position?=?p;
????????????}
????????}
????????void?gMapControl1_OnMarkerLeave(GMapMarker?item)
????????{
????????????isMarkerEnter?=?false;
????????}
????????void?gMapControl1_OnMarke
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????229??2016-11-01?21:29??GMapTest1\GMapTest1\App.config
?????文件????2462720??2016-08-01?09:32??GMapTest1\GMapTest1\bin\Debug\GMap.NET.Core.dll
?????文件?????159232??2016-08-01?09:32??GMapTest1\GMapTest1\bin\Debug\GMap.NET.WindowsForms.dll
?????文件??????11776??2016-11-01?23:08??GMapTest1\GMapTest1\bin\Debug\GMapTest1.exe
?????文件????????229??2016-11-01?21:29??GMapTest1\GMapTest1\bin\Debug\GMapTest1.exe.config
?????文件??????26112??2016-11-01?23:08??GMapTest1\GMapTest1\bin\Debug\GMapTest1.pdb
?????文件??????24224??2016-11-01?23:10??GMapTest1\GMapTest1\bin\Debug\GMapTest1.vshost.exe
?????文件????????229??2016-11-01?21:29??GMapTest1\GMapTest1\bin\Debug\GMapTest1.vshost.exe.config
?????文件????????490??2013-03-18?17:00??GMapTest1\GMapTest1\bin\Debug\GMapTest1.vshost.exe.manifest
?????文件???????4481??2016-11-01?23:08??GMapTest1\GMapTest1\Form1.cs
?????文件???????3101??2016-11-01?23:08??GMapTest1\GMapTest1\Form1.Designer.cs
?????文件???????5817??2016-11-01?23:08??GMapTest1\GMapTest1\Form1.resx
?????文件???????4328??2016-08-01?13:32??GMapTest1\GMapTest1\GMapTest1.csproj
?????文件??????14745??2016-11-01?23:10??GMapTest1\GMapTest1\obj\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件???????7129??2016-10-29?22:48??GMapTest1\GMapTest1\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
?????文件????????708??2016-11-01?23:10??GMapTest1\GMapTest1\obj\Debug\GMapTest1.csproj.FileListAbsolute.txt
?????文件????????977??2016-11-01?23:08??GMapTest1\GMapTest1\obj\Debug\GMapTest1.csproj.GenerateResource.Cache
?????文件??????15202??2016-11-01?23:10??GMapTest1\GMapTest1\obj\Debug\GMapTest1.csprojResolveAssemblyReference.cache
?????文件??????11776??2016-11-01?23:08??GMapTest1\GMapTest1\obj\Debug\GMapTest1.exe
?????文件????????180??2016-11-01?23:08??GMapTest1\GMapTest1\obj\Debug\GMapTest1.Form1.resources
?????文件??????26112??2016-11-01?23:08??GMapTest1\GMapTest1\obj\Debug\GMapTest1.pdb
?????文件????????180??2016-11-01?21:28??GMapTest1\GMapTest1\obj\Debug\GMapTest1.Properties.Resources.resources
?????文件??????????0??2016-10-29?22:48??GMapTest1\GMapTest1\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
?????文件??????????0??2016-10-29?22:48??GMapTest1\GMapTest1\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
?????文件??????????0??2016-10-29?22:48??GMapTest1\GMapTest1\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
?????文件????????521??2016-08-01?11:55??GMapTest1\GMapTest1\Program.cs
?????文件???????1360??2016-08-01?11:55??GMapTest1\GMapTest1\Properties\AssemblyInfo.cs
?????文件???????2870??2016-08-01?11:55??GMapTest1\GMapTest1\Properties\Resources.Designer.cs
?????文件???????5612??2016-08-01?11:55??GMapTest1\GMapTest1\Properties\Resources.resx
?????文件???????1096??2016-08-01?11:55??GMapTest1\GMapTest1\Properties\Settings.Designer.cs
............此處省略14個文件信息
評論
共有 條評論