Layers.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <template>
  2. <div class="layer">
  3. <div class="title">重点图层</div>
  4. <div>
  5. <el-row v-for="(item, index) in arr" :key="index">
  6. <el-checkbox v-model="item.added" :label="item.label" @change="addedChange(item)" />
  7. <el-switch
  8. v-model="item.show"
  9. class="ml-2"
  10. style="--el-switch-on-color: #409eff; --el-switch-off-color: #ff4949"
  11. @change="hideChange(item)"
  12. :disabled="!item.added"
  13. />
  14. </el-row>
  15. </div>
  16. <el-dialog
  17. v-if="from != null"
  18. append-to-body
  19. v-model="dialogFormVisible"
  20. title="详细信息"
  21. width="800"
  22. >
  23. <div class="info_container">
  24. <el-form :model="form">
  25. <el-form-item
  26. v-for="(value, key) in from"
  27. :key="key"
  28. :label="key"
  29. :label-width="'120px'"
  30. >{{ value }}</el-form-item>
  31. </el-form>
  32. </div>
  33. <template #footer>
  34. <div class="dialog-footer">
  35. <el-button
  36. @click="
  37. dialogFormVisible = false;
  38. from = null;
  39. "
  40. >关闭</el-button>
  41. </div>
  42. </template>
  43. </el-dialog>
  44. </div>
  45. </template>
  46. <script>
  47. export default {
  48. data() {
  49. let arr = [
  50. {
  51. label: "公立学校",
  52. url: "./static/data/徐泾镇公立学校.geojson",
  53. style: {
  54. point: {
  55. imgUrl: "/static/image/layer/point.png"
  56. }
  57. }
  58. },
  59. {
  60. label: "私立学校",
  61. url: "./static/data/徐泾镇私立学校.geojson",
  62. style: {
  63. point: {
  64. imgUrl: "/static/image/layer/point.png"
  65. }
  66. }
  67. },
  68. {
  69. label: "公立医院",
  70. url: "./static/data/徐泾镇公立医疗.geojson",
  71. style: {
  72. point: {
  73. imgUrl: "/static/image/layer/point.png"
  74. }
  75. }
  76. },
  77. {
  78. label: "私立医院",
  79. url: "./static/data/徐泾镇民营医疗.geojson",
  80. style: {
  81. point: {
  82. imgUrl: "/static/image/layer/point.png"
  83. }
  84. }
  85. },
  86. {
  87. label: "养老机构",
  88. url: "./static/data/徐泾镇养老机构.geojson",
  89. style: {
  90. point: {
  91. imgUrl: "/static/image/layer/point.png"
  92. }
  93. }
  94. }
  95. ];
  96. arr = arr.map(function(item, index) {
  97. item.id = "layer" + index;
  98. item.added = true;
  99. item.show = true;
  100. return item;
  101. });
  102. return {
  103. arr: arr,
  104. from: null,
  105. dialogFormVisible: false
  106. };
  107. },
  108. mounted() {
  109. window.layerQJ = {
  110. geojsonDataSource: {}
  111. };
  112. },
  113. methods: {
  114. addedChange(item) {
  115. console.log(item);
  116. if (item.added) {
  117. // 添加图层
  118. this.addGeoJson(item.url, item.style, item.id);
  119. } else {
  120. item.show = true;
  121. // 移除图层
  122. if (layerQJ.geojsonDataSource[item.id] != null) {
  123. }
  124. viewer.dataSources.remove(layerQJ.geojsonDataSource[item.id]);
  125. layerQJ.geojsonDataSource[item.id] = null;
  126. delete layerQJ.geojsonDataSource[item.id];
  127. }
  128. },
  129. hideChange(item) {
  130. // 控制显隐
  131. if (item.show) {
  132. if (layerQJ.geojsonDataSource[item.id])
  133. layerQJ.geojsonDataSource[item.id].show = true;
  134. } else {
  135. if (layerQJ.geojsonDataSource[item.id])
  136. layerQJ.geojsonDataSource[item.id].show = false;
  137. }
  138. },
  139. openClick() {
  140. let that = this;
  141. if (layerQJ.handler) return;
  142. // 绑定点击事件
  143. layerQJ.handler = new SkyScenery.ScreenSpaceEventHandler(viewer.canvas);
  144. layerQJ.handler.setInputAction(function(movement) {
  145. var pick = viewer.scene.pick(movement.position); // 拾取鼠标所在的entity
  146. if (SkyScenery.defined(pick)) {
  147. let entity = pick.id;
  148. if (!entity) return;
  149. if (entity.type && entity.type == "layers") {
  150. // let properties = entity.properties.getValue();
  151. that.$store.state.showEntity = entity;
  152. // console.log(properties);
  153. // that.from = properties;
  154. // that.dialogFormVisible = true;
  155. // openEntityPropertiesDialog(properties, entity.layerId);
  156. }
  157. }
  158. }, SkyScenery.ScreenSpaceEventType.LEFT_CLICK);
  159. },
  160. // closeClick() {
  161. // if (layerQJ.handler) {
  162. // layerQJ.handler.removeInputAction(
  163. // SkyScenery.ScreenSpaceEventType.LEFT_CLICK
  164. // );
  165. // layerQJ.handler = null;
  166. // }
  167. // this.dialogFormVisible = false;
  168. // this.from = null;
  169. // },
  170. // 加载geojson数据
  171. addGeoJson(url, options, id) {
  172. // options = {
  173. // point: {
  174. // imgUrl: ""
  175. // },
  176. // polyline: {
  177. // color: "#ffffff",
  178. // width: 3,
  179. // alpha: 0.7
  180. // },
  181. // polygon: {
  182. // outerColor: "#ffffff",
  183. // outerWidth: 3,
  184. // innerColor: "#ffffff",
  185. // alpha: 0.7
  186. // }
  187. // };
  188. SkyScenery.GeoJsonDataSource.load(url).then(function(dataSource) {
  189. viewer.dataSources.add(dataSource);
  190. layerQJ.geojsonDataSource[id] = dataSource;
  191. var entities = dataSource.entities.values;
  192. for (var i = 0; i < entities.length; i++) {
  193. var entity = entities[i];
  194. if (entity.billboard) {
  195. entity.billboard = undefined;
  196. entity.billboard = new SkyScenery.BillboardGraphics({
  197. image: options.point.imgUrl,
  198. width: 48,
  199. height: 48,
  200. pixelOffset: new SkyScenery.Cartesian2(0, -25),
  201. heightReference: SkyScenery.HeightReference.CLAMP_TO_GROUND
  202. });
  203. }
  204. if (entity.polyline) {
  205. entity.polyline.width = options.polyline.width;
  206. entity.polyline.material = SkyScenery.Color.fromCssColorString(
  207. options.polyline.color
  208. ).withAlpha(options.polyline.alpha); // 颜色
  209. }
  210. if (entity.polygon) {
  211. // entity.polygon.height = 0.2;
  212. // entity.polygon.outline = true; // 边框是否显示
  213. // entity.polygon.outlineColor = SkyScenery.Color.fromCssColorString(
  214. // options.polygon.outerColor
  215. // ); // 边框颜色
  216. // entity.polygon.outlineWidth = options.polygon.outerWidth; // 边框宽度
  217. // entity.polygon.material = SkyScenery.Color.fromCssColorString(
  218. // options.polygon.innerColor
  219. // ).withAlpha(options.polygon.alpha); // 填充色
  220. entity.polygon.outline = true;
  221. entity.polygon.outlineWidth = 5; // 边框宽度
  222. entity.polygon.height = 5;
  223. entity.polygon.material = new SkyScenery.ImageMaterialProperty({
  224. image: "/static/image/b2.png", // 图片路径
  225. transparent: true // 是否透明
  226. });
  227. }
  228. entity.type = "layers";
  229. }
  230. });
  231. }
  232. },
  233. computed: {
  234. mapStatus() {
  235. return this.$store.state.initMap;
  236. }
  237. },
  238. watch: {
  239. mapStatus(newVal, oldVal) {
  240. if (newVal) {
  241. setTimeout(() => {
  242. this.addedChange(this.arr[0]);
  243. this.addedChange(this.arr[1]);
  244. this.addedChange(this.arr[2]);
  245. this.addedChange(this.arr[3]);
  246. this.addedChange(this.arr[4]);
  247. }, 2000);
  248. // this.openClick();
  249. }
  250. }
  251. }
  252. };
  253. </script>
  254. <style lang="less" scoped>
  255. .layer {
  256. width: 140px;
  257. background: #00000080;
  258. padding: 10px 15px;
  259. border-radius: 5px;
  260. .title {
  261. color: #ffffff;
  262. }
  263. .el-switch {
  264. margin-left: 20px;
  265. vertical-align: top;
  266. }
  267. .info_container {
  268. height: 300px;
  269. overflow: hidden;
  270. overflow-y: auto;
  271. }
  272. .el-checkbox {
  273. color: #ffffff;
  274. // :v-deep(.el-checkbox__label) {
  275. // color: #ffffff;
  276. // }
  277. }
  278. }
  279. </style>