You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
3.1 KiB
HTML
86 lines
3.1 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="ch">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Title</title>
|
|
<link rel="stylesheet" href="/Cesium/Widgets/widgets.css">
|
|
<style>
|
|
#map3d{
|
|
width: 100%;
|
|
height: 100%;
|
|
margin: 0;
|
|
padding: 0;
|
|
overflow: hidden;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div id="map3d"></div>
|
|
</body>
|
|
<script src="/Cesium/Cesium.js"></script>
|
|
<script>
|
|
viewer = new Cesium.Viewer('map3d', {
|
|
selectionIndicator: false,
|
|
animation: false,
|
|
baseLayerPicker: false,
|
|
timeline: false,
|
|
sceneModePicker: false,
|
|
navigationHelpButton: false,
|
|
useDefaultRenderLoop: true,
|
|
showRenderLoopErrors: false,
|
|
fullscreenButton: false,
|
|
infoBox: false,
|
|
});
|
|
viewer._cesiumWidget._creditContainer.style.display = "none";
|
|
viewer.camera.setView({
|
|
destination:Cesium.Cartesian3.fromDegrees(116.46,39.92,10000000.0),
|
|
}); // 设置初始位置
|
|
let handler = new Cesium.ScreenSpaceEventHandler(viewer.canvas);
|
|
handler.setInputAction(function(event) {
|
|
var earthPosition = viewer.camera.pickEllipsoid(event.position,viewer.scene.globe.ellipsoid);
|
|
if (Cesium.defined(earthPosition)) {
|
|
let ellipsoid = viewer.scene.globe.ellipsoid;
|
|
let cartographic = ellipsoid.cartesianToCartographic(earthPosition);
|
|
let lat = Cesium.Math.toDegrees(cartographic.latitude);
|
|
let lon = Cesium.Math.toDegrees(cartographic.longitude);
|
|
let params = {
|
|
id:'测试'+lon,
|
|
name:'text',
|
|
lon:lon,
|
|
lat:lat
|
|
};
|
|
alert = AddPoint(params);
|
|
}
|
|
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
|
|
</script>
|
|
<script>
|
|
let AddPoint = function (params) {
|
|
if(params.lon === undefined || params.lat === undefined){
|
|
alert('请提供经纬度!');
|
|
return;
|
|
}
|
|
// alert(params.lon+','+params.lat);
|
|
console.log(params.lon,params.lat);
|
|
let entity = new Cesium.Entity({
|
|
id: params.id || `${params.lon}点`,
|
|
name:params.name || '点',
|
|
show:true,
|
|
position:Cesium.Cartesian3.fromDegrees(params.lon, params.lat),
|
|
point:new Cesium.PointGraphics ( {
|
|
show : true,
|
|
pixelSize : params.pixelSize || 5,
|
|
heightReference : params.pixelSize || Cesium.HeightReference.NONE,
|
|
color : params.color || new Cesium.Color ( 255 , 255 , 0 , 1 ),
|
|
outlineColor : params.color || new Cesium.Color ( 0 , 0 , 0 , 0 ),
|
|
outlineWidth : params.outlineWidth || 0,
|
|
scaleByDistance : params.scaleByDistance || new Cesium.NearFarScalar ( 0 , 1 , 5e10 , 1 ),
|
|
translucencyByDistance : params.translucencyByDistance || new Cesium.NearFarScalar ( 0 , 1 , 5e10 , 1 ),
|
|
distanceDisplayCondition : params.translucencyByDistance || new Cesium.DistanceDisplayCondition(0, 4.8e10),
|
|
} )
|
|
});
|
|
viewer.entities.add(entity);
|
|
return entity;
|
|
}
|
|
</script>
|
|
</html>
|