当前位置:网站首页>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
边栏推荐
- C language programming | single dog topic explanation
- Huawei's Hubble investment shares in VCSEL chip manufacturer Zonghui Xinguang
- Arm中国夺权大战的背后:“独立”两年,仍难“自主”?
- 数据库故障容错之系统时钟故障
- The cooperation between starfish OS and metabell is just the beginning
- Xinyi information technology, a domestic NB IOT chip manufacturer, received 200million yuan of a+ round financing
- 华为旗下哈勃投资入股VCSEL芯片厂商纵慧芯光
- At the meeting on June 19, SMIC may set the fastest listing record in China!
- 闻泰科技收购安世半导体剩余股权获得无条件通过
- Lua进阶
猜你喜欢

BSP video tutorial issue 21: easy one key implementation of serial port DMA variable length transceiver, support bare metal and RTOS, including MDK and IAR, which is more convenient than stm32cubemx (

ABAP CDS Table Function介绍与示例

110. In depth introduction to sap ui5 fileuploader control - why do you need a hidden iframe

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

2022/07/27 learning notes (Day17) code blocks and internal classes

文件系统挂载

mysql查询条件字段值末尾有空格也能查到数据问题

Spool timer

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

Six relationships of UML class diagram, the best way to learn and understand
随机推荐
Swoole定时器
Starfish Os打造的元宇宙生态,跟MetaBell的合作只是开始
S-RPN: Sampling-balanced region proposal network for small crop pest detection
EWM receiving ECC delivery note verification logic problem
Swoole collaboration
node-red与TDengine交互
晶方科技:光刻机厂商ASML为公司参与并购的Anteryon公司的最主要客户之一
Knowledge of two-dimensional array
Wentai technology acquired the remaining equity of ANSYS semiconductor and obtained unconditional approval
Unknown database ‘xxxxx‘
激光器芯片厂商陕西源杰半导体获广发证券、中信证券等8家投资机构入股
Introduction to the browser video frame operation method requestvideoframecallback()
Code random notes_ Hash_ 1002 find common characters
闻泰科技收购安世半导体剩余股权获得无条件通过
Storage of deep planing data in memory
诺基亚宣布与博通合作开发5G芯片
Lua advanced
Software process that testers need to know
如何解决12,000家中小客户的元器件采购痛点?告别加班!
Basic learning of cesium