使用VB.NET中的GoogleEarth插件通过FC.GEPluginCtrls加载本地KML

时间:2014-02-10 10:40:44

标签: vb.net google-earth-plugin

我正在尝试在VB.NET(VS2010)上开发一个使用GEPlugin(https://code.google.com/p/winforms-geplugin-control-library/)的应用程序。

当然,我已经能够将插件加载到表单中并且可以正常工作。我可以在插件上看到地球,用户可以移动它。但现在我正在尝试使用KmlTreeView将本地kml文件加载到插件中,但没有成功。

我可以使用以下代码加载插件外部kml文件,例如“http://onearth.jpl.nasa.gov/OnEarth_BMNG.kml”:

Private Sub GeWebBrowser1_PluginReady(ByVal sender As System.Object, ByVal e As FC.GEPluginCtrls.GEEventArgs) Handles GeWebBrowser1.PluginReady

    KmlTreeView1.SetBrowserInstance(GeWebBrowser1)
    GeWebBrowser1.FetchKml("http://onearth.jpl.nasa.gov/OnEarth_BMNG.kml")

End Sub

Private Sub GeWebBrowser1_KmlLoaded(sender As Object, e As FC.GEPluginCtrls.GEEventArgs) Handles GeWebBrowser1.KmlLoaded
    Dim kml As Object

    kml = e.ApiObject

    GeWebBrowser1.ParseKmlObject(kml)
    KmlTreeView1.ParseKmlObject(kml)
End Sub


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    GeWebBrowser1.LoadEmbeddedPlugin() ' load the plugin
End Sub

但是,我找不到加载本地kml文件的方法。我已经检查过存在一个GeWebBrowser控件的方法应该允许这个:GeWebBrowser1.FetchKmlLocal(“local path”)。但它不起作用。

是否有人使用过此库?如果是,已成功加载了本地kml文件?

可能我正在使用旧库版本(1.010)?我没有在网上找到发布版本,而且我无法创建发布版本,因为我在尝试加载解决方案时遇到错误。

提前致谢, 丹尼尔。

1 个答案:

答案 0 :(得分:0)

您应该使用内置服务器来处理本地kml文件。

请参阅https://code.google.com/p/winforms-geplugin-control-library/wiki/GEServer

namespace ServerTest
{
    using System;
    using System.Windows.Forms;
    using FC.GEPluginCtrls;
    using FC.GEPluginCtrls.HttpServer;

    public partial class Form1 : Form
    {
        // initialise the server and tell it where the
        // root directory is 
        private GEServer server = new GEServer("webroot");

        public Form1()
        {
            InitializeComponent();

            // the server is fully configurable...
            // server.RootDirectory = "/foo/bar/";
            // server.DefaultFileName = "bat.kml"
            // server.IPAddress = System.Net.IPAddress.Any;
            // server.Port = 80;

            // start the server
            server.Start();

            // load the plugin
            geWebBrowser1.LoadEmbededPlugin();

            // when the plug-in has loaded
            geWebBrowser1.PluginReady += (o, e) =>
            {
                // load the kml from the local server
                geWebBrowser1.FetchKml("http://localhost:8080/KML_Samples.kml");
            };

            geWebBrowser1.KmlLoaded += (o, e) =>
            {
                // add the kml to the plugin
                geWebBrowser1.ParseKmlObject(e.ApiObject);
            };
        }
    }