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,158 +21,152 @@ 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 = { const map = new mars3d.Map("mars3dContainer", {
basemaps: [{ name: "天地图", type: "tdt", layer: "img_d", show: true }], scene: {
}; center: { lat: 30.054604, lng: 108.885436, alt: 100, heading: 316, pitch: 10},
// var map = new mars3d.Map("mars3dContainer", mapOptions); //APIhttp://mars3d.cn/api/Map.html },
const map = new mars3d.Map("mars3dContainer", { })
scene: { map.fixedLight = true // gltf
center: { lat: 30.054604, lng: 108.885436, alt: 17036414, heading: 0, pitch: -90 },
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
}
]
})
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) {
.catch((e) => { // let propertyNames = feature.getPropertyNames();
// // let length = propertyNames.length;
console.log("模型加载失败", e) // for (var i = 0; i < length; ++i) {
}) // let propertyName = propertyNames[i];
// console.log(propertyName + ': ' + feature.getProperty(propertyName));
// // }
tilesetLayer.on(mars3d.EventType.updatePosition, function (event) {
eventTarget.fire("changePoition", {
center: tilesetLayer.center,
rotation: tilesetLayer.rotation
})
})
//
let layerWall = new mars3d.layer.GraphicLayer({
name: "墙",
show: true,
//
strokestyle: "#3388ff",
strokewidth: 2,
fill: true,
fillcolor: "#00ffff",
opacity: 0.5,
//
style: {
//
distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0, 20000),
//
},
semicolon: true
})
//
let wallGraphic = new mars3d.graphic.WallEntity({
positions: [point1, point2],
// @param [options.allowDrillPick] - 穿
allowDrillPick: true,
style: {
//
distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0, 20000),
//
diffHeight:15 ,
materialType: mars3d.MaterialType.Text,
materialOptions: {
text: "显示文本",
font_family: "楷体",
color: "#00ffff"
} }
}, })
flyTo:true, //
attr: { remark: "test" } let GraphicLayer = new mars3d.layer.GraphicLayer({
}) name: "墙",
show: true,
//
// graphic strokestyle: "#3388ff",
var graphic = new mars3d.graphic.BoxEntity({ strokewidth: 2,
position: new mars3d.LngLatPoint(30.054604, 108.885436, 1), fill: true,
style: { fillcolor: "#00ffff",
dimensions: new Cesium.Cartesian3(2000.0, 2000.0, 2000.0), opacity: 0.5,
fill: true, //
color: "#00ff00", style: {
opacity: 0.9, //
label: { distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0, 200000),
text: "graphic绑定的演示", //
font_size: 25,
font_family: "楷体",
color: "#003da6",
outline: true,
outlineColor: "#bfbfbf",
outlineWidth: 2,
horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
verticalOrigin: Cesium.VerticalOrigin.BOTTOM
}, },
semicolon: true semicolon: true
})
map.addLayer(GraphicLayer);
//
let wallGraphic = new mars3d.graphic.WallEntity({
positions: [point1, point2],
// @param [options.allowDrillPick] - 穿
allowDrillPick: true,
style: {
//
distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0.0, 20000),
//
diffHeight:15 ,
materialType: mars3d.MaterialType.Text,
materialOptions: {
text: "显示文本",
font_family: "楷体",
color: "#00ffff"
}
},
flyTo:true,
attr: { remark: "test" }
})
GraphicLayer.addGraphic(wallGraphic);
// [idattridid]
const graphic = new mars3d.graphic.FontBillboardEntity({
position: new mars3d.LngLatPoint(117.084699, 31.65172, 6),
style: {
image: "img/enp_blue/ball.png",
color: "#00ffff",
cale: 0.5,
horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
label: {
text: "设备名称",
font_size: 20,
color: "#ff0000",
pixelOffsetY: -120,
distanceDisplayCondition: true,
distanceDisplayCondition_far: 50000,
distanceDisplayCondition_near: 0
}
},
attr: { remark: "设备id" }
})
// Popup
// const inthtml = `<table style="width: auto;">
// <tr>
// <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();
map.graphicLayer.addGraphic(graphic) // const graphic2 = new mars3d.graphic.BillboardEntity({
// position: [117.084699, 31.65172, 6],
layerWall.addGraphic(wallGraphic) // style: {
map.addLayer(layerWall) // 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>