渐变纹理-源代码示例 运行 重置

                    <!DOCTYPE html>

<html>
<head>
    <meta charset='UTF-8'/>
    <meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no'/>
    <link href='http://bigemap.com:9000/bigemap-gl.js/v1.1.0/Widgets/widgets.css' rel='stylesheet'/>
    <script src='http://bigemap.com:9000/bigemap-gl.js/v1.1.0/bigemap-gl.js'></script>
    <style>
        body {
            margin: 0;
            padding: 0;
        }

        #container {
            position: absolute;
            top: 0;
            bottom: 0;
            width: 100%;
        }
           .canvas {
            position: absolute;
            left: 10px;
            top: 10px;
            display: none;
        }

        #canvas-a {
            top: 10px;
        }

        #canvas-b {
            top: 120px;
        }
        .bmgl-widget-credits{display:none}
    </style>
    <title>part_test</title>
</head>
<body>

<canvas id="canvas-a" class="canvas" width="700" height="100"></canvas>
<canvas id="canvas-b" class="canvas" width="700" height="100"></canvas>
<div id='container'></div>

<script>
 bmgl.Config.HTTP_URL = 'http://bigemap.com:9000';
    var viewer = new bmgl.Viewer('container', {mapId: 'bigemap.googlemap-satellite'});
    //设置初始位置
    viewer.camera.setView({
        destination: bmgl.Cartesian3.fromDegrees(110.20, 34.55, 3000000)
    });
    //不启用地形遮挡
    viewer.scene.globe.depthTestAgainstTerrain=false;
    //取消双击事件
    viewer.BMWidget.screenSpaceEventHandler.removeInputAction(bmgl.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
    viewer.entities.add({
        name: 'Red wall at height',
        wall: {
            positions: bmgl.Cartesian3.fromDegreesArrayHeights([
                121.444409, 31.247417, 200.0,
                121.533521, 31.235685, 200.0,
                121.563273, 31.190347, 200.0,
                121.546744, 31.194054, 200.0,
                121.516705, 31.191459, 200.0,
                121.502188, 31.203074, 200.0
            ]),
            minimumHeights: [3000.0, 2000.0, 2000, 2000, 2000, 3000],
            material: getColorRamp([0.0, 0.045, 0.1, 0.15, 0.37, 0.54, 1.0], true)
        }
    });

    viewer.entities.add({
        name: 'Red wall at height',
        wall: {
            positions: bmgl.Cartesian3.fromDegreesArrayHeights([
                121.554409, 31.247417, 200.0,
                121.643521, 31.235685, 200.0,
                121.673273, 31.190347, 200.0,
                121.656744, 31.194054, 200.0,
                121.626705, 31.191459, 200.0,
                121.612188, 31.203074, 200.0
            ]),
            minimumHeights: [3000.0, 2000.0, 2000, 2000, 2000, 3000],
            material: getColorRamp([0.0, 0.045, 0.1, 0.15, 0.37, 0.54, 1.0], false)
        }
    });

    viewer.zoomTo(viewer.entities);

    function getColorRamp(elevationRamp, isVertical = true) {
        let ramp = document.createElement('canvas');
        ramp.width = isVertical ? 1 : 100;
        ramp.height = isVertical ? 100 : 1;
        let ctx = ramp.getContext('2d');

        let values = elevationRamp;
        let grd = isVertical ? ctx.createLinearGradient(0, 0, 0, 100) : ctx.createLinearGradient(0, 0, 100, 0);
        grd.addColorStop(values[0], '#000000'); //black
        grd.addColorStop(values[1], '#2747E0'); //blue
        grd.addColorStop(values[2], '#D33B7D'); //pink
        grd.addColorStop(values[3], '#D33038'); //red
        grd.addColorStop(values[4], '#FF9742'); //orange
        grd.addColorStop(values[5], '#ffd700'); //yellow
        grd.addColorStop(values[6], '#ffffff'); //white

        ctx.fillStyle = grd;
        if (isVertical)
            ctx.fillRect(0, 0, 1, 100);
        else
            ctx.fillRect(0, 0, 100, 1);
        return ramp;
    }
</script>
</body>
</html>                                                                                                                                                                    
源码