我正在开发一个使用Google API和Sketchup的交互式地图。我已经使用以下代码创建并放置了3D对象:
var loc = ge.createLocation('');
loc.setLatitude(lookAt.getLatitude());
loc.setLongitude(lookAt.getLongitude());
model.setLocation(loc);
// set up the model's link (must be a COLLADA file).
// this model was created in SketchUp
var link = ge.createLink('');
model.setLink(link);
link.setHref('http://earth-api-samples.googlecode.com/svn/trunk/' +
'examples/static/splotchy_box.dae');
// create the model placemark and add it to Earth
var modelPlacemark = ge.createPlacemark('');
modelPlacemark.setGeometry(model);
ge.getFeatures().appendChild(modelPlacemark);
// zoom in on the model
lookAt.setRange(300);
lookAt.setTilt(80);
ge.getView().setAbstractView(lookAt);
// persist the placemark for other interactive samples
window.placemark = modelPlacemark;
来自此示例网站:http://earth-api-samples.googlecode.com/svn/trunk/demos/interactive/index.html
我正在尝试添加到3D模型的选项,一个常规的地标(所以它改变大小时,鼠标悬停&是可点击的)。
我对Google API比较陌生,所以我想知道:如何将这些函数添加到3D对象中?
我知道如何创建常规的placemark (来自同一网站),但我不知道如何将3D模型创建为placemark。
谢谢。
发布于 2013-01-28 12:50:38
var placemark是一个全局变量,这是在创建一个3D模型来代替一个placemark。试试这段代码,它对我很有效。我在这里使用了Google Earth插件。
function createPlacemark() {
console.log("in create placemark");
placemark = ge.createPlacemark('');
placemark.setName('placemark ' + counter);
var model = ge.createModel('');
ge.getFeatures().appendChild(placemark);
var loc = ge.createLocation('');
model.setLocation(loc);
var link = ge.createLink('');
// A textured model created in Sketchup and exported as Collada.
link.setHref('https://sites.google.com/site/siddharthuit/downloads/crane.dae');
model.setLink(link);
var la = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
// set location
loc.setLatitude(la.getLatitude());
loc.setLongitude(la.getLongitude());
placemark.setGeometry(model);
la.setRange(300);
la.setTilt(45);
ge.getView().setAbstractView(la);
}
我还有一个问题,你知道如何根据数据库中动态给出的坐标来移动地标吗?
https://stackoverflow.com/questions/12980604
复制相似问题