通过基于区域的网络链接 kml 文件使用 google Earth api 访问地标

发布于 2024-12-25 02:07:11 字数 1219 浏览 4 评论 0原文

我有一组使用区域化 kml 文件加载的地标。 (生成了大约 1000 个 kml 文件)。 例如,我有一个按钮,单击时相机会飞到我想要访问的地标的位置。所以我认为包含这个地标的kml文件是在这个过程之后加载的。假设这是 5.kml,我尝试使用 getElementByUrl 方法获取地标对象。但这没有用。我还可以使用 ge.getElementsByType("KmlPlacemark") 方法,但我需要一个循环来获取我需要的地标对象。这可行,但我找不到让它快速工作的方法。下面是我的代码,

google.earth.addEventListener(ge.getView(), 'viewchangeend', function() {                 
      // after button click and camera centered on the placemark with id 1767
      var p = ge.getElementByUrl('http://localhost/Test/5.kml#1767');
      alert(p.getId());  // this does not work because p is null
      var placemarks = ge.getElementsByType('KmlPlacemark'); 
      for (var i = 0; i < placemarks.getLength(); ++i) {
         var placemark = placemarks.item(i);
         if(placemark.getId() == 1767)
         {              
            alert(placemark.getId()); // this works      
            return;
         }
     }      
});

 function button_click()
{
    var camera = ge.getView().copyAsCamera(ge.ALTITUDE_RELATIVE_TO_GROUND);
    camera.setLatitude(30);
    camera.setLongitude(50);
    camera.setAltitude(2000);
    ge.getView().setAbstractView(camera);   
  }

我希望我找到了一种访问从 KML 导入的对象的方法(当区域处于活动状态时)。等待您的答复。谢谢。

I have a huge set of placemarks loaded using regionated kml files. (around 1000 kml files generated).
For example , I have a button, when clicked camera flies to the location of the placemark I want to access. So I think the kml file that includes this placemark is loaded after this process. Let's say this is 5.kml and I tried to get the placemark object using getElementByUrl method. But this didn't work. I can also use ge.getElementsByType("KmlPlacemark") method but I need to have a loop to get the placemark object I need. This works but I couldn't find a way to make it work fast. Below is my code

google.earth.addEventListener(ge.getView(), 'viewchangeend', function() {                 
      // after button click and camera centered on the placemark with id 1767
      var p = ge.getElementByUrl('http://localhost/Test/5.kml#1767');
      alert(p.getId());  // this does not work because p is null
      var placemarks = ge.getElementsByType('KmlPlacemark'); 
      for (var i = 0; i < placemarks.getLength(); ++i) {
         var placemark = placemarks.item(i);
         if(placemark.getId() == 1767)
         {              
            alert(placemark.getId()); // this works      
            return;
         }
     }      
});

 function button_click()
{
    var camera = ge.getView().copyAsCamera(ge.ALTITUDE_RELATIVE_TO_GROUND);
    camera.setLatitude(30);
    camera.setLongitude(50);
    camera.setAltitude(2000);
    ge.getView().setAbstractView(camera);   
  }

I wish I found a way to access the object which is imported from KML(when region beomes active). Waiting for your answers. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你另情深 2025-01-01 02:07:11

NetworkLink 不会将文件加载到 DOM 中,这就是为什么 getElementByUrl 找不到您要查找的地标的原因。您需要获取 KML。 本文应该有助于解释在谷歌地球 API。

NetworkLink's don't load files into the DOM, which is why getElementByUrl doesn't find the Placemark you're looking for. You would need to fetch the KML. This article should be helpful in explaining the different ways to load KML in the Google Earth API.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文