简体   繁体   English

在Google Earth API KML文件中搜索String Value placemarker?

[英]Search String Value placemarker in Google Earth API KML File?

Trying to create search box for Google Earth API Plugin for javascript I am able to parse KMLFile and load in GE API and now I have to embed search by Placemarker name loaded by KML. 尝试为javascript的Google Earth API插件创建搜索框我能够解析KMLFile并加载到GE API中,现在我必须通过KML加载的Placemarker名称嵌入搜索。

Code using Lat & Long 使用Lat&Long的代码

var lookAt = ge.createLookAt('');
lookAt.set(point.y, point.x, 600, ge.ALTITUDE_RELATIVE_TO_GROUND, 0, 00, 0);
ge.getView().setAbstractView(lookAt);

Is there any possibility for LookAt using Placemarker Name (string value) instead searching of using LAT, LONG? LookAt是否有可能使用Placemarker Name(字符串值)而不是使用LAT搜索,LONG?

Yes there are a few ways to do this depending on your set-up. 是的,有几种方法可以执行此操作,具体取决于您的设置。

One general way would be to give each placemark a unique ID, then use that ID to look at it. 一般的方法是给每个地标一个唯一的ID,然后使用该ID来查看它。

For example, imagine you have the following kml placemark and that you have loaded into the api from the url http://localhost/foo.kml 例如,假设您有以下kml地标,并且您已从网址http://localhost/foo.kml加载到api中

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
  <Placemark id="myPlacemark">
    <name>Myplacemark</name>
    <Point>
      <coordinates>-122.0822035425683,37.42228990140251,0</coordinates>
    </Point>
  </Placemark>
</kml>

You could then 'look at' the placemark myPlacemark like so. 然后,您可以“查看”地标myPlacemark就像这样。

var placemark = ge.getElementByUrl('http://localhost/foo.kml#myPlacemark');
var point = placemark.getGeometry();
var lookAt = ge.createLookAt('');
lookAt.set(point.getLatitude(), point.getLongitude(), 600, ge.ALTITUDE_RELATIVE_TO_GROUND, 0, 00, 0);
ge.getView().setAbstractView(lookAt);

A simple function could be made so you can simply pass the correct ID in to look at any point placemark loaded from KML that has an ID. 可以创建一个简单的函数,这样您就可以简单地传入正确的ID来查看从具有ID的KML加载的任何点标记。

var myLookAt = function(id) {
  var placemark = ge.getElementByUrl(id);
  if('getGeometry' in placemark && 
    placemark.getGeometry().getType() == 'KmlPoint') {
    var point = placemark.getGeometry();
    var lookAt = ge.createLookAt('');
    lookAt.set(point.getLatitude(), point.getLongitude(), 600, ge.ALTITUDE_RELATIVE_TO_GROUND, 0, 00, 0);
    ge.getView().setAbstractView(lookAt);
  }
};

// useage
myLookAt('http://localhost/foo.kml#myPlacemark');

You could obviously alter the myLookAt function to look for lookAt and camera elements, or to handle other types of objects as well - such as multi geometries, etc. 显然,您可以更改myLookAt函数以查找lookAtcamera元素,或者处理其他类型的对象 - 例如多个几何体等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM