Cesium上实现地形模拟量测的功能

这个接触Cesium已经三个月了,但是除了刚接触的时候写了一篇Cesium的文章,后面做的一些研究都没有继续po上来。而且Cesium的发展真的很快,三个月更新了三个版本。


说正题,这篇说的是在地形上的模拟量测,模拟指的是本方法精度并不高,因为采用的方式是在线段上采样来进行量算的(采样点越多,精度越高),并且可视化的线并不完全贴地。


下面是量测函数部分。这个写的并不规范,也没怎么做注释,有兴趣的私信。

var long = false;
var Points_lc = []; //记录所点击的路径
var polyline_lc = new Cesium.Entity();
var length_lc;
function HowLong() {
    if (!long) {
        handler.setInputAction(function (leftclick) {
            viewer.entities.remove(polyline_lc);
            var cartesian = viewer.camera.pickEllipsoid(leftclick.position, viewer.scene.globe.ellipsoid);
            if (cartesian) {
                var cartographic = viewer.scene.globe.ellipsoid.cartesianToCartographic(cartesian);
                var longitudeString = Cesium.Math.toDegrees(cartographic.longitude).toFixed(8);
                var latitudeString = Cesium.Math.toDegrees(cartographic.latitude).toFixed(8);
                Points_lc.push({
   lon: longitudeString, lat: latitudeString});
            }
            //大于两个点就要进行画图
            if (Points_lc.length > 1) {
                polyline_lc.show = true;
                var polyPoints = [];
                for (var i = 0; i < Points_lc.length; i++) {
                    polyPoints.push(Points_lc[i].lon);
                    polyPoints.push(Points_lc[i].lat);
                }
                polyline_lc.name = i;
                polyline_lc.polyline = {
                    positions: Cesium.Cartesian3.fromDegreesArray(polyPoints),
                    width: 5,
                    material: new Cesium.PolylineOutlineMaterialProperty({
                        color: Cesium.Color.ORANGE,
                        outlineWidth: 2,
                        outlineColor: Cesium.Color.BLACK
                    })
                };
            }
            else {
                polyline_lc.show = false;
            }
            viewer.entities.add(polyline_lc);
            length_lc = computeLength(Points_lc);
        }, Cesium.ScreenSpaceEventType.LEFT_CLICK);

        handler.setInputAction(function (leftdoubleclick) {
            $('#txt_lc').html("长度:" + length_lc + "米");
            $('.cd-popup').addClass('is-visible');
        }, Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
        handler.setInputAction(function (doublerightclick) {
            Points_lc = [];
            Points_lc.length = 0;
            viewer.entities.remove(polyline_lc);
        }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
        document.getElementById('lc').innerHTML = '量测(On)';
    }
    else {
        Points_lc = [];
        Points_lc.length = 0;
        viewer.entities.remove(polyline_lc);
        handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
        handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
        handler.removeInputAction(Cesium.ScreenSpaceEventType.RIGHT_CLICK);
        document.getElementById('lc').innerHTML = '量测(Off)';
    }
    long = !long;
}

你可能感兴趣的:(Cesium,Cesium)