Layers.vue 7.5 KB

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