"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _store = _interopRequireDefault(require("../../store")); var _mapServer = _interopRequireDefault(require("./map/mapServer")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } var mapSetFunc = { layerList: [], place: null, init: function init(res) { this.removeAll(); this.place = res.place; switch (res.func) { case "poiMap": this.creatPoiMap(res); break; case "aroundPoi": this.creatAroundPoi(res); break; case "queryRelationship": this.creatQueryRelationship(res); break; case "queryMeta": this.creatQueryMeta(res); break; } }, creatQueryMeta: function creatQueryMeta(res) { var ids = res.ids; var colors = []; for (var i in ids) { colors.push({ name: ids[i].name, color: this.getRandomColor(), ids: ids[i].ids }); } _store["default"].state.setListColor = colors; _store["default"].state.showLenged = true; this.setModelChangeColor(colors); }, setModelChangeColor: function setModelChangeColor(res) { var modelLayer = _mapServer["default"].listData.filter(function (res) { if (res.name == config.modelLayer) { return res; } }); if (modelLayer.length <= 0) return; modelLayer[0].layer.style = new Cesium.Cesium3DTileStyle({ color: { evaluateColor: function evaluateColor(feature) { var id = feature.getProperty("id"); var color = res.filter(function (item) { if (item.ids.indexOf(id) > -1) { return item; } }); if (color.length > 0) { return new SmartEarth.Cesium.Color.fromCssColorString(color[0].color); } } } }); }, getRandomColor: function getRandomColor() { var letters = "0123456789ABCDEF"; var color = "#"; for (var i = 0; i < 6; i++) { color += letters[Math.floor(Math.random() * 16)]; } return color; }, creatQueryRelationship: function creatQueryRelationship(res) { if (!res.data) return; var center = res.data.center; var centerPoint = { lon: center._x, lat: center._y }; var items = res.data.positions; var groupByName = items.reduce(function (acc, item) { acc[item.targettype] = acc[item.targettype] || []; acc[item.targettype].push(item); return acc; }, {}); var colors = []; for (var key in groupByName) { var color = this.getRandomColor(); colors.push({ name: key, color: color }); this.setShowPathLine(groupByName[key], color, res.func, centerPoint); } this.setShowTextPoint(center); // store.state.setListColor = colors; // store.state.showLenged = true; }, setShowTextPoint: function setShowTextPoint(res) { var alt = res.height ? res.height + 10 : 100; var richTextPoint = earthCtrl.factory.createRichTextPoint(res.name_1, [res._x, res._y, alt], { fontColor: "#ffff00", fontSize: 18 }, "0"); var position = SmartEarth.Cesium.Cartesian3.fromDegrees(res._x, res._y, 10000); Viewer.camera.setView({ destination: position, // 目的地位置 orientation: { heading: Cesium.Math.toRadians(0.0), // 方向,以弧度为单位 pitch: Cesium.Math.toRadians(-90.0), // 倾斜角,以弧度为单位 roll: 0.0 // 滚动角,以弧度为单位 } }); this.layerList.push({ path: richTextPoint, func: "TextPoint" }); }, setShowPathLine: function setShowPathLine(positions, color, func, centerPoint) { var cities = []; for (var i = 0; i < positions.length; i++) { var item = { lon: positions[i]._x, lat: positions[i]._y }; if (item.lon != centerPoint.lon && item.lat != centerPoint.lat) cities.push(item); } var pathOption = { width: 3, //线宽(可选) color: color, //线颜色(可选), LightSpot: true, //是否使用光点效果(可选) LightSpotColor: "#ffffff", //光点颜色(可选) height: 200 }; var path = earthCtrl.factory.createTrailLinePath(centerPoint, cities, pathOption); this.layerList.push({ path: path, func: func }); }, containsObject: function containsObject(arr, obj) { return arr.some(function (element) { return element.lon === obj.lon && element.lat === obj.lat; // 假设对象有一个名为'id'的属性 }); }, creatPoiMap: function creatPoiMap(res) { var _this = this; var poi = res.data; // const label = earthCtrl.factory.createLabel({ // lon: poi._x, // lat: poi._y, // text: this.getName(poi), // alt: 150, // image: SmartEarthRootUrl + "Workers/image/fighter.png", // // 文本偏移量 // pixelOffset: new SmartEarth.Cesium.Cartesian2(0, -50), // // 图片偏移量 // iPixelOffset: new SmartEarth.Cesium.Cartesian2(0, -20) // }); var label = earthCtrl.factory.createLabel({ name: "创建文本", id: earthCtrl.factory.createUUID(), text: this.getName(poi), font: "22pt monospace", outlineWidth: 2, fillColor: SmartEarth.Cesium.Color.YELLOW, lon: poi._x, lat: poi._y, alt: poi.height ? poi.height + 10 : 100, iDistanceDisplayCondition: (100, 3000) }); setTimeout(function () { _this.setEntityTitlesChangeColor(poi.seid); }, 200); earthCtrl.userScene.flyTo(label); this.layerList.push({ layer: label, func: res.func }); }, setEntityTitlesChangeColor: function setEntityTitlesChangeColor(res) { var modelLayer = _mapServer["default"].listData.filter(function (res) { if (res.name == config.modelLayer) { return res; } }); if (modelLayer.length <= 0) return; // for(var i in Viewer.scene.primitives._primitives){ // console.log(Viewer.scene.primitives._primitives[i].name); // } // debugger // modelLayer[0].layer.style = new Cesium.Cesium3DTileStyle({ // color: { // conditions: [ // ['${id} === "'+res+'"', 'rgba(255, 0, 0, 1)'], // 当id匹配时变为红色 // ['true', 'rgba(0, 0, 0, 1)'] // 其他情况为蓝色 // ] // } // }); modelLayer[0].layer.style = new Cesium.Cesium3DTileStyle({ color: { evaluateColor: function evaluateColor(feature) { var id = feature.getProperty("id"); if (id.toString() == res) { return new SmartEarth.Cesium.Color.fromCssColorString("#FF8C00"); } } } }); }, getName: function getName(res) { var name = ""; if (res.entityname && res.entityname.indexOf(this.place) > -1) { name = res.entityname; } if (!name) { if (res.entityname) { name = res.entityname; } } return name; }, creatAroundPoi: function creatAroundPoi(res) { var _this2 = this; var poi = res.data; var std = []; var feature = { type: "FeatureCollection", features: [] }; var ids = []; for (var i in poi) { ids.push(poi[i].seid); var attri = poi[i].height ? poi[i].height + 10 : 100; std.push({ type: "Feature", geometry: { type: "Point", coordinates: [poi[i]._x, poi[i]._y, attri] }, properties: { name: this.getName(poi[i]) } }); } feature.features = std; var geoJsonDataSource = new SmartEarth.Cesium.GeoJsonDataSource(); // 加载GeoJSON数据 geoJsonDataSource.load(feature).then(function (dataSource) { _this2.layerList.push({ layer: dataSource, func: res.func }); Viewer.dataSources.add(dataSource); var entities = dataSource.entities.values; // 遍历所有GeoJSON中的点 for (var i = 0; i < entities.length; i++) { var entity = entities[i]; if (entity.billboard) { entity.billboard.show = false; } // // 设置点的图片(billboard) // entity.billboard = { // image: SmartEarthRootUrl + "Workers/image/mark.png", // 使用properties中的iconUrl作为图片路径 // width: 16, // height: 22, // // 文本偏移量 // pixelOffset: new SmartEarth.Cesium.Cartesian2(0, -20), // // 图片偏移量 // iPixelOffset: new SmartEarth.Cesium.Cartesian2(0, -20) // }; entity.label = new SmartEarth.Cesium.LabelGraphics({ text: entity.properties.name, // 使用properties中的name作为文本内容 font: "10pt monospace", fillColor: new SmartEarth.Cesium.Color.fromCssColorString("#FFFF00"), outlineColor: SmartEarth.Cesium.Color.BLACK, outlineWidth: 2, pixelOffset: new SmartEarth.Cesium.Cartesian2(0, -50), style: SmartEarth.Cesium.LabelStyle.FILL_AND_OUTLINE }); } // Viewer.zoomTo(dataSource); earthCtrl.userScene.flyTo(dataSource); }); var modelLayer = _mapServer["default"].listData.filter(function (res) { if (res.name == config.modelLayer) { return res; } }); if (modelLayer.length <= 0) return; modelLayer[0].layer.style = new Cesium.Cesium3DTileStyle({ color: { evaluateColor: function evaluateColor(feature) { var id = feature.getProperty("id"); if (ids.indexOf(id) > -1) { return new SmartEarth.Cesium.Color.fromCssColorString("#FF8C00"); } } } }); }, removeAll: function removeAll() { _store["default"].state.setListColor = []; _store["default"].state.showLenged = false; var modelLayer = _mapServer["default"].listData.filter(function (res) { if (res.name == config.modelLayer) { return res; } }); if (modelLayer.length > 0) { modelLayer[0].layer.style = new Cesium.Cesium3DTileStyle({ color: { evaluateColor: function evaluateColor(feature) { return new SmartEarth.Cesium.Color.fromCssColorString("#FFFFFF"); } } }); } for (var i = 0; i < this.layerList.length; i++) { var obj = this.layerList[i]; if (obj.func == "poiMap") { this.layerList[i].layer.removeFromMap(); this.layerList.splice(i, 1); i--; } else if (obj.func == "aroundPoi") { Viewer.dataSources.removeAll(); this.layerList.splice(i, 1); i--; } else if (obj.func == "queryRelationship") { this.layerList[i].path.deleteObject(); this.layerList.splice(i, 1); i--; } else if (obj.func == "TextPoint") { this.layerList[i].path.deleteObject(); this.layerList.splice(i, 1); i--; } } } }; var _default = mapSetFunc; exports["default"] = _default;