是的,根据您的设置,有几种方法可以做到这一点。
一种通用的方法是给每个地标一个唯一的ID,然后使用该ID来查看它。
例如,假设您有以下KML地标,并且已经加载到API从URL http://localhost/foo.kml
<?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>
然后,您可以“看”的标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);
一个简单的功能,可以作出这样你就可以简单地传递正确的ID来看看从KML有一个ID加载的任何点地标。
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');
你可以明显地改变myLookAt
功能寻找lookAt
和camera
元素,或者处理其他类型的对象,以及 - 如多几何形状等