Setting.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <div style="position: relative">
  3. <div class="title">
  4. <div class="my-name">设置</div>
  5. </div>
  6. <div class="tools">
  7. </div>
  8. <div class="mini-map" ref="mapRef"></div>
  9. </div>
  10. </template>
  11. <script setup>
  12. import * as util from "@/common/ol_common.js"
  13. import * as KMap from '@/utils/ol-map/KMap';
  14. import config from "@/api/config.js"
  15. import {onMounted, ref} from "vue";
  16. import {useStore} from "vuex";
  17. import {newPoint,bboxToFeature} from "../map.js"
  18. import {miniStyle, miniSelectStyle} from "./Style";
  19. let emits = defineEmits(["moveMap","selectTree","selectPeriod","selectAttr"])
  20. let props = defineProps({
  21. periodMap:{type:Object,require: true},
  22. treeList:{type:Object,require: true},
  23. })
  24. let store = useStore()
  25. const mapRef = ref("mapRef")
  26. let curPeriod = ref({})
  27. let attrList = ref([])
  28. let curAttrField = ref(-1)
  29. let map = null;
  30. let treeLayer = new KMap.VectorLayer("treeLayer",1000, {style:miniStyle})
  31. const initMap = async () => {
  32. let location = store.getters.userinfo.location;
  33. let coordinate = util.wktCastGeom(location).getFirstCoordinate()
  34. map = new KMap.Map(mapRef.value, 20, coordinate[0], coordinate[1], null, 20, 20);
  35. let xyz = config.base_img_url + 'map/lby/{z}/{x}/{y}.png';
  36. map.addXYZLayer(xyz,{minZoom:15,maxZoom:20});
  37. let xyz2 = config.base_img_url3 + 'map/lby/{z}/{x}/{y}.png';
  38. map.addXYZLayer(xyz2,{minZoom:15,maxZoom:20});
  39. map.addLayer(treeLayer.layer)
  40. }
  41. const initTree = () => {
  42. for(let item of props.treeList){
  43. treeLayer.addFeature(newPoint(item))
  44. }
  45. }
  46. onMounted(async()=>{
  47. initMap()
  48. initTree()
  49. initListener()
  50. })
  51. /**
  52. * 初始化事件
  53. */
  54. function initListener(){
  55. map.map.on("moveend", function (evt) {
  56. emits("moveMap",getExtentFeature())
  57. });
  58. treeLayer.addSingleSelect(function (e){
  59. if(e.selected.length > 0){
  60. emits("selectTree", e.selected[0])
  61. }else{
  62. emits("selectTree", null)
  63. }
  64. },map.map, miniSelectStyle)
  65. }
  66. /**
  67. * 返回地图范围的Feature
  68. * @returns {Feature<{geometry: any}>}
  69. */
  70. function getExtentFeature(){
  71. let extent = map.view.calculateExtent(map.map.getSize())
  72. return bboxToFeature(extent[0],extent[1],extent[2],extent[3])
  73. }
  74. /**
  75. * 设置选中的树
  76. * @param treeId
  77. */
  78. function setSelected(treeId){
  79. treeLayer.singleSelect.getFeatures().clear()
  80. if(!treeId)
  81. return;
  82. let f = treeLayer.getFeatureById(treeId);
  83. treeLayer.singleSelect.getFeatures().insertAt(0,f)
  84. map.view.setCenter(f.getGeometry().getFirstCoordinate())
  85. }
  86. function setCenter(coordinate){
  87. map.setCenter2(coordinate)
  88. }
  89. defineExpose({
  90. setSelected,setCenter
  91. });
  92. </script>
  93. <style lang="scss" scoped>
  94. $title-height:44px;
  95. .title{
  96. width: 100%;
  97. height: $title-height;
  98. box-sizing: border-box;
  99. background: rgba(0,77,101,0.8);
  100. border-radius: 4px 4px 0px 0px;
  101. border-bottom: 2px solid rgba(81,233,240,0.3);
  102. display: flex;
  103. align-items: center;
  104. justify-content: space-between;
  105. .my-name{
  106. margin-left: 20px;
  107. font-size: 16px;
  108. font-weight: 600;
  109. color: #00FFF0;
  110. height: 22px;
  111. }
  112. .my-close{
  113. margin-right: 20px;
  114. width: 16px;
  115. height: 16px;
  116. background-image: url("@/assets/img/close.png");
  117. background-size: 100% 100%;
  118. }
  119. }
  120. .tools{
  121. position: absolute;
  122. top: calc($title-height + 10px);
  123. width: 100%;
  124. height: 0px;
  125. display: flex;
  126. flex-direction: row;
  127. justify-content: right;
  128. color: #f0f0f0;
  129. line-height: 30px;
  130. .select{
  131. width: 80px;
  132. margin-right: 20px;
  133. }
  134. .cols{
  135. display: flex;
  136. flex-direction: row;
  137. justify-content: space-around;
  138. }
  139. }
  140. .mini-map{
  141. border: 1px solid rgba(81,233,240,0.6);
  142. position: absolute;
  143. top: $title-height + 0px;
  144. bottom: 0px;
  145. left: 0px;
  146. right: 0px;
  147. }
  148. </style>