【问题标题】:Google Earth API - drawing lines that curve?Google Earth API - 绘制曲线的线条?
【发布时间】:2012-04-05 00:06:06
【问题描述】:

我一直在玩谷歌地球 API。我认为从相对 3D 的角度在地点之间画一些线会很整洁。我搜索了 GE 文档并在谷歌上搜索了答案,但没有找到任何让我走上正确道路的东西,所以我想我会发布一些代码,也许会得到一些见解。

下面的代码绘制了两个地方,然后在这些地方之间画了一条线。不幸的是,绘制的线连接了地球。当像这样以 3D 绘制时,有没有一种方法可以让它包裹到地球的轮廓?我尝试改变线的高度位置并取得了不同程度的成功,但是当线似乎没有连接这些地方时,会以准确性和整体视觉吸引力为代价。

function init() {
    google.earth.createInstance('map3d', initCB, failureCB);
}

function initCB(instance) {
    ge = instance;
    ge.getWindow().setVisibility(true);


    //---------------------------------PLACES   

    // Create the placemark.
    var placemark = ge.createPlacemark('');
    placemark.setName("Location 1");

    // Set the placemark's location.  
    var point = ge.createPoint('');
    point.setLatitude(39.96028);
    point.setLongitude(-82.979736);
    placemark.setGeometry(point);

    // Add the placemark to Earth.
    ge.getFeatures().appendChild(placemark);


    // Create the placemark.
    var placemark2 = ge.createPlacemark('');
    placemark2.setName("Hop #2");

    // Set the placemark's location.  
    var point2 = ge.createPoint('');
    point2.setLatitude(25.7615);
    point2.setLongitude(-80.2939);
    placemark2.setGeometry(point2);

    // Add the placemark to Earth.
    ge.getFeatures().appendChild(placemark2);

    //---------------------------------FOCUS

    var lookAt = ge.createLookAt('');
    lookAt.setLatitude(39.96028);
    lookAt.setLongitude(-82.979736);
    lookAt.setRange(1000000.0);
    lookAt.setAltitude(0);
    lookAt.setTilt(45);
    ge.getView().setAbstractView(lookAt);


    //---------------------------------LINES

    // Create the placemark
    var lineStringPlacemark = ge.createPlacemark('');

    // Create the LineString
    var lineString = ge.createLineString('');
    lineStringPlacemark.setGeometry(lineString);

    // Add LineString points
    lineString.getCoordinates().pushLatLngAlt(39.96028, -82.979736, 0);
    lineString.getCoordinates().pushLatLngAlt(25.7615, -80.2939, 0);
    //lineString.setAltitudeMode(ge.ALTITUDE_CLAMP_TO_GROUND);
    //lineString.setAltitudeMode(ge.ALTITUDE_RELATIVE_TO_GROUND);
    lineString.setAltitudeMode(ge.absolute);

    // Create a style and set width and color of line
    lineStringPlacemark.setStyleSelector(ge.createStyle(''));
    var lineStyle = lineStringPlacemark.getStyleSelector().getLineStyle();
    lineStyle.setWidth(2);
    lineStyle.getColor().set('9900ffff');  // aabbggrr format

    // Add the feature to Earth
    ge.getFeatures().appendChild(lineStringPlacemark);

}

function failureCB(errorCode) {
}

google.setOnLoadCallback(init);

【问题讨论】:

    标签: google-earth google-earth-plugin


    【解决方案1】:

    您需要将线串上的镶嵌和拉伸(可选)设置为 true。

    详情请参阅https://developers.google.com/kml/documentation/kmlreference#tessellatehttps://developers.google.com/kml/documentation/kmlreference#extrude

    对于 API,您的语法类似于

    lineStringPlacemark.setTessellate(true);
    lineStringPlacemark.setExtrude(true);
    

    https://developers.google.com/earth/documentation/geometries 上还有一些其他 API 示例

    【讨论】:

    • 我正在寻找的东西真是太棒了。非常感谢您指出我在文档中明显忽略的内容。
    猜你喜欢
    • 1970-01-01
    • 2019-08-31
    • 1970-01-01
    • 1970-01-01
    • 2019-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多