当前位置:网站首页>Basic use of cesium, including loading images, terrain, models, vector data, etc

Basic use of cesium, including loading images, terrain, models, vector data, etc

2022-06-13 08:44:00 Dependency_ Lai

Load sphere

1、 download cesium package https://download.csdn.net/download/weixin_39150852/20303629, stay html In the introduction

<link href="static/Cesium-1.82/Build/Cesium/Widgets/widgets.css" rel="stylesheet"/>
<script src="static/Cesium-1.82/Build/Cesium/Cesium.js" type="text/javascript"></script>

2、 Define public methods , Introduced the global

Array.prototype.filter = Array.prototype.filter || function (func) {
    
    var arr = this;
    var r = [];
    for (var i = 0; i < arr.length; i++) {
    
        if (func(arr[i], i, arr)) {
    
            r.push(arr[i]);
        }
    }
    return r;
}

Array.prototype.firstOrDefault = Array.prototype.firstOrDefault || function (func) {
    
    var arr = this;
    var r=null ;
    for (var i = 0; i < arr.length; i++) {
    
        if (func(arr[i], i, arr)) {
    
            r=arr[i];
            break;
        }
    }
    return r;
}

Array.prototype.where = Array.prototype.where || function (func) {
    
    var arr = this;
    var r = [];
    for (var i = 0; i < arr.length; i++) {
    
        if (func(arr[i], i, arr)) {
    
            r.push(arr[i]);
        }
    }
    return r;
}

3、 Initialize map

<template>
    <div>
		<div id='cesiumContainer'></div>
    </div>
</template>

<script>
	var viewer = null;
    export default {
    
        components: {
    },
        data() {
    
            return {
    

            }
        },
		mounted(){
    
        	this.initMap();
		},
		methods: {
    
			initMap(){
    
				viewer = new Cesium.Viewer('cesiumContainer', {
    
					geocoder: false,// Place name search , Default true
					homeButton: false,// Home button , Default true
					sceneModePicker: false,// 2D,3D and Columbus View Toggle control 
					baseLayerPicker: false,// Map switch control ( Base map and topographic map ) Whether or not shown , Default display true
					navigationHelpButton: false,//  Help prompt control 
					animation: false, // View animation playback speed control , Default true
					timeline: false,// Timeline , Default true
					fullscreenButton: false,// Full screen button , Default display true
					infoBox: false,// Information displayed after clicking on the element , Default true
					selectionIndicator: false,// The selected element displays , Default true
					scene3DOnly: true, //  only 3D Rendering , save GPU Memory 
					// If not set imageryProvider attribute , An image will be loaded by default 
					// If not set terrainProvider attribute , A terrain will be loaded by default 
				});
				viewer.scene.globe.depthTestAgainstTerrain = true; // Solve the problem of clicking and reporting errors in vertical view 
      			viewer.cesiumWidget.creditContainer.style.display = "none";//  hide Logo, watermark 
				viewer.imageryLayers.removeAll(); // Delete default video 
			}
		}
    }
</script>

<style lang="scss" scoped>
	// Set map width and height , If it is not set canvas The height of will always increase 
	#cesiumContainer {
    
		width: 98%;
		height: 87%;
		position: absolute
	}
</style>

 Insert picture description here

Hiding watermarks can also be done by css Method realization :

.cesium-viewer-timelineContainer,
.cesium-viewer-animationContainer,
.cesium-viewer-bottom {
    
	display: none !important;
}

Load image ( Multi layer images can be superimposed )

		addImagery() {
    
			var _lyr = viewer.imageryLayers._layers.firstOrDefault(t => {
    
				if (t.lyr_ID && t.lyr_ID == 'baseImageLayerID' && t.lyr_NAME && t.lyr_NAME == ' Image basemap ') {
     return t; }
			});
			if (_lyr) return;
			// Sky map image 、arcgis Local slicing service for 、arcgis released imageServer、 Kylin map 、 released zxy Form of map service 
			/*let imageryProvider = new Cesium.UrlTemplateImageryProvider({ url: "http://t4.tianditu.com/DataServer?T=img_w&x={x}&y={y}&l={z}&tk=4b01c1b56c6bcba2eb9b8e987529c44f", //url: "http://117.176.159.208:48021/ National image /{z}/{x}/{y}.png", tileWidth: 512, tileHeight: 512, maximumLevel: 18, })*/
			//arcgisserver Published base map service , Currently only supported 4326 and 3857 Slice map loading of coordinate system 
			let imageryProvider = new ArcGisMapServerImageryProvider({
    
		        url: "http://cache1.arcgisonline.cn/arcgis/rest/services/ChinaOnlineStreetPurplishBlue/MapServer",
       		})
			//wmts service 
			/*let imageryProvider = new Cesium.WebMapTileServiceImageryProvider({ url: "http://t{s}.tianditu.com/img_w/wmts?service=wmts&request=GetTile&version=1.0.0&LAYER=img&tileMatrixSet=w&TileMatrix={TileMatrix}&TileRow={TileRow}&TileCol={TileCol}&style=default&format=tiles&tk=0911bd7d5242feed8ec0fa67f3d47afd", layer: "tdtBasicLayer", style: "default", format: "image/jpeg", tileMatrixSetID: "GoogleMapsCompatible", subdomains: ["0", "1", "2"] })*/
		    // Background map 
	        /* let baseImagery = new Cesium.SingleTileImageryProvider({ url: "/imgs/home/world.jpg", });*/
			let layer = viewer.imageryLayers.addImageryProvider(imageryProvider);
			layer["lyr_ID"] = "baseImageLayerID";
			layer["lyr_NAME"] = " Image basemap ";
		}

 Insert picture description here

Remove image

	removeImagery() {
    
        var _lyr = viewer.imageryLayers._layers.firstOrDefault(t => {
    
            if (t.lyr_ID && t.lyr_ID == 'baseImageLayerID' && t.lyr_NAME && t.lyr_NAME == ' Image basemap ') {
     return t; }
        });
        if (_lyr) viewer.imageryLayers.remove(_lyr, true);
    }

Top image

	TotopTiandituImageMap() {
    
        var _lyr = viewer.imageryLayers._layers.firstOrDefault(t => {
    
            if (t.lyr_ID && t.lyr_ID == 'baseImageLayerID' && t.lyr_NAME && t.lyr_NAME == ' Image basemap ') {
     return t; }
        });
        if (_lyr) viewer.imageryLayers.raiseToTop(_lyr);
    }

Load terrain ( There can only be one terrain service )

Failure to load the terrain address will cause the sphere to be invisible

		addTerrain() {
    
			// load cesium Terrain data in 
			let terrainLayer = new Cesium.CesiumTerrainProvider({
    
				url: "http://117.175.169.58:48002/",
				requestVertexNormals: true,
				requestWaterMask: true
			});
		
			//arcgis Published terrain data 
			/*let terrainLayer = new Cesium.ArcGISTiledElevationTerrainProvider({ url: "https://elevation3d.arcgis.com/arcgis/rest/services/WorldElevation3D/Terrain3D/ImageServer", });*/

			// Add a height of 0 The terrain of the city , cesium This terrain object is loaded by default 
	    	/*let terrainLayer = new Cesium.EllipsoidTerrainProvider()};*/
			
			viewer.terrainProvider = terrainLayer
			

Remove terrain

	removeTerrain() {
    
		if (viewer.terrainProvider instanceof Cesium.EllipsoidTerrainProvider) {
    
            return
        } else {
    
            viewer.terrainProvider = new Cesium.EllipsoidTerrainProvider();
        }
	}

load 3dtiles Model

			addModel(){
    
				// Prevent duplicate loading 
			    let model = viewer.scene.primitives._primitives.filter(t => {
    
			        return t && t.id === '3dTilesModel1';
			    });
			    if (model.length) return;
				let primitive = new Cesium.Cesium3DTileset({
    
					url: 'http://117.175.169.58:48012/%E6%B5%81%E5%9F%9F%E5%AE%89%E5%85%A8%E6%B0%B4%E7%94%B5%E7%AB%99/tileset.json'
				})
				primitive["name"] = 'mainModel_3dtitles';
    			primitive["id"] = '3dTilesModel1';
				viewer.scene.primitives.add(primitive);
				primitive.readyPromise.then(function (argument) {
    
					viewer.flyTo(argument);// Fly to the model 
				})
				// Raise the model 0.5m
				primitive.readyPromise.then(function(tileset) {
    
			        viewer.scene.primitives.add(tileset);
			        let boundingSphere = tileset.boundingSphere;
			        let cartographic = Cesium.Cartographic.fromCartesian(boundingSphere.center);
			        let surface = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, 0.0);
			        let offset = Cesium.Cartesian3.fromRadians(cartographic.longitude, cartographic.latitude, 0.5);
			        let translation = Cesium.Cartesian3.subtract(offset, surface, new Cesium.Cartesian3());
			        tileset.modelMatrix = Cesium.Matrix4.fromTranslation(translation);
			    });
			}

 Insert picture description here

load glb,gltf Model

addModel() {
    
	// Prevent duplicate loading 
    let model = viewer.scene.primitives._primitives.filter(t => {
    
        return t && t.id === "gltfModel1";
    });
    if (model.length) return;
    let position = Cesium.Cartesian3.fromDegrees(116.523753404617, 40.2340042591095, 0);
    let hpRoll = new Cesium.HeadingPitchRoll(
        Cesium.Math.toRadians(90),
        0,
        Cesium.Math.toRadians(0)
    );
    /*let m = Cesium.Transforms.eastNorthUpToFixedFrame( Cesium.Cartesian3.fromDegrees(116.523753404617, 40.2340042591095, 0) ); let m1 = Cesium.Matrix3.fromRotationZ(Cesium.Math.toRadians(-90)); Cesium.Matrix4.multiplyByMatrix3(m, m1, m); //  Matrix computing */
    let primitive = Cesium.Model.fromGltf({
    
        url: "/model/home/mx.glb",
        modelMatrix: Cesium.Transforms.headingPitchRollToFixedFrame(position, hpRoll),
        //modelMatrix: m
    });
	primitive["name"] = 'mainModel_gltf';
    primitive["id"] = 'gltfModel1';
    viewer.scene.primitives.add(primitive)
    // Fly to the model view 
    getViewer().camera.flyTo({
    
        "destination": {
    "x": -2177813.7852421473, "y": 4362755.897898611, "z": 4097937.821940227},
        "orientation": {
    "pitch": -0.5192370076293065, "heading": 4.733198787733471, "roll": 6.2793732598153}
    });
}

Adjust the map color

	let layer = viewer.imageryLayers.get(0)
	// Layer brightness ,1.0 Use unmodified image colors . Less than 1.0 Will make the image darker , But more than 1.0 Will make the image brighter 
    layer.brightness = 1.0;
    // Layer contrast ,1.0 Use unmodified image colors . Less than 1.0 Will reduce the contrast , Greater than 1.0 Will increase the contrast .
     layer.contrast = 1.0;
    // Layer saturation ,1.0 Use unmodified image colors . Less than 1.0 Will reduce the saturation , Greater than 1.0 Will increase saturation .
    layer.saturation = 1.0;
    // Layer hue , In radians ,0 Indicates to use the unmodified image color 
   	layer.hue = 0;
    // Gamma correction applied to this layer ,1.0 Use unmodified image colors .
    layer.gamma = 1.0;

Set up ambient light

If the model shadow is displayed after setting the ambient light , Then the shadow direction is not controlled by time , With ambient light direction The direction shall prevail

 viewer.scene.light = new Cesium.DirectionalLight({
    
            direction: new Cesium.Cartesian3(1, -1, -1),// Direction 
            color: Cesium.Color.WHITE,// Color 
            intensity: 0.5 // Strength 
        });

following map_common_addDatasouce, jsonParse Method reference https://blog.csdn.net/weixin_39150852/article/details/119676613

Load icons and text labels

let data = [
      {
    
        id: '1',
        name: ' camera 1',
        coordinate: [116.5237896183484, 40.23425089061218, 1]
      },
      {
    
        id: '2',
        name: ' camera 2',
        coordinate: [116.52442547004496, 40.234225534772044, 1]
      },
      {
    
        id: '3',
        name: ' camera 3',
        coordinate: [116.52386941878123, 40.233503276564576, 1]
      }
    ];
addPoints(data) {
    
    if (data && data.length > 0) {
    
        let datasource = map_common_addDatasouce("point");
        datasource.entities.removeAll();
        data.forEach(item => {
    
            datasource.entities.add({
    
                position: Cesium.Cartesian3.fromDegrees(item.coordinate[0], item.coordinate[1], item.coordinate[2]),// Icon position 
                billboard: {
    
                    image: `/images/marker.png`,// Icon address 
                    horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
                    verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
                    disableDepthTestDistance: Number.POSITIVE_INFINITY,
                    pixelOffset: new Cesium.Cartesian2(-6, 6),
                    scale: 0.8,
                },
                label: {
    
                    scale: 1,
                    font: "bolder 16px sans-serif",
                    style: Cesium.LabelStyle.FILL_AND_OUTLINE,
                    text: item.name,// Icon name 
                    fillColor: Cesium.Color.fromCssColorString("#ffffff"),
                    pixelOffset: new Cesium.Cartesian2(0, -60)
                },
                properties: new Cesium.PropertyBag({
    
                    type: "point",
                    details: item
                })
            });
        })
    }
}

Load alarm point animation effect

let data = [
      {
    
        id: '1',
        name: ' Alarm point 1',
        coordinate: [116.52329742014058, 40.234779669561995, 1]
      },
      {
    
        id: '2',
        name: ' Alarm point 2',
        coordinate: [116.5237795168529, 40.23282475084235, 1]
      }
    ];
addWarnings(data) {
    
    if (data && data.length > 0) {
    
        let datasource = map_common_addDatasouce("warning");
        datasource.entities.removeAll();
        //let x = 1;
        //let flog = true;
        data.forEach(item => {
    
            datasource.entities.add({
    
                position: Cesium.Cartesian3.fromDegrees(item.coordinate[0], item.coordinate[1], item.coordinate[2]),
                /* ellipse: { height: 35,// Height  semiMinorAxis: 10,// Long half axis  semiMajorAxis: 10,// Short half shaft  // Hypergraph animation effect  material: new Cesium.CircleWaveMaterialProperty({ duration: 1000,// Speed  gradient: 0.5,// The gradient  color: Cesium.Color.fromCssColorString("#f71a1a").withAlpha(0.2), count: 2 // Number  }), },*/
                // Flash animation is realized by dynamically changing the zoom size 
                billboard: {
    
	                image: `/images/marker.png`,
	                pixelOffset: new Cesium.Cartesian2(0, -50),
	                scale: new Cesium.CallbackProperty(function () {
    
	                    if (flog) {
    
	                        x = x - 0.03;
	                        if (x <= 0.2) {
    
	                            flog = false;
	                        }
	                    } else {
    
	                        x = x + 0.03;
	                        if (x >= 0.8) {
    
	                            flog = true;
	                        }
	                    }
	                    return x;
	                }, false)
            	}
                properties: new Cesium.PropertyBag({
    
                    type: "warning",
                    details: item
                })
            });
        })
    }
}

Animation 1
 Insert picture description here

Animation 2
 Insert picture description here

Load line

let data = {
    
      id: '1',
      name: ' Border camp... Gaoli ',
      rangerArr: [[116.52320712206836, 40.23406811024757, 5], [116.52321177601786, 40.23347668875855, 5], [116.52452838827061, 40.23347827970169, 5], [116.52453120516144, 40.23515431118559, 5], [116.52321855758989, 40.23407917327679, 5], [116.52320712206836, 40.23406811024757, 5]]
};
addLine(data) {
    
    if (data && data.rangerArr && data.rangerArr.length > 0) {
    
        let datasource = map_common_addDatasouce("line");
        datasource.entities.removeAll();
        let positions = Array.prototype.concat.apply(
            [],
            data.rangerArr
        );
        datasource.entities.add(
            new Cesium.Entity({
    
                polyline: {
    
                    positions: Cesium.Cartesian3.fromDegreesArrayHeights(positions),
                    width: 5.0,
                    // Pure color 
                    /* material: Cesium.Color.fromCssColorString("#73f9f0").withAlpha( 1.0 ),*/
                    // Glow effect 
                    material: new Cesium.PolylineGlowMaterialProperty({
    
                         color: Cesium.Color.fromCssColorString("#fff"),
                         glowPower: 0.1
                    })
                },
                properties: new Cesium.PropertyBag({
    
                    type: "line",
                    details: data
                })
            })
        );
    }
}

 Insert picture description here

Loading surface

let data = {
    
      id: '1',
      name: ' Koryo camp range ',
      rangerArr: [[116.52320712206836, 40.23406811024757, 5], [116.52321177601786, 40.23347668875855, 5], [116.52452838827061, 40.23347827970169, 5], [116.52453120516144, 40.23515431118559, 5], [116.52321855758989, 40.23407917327679, 5], [116.52320712206836, 40.23406811024757, 5]]
};
addPoly(data) {
    
    if (data && data.rangerArr && data.rangerArr.length > 0) {
    
        let datasource = map_common_addDatasouce("poly");
        datasource.entities.removeAll();
        let positions = Array.prototype.concat.apply(
            [],
            data.rangerArr
        );
        let x = 1;
        let flog = true
        datasource.entities.add(
            new Cesium.Entity({
    
                polygon: {
    
                	height: 2000,
                    hierarchy: Cesium.Cartesian3.fromDegreesArrayHeights(positions),
                    // Pure color 
                    /*material: Cesium.Color.fromCssColorString('73f9f0').withAlpha(1),*/
                    // picture 
                    /*material: new Cesium.ImageMaterialProperty({ image: "/images/home/ The Beijing municipal .png", }),*/
                    // Flash animation by dynamically changing transparency 
           			material: new Cesium.ColorMaterialProperty(
                        new Cesium.CallbackProperty(function () {
    
                            if (flog) {
    
                                x = x - 0.03;
                                if (x <= 0.2) {
    
                                    flog = false;
                                }
                            } else {
    
                                x = x +  0.03;
                                if (x >= 0.8) {
    
                                    flog = true;
                                }
                            }
                            return Cesium.Color.RED.withAlpha(x);
                        }, false)),
                	clampToS3M: true, // Face paste 3dTiles Model , if gltf Model , This parameter does not take effect , Then combine extrudedHeight and height Attribute pull into a body  
                    outline: true,
                    outlineColor: Cesium.Color.fromCssColorString("#a2ffba"),
                    outlineWidth: 1.0,// Range face data settings outline by true when , The width can only be displayed 1px
                    // Control the height range of display and concealment 
                    distanceDisplayCondition: new Cesium.DistanceDisplayCondition(
                            100000,
                            1000000.0
                        ),
                },
                properties: new Cesium.PropertyBag({
    
                    type: "poly",
                    details: data
                })
            })
        );
    }
}

 Insert picture description here

Load background image

loadCircle() {
    
    let datasource = map_common_addDatasouce("circleImage");
    datasource.entities.add({
    
        position: Cesium.Cartesian3.fromDegrees(
            93.97039653185051, 29.950970087104018, 4000
        ),
        ellipse: {
    
            height: 3000,
            semiMajorAxis: 220000,
            semiMinorAxis: 220000,
            material: new Cesium.ImageMaterialProperty({
    
                image: "/images/map/circle.png",
                transparent: true,
                color: new Cesium.Color(0.4, 0.4, 0.4, 0.8),
            }),
            stRotation: 0 // Rotation Angle 
        },
    });
}

 Insert picture description here

Load fence

/** *  Color gradient  */
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], 'rgba(22,35,64,1)');
    grd.addColorStop(values[1], 'rgba(49,67,71,1)');
    grd.addColorStop(values[2], 'rgba(22,35,64,1)');
    grd.addColorStop(values[3], 'rgba(49,67,71,1)');
    grd.addColorStop(values[4], 'rgba(22,35,64,1)');
    grd.addColorStop(values[5], 'rgba(49,67,71,1)');
    ctx.globalAlpha = 0.3;
    ctx.fillStyle = grd;
    if (isVertical)
        ctx.fillRect(0, 0, 1, 100);
    else
        ctx.fillRect(0, 0, 100, 1);

    return ramp;
}



let data = {
    
      id: '1',
      name: ' Gaoliying electronic fence ',
      rangerArr: [[116.52320712206836, 40.23406811024757, 20], [116.52321177601786, 40.23347668875855, 20], [116.52452838827061, 40.23347827970169, 20], [116.52453120516144, 40.23515431118559, 20], [116.52321855758989, 40.23407917327679, 20], [116.52320712206836, 40.23406811024757, 20]]
};
addWall(data) {
    
    if (data && data.rangerArr && data.rangerArr.length > 0) {
    
        let datasource = map_common_addDatasouce("wall");
        datasource.entities.removeAll();
        let positions = Array.prototype.concat.apply(
            [],
            data.rangerArr
        );
        datasource.entities.add(
            new Cesium.Entity({
    
                wall: {
    
                    positions: Cesium.Cartesian3.fromDegreesArrayHeights(positions),
                    material: new Cesium.ImageMaterialProperty({
    
                    	// Customize 
                        image: getColorRamp([0.0, 0.2, 0.4, 0.6, 0.8, 1.0], true,"county_border_line"),
                        // Pure color 
                        /*color: Cesium.Color.fromCssColorString('#faff12').withAlpha(0.3)*/
                        // picture 
                       /*image: "/imgs/home/ Group .png", repeat: new Cesium.Cartesian2(1.0, 1), transparent: true*/
                    }),
                    outline: false,
                },
                properties: new Cesium.PropertyBag({
    
                    type: "wall",
                    details: data
                })
            })
        );
    }
}

 Insert picture description here

Loading surface + The fence realizes three-dimensional layered effect

/** *  Load Beijing area  */
function mapView_BeiJing() {
    
    jsonParse("/json/home/ The Beijing municipal .json").then((val) => {
    
        if (val && val.length > 0) {
    
            let datasource = map_common_addDatasouce(datasourceName.BEIJING_DATASOURCE);
            val.forEach((el) => {
    
                let positions = Array.prototype.concat.apply(
                    [],
                    el.geometry.coordinates[0]
                );

                datasource.entities.add({
    
                    polygon: {
    
                        hierarchy: Cesium.Cartesian3.fromDegreesArray(positions),
                        height: 4000,
                        material: new Cesium.ImageMaterialProperty({
    
                            image: "/imgs/home/ The Beijing municipal .png",
                        }),
                        outline: false
                    }
                });
                let positions2 = el.geometry.coordinates[0].map(item => {
    
                    item.push(initHeight);
                    return item
                })
                let positions3 = Array.prototype.concat.apply(
                    [],
                    positions2
                );
                datasource.entities.add({
    
                    wall: {
    
                        positions: Cesium.Cartesian3.fromDegreesArrayHeights(positions3),
                        material: new Cesium.ImageMaterialProperty({
    
                            image: "/imgs/home/ Group .png",
                            repeat: new Cesium.Cartesian2(1.0, 1),
                            transparent: true,
                        }),
                        outline: false
                    },
                });
            });
        }
    });
}

picture :
 Insert picture description here  Insert picture description here
effect :

 Insert picture description here

Load gradient cylinder

/** *  Color gradient  */
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], '#0084FF');
    grd.addColorStop(values[1], '#00FCFF');
    grd.addColorStop(values[2], '#00FF7E');
    ctx.globalAlpha = 0.3;
    ctx.fillStyle = grd;
    if (isVertical)
        ctx.fillRect(0, 0, 1, 100);
    else
        ctx.fillRect(0, 0, 100, 1);

    return ramp;
}

let data = [
      {
    
        id: '1',
        name: ' Rainfall column 1',
        coordinate: [116.5237896183484, 40.23425089061218],
        rainValue: 14000
      },
      {
    
        id: '2',
        name: ' Rainfall column 2',
        coordinate: [116.52442547004496, 40.234225534772044],
        rainValue: 11000
      },
      {
    
        id: '3',
        name: ' Rainfall column 3',
        coordinate: [116.52386941878123, 40.233503276564576],
        rainValue: 8000
      }
    ];
addCylinder(data) {
    
    if (data && data.length > 0) {
    
        let datasource = map_common_addDatasouce("point");
        datasource.entities.removeAll();
        data.forEach(item => {
    
        		let center = item.coordinates;
                let radius = 1;// radius 
                let options = {
    steps: 64, units: 'kilometers', properties: {
    foo: 'bar'}};
                // introduce turf Build a range surface  
                //import circle from '@turf/circle';
                let circleData = circle(center, radius, options);
                let height = item.rainValue;// Height 
                let wallPositions = circleData.geometry.coordinates[0].map(item => {
    
                    return [...item, height]
                });
                let positions = Array.prototype.concat.apply(
                    [],
                    wallPositions
                );
                // Gradient filling is realized through the enclosure 
                datasource.entities.add({
    
                    wall: {
    
                        positions: Cesium.Cartesian3.fromDegreesArrayHeights(positions),
                        material: new Cesium.ImageMaterialProperty({
    
                            image: getColorRamp([0.1, 0.5, 1.0], true, "county_border_line"),
                            repeat: new Cesium.Cartesian2(1.0, 1),
                            transparent: false,
                        }),
                        minimumHeights: wallPositions.map(() => 10500),
                        outline: false,
                    }
                });
                // Fill solid color fence 
                datasource.entities.add({
    
                    position: Cesium.Cartesian3.fromDegrees(item.coordinates[0], item.coordinates[1], 10500),
                    cylinder: {
    
                        length: height - 10500,
                        heightReference: Cesium.HeightReference.RELATIVE_TO_GROUND,
                        topRadius: 990,
                        bottomRadius: 990,
                        material: Cesium.Color.fromCssColorString('#0077AF'),
                        outline: false
                    }
                })
        })
    }
}

 Insert picture description here

原网站

版权声明
本文为[Dependency_ Lai]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202270538334935.html