如何 import/export kml 并在 gmap.net 中显示
How to import/export kml and display in gmap.net
我想使用 Microsoft Visual Studio 和 GMaps.NET 创建一个简单的数据库查看器,它可以 (1) 进行特定搜索并更新列表,(2) 将列表导出为 KML,以及(3) 上传要在嵌入式gmap中查看的KML文件。第 1 步已解决,但我找不到继续执行第 2 步和第 3 步的参考资料。非常感谢任何帮助!
这是我的代码:
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.WindowsForms;
using GMap.NET.WindowsForms.Markers;
using GMap.NET.MapProviders;
//if these GMap statements are not enabled, these will have to be typed with the namespaces e.g. GMap.Net.MapProviders.GoogleMap
namespace KDMI_DBViewer_v1._0
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void existingPermitsBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
this.existingPermitsBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.permits_2016DataSet);
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'permits_2016DataSet.ExistingPermits' table. You can move, or remove it, as needed.
this.existingPermitsTableAdapter.Fill(this.permits_2016DataSet.ExistingPermits);
}
private void gMapControl1_Load(object sender, EventArgs e)
{
gMapControl1.MapProvider = GMapProviders.GoogleTerrainMap;
//gMapControl1.ShowCenter = false; if enabled, this will remove the red cross
gMapControl1.Position = new PointLatLng(12.0725555, 122.895494);
gMapControl1.DragButton = MouseButtons.Left;
gMapControl1.Zoom = 5;
gMapControl1.MinZoom = 5;
gMapControl1.MaxZoom = 12;
}
private void specificSearchToolStripButton_Click(object sender, EventArgs e)
{
try
{
this.existingPermitsTableAdapter.SpecificSearch(this.permits_2016DataSet.ExistingPermits, provinceToolStripTextBox.Text, municipalityToolStripTextBox.Text, typeToolStripTextBox.Text);
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
不幸的是,GMap.Net 的创建者说 gmap.net issues。
还没有实施 KML 解析器
但是您可以使用名为 SharpKML 的库自己创建 import \ export KML\KMZ 方法
SharpKML is an implementation of the Open Geospatial Consortium (OGC)
KML 2.2 standard developed in C#, able to read/write both KML files
and KMZ files.
入门:
The easiest way to use the library is to install the SharpKml.Core
NuGet package, however, you can also download the binaries/source code
from this project page.
我想使用 Microsoft Visual Studio 和 GMaps.NET 创建一个简单的数据库查看器,它可以 (1) 进行特定搜索并更新列表,(2) 将列表导出为 KML,以及(3) 上传要在嵌入式gmap中查看的KML文件。第 1 步已解决,但我找不到继续执行第 2 步和第 3 步的参考资料。非常感谢任何帮助!
这是我的代码:
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.WindowsForms;
using GMap.NET.WindowsForms.Markers;
using GMap.NET.MapProviders;
//if these GMap statements are not enabled, these will have to be typed with the namespaces e.g. GMap.Net.MapProviders.GoogleMap
namespace KDMI_DBViewer_v1._0
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void existingPermitsBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
this.existingPermitsBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.permits_2016DataSet);
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'permits_2016DataSet.ExistingPermits' table. You can move, or remove it, as needed.
this.existingPermitsTableAdapter.Fill(this.permits_2016DataSet.ExistingPermits);
}
private void gMapControl1_Load(object sender, EventArgs e)
{
gMapControl1.MapProvider = GMapProviders.GoogleTerrainMap;
//gMapControl1.ShowCenter = false; if enabled, this will remove the red cross
gMapControl1.Position = new PointLatLng(12.0725555, 122.895494);
gMapControl1.DragButton = MouseButtons.Left;
gMapControl1.Zoom = 5;
gMapControl1.MinZoom = 5;
gMapControl1.MaxZoom = 12;
}
private void specificSearchToolStripButton_Click(object sender, EventArgs e)
{
try
{
this.existingPermitsTableAdapter.SpecificSearch(this.permits_2016DataSet.ExistingPermits, provinceToolStripTextBox.Text, municipalityToolStripTextBox.Text, typeToolStripTextBox.Text);
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
不幸的是,GMap.Net 的创建者说 gmap.net issues。
还没有实施 KML 解析器但是您可以使用名为 SharpKML 的库自己创建 import \ export KML\KMZ 方法
SharpKML is an implementation of the Open Geospatial Consortium (OGC) KML 2.2 standard developed in C#, able to read/write both KML files and KMZ files.
入门:
The easiest way to use the library is to install the SharpKml.Core NuGet package, however, you can also download the binaries/source code from this project page.