map.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <template>
  2. <tlbs-map
  3. ref="mapRef"
  4. api-key="3SVBZ-6MYYZ-Q75X5-7YN43-BMIBZ-YABND"
  5. :center="center"
  6. :zoom="zoom"
  7. :control="control"
  8. class="mapBox"
  9. :options="mapOption"
  10. @click="onClick"
  11. @map_inited="onMapInited"
  12. >
  13. <tlbs-multi-marker
  14. ref="markerRef"
  15. :geometries="geometries"
  16. :styles="styles"
  17. :options="options"
  18. @click="openInfo"
  19. />
  20. </tlbs-map>
  21. <el-dialog
  22. v-model="dialogVisible"
  23. width="350px"
  24. title="隧道信息"
  25. align-center
  26. >
  27. <el-form
  28. size="large"
  29. label-width="70px"
  30. label-position="left"
  31. label-suffix=""
  32. >
  33. <el-form-item label="名称:">
  34. <el-text size="large">{{ dialogData.name }}</el-text>
  35. </el-form-item>
  36. <el-form-item label="类型:">
  37. <el-text size="large">{{ dialogData.switchType }}</el-text>
  38. </el-form-item>
  39. <el-form-item label="灯控1:">
  40. <el-slider
  41. v-if="dialogData.switchType === '单灯控制器'"
  42. v-model="transparency"
  43. :step="50"
  44. show-stops
  45. :show-tooltip="false"
  46. @change="changeTransparency($event,'单灯','')"
  47. />
  48. <div
  49. v-if="dialogData.switchType === '四路控制器'"
  50. style="width: 100%;display: flex; justify-content: space-between"
  51. >
  52. <el-switch
  53. v-for="(item,index) in relayList[0].relay"
  54. :key="item.id"
  55. v-model="item.state"
  56. :disabled="index === 0"
  57. @change="changeTransparency($event,'四路',item)"
  58. />
  59. </div>
  60. </el-form-item>
  61. <el-form-item label="灯控2:">
  62. <el-slider
  63. v-if="dialogData.switchType === '单灯控制器'"
  64. v-model="transparencyTwo"
  65. :step="50"
  66. show-stops
  67. :show-tooltip="false"
  68. @change="changeTransparencyTwo($event,'单灯','')"
  69. />
  70. <div
  71. v-if="dialogData.switchType === '四路控制器'"
  72. style="width: 100%;display: flex; justify-content: space-between"
  73. >
  74. <el-switch
  75. v-for="(item,index) in relayList[1].relay"
  76. :key="item.id"
  77. v-model="item.state"
  78. :disabled="index === 0"
  79. @change="changeTransparencyTwo($event,'四路',item)"
  80. />
  81. </div>
  82. </el-form-item>
  83. <el-form-item
  84. v-if="dialogData.switchType === '单灯控制器'"
  85. label-width="0"
  86. >
  87. <el-button
  88. type="primary"
  89. style="width: 100%"
  90. @click="singleLamp"
  91. >
  92. 设定
  93. </el-button>
  94. </el-form-item>
  95. <el-form-item label-width="0">
  96. <div style="width: 100%; display: flex; justify-content: space-between">
  97. <el-button
  98. type="primary"
  99. @click="callParentMethod"
  100. >查看数据</el-button>
  101. <el-button
  102. type="primary"
  103. >查看模型</el-button>
  104. </div>
  105. </el-form-item>
  106. </el-form>
  107. </el-dialog>
  108. </template>
  109. <script>
  110. import { defineComponent, ref, reactive, onMounted } from 'vue-demi'
  111. import { useScreenStore } from '@/pinia/modules/screen'
  112. import { updateTunnelLamp } from '@/api/tunnel'
  113. import { ElMessage } from 'element-plus'
  114. import { deviceSwitch } from '@/api/device'
  115. const useScreen = useScreenStore()
  116. export default defineComponent({
  117. name: 'MarkerDemo',
  118. setup() {
  119. const mapRef = ref(null)
  120. const markerRef = ref(null)
  121. const center = ref({ lat: 28.7052848, lng: 113.5759597 })
  122. const zoom = ref(10)
  123. const geometries = ref(useScreen.placeList)
  124. const dialogVisible = ref(false)
  125. const dialogData = ref({})
  126. const mapOption = ref({
  127. mapStyleId: 'style1'
  128. })
  129. const onClick = (e) => {
  130. console.log(e.latLng)
  131. }
  132. const onMapInited = () => {
  133. // 地图加载完成后,可以获取地图实例、点标记实例,调用地图实例、点标记实例方法
  134. // console.log(mapRef.value.map)
  135. // console.log(markerRef.value.marker)
  136. }
  137. const getLayerInstance = () => {
  138. // 可以获取点标记实例,调用点标记实例方法
  139. console.log(markerRef.value.marker)
  140. }
  141. const openInfo = (e) => {
  142. dialogVisible.value = true
  143. const id = e.geometry.styleId
  144. const list = useScreen.tunnelList
  145. list.forEach(item => {
  146. if (item.ID === id) {
  147. dialogData.value = item
  148. brightness(item)
  149. }
  150. })
  151. }
  152. const callParentMethod = () => {
  153. useScreen.setCurrentTunnel(dialogData.value)
  154. dialogVisible.value = false
  155. }
  156. // 亮度调节
  157. const transparency = ref(0)
  158. const transparencyTwo = ref(0)
  159. const materialOne = reactive({})
  160. const materialTwo = reactive({})
  161. const relayList = reactive([])
  162. const lampData = reactive({})
  163. const brightness = (item) => {
  164. Object.assign(lampData, item)
  165. if (item.switchType === '单灯控制器') {
  166. const val1 = item.lampValue1
  167. const val2 = item.lampValue2
  168. const judge = {
  169. 0: [0.8, 0],
  170. 33: [0.8, 0],
  171. 66: [0.5, 50],
  172. 100: [0.2, 100],
  173. }
  174. transparency.value = judge[val1][1]
  175. transparencyTwo.value = judge[val2][1]
  176. materialOne.opacity = judge[val1][0]
  177. materialTwo.opacity = judge[val2][0]
  178. } else if (item.switchType === '四路控制器') {
  179. relayList.length = 0
  180. item.devices.forEach(option => {
  181. if (option.genre === 6) {
  182. relayList.push({ radarId: option.radarId, relay: option.deviceRelays })
  183. }
  184. })
  185. }
  186. }
  187. const changeTransparency = (e, type, data) => {
  188. // materialOne.opacity = option[e][0]
  189. if (type === '单灯') {
  190. transparency.value = e
  191. } else {
  192. deviceSwitch({
  193. tunnelSn: lampData.tunnelSn,
  194. radarId: relayList[0].radarId,
  195. relayId: data.relayId,
  196. state: e
  197. }).then(res => {
  198. if (res.code === 0) {
  199. console.log('发送成功')
  200. }
  201. })
  202. }
  203. }
  204. const changeTransparencyTwo = (e, type, data) => {
  205. // materialOne.opacity = option[e][0]
  206. if (type === '单灯') {
  207. transparencyTwo.value = e
  208. } else {
  209. deviceSwitch({
  210. tunnelSn: lampData.tunnelSn,
  211. radarId: relayList[1].radarId,
  212. relayId: data.relayId,
  213. state: e
  214. }).then(res => {
  215. if (res.code === 0) {
  216. console.log('发送成功')
  217. }
  218. })
  219. }
  220. }
  221. const singleLamp = () => {
  222. const option = {
  223. 0: [0.8, 33, 1],
  224. 50: [0.5, 66, 2],
  225. 100: [0.2, 100, 3]
  226. }
  227. const lamp1 = option[transparency.value][1]
  228. const lamp2 = option[transparencyTwo.value][1]
  229. updateTunnelLamp({
  230. id: lampData.ID,
  231. tunnelSn: lampData.tunnelSn,
  232. lampValue1: lamp1,
  233. lampValue2: lamp2
  234. }).then(res => {
  235. if (res.code === 0) {
  236. ElMessage.success('已发送')
  237. }
  238. })
  239. }
  240. onMounted(() => {
  241. setTimeout(function() {
  242. center.value = useScreen.placeList[0].position
  243. }, 500)
  244. })
  245. return {
  246. center,
  247. zoom,
  248. onClick,
  249. onMapInited,
  250. getLayerInstance,
  251. control: {
  252. scale: {},
  253. zoom: {
  254. position: 'topRight',
  255. },
  256. },
  257. mapRef,
  258. markerRef,
  259. geometries,
  260. styles: {
  261. marker: {
  262. width: 20,
  263. height: 30,
  264. anchor: { x: 10, y: 30 },
  265. },
  266. },
  267. options: {
  268. minZoom: 5,
  269. maxZoom: 15,
  270. },
  271. openInfo,
  272. dialogVisible,
  273. dialogData,
  274. callParentMethod,
  275. mapOption,
  276. // 亮度调节
  277. transparency,
  278. transparencyTwo,
  279. materialOne,
  280. materialTwo,
  281. brightness,
  282. changeTransparency,
  283. changeTransparencyTwo,
  284. relayList,
  285. singleLamp
  286. }
  287. },
  288. })
  289. </script>
  290. <style scoped lang="less">
  291. .mapBox{
  292. width: 1200px;
  293. height: 600px;
  294. }
  295. .infoDialog{
  296. width: 300px;
  297. height: 100px;
  298. }
  299. </style>