Skip to content

缓冲区

缓冲区需要额外调用接口,需要引用插件 BufferAnalysis.js

HTML
<script src="SDK/Plugins/BufferAnalysis.js"></script>

缓冲区开始

JavaScript
  function createBuffer(geometry, width) {
        var bufferGeometry = undefined;
        if (geometry instanceof LSGlobe.Cartesian3 || geometry instanceof LSGlobe.SimplePolylineGeometry
            || geometry instanceof LSGlobe.PolygonGeometry) {
            bufferGeometry = geometry;
        }

        if (LSGlobe.defined(bufferGeometry)) {
            var buffer = viewer.bufferAnalysis.viewModel.buffer(bufferGeometry, width);
            viewer.scene.primitives.add(new LSGlobe.GroundPrimitive({
                geometryInstances: new LSGlobe.GeometryInstance({
                    geometry: buffer,
                    attributes: {
                        color: LSGlobe.ColorGeometryInstanceAttribute.fromColor(LSGlobe.Color.CORAL.withAlpha(0.5))
                    }
                }),
                appearance: new LSGlobe.PerInstanceColorAppearance({
                    flat: true,
                    translucent: false
                }),
                asynchronous: true
            }))
        }
    }

缓冲点

JavaScript
var point = viewer.entities.add({
        position: new LSGlobe.Cartesian3.fromDegrees(112, 30),
        point: {
            show: true,
            heightReference: LSGlobe.HeightReference.CLAMP_TO_GROUND,
            pixelSize: 10, // 像素点大小
            color: LSGlobe.Color.YELLOW // 点位颜色
        },
        show: true
    });

    createBuffer(point.position.getValue(), 5000);

缓冲线

JavaScript
var line = viewer.entities.add({
        polyline: {
            positions: LSGlobe.Cartesian3.fromDegreesArray(['120.5070604588', '31.4468232691', '120.5357608787', '31.4541161043', '120.5468011104', '31.4586169902', '120.5676789334', '31.4685878382', '120.5836159563', '31.4706913162', '120.5959846813', '31.4698773817', '120.6143626015', '31.4791599173', '120.6252667821', '31.484252155']),
            width: 2,
            material: LSGlobe.Color.RED
        }
    });

    createBuffer(new LSGlobe.SimplePolylineGeometry({
        positions: line.polyline.positions.getValue()
    }), 5000);

缓冲面

JavaScript
var polygon = viewer.entities.add({
        polygon: {
            hierarchy: new LSGlobe.PolygonHierarchy(
                LSGlobe.Cartesian3.fromDegreesArray([
                    112, 30,
                    111, 31,
                    112, 31,
                    112, 30
                ])
            ),
            outline: true,
            outlineColor: LSGlobe.Color.WHITE,
            outlineWidth: 4
        },
    });

    createBuffer(new LSGlobe.PolygonGeometry({
        polygonHierarchy: new LSGlobe.PolygonHierarchy(polygon.polygon.hierarchy.getValue().positions),
        perPositionHeight: true
    }), 5000);

示例代码 code

code示例地址

Released under the MIT License.