This commit is contained in:
shijing 2024-03-11 16:32:01 +08:00
parent c50cd6656d
commit e19b401ae5
1 changed files with 134 additions and 140 deletions

View File

@ -6,7 +6,7 @@
<script> <script>
// import * as mars3d from "mars3d"; // import * as mars3d from "mars3d";
const Cesium = mars3d.Cesium; const Cesium = mars3d.Cesium;
const point1 = [116.027404,36.414659,42] const point1 = [117.083458,31.655321,42]
const point2 = [116.027392, 36.413562, 42] const point2 = [116.027392, 36.413562, 42]
const point3 = mars3d.PointUtil.getOnLinePointByLen( const point3 = mars3d.PointUtil.getOnLinePointByLen(
mars3d.LngLatPoint.toCartesian(point1), mars3d.LngLatPoint.toCartesian(point1),
@ -21,90 +21,49 @@ export default {
} }
}, },
created() { created() {
// const scriptInfo = document.createElement("script"); const scriptInfo = document.createElement("script");
// scriptInfo.setAttribute("data-callType", "callScript"); scriptInfo.setAttribute("data-callType", "callScript");
// scriptInfo.src = "http://mars3d.cn/lib/Cesium/Cesium.js"; scriptInfo.src = "http://mars3d.cn/lib/Cesium/Cesium.js";
// document.head.appendChild(scriptInfo); document.head.appendChild(scriptInfo);
}, },
mounted() { mounted() {
var mapOptions = {
basemaps: [{ name: "天地图", type: "tdt", layer: "img_d", show: true }],
};
// var map = new mars3d.Map("mars3dContainer", mapOptions); //APIhttp://mars3d.cn/api/Map.html
const map = new mars3d.Map("mars3dContainer", { const map = new mars3d.Map("mars3dContainer", {
scene: { scene: {
center: { lat: 30.054604, lng: 108.885436, alt: 17036414, heading: 0, pitch: -90 }, center: { lat: 30.054604, lng: 108.885436, alt: 100, heading: 316, pitch: 10},
showSun: true,
showMoon: true,
showSkyBox: true,
showSkyAtmosphere: false, // map.scene.skyAtmosphere = false
fog: true,
fxaa: true,
globe: {
depthTestAgainstTerrain: false,
baseColor: "#546a53"
}, },
cameraController: {
zoomFactor: 3.0,
minimumZoomDistance: 1,
maximumZoomDistance: 50000000,
enableRotate: true,
enableZoom: true
},
mapProjection: mars3d.CRS.EPSG3857, // 2D
mapMode2D: Cesium.MapMode2D.INFINITE_SCROLL// 2D
},
control: {
baseLayerPicker: true, // basemaps
homeButton: true, //
sceneModePicker: true, //
navigationHelpButton: true, //
fullscreenButton: true, //
contextmenu: { hasDefault: true } //
},
terrain: {
url: "//data.mars3d.cn/terrain",
show: true
},
basemaps: [
{
name: "天地图影像",
// icon: "img/basemaps/tdt_img.png",
type: "tdt",
layer: "img_d",
show: true
}
]
}) })
map.fixedLight = true // gltf
let tilesetLayer = new mars3d.layer.TilesetLayer({ let tilesetLayer = new mars3d.layer.TilesetLayer({
name:'', type: "3dtiles",
name:'超低排放',
url: "/3dtiles/tileset.json", url: "/3dtiles/tileset.json",
popup: "all", popup: "all",
scale: 1,
// rotation: {x:0, y:1,z: 0 }, // Z沿Z45
highlight: { type: "click", color: "#00ffff" },
flyTo: true, // flyTo: true, //
heading: 0, // Z
pitch: -5, //
roll: 10 // Y
}); });
map.addLayer(tilesetLayer); map.addLayer(tilesetLayer);
tilesetLayer.readyPromise.then(() => { map.on(mars3d.EventType.click, function (event) {
// let feature = event.pickedObject;
console.log("模型加载完成", tilesetLayer) //event.graphic.attr
console.log("feature", feature);
localforage.setItem(storageName, url) // console.log("Cesium.Cesium3DTileFeature", Cesium.Cesium3DTileFeature);
eventTarget.fire("tilesetLayerLoad", { layer: tilesetLayer }) console.log(feature instanceof Cesium.Cesium3DTileFeature)
if (feature instanceof Cesium.Cesium3DTileFeature) {
// let propertyNames = feature.getPropertyNames();
// let length = propertyNames.length;
// for (var i = 0; i < length; ++i) {
// let propertyName = propertyNames[i];
// console.log(propertyName + ': ' + feature.getProperty(propertyName));
// }
}
}) })
.catch((e) => { //
// let GraphicLayer = new mars3d.layer.GraphicLayer({
console.log("模型加载失败", e)
})
//
tilesetLayer.on(mars3d.EventType.updatePosition, function (event) {
eventTarget.fire("changePoition", {
center: tilesetLayer.center,
rotation: tilesetLayer.rotation
})
})
//
let layerWall = new mars3d.layer.GraphicLayer({
name: "墙", name: "墙",
show: true, show: true,
// //
@ -116,12 +75,12 @@ export default {
// //
style: { style: {
// //
distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0, 20000), distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0, 200000),
// //
}, },
semicolon: true semicolon: true
}) })
map.addLayer(GraphicLayer);
// //
let wallGraphic = new mars3d.graphic.WallEntity({ let wallGraphic = new mars3d.graphic.WallEntity({
positions: [point1, point2], positions: [point1, point2],
@ -142,37 +101,72 @@ export default {
flyTo:true, flyTo:true,
attr: { remark: "test" } attr: { remark: "test" }
}) })
GraphicLayer.addGraphic(wallGraphic);
// [idattridid]
// graphic const graphic = new mars3d.graphic.FontBillboardEntity({
var graphic = new mars3d.graphic.BoxEntity({ position: new mars3d.LngLatPoint(117.084699, 31.65172, 6),
position: new mars3d.LngLatPoint(30.054604, 108.885436, 1),
style: { style: {
dimensions: new Cesium.Cartesian3(2000.0, 2000.0, 2000.0), image: "img/enp_blue/ball.png",
fill: true, color: "#00ffff",
color: "#00ff00", cale: 0.5,
opacity: 0.9,
label: {
text: "graphic绑定的演示",
font_size: 25,
font_family: "楷体",
color: "#003da6",
outline: true,
outlineColor: "#bfbfbf",
outlineWidth: 2,
horizontalOrigin: Cesium.HorizontalOrigin.CENTER, horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
verticalOrigin: Cesium.VerticalOrigin.BOTTOM verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
}, label: {
semicolon: true text: "设备名称",
font_size: 20,
color: "#ff0000",
pixelOffsetY: -120,
distanceDisplayCondition: true,
distanceDisplayCondition_far: 50000,
distanceDisplayCondition_near: 0
} }
},
attr: { remark: "设备id" }
}) })
map.graphicLayer.addGraphic(graphic) // Popup
// const inthtml = `<table style="width: auto;">
layerWall.addGraphic(wallGraphic) // <tr>
map.addLayer(layerWall) // <th scope="col" colspan="2" style="text-align:center;font-size:15px;">graphicPopup </th>
}, // </tr>
// <tr>
// <td></td>
// <td>html</td>
// </tr>
// </table>`
// graphic.bindPopup(inthtml).openPopup()
GraphicLayer.addGraphic(graphic);
// GraphicLayer.on(mars3d.EventType.click, function (event) {
// console.log("layer", event)
// })
function bindLayerPopup() {
GraphicLayer.bindPopup(function (event) {
console.log("监听layer绑定popup", event)
const attr = event.graphic.attr || {}
attr["类型"] = event.graphic.type
attr["来源"] = "我是layer上绑定的Popup"
attr["备注"] = "我支持鼠标交互"
return mars3d.Util.getTemplateHtml({ title: "矢量图层", template: "all", attr })
})
}
bindLayerPopup();
// const graphic2 = new mars3d.graphic.BillboardEntity({
// position: [117.084699, 31.65172, 6],
// style: {
// image: "img/enp_blue/ball.png",
// scale: 1.0,
// horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
// verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
// clampToGround: true
// },
// attr: { remark: "1" }
// })
// GraphicLayer.addGraphic(graphic2);
},
mothods: { mothods: {
},
onUnload() {
map.destroy()
} }
} }
</script> </script>