【问题标题】:3D model with Placemark functionality具有地标功能的 3D 模型
【发布时间】:2012-10-19 18:49:38
【问题描述】:

我正在使用 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 对象?

我知道如何创建常规地标(来自同一网站),但我不知道如何将 3D 模型制作为地标。

谢谢。

【问题讨论】:

    标签: google-maps-api-3 google-api


    【解决方案1】:

    var placemark 是一个全局变量,这是创建一个 3D 模型来代替地标。 试试这个代码,它对我有用。 我在这里使用了 Google 地球插件。

        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);
    
        }
    

    我还有一个问题,你知道如何根据数据库动态给出的坐标移动地标

    【讨论】:

    • 建筑物(3d 对象)出现,但没有做任何事情......我想要完成的是它是一个可点击的对象,并且某些东西(如 HTML 气球)将出现在顶部当你点击它时。
    • 抱歉延迟回复,但如果您在其上方添加一个不可见的地标,如果您需要代码,我可以帮助您。
    • 嘿,感谢您的延迟回复,我也为我的延迟道歉...如果您能帮助我提供代码,我将不胜感激。
    猜你喜欢
    • 2015-02-14
    • 2013-11-11
    • 1970-01-01
    • 2017-03-29
    • 1970-01-01
    • 2020-10-15
    • 1970-01-01
    • 2020-01-30
    • 1970-01-01
    相关资源
    最近更新 更多