<!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>
<style>
body {
margin: 0;
padding: 0;
}
#container {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
}
.bmgl-widget-credits {
display: none;
}
</style>
<title>part_test</title>
</head>
<body>
<div id="container"></div>
<script type="module">
import { modifyMap } from "/offline_data/newjunbiao/fslj.js";
bmgl.Config.HTTP_URL = 'http://ua.bigemap.com:30081/bmsdk/';
window.viewer = new bmgl.Viewer("container", {
mapId: "bigemap.dc-map",
infoBox: false,
});
if (bmgl.FeatureDetection.supportsImageRenderingPixelated()) {
viewer.resolutionScale = window.devicePixelRatio;
}
//開啟抗鋸齒,讓圖像更加順滑
viewer.scene.postProcessStages.fxaa.enabled = true;
//不啟用地形遮擋
viewer.scene.globe.depthTestAgainstTerrain = false;
var tilesets = new bmgl.BM3DTileset({ url: "/offline_data/newjunbiao/zh/tileset.json" });
tilesets.readyPromise
.then(function (tileset) {
viewer.scene.primitives.add(tileset);
var default_HeadingPitchRange = new bmgl.HeadingPitchRange(
0.0,
-0.5,
tileset.boundingSphere.radius * 2.0
);
viewer.zoomTo(tileset, default_HeadingPitchRange);
var cartographic = bmgl.Cartographic.fromCartesian(
tileset.boundingSphere.center
);
var delta_lng = 0,
delta_lat = 0;
var surface = bmgl.Cartesian3.fromRadians(
cartographic.longitude + delta_lng,
cartographic.latitude + delta_lat,
0.0
);
var offset = bmgl.Cartesian3.fromRadians(
cartographic.longitude + delta_lng,
cartographic.latitude + delta_lat,
0.0
);
var translation = bmgl.Cartesian3.subtract(
offset,
surface,
new bmgl.Cartesian3()
);
tileset.modelMatrix = bmgl.Matrix4.fromTranslation(translation);
addColor(tileset)
})
.otherwise(function (error) {
console.log(error);
});
modifyMap(viewer);
function addColor(tiles3d) {
// 添加一個(gè)事件監(jiān)聽器,監(jiān)聽瓦片是否可見(即被加載進(jìn)來)。
tiles3d.tileVisible.addEventListener(function (tile) {
// 獲取瓦片內(nèi)容。
const cesium3DTileCon = tile.content;
// 獲取瓦片內(nèi)部的特征(features)數(shù)量。
const featuresLength = cesium3DTileCon.featuresLength;
// 循環(huán)遍歷所有的特征。
for (let i = 0; i < featuresLength; i++) {
// 獲取單個(gè)特征(例如,一個(gè)建筑)并訪問其模型內(nèi)容。
const model =
cesium3DTileCon.getFeature(i).content._model;
// 修改該模型的片元著色器。
const fragmentShaderSource =
(model._rendererResources.sourceShaders[1] = `
varying vec3 v_positionEC;
void main()
{
czm_materialInput materialInput;
// 轉(zhuǎn)換模型的位置信息到視圖坐標(biāo)。
vec4 position = czm_inverseModelView * vec4(v_positionEC, 1.0);
// 根據(jù)高度設(shè)置漸變顏色。
// float strength = position.z/200.0;
float strength = position.z/30.0;
// gl_FragColor = vec4(strength,0.3*strength,strength, 1.0);
gl_FragColor = vec4(strength*0.3,0.4*strength,strength*0.8,0.8);
// gl_FragColor = vec4(0.0, 0.3 * 0.4, 0.8*0.6, 0.8);
}
`);
// 片元著色器已被修改,設(shè)置標(biāo)志以便重新生成著色器。
model._shouldRegenerateShaders = true;
}
});
}
</script>
</body>
</html>