当前位置:网站首页>Cesium add inundation analysis measurement area
Cesium add inundation analysis measurement area
2022-07-28 01:21:00 【Yue Yan Shao Falcon】
var viewer=ysc.createNormalCesium("cesiumContainer",{
// add to cesium Basic properties in
infoBox:true
,globalImagery:" Google "
,navigationHelpButton:true
,showGroundAtmosphere:false// Turn off the atmosphere Default on ,true;
});
viewer.terrainProvider=new Cesium.CesiumTerrainProvider({ // terrain
url : Cesium.IonResource.fromAssetId(3956),
requestVertexNormals : true
});
function measureAreaSpace(viewer,maxH,interval,speed){
var waterEntity;
// Cancel double click event - Track the location
viewer.cesiumWidget.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
// Mouse events
handler = new Cesium.ScreenSpaceEventHandler(viewer.scene._imageryLayerCollection);
var positions = [];
var tempPoints = [];
var polygon = null;
// var tooltip = document.getElementById("toolTip");
var cartesian = null;
var floatingPoint;// Floating point
// tooltip.style.display = "block";
handler.setInputAction(function(movement){
// tooltip.style.left = movement.endPosition.x + 3 + "px";
// tooltip.style.top = movement.endPosition.y - 25 + "px";
// tooltip.innerHTML ='<p> click start , Right click to finish </p>';
// cartesian = viewer.scene.pickPosition(movement.endPosition);
let ray = viewer.camera.getPickRay(movement.endPosition);
cartesian = viewer.scene.globe.pick(ray, viewer.scene);
//cartesian = viewer.scene.camera.pickEllipsoid(movement.endPosition, viewer.scene.globe.ellipsoid);
if(positions.length >= 2){
if (!Cesium.defined(polygon)) {
polygon = new PolygonPrimitive(positions);
}else{
positions.pop();
// cartesian.y += (1 + Math.random());
positions.push(cartesian);
}
// tooltip.innerHTML='<p>'+distance+' rice </p>';
}
},Cesium.ScreenSpaceEventType.MOUSE_MOVE);
handler.setInputAction(function(movement){
// tooltip.style.display = "none";
// cartesian = viewer.scene.pickPosition(movement.position);
let ray = viewer.camera.getPickRay(movement.position);
cartesian = viewer.scene.globe.pick(ray, viewer.scene);
// cartesian = viewer.scene.camera.pickEllipsoid(movement.position, viewer.scene.globe.ellipsoid);
if(positions.length == 0) {
positions.push(cartesian.clone());
}
//positions.pop();
positions.push(cartesian);
// Add points to the 3D scene
var cartographic = Cesium.Cartographic.fromCartesian(positions[positions.length - 1]);
var longitudeString = Cesium.Math.toDegrees(cartographic.longitude);
var latitudeString = Cesium.Math.toDegrees(cartographic.latitude);
var heightString = cartographic.height;
tempPoints.push({ lon: longitudeString, lat: latitudeString ,hei:heightString});
floatingPoint = viewer.entities.add({
name : ' Polygon area ',
position : positions[positions.length - 1],
point : {
pixelSize : 10,
color : Cesium.Color.RED,
outlineColor : Cesium.Color.WHITE,
outlineWidth : 3,
heightReference:Cesium.HeightReference.CLAMP_TO_GROUND
}
});
},Cesium.ScreenSpaceEventType.LEFT_CLICK);
handler.setInputAction(function(movement){
handler.destroy();
positions.pop();
var textArea = getArea(tempPoints) + " Square kilometers ";
// Area label
viewer.entities.add({
name : ' Polygon area ',
position : positions[positions.length - 1],
label : {
text : textArea,
font : '18px sans-serif',
fillColor : Cesium.Color.GOLD,
style: Cesium.LabelStyle.FILL_AND_OUTLINE,
outlineWidth : 2,
verticalOrigin : Cesium.VerticalOrigin.BOTTOM,
pixelOffset : new Cesium.Cartesian2(20, -40),
heightReference:Cesium.HeightReference.CLAMP_TO_GROUND
}
});
// Enter the inundation analysis after two seconds
setTimeout(function () {
if(waterEntity){
viewer.scene.globe.depthTestAgainstTerrain = true;
waterEntity.polygon.heightReference="CLAMP_TO_GROUND";
waterEntity.polygon.material="../images/water.png";
// var h=0;
// waterEntity.polygon.extrudedHeight=new Cesium.CallbackProperty(function () { // or water.polygon.extrudedHeight To carry out Timing settings
// h+=speed;
// if(h>maxH){
// h=maxH;// Give me a maximum
// }
// return h
// });
var h=0;
waterEntity.polygon.extrudedHeight=0;// It needs to be set up in advance Otherwise, it will all appear
var st=setInterval(function () {
h=h+speed;
if(h>=maxH){
h=maxH;// Give me a maximum
alert(" To reach the highest value ");
clearTimeout(st);
}
waterEntity.polygon.extrudedHeight=h;
},interval);
}
},2000);
}, Cesium.ScreenSpaceEventType.RIGHT_CLICK );
var radiansPerDegree = Math.PI / 180.0;// Angle into radians (rad)
var degreesPerRadian = 180.0 / Math.PI;// Radians are converted to angles
// Calculate the area of the polygon
function getArea(points) {
var res = 0;
// Split triangular surface
for (var i = 0; i < points.length - 2; i++) {
var j = (i + 1) % points.length;
var k = (i + 2) % points.length;
var totalAngle = Angle(points[i], points[j], points[k]);
var dis_temp1 = distance(positions[i], positions[j]);
var dis_temp2 = distance(positions[j], positions[k]);
res += dis_temp1 * dis_temp2 * Math.abs(Math.sin(totalAngle)) ;
console.log(res);
}
return (res/1000000.0).toFixed(4);
}
/* angle */
function Angle(p1, p2, p3) {
var bearing21 = Bearing(p2, p1);
var bearing23 = Bearing(p2, p3);
var angle = bearing21 - bearing23;
if (angle < 0) {
angle += 360;
}
return angle;
}
/* Direction */
function Bearing(from, to) {
var lat1 = from.lat * radiansPerDegree;
var lon1 = from.lon * radiansPerDegree;
var lat2 = to.lat * radiansPerDegree;
var lon2 = to.lon * radiansPerDegree;
var angle = -Math.atan2(Math.sin(lon1 - lon2) * Math.cos(lat2), Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(lon1 - lon2));
if (angle < 0) {
angle += Math.PI * 2.0;
}
angle = angle * degreesPerRadian;// angle
return angle;
}
/* polygon */
var PolygonPrimitive = (function(){
function _(positions){
this.options = {
name:' polygon ',
polygon : {
hierarchy : [],
material:Cesium.Color.WHITE.withAlpha(0)
}
};
this.hierarchy = positions;
this._init();
}
_.prototype._init = function(){
var _self = this;
var _update = function(){
return _self.hierarchy;
};
// Real time updates polygon.hierarchy
this.options.polygon.hierarchy = new Cesium.CallbackProperty(_update,false);
waterEntity= viewer.entities.add(this.options);
};
return _;
})();
// Calculated distance
function distance(point1,point2){
var point1cartographic = Cesium.Cartographic.fromCartesian(point1);
var point2cartographic = Cesium.Cartographic.fromCartesian(point2);
/** Calculate the distance according to longitude and latitude **/
var geodesic = new Cesium.EllipsoidGeodesic();
geodesic.setEndPoints(point1cartographic, point2cartographic);
var s = geodesic.surfaceDistance;
//console.log(Math.sqrt(Math.pow(distance, 2) + Math.pow(endheight, 2)));
// Return the distance between two points
s = Math.sqrt(Math.pow(s, 2) + Math.pow(point2cartographic.height - point1cartographic.height, 2));
return s;
}
}
// function
measureAreaSpace(viewer,2000,10,1); //maxH Set to 2000; Maximum inundation altitude Every time 10 Milliseconds forward 1 At an altitude of ;
viewer.camera.flyTo({
destination : Cesium.Cartesian3.fromDegrees(102.5, 30.0,50000)
});
Details visible
边栏推荐
- 力挺吴雄昂!Arm中国管理层发公开信:对莫须有的指控感到震惊和愤怒!
- 氧气温湿度模组
- From functional testing to automated testing, my monthly salary has exceeded 30k+, and I have 6 years of testing experience.
- Support Wu xiongang! Arm Chinese management sent an open letter: shocked and angry at the unwarranted allegations!
- Wentai technology acquired the remaining equity of ANSYS semiconductor and obtained unconditional approval
- Redis-哨兵模式
- uni-app进阶之样式框架/生产环境
- spreadsheet 导出 excel表格
- C language programming | explanation and Simulation of offsetof macro
- 杂谈:一份最初就非常完善的FS跟第一版程序就要求没bug一样不切实际
猜你喜欢

重新定义分析 - EventBridge 实时事件分析平台发布

Tear the source code of gateway by hand, and tear the source code of workflow and load balancing today

Basic concept and classification of i/o equipment

Swoole定时器

Demo: the test interface receives duplicate data and creates documents in a short time

Starfish Os打造的元宇宙生态,跟MetaBell的合作只是开始

EWM receiving ECC delivery note verification logic problem

2022/07/27 学习笔记 (day17) 代码块和内部类

Focal Loss讲解

Oxygen temperature and humidity module
随机推荐
Learning note 12: Eratosthenes screening method to find prime numbers (within 100) and magic square matrix
安全检测风险
《安富莱嵌入式周报》第275期:2022.07.18--2022.07.24
node-red与TDengine交互
糟糕程序员的20个坏习惯
JS global function method module exports exports
Vandermond convolution learning notes
Redis-哨兵模式
Shaanxi Yuanjie semiconductor, a laser chip manufacturer, was invested by 8 investment institutions including GF Securities and CITIC Securities
[STM32] watchdog module
Demo: the test interface receives duplicate data and creates documents in a short time
spreadsheet 导出 excel表格
mysql查询条件字段值末尾有空格也能查到数据问题
Basic use of calculation attributes
“蔚来杯“2022牛客暑期多校训练营3 补题题解(A、C、J)
Fabric2.4.4 version building process (complete process)
Matlab drawing - points and vectors: method and source code of vector addition and subtraction
If asynchronous processing is implemented according to the framework
Six relationships of UML class diagram, the best way to learn and understand
I want to get 20K after 3 years of experience, but I haven't got it for half a month?