CesiumJS
-
CesiumJS API:https://cesium.com/learn/cesiumjs/ref-doc/index.html
-
CesiumJS 是一个开源的 JavaScript 库,它用于在网页中创建和控制 3D 地球仪(地图)
一、添加图片图层异常
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>ImageryProvider - 添加图片图层异常</title>
<link rel="stylesheet" href="../js/Cesium-1.112/Build/Cesium/Widgets/widgets.css" />
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
}
.container {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id="container"></div>
</body>
<script src="../js/Cesium-1.112/Build/Cesium/Cesium.js"></script>
<script>
const viewer = new Cesium.Viewer("container");
const test1 = () => {
const imageryProvider = new Cesium.SingleTileImageryProvider({
url: "",
});
const imageryLayer = viewer.imageryLayers.addImageryProvider(imageryProvider);
// 异常
// An error occurred in "tT": Failed to load image : The source image could not be decoded.
// An error occurred in "tT": Failed to obtain image tile X: 0 Y: 0 Level: 0.
};
const test2 = () => {
const imageryProvider = new Cesium.SingleTileImageryProvider({
url: null,
});
const imageryLayer = viewer.imageryLayers.addImageryProvider(imageryProvider);
// 异常
// An error occurred in "tT": Failed to obtain image tile X: 0 Y: 0 Level: 0.
};
test2();
</script>
</html>
二、添加标记
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Billboard - 添加标记</title>
<link rel="stylesheet" href="../js/Cesium-1.112/Build/Cesium/Widgets/widgets.css" />
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
}
.container {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id="container"></div>
</body>
<script src="../js/Cesium-1.112/Build/Cesium/Cesium.js"></script>
<script>
const viewer = new Cesium.Viewer("container");
const billboards = viewer.scene.primitives.add(new Cesium.BillboardCollection());
const billboard = billboards.add({
image: "../img/marker-icon.png",
position: Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883),
});
const entity = viewer.entities.add({
position: Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883),
point: {
pixelSize: 5,
color: new Cesium.Color(0, 1, 0, 1),
},
});
</script>
</html>
三、添加标记并指定大小
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Billboard - 添加标记并指定大小</title>
<link rel="stylesheet" href="../js/Cesium-1.112/Build/Cesium/Widgets/widgets.css" />
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
}
.container {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id="container"></div>
</body>
<script src="../js/Cesium-1.112/Build/Cesium/Cesium.js"></script>
<script>
const viewer = new Cesium.Viewer("container");
const billboards = viewer.scene.primitives.add(new Cesium.BillboardCollection());
const billboard = billboards.add({
image: "../img/marker-icon.png",
position: Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883),
width: 100.0,
height: 100.0,
});
const entity = viewer.entities.add({
position:Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883),
point: {
pixelSize: 5,
color: new Cesium.Color(0, 1, 0, 1),
},
});
</script>
</html>
四、添加标记并指定原点
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Billboard - 添加标记并指定原点</title>
<link rel="stylesheet" href="../js/Cesium-1.112/Build/Cesium/Widgets/widgets.css" />
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
}
.container {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id="container"></div>
</body>
<script src="../js/Cesium-1.112/Build/Cesium/Cesium.js"></script>
<script>
const viewer = new Cesium.Viewer("container");
const billboards = viewer.scene.primitives.add(new Cesium.BillboardCollection());
const billboard = billboards.add({
image: "../img/marker-icon.png",
position: Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883),
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
});
const entity = viewer.entities.add({
position: Cesium.Cartesian3.fromDegrees(-75.59777, 40.03883),
point: {
pixelSize: 5,
color: new Cesium.Color(0, 1, 0, 1),
},
});
</script>
</html>
标签:const,标记,viewer,100%,指定,add,添加,Cesium,new
From: https://blog.csdn.net/weixin_52173250/article/details/143325702