上次我们讲了,怎么样加载地图,并使它显示出来.我当时一看到它显示出来,内心就很惊喜.说实话这个控件大有用处
下面是重载这个控件的一些其他属性
1比如双击控件使它放大
private void gMapControl1_DoubleClick(object sender, EventArgs e) { this.gMapControl1.Zoom += 1; this.gMapControl1.Position = lastPosition; this.Center = new GMapMarkerCross(this.gMapControl1.Position); this.routes.Markers.Clear(); this.routes.Markers.Add(Center); }
2.鼠标滑动时,可以显示当前经纬度,与屏幕坐标
private void gMapControl1_MouseMove(object sender, MouseEventArgs e) { PointLatLng latLng = this.gMapControl1.FromLocalToLatLng(e.X, e.Y); this.label1.Text = latLng.Lng.ToString() + " " + latLng.Lat.ToString()+" "+e.X.ToString()+" "+e.Y.ToString(); lastPosition = latLng; }
FromLocalToLatLng(e.x,e.y)是将屏幕坐标转换成对应的经纬度,这个控件自带了一套算法,我们只要会用就可以啦,想搞懂也不是一天两天的事情.
3.保存地图缓存(点击"保存缓存"按钮)
private void Save_Btn_Click(object sender, EventArgs e)
{
if (this.gMapControl1.ShowExportDialog() == true)
{
//this.gMapControl1.ShowTileGridLines = true;//显示瓦片,也就是显示方格
this.gMapControl1.ReloadMap();
}
}
4.读取地图缓存(点击"读取缓存"按钮)
private void Read_Btn_Click(object sender, EventArgs e) { this.gMapControl1.Manager.Mode = AccessMode.CacheOnly; if (this.gMapControl1.ShowImportDialog() == true) { // GMap.NET.CacheProviders.SQLitePureImageCache ms = new SQLitePureImageCache(); // ms.CacheLocation = "E:\\123\\"; // MessageBox.Show(ms.db); //MessageBox.Show(ms.dir); this.gMapControl1.Position = new PointLatLng(31.7543, 121.6281); this.gMapControl1.ReloadMap(); } }
5.保存截图(点击"截图"按钮)
private void PrintScreen_Click(object sender, EventArgs e) { try { using (SaveFileDialog dlg = new SaveFileDialog()) { dlg.Filter = "PNG(*.png)|*.png"; dlg.FileName = "GMap.NET image"; Image image = this.gMapControl1.ToImage(); if (image != null) { using (image) { if (dlg.ShowDialog() == DialogResult.OK) { string filename = dlg.FileName; if (!filename.EndsWith(".png", StringComparison.OrdinalIgnoreCase)) { filename += ".png"; } image.Save(filename); MessageBox.Show("图片已保存:" + dlg.FileName, "GMap.NET"); } } } } } catch (Exception exception) { MessageBox.Show("图片保存失败:" + exception.Message, "GMap.NET"); } }
我想大家都能看懂,刚开始不明白原理不要紧,先实现自己想要的,再慢搞懂就可以啦
后期还有相关的文章出来,希望大家继续关注