<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8'/>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no'/>
<link href='http://ua.bigemap.com:30081/bmsdk/bigemap-gl.js/v1.1.0/Widgets/widgets.css' rel='stylesheet'/>
<script src='http://ua.bigemap.com:30081/bmsdk/bigemap-gl.js/v1.1.0/bigemap-gl.js'></script>
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
<style>
body {
margin: 0;
padding: 0;
}
#container {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
}
#add{
position: absolute;
left: 25px;
top:20px;
color: #333;
background-color: #f1f1f1;
padding: 15px;
}
#add a{
display: inline-block;
padding: 5px 10px;
}
.bmgl-widget-credits{display:none}
</style>
<title>part_test</title>
</head>
<body>
<div id='container'></div>
<div id="add">
<a href="javascript:void(0);" id="start" data-type="start">开始</a>
<a href="javascript:void(0);" data-type="stop">停止</a>
<a href="javascript:void(0);" data-type="show">显示/隐藏</a>
</div>
<script>
bmgl.Config.HTTP_URL = 'http://ua.bigemap.com:30081/bmsdk/';
var viewer = new bmgl.Viewer('container', {
terrainId: 'bigemap.dc-terrain',
mapId: 'bigemap.dc-tian-w-satellite',
requestRenderMode:false,
});
//启用地形遮挡
viewer.scene.globe.depthTestAgainstTerrain=true;
viewer.camera.setView({
destination:bmgl.Cartesian3.fromDegrees(103.62908521232548,30.925160500796443,9271.09381883),
orientation:{"heading":6.282927573132531,"roll":6.283184223254143,"pitch":-0.7898537685249098}
});
let points = [103.67642392404379,30.979978615804974,103.64449597662316,30.950517790429306,103.59338702866808,30.940714212782957,103.53219402255492,30.961381555053634,103.51394213503228,31.000584107166144,103.50470567587763,31.035048201444695,103.54711355874316,31.05039059266936,103.64366019610316,31.063488152089803,103.70637133251877,31.06890226409121,103.73128368984909,31.047311092748085,103.71700788382444,31.012171641339606,103.70410968549551,30.981436193269417,103.67715457454325,30.980169097270256]
class WaterPrimitive {
_viewer = null;
water;
points; // 淹没区域坐标
height; // 初始高度
maxHeight; // 最大高度
url; // 材质贴图地址
setup = 0.25; // 当前高度增量
times = null; // 定时器
constructor(viewer, options) {
this._viewer = viewer;
this.points = bmgl.Cartesian3.fromDegreesArray(options.points);
this.height = options.height;
this.maxHeight = options.maxHeight || 2000;
this.url = options.url;
this.init();
}
init () {
this.create();
}
create () {
let that = this
this.water = new bmgl.Primitive({
show: false,
geometryInstances: new bmgl.GeometryInstance({
geometry: new bmgl.PolygonGeometry({
polygonHierarchy: new bmgl.PolygonHierarchy(that.points),
height: 0,
extrudedHeight: Number(that.height),
})
}),
appearance: new bmgl.EllipsoidSurfaceAppearance({
material: new bmgl.Material({
fabric: {
type: "Water",
uniforms: {
// baseWaterColor: new bmgl.Color(64 / 255.0, 157 / 255.0, 253 / 255.0, 0.7),
baseWaterColor: new bmgl.Color(1 / 255.0, 157 / 255.0, 253 / 255.0, 0.7),
normalMap: that.url,
frequency: 100.0, // 频率
animationSpeed: 0.01, // 动画速度
// amplitude: 10, // 振幅
amplitude: 50, // 振幅
specularIntensity: 10 //高光强度
}
}
})
}),
modelMatrix: bmgl.Matrix4.IDENTITY // 初始单位矩阵
});
this.add();
}
isShow(show) {
this.water.show = show;
}
add() {
this._viewer.scene.primitives.add(this.water);
}
updateHeight() {
let that = this;
let setupHeight = that.maxHeight - that.height;
this.times = setInterval(() => {
that.setup = that.setup < setupHeight ? that.setup += 0.25 : setupHeight;
if(that.setup >= setupHeight) {
clearInterval(that.times);
this.times = null
}
// 通过矩阵平移控制高度
const translation = bmgl.Cartesian3.fromElements(
0,
0,
Number(that.setup)
);
this.water.modelMatrix = bmgl.Matrix4.fromTranslation(translation);
}, 10)
}
suspend() {
clearInterval(this.times);
this.times = null
}
stop() {
this.suspend();
this.setup = 0.25;
}
remove() {
this._viewer.scene.primitives.remove(this.water);
}
}
var water = new WaterPrimitive(viewer, {
points: points,
height: 650,
maxHeight: 2000,
url: '/offline_data/water.jpg',
});
let bol = false
document.getElementById('add').addEventListener('click',function (e) {
var dataset= e.target.dataset;
switch (dataset.type) {
case 'stop':
document.getElementById('start').innerHTML='开始';
water.stop();
bol = false;
break;
case 'start':
bol = !bol;
if(bol){
water.isShow(true);
e.target.innerHTML='暂停';
water.updateHeight()
} else {
water.suspend();
e.target.innerHTML='开始';
}
break;
case 'show':
water.isShow(!water.water.show);
break;
}
});
</script>
</body>
</html>