我正在为我正在编写的应用程序尝试使用 Google 地球插件 API。我希望能够从地图中删除地标。我能想到的最简单的方法是创建一个带有“删除”链接的气球弹出窗口,但我一直无法弄清楚如何删除:
balloon.setContentString(
'Location: ' + event.getLatitude().toString() + ", " +
event.getLongitude().toString() + '<br /> <br />' +
'<a href="#" onclick="ge.getFeatures().removeChild(event.getCurrentTarget())">Delete</a><br /><a href="#" onclick="prompt(\'Enter new name\', \'blah\'\)">Rename</a>');
这导致:
Uncaught TypeError: Object #<MouseEvent> has no method 'getCurrentTarget' earth2.html:1 onclick
(如您所见,我也希望能够重命名,但大概在我想出删除时不会那么难弄清楚?)
整个代码可以在以下位置找到:
http://chrishowells.co.uk:81/earth2.html
整个区块:
google.earth.addEventListener(ge.getWindow(), 'mousedown', function(event) {
if (event.getTarget().getType() == 'KmlPlacemark' &&
event.getTarget().getGeometry().getType() == 'KmlPoint') {
// don't show the default popup
//http://code.google.com/apis/ajax/playground/?exp=earth#javascript_in_balloons
event.preventDefault();
var balloon = ge.createHtmlStringBalloon('');
balloon.setFeature(event.getTarget());
//balloon.setMaxWidth(300);
balloon.setContentString(
'Location: ' + event.getLatitude().toString() + ", " +
event.getLongitude().toString() + '<br /> <br />' +
'<a href="#" onclick="ge.getFeatures().removeChild(event.getCurrentTarget())">Delete</a><br /><a href="#" onclick="prompt(\'Enter new name\', \'blah\'\)">Rename</a>');
ge.setBalloon(balloon);
var placemark = event.getTarget();
dragInfo = {
placemark: event.getTarget(),
dragged: false
};
}
});