import * as mars3d from "mars3d" export let map // mars3d.Map三维地图对象 // 需要覆盖config.json中地图属性参数(当前示例框架中自动处理合并) export const mapOptions = { scene: { center: { lat: 31.215956, lng: 121.508605, alt: 887, heading: 5, pitch: -26 } }, layers: [ { type: "3dtiles", name: "上海市建筑物", url: "//data.mars3d.cn/3dtiles/jzw-shanghai/tileset.json", maximumScreenSpaceError: 1, maximumMemoryUsage: 1024, style: { color: "rgb(0, 99, 255)" }, marsJzwStyle: true, popup: [ { field: "objectid", name: "编号" }, { field: "name", name: "名称" }, { field: "height", name: "楼高", unit: "米" } ], show: true }, { type: "geojson", name: "市区一级道路", url: "//data.mars3d.cn/file/geojson/shanghai-road.json", symbol: { styleOptions: { width: 2.0, material: mars3d.MaterialUtil.createMaterial(mars3d.MaterialType.ODLine, { bgColor: new Cesium.Color(0.1, 0.7, 0.5, 0.4), color: new Cesium.Color(Math.random() * 0.5 + 0.5, Math.random() * 0.8 + 0.2, 0.0, 1.0), speed: 20 + 1.0 * Math.random(), startTime: Math.random() }) } }, popup: "{Name}", show: true } ] } /** * 初始化地图业务,生命周期钩子函数(必须) * 框架在地图初始化完成后自动调用该函数 * @param {mars3d.Map} mapInstance 地图对象 * @returns {void} 无 */ export function onMounted(mapInstance) { map = mapInstance // 记录map map.basemap = 2017 // 切换到蓝色底图 // 3d模型裁剪 const tilesetPlanClip = new mars3d.thing.TilesetPlanClip({ layer: map.getLayer("上海市建筑物", "name"), clipOutSide: true, positions: [ [121.477666, 31.217061, 19.1], [121.531567, 31.217061, 19.1], [121.531567, 31.258551, 19.1], [121.477666, 31.258551, 19.1] ] }) map.addThing(tilesetPlanClip) // 特效 const bloomEffect = new mars3d.effect.BloomEffect({ enabled: true }) map.addEffect(bloomEffect) // // 围绕旋转 // const rotatePoint = new mars3d.thing.RotatePoint({ // direction: true, // 方向 true逆时针,false顺时针 // time: 50 // 给定飞行一周所需时间(单位 秒),控制速度 // }) // map.addThing(rotatePoint) // 添加矢量数据 addCityGraphics() } /** * 释放当前地图业务的生命周期函数 * @returns {void} 无 */ export function onUnmounted() { map = null } function addCityGraphics() { // 创建Graphic图层 const graphicLayer = new mars3d.layer.GraphicLayer() map.addLayer(graphicLayer) // 模型的中心点 const position = [121.510608, 31.234322, 0] // 用于围绕旋转 + 中心点扩散 + 旋转的图片 const center = Cesium.Cartesian3.fromDegrees(position[0], position[1], 140) // 用于div标注和远眺的线 // 中心扩散点 const circleDiffuseWallGlow = new mars3d.graphic.DiffuseWall({ name: "中心扩散点", position: position, style: { diffHeight: 500, // 高度 radius: 150, // 半径 color: "#7ffeff", speed: 6 // 速度 } }) graphicLayer.addGraphic(circleDiffuseWallGlow) // 旋转的图片 -- 中心围墙 const WallImagePositions = mars3d.PolyUtil.getEllipseOuterPositions({ position: position, radius: 50, // 半径 count: 50 // 共返回(count*4)个点 }) const rotatWallImage = new mars3d.graphic.WallPrimitive({ positions: WallImagePositions, style: { diffHeight: 190, closure: true, material: mars3d.MaterialUtil.createMaterial(mars3d.MaterialType.RectSlide, { image: "img/tietu/circular.png", speed: 2 }) } }) graphicLayer.addGraphic(rotatWallImage) // 旋转的图片 -- 底部 let rotation = Cesium.Math.toRadians(50) function getRotationValue() { rotation -= 0.007 return rotation } const rotatCicleImage = new mars3d.graphic.CircleEntity({ position: position, style: { radius: 500, height: 50, material: mars3d.MaterialUtil.createMaterialProperty(mars3d.MaterialType.Image2, { image: "/img/textures/circle-two.png" }), rotation: new Cesium.CallbackProperty(getRotationValue, false), stRotation: new Cesium.CallbackProperty(getRotationValue, false) } }) graphicLayer.addGraphic(rotatCicleImage) // gltf的方式:四面体 // const graphic = new mars3d.graphic.ModelEntity({ // name: "四面体", // position: [position[0], position[1], 180], // style: { // url: "//data.mars3d.cn/gltf/mars/zhui.glb", // scale: 30 // } // }) // graphicLayer.addGraphic(graphic) // 开始 自旋转效果 // graphic.rotateStart({ // direction: true, // 控制方向, true逆时针,false顺时针 // time: 6 // time:给定飞行一周所需时间(单位 秒),控制速度 // }) // 四面体 const tetrahedron = new mars3d.graphic.Tetrahedron({ position: [position[0], position[1], 180], style: { width: 20, height: 30, color: "rgba(200,200,0,0.7)", moveHeight: 50 } }) graphicLayer.addGraphic(tetrahedron) // divgraphic标注 const divgraphic = new mars3d.graphic.DivGraphic({ position: center, style: { html: `