|
@@ -1,253 +0,0 @@
|
|
|
-import config from "@/api/config.js";
|
|
|
-
|
|
|
-//引入cesium基础库
|
|
|
-import "mars3d-cesium/Build/Cesium/Widgets/widgets.css";
|
|
|
-import * as Cesium from "mars3d-cesium";
|
|
|
-
|
|
|
-//导入mars3d主库
|
|
|
-import "mars3d/mars3d.css"; //v3.8.6及之前版本使用 import "mars3d/dist/mars3d.css";
|
|
|
-import * as mars3d from "mars3d";
|
|
|
-import "mars3d-tdt";
|
|
|
-import { LayerType } from "mars3d";
|
|
|
-import router from "@/router";
|
|
|
-
|
|
|
-/**
|
|
|
- * @description
|
|
|
- */
|
|
|
-class GardenMap {
|
|
|
- constructor() {
|
|
|
- }
|
|
|
- //初始化地图
|
|
|
- initMap(coord, targetId) {
|
|
|
- mars3d.Token.updateAll({ tianditu: 'e95115c454a663cd052d96019fd83840' })
|
|
|
- // lat纬度,lng经度,alt高度,heading方向角度值,pitch俯仰角度值
|
|
|
- let mapOptions = {
|
|
|
- scene: {
|
|
|
- center: { lat: coord[1], lng: coord[0], alt: 500, heading: 150, pitch: -46 },
|
|
|
- showSun: true,
|
|
|
- showMoon: false,
|
|
|
- showSkyBox: false,
|
|
|
- scene3DOnly: true,
|
|
|
- skyBox: {
|
|
|
- type: "ground",
|
|
|
- sources: {
|
|
|
- positiveX: "//data.mars3d.cn/img/skybox-near/lantian/Right.jpg",
|
|
|
- negativeX: "//data.mars3d.cn/img/skybox-near/lantian/Left.jpg",
|
|
|
- positiveY: "//data.mars3d.cn/img/skybox-near/lantian/Front.jpg",
|
|
|
- negativeY: "//data.mars3d.cn/img/skybox-near/lantian/Back.jpg",
|
|
|
- positiveZ: "//data.mars3d.cn/img/skybox-near/lantian/Up.jpg",
|
|
|
- negativeZ: "//data.mars3d.cn/img/skybox-near/lantian/Down.jpg"
|
|
|
- }
|
|
|
- },
|
|
|
- backgroundImage: "url(//birdseye-img.sysuimars.com/birdseye-look-mini/home/20250123113804.png)",
|
|
|
- backgroundColor: "rgba(0,0,0,0)",
|
|
|
- sceneMode: Cesium.SceneMode.SCENE3D,
|
|
|
- showSkyAtmosphere: false,
|
|
|
- requestRenderMode: true, // 显式渲染
|
|
|
- cameraController: {
|
|
|
- enableRotate: true,
|
|
|
- enableTilt: false,
|
|
|
- enableTranslate: true,
|
|
|
- },
|
|
|
- shadowMap: {
|
|
|
- enabled: false,
|
|
|
- softShadows: true
|
|
|
- },
|
|
|
- fog: false,
|
|
|
- globe: {
|
|
|
- show: true,
|
|
|
- showGroundAtmosphere: false,
|
|
|
- enableLighting: true,
|
|
|
- backgroundImage: "url(//data.mars3d.cn/img/busines/background1.jpg)",
|
|
|
- }
|
|
|
- },
|
|
|
- basemaps: [{ name: "天地图", type: "tdt", layer: "img_d", show: true }],
|
|
|
- // basemaps: [],
|
|
|
- terrain: {
|
|
|
- show: true,
|
|
|
- type: LayerType.tdt
|
|
|
- },
|
|
|
- locationBar: {},
|
|
|
- control: {
|
|
|
- contextmenu: false
|
|
|
- }
|
|
|
-
|
|
|
- };
|
|
|
- let map = new mars3d.Map(targetId, mapOptions); //支持的参数请看API文档:http://mars3d.cn/api/Map.html
|
|
|
- map.fixedLight = true // 固定光照,避免gltf模型随时间存在亮度不一致。
|
|
|
- // 固定光照方向
|
|
|
- map.scene.light = new Cesium.DirectionalLight({
|
|
|
- direction: map.scene.camera.direction
|
|
|
- })
|
|
|
- map.scene.globe.depthTestAgainstTerrain = true
|
|
|
-
|
|
|
- // let xyz = config.base_img_url3 + "map/lby/{z}/{x}/{y}.png";
|
|
|
- // map.addLayer(new mars3d.layer.XyzLayer({ url: xyz }), true);
|
|
|
- this.map = map;
|
|
|
- this.mapNum = 0
|
|
|
- this.graphicLayer = new mars3d.layer.GraphicLayer();
|
|
|
- this.map.addLayer(this.graphicLayer);
|
|
|
-
|
|
|
- // 创建视点,duration参数调节每个步骤时长
|
|
|
- const viewPoints = [
|
|
|
- { lng: coord[0], lat: coord[1], alt: 189910.3, heading: 150, pitch: -26, duration: 0.1 },
|
|
|
- ]
|
|
|
-
|
|
|
- // 视角切换(分步执行)
|
|
|
- let that = this
|
|
|
- this.map.setCameraViewList(viewPoints, {
|
|
|
- // complete: function () {
|
|
|
- // that.map.fire("complateCameraView")
|
|
|
- // }
|
|
|
- })
|
|
|
- // this.addDivGraphic()
|
|
|
- }
|
|
|
-
|
|
|
- addDivGraphic(point) {
|
|
|
- let graphicLayer = new mars3d.layer.GraphicLayer()
|
|
|
- this.map.addLayer(graphicLayer)
|
|
|
-
|
|
|
- const graphic = new mars3d.graphic.DivGraphic({
|
|
|
- position: [point[0], point[1], 86],
|
|
|
- style: {
|
|
|
- html: `<div class="tree-detail">
|
|
|
- <div class="tree-title">
|
|
|
- <div class="name">
|
|
|
- <span class="main-name">桂味</span>
|
|
|
- <div class="mark">高质果率:92%</div>
|
|
|
- <div class="age">树龄:16年</div>
|
|
|
- </div>
|
|
|
- <div class="btn-detail">溯源详情></div>
|
|
|
- </div>
|
|
|
- <div class="tree-content">
|
|
|
- <div class="tree-item">
|
|
|
- <div class="item-value">#AA653</div>
|
|
|
- <div class="item-text">编码</div>
|
|
|
- </div>
|
|
|
- <div class="item-line"></div>
|
|
|
- <div class="tree-item">
|
|
|
- <div class="item-value">200斤</div>
|
|
|
- <div class="item-text">预估产量</div>
|
|
|
- </div>
|
|
|
- <div class="item-line"></div>
|
|
|
- <div class="tree-item">
|
|
|
- <div class="item-value">100斤</div>
|
|
|
- <div class="item-text">剩余产量</div>
|
|
|
- </div>
|
|
|
- <div class="item-line"></div>
|
|
|
- <div class="tree-item">
|
|
|
- <div class="item-value">2025.01.30</div>
|
|
|
- <div class="item-text">编码</div>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- </div>`,
|
|
|
- horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
|
|
|
- verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
|
|
|
- offsetX: 0,
|
|
|
- offsetY: -10,
|
|
|
-
|
|
|
- // 高亮时的样式
|
|
|
- // highlight: {
|
|
|
- // type: mars3d.EventType.click,
|
|
|
- // className: "marsGreenGradientPnl-highlight"
|
|
|
- // }
|
|
|
- },
|
|
|
- attr: { remark: "示例3" }
|
|
|
- })
|
|
|
- graphicLayer.addGraphic(graphic)
|
|
|
-
|
|
|
- // 监听 graphic 的点击事件
|
|
|
- graphic.on(mars3d.EventType.click, (event) => {
|
|
|
- const container = graphic._container; // 获取实际的 DOM 容器
|
|
|
- if (container) {
|
|
|
- const textBg = container.querySelector('.btn-detail'); // 获取子元素
|
|
|
- if (textBg) {
|
|
|
- textBg.addEventListener('click', (event) => {
|
|
|
- event.stopPropagation(); // 阻止事件冒泡
|
|
|
- console.log('push');
|
|
|
- router.push("/garden_detail")
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- // 点击列表高亮点位
|
|
|
- highlightPoint(point) {
|
|
|
- this.graphicLayer.eachGraphic(graphic => {
|
|
|
- if (graphic.attr.id === point.id) {
|
|
|
- graphic.setStyle({ color: "#18E0FF", pixelSize: 15 });
|
|
|
- this.addDivGraphic([point.lng, point.lat])
|
|
|
- // 显示信息窗口
|
|
|
- // map.openPopup("112233", graphic.position);
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- // 平移到该点位
|
|
|
- this.map.flyToPoint([point.lng, point.lat], { duration: 1 });
|
|
|
- }
|
|
|
-
|
|
|
- // 点位
|
|
|
- addGraphicPoint(arr) {
|
|
|
- const pointsData = [
|
|
|
- { lng: 113.6149629, lat: 23.58594117, id: 1, fruitType: 1, age: 1, },
|
|
|
- { lng: 113.6146207, lat: 23.58591316, id: 2, fruitType: 2, age: 2, },
|
|
|
- { lng: 113.6147351, lat: 23.586311962, id: 3, fruitType: 1, age: 2, },
|
|
|
- { lng: 113.6144588, lat: 23.58577547, id: 4, fruitType: 3, age: 3, },
|
|
|
- { lng: 113.6139674, lat: 23.58594271, id: 5, fruitType: 0, age: 1, },
|
|
|
- ];
|
|
|
- pointsData.forEach((item, index) => {
|
|
|
- const graphic = new mars3d.graphic.PointEntity({
|
|
|
- position: [item.lng, item.lat, 75],
|
|
|
- style: {
|
|
|
- color: "rgba(255, 255, 255, 0.8)",
|
|
|
- pixelSize: 12,
|
|
|
- outlineColor: "#ffffff",
|
|
|
- outlineWidth: 2,
|
|
|
- scaleByDistance: new Cesium.NearFarScalar(10000, 1.0, 30000, 0.1)
|
|
|
- },
|
|
|
- attr: { id: item.id, itemIndex: index }
|
|
|
- })
|
|
|
- // graphic转geojson
|
|
|
- // const geojson = graphic.toGeoJSON()
|
|
|
- // console.log("转换后的geojson", geojson)
|
|
|
- this.graphicLayer.addGraphic(graphic)
|
|
|
-
|
|
|
- })
|
|
|
- // for(let item in pointsData){
|
|
|
- // const graphic = new mars3d.graphic.PointEntity({
|
|
|
- // position: [item.lng, item.lat, 75],
|
|
|
- // style: {
|
|
|
- // color: "#3BC250",
|
|
|
- // pixelSize: 12,
|
|
|
- // outlineColor: "#ffffff",
|
|
|
- // outlineWidth: 2,
|
|
|
- // scaleByDistance: new Cesium.NearFarScalar(10000, 1.0, 30000, 0.1)
|
|
|
- // },
|
|
|
- // attr: { id: item.id, itemIndex: }
|
|
|
- // })
|
|
|
- // this.graphicLayer.addGraphic(graphic)
|
|
|
- // }
|
|
|
-
|
|
|
- // 提取坐标和高度
|
|
|
- let coordinates = [];
|
|
|
- let heights = [];
|
|
|
-
|
|
|
- pointsData.forEach(point => {
|
|
|
- // 使用正则表达式提取WKT中的坐标
|
|
|
- coordinates.push({ lng: point.lng, lat: point.lat });
|
|
|
- // 提取高度
|
|
|
- heights.push(200);
|
|
|
- });
|
|
|
- // 计算边界
|
|
|
- let xmin = Math.min(...coordinates.map(coord => coord.lng));
|
|
|
- let xmax = Math.max(...coordinates.map(coord => coord.lng));
|
|
|
- let ymin = Math.min(...coordinates.map(coord => coord.lat));
|
|
|
- let ymax = Math.max(...coordinates.map(coord => coord.lat));
|
|
|
- let height = heights.reduce((sum, height) => sum + height, 0) / heights.length;
|
|
|
- this.map.flyToExtent({ xmin, ymin, xmax, ymax, height }, { scale: 1, pitch: -26, duration: 1.6 })
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-export default GardenMap;
|