mapStore.js 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. import { ref } from 'vue';
  2. import { defineStore } from 'pinia';
  3. import {
  4. addImagePoint,
  5. addJuHePoint,
  6. closePoint,
  7. stopTrajectory,
  8. startBidding,
  9. closeOutputPoint,
  10. addPoint,
  11. fullExtent,
  12. change3DTheme,
  13. regionZone
  14. } from '@/utils/map/mapOperation.js';
  15. import {
  16. getTrajectorPointOnPeople,
  17. getTrajectorPointOnCar,
  18. sprinkleSomeByType
  19. } from '@/service/api/mapRequest.js';
  20. import { useDrawPointStore } from '@/stores/drawPointManage';
  21. export const useMapStore = defineStore('mapStore', () => {
  22. //当前病例点位列表
  23. const currentToolSelectArray = ref(['newAdress', 'touch', 'autoPlay']);
  24. //自动播放类型
  25. const autoPlayType = ref(1);
  26. //自动播放时间范围
  27. const autoPlayTime = ref(1);
  28. const getTimeArray = () => {
  29. const nowTime = Date.now();
  30. let resultArr = [];
  31. if (autoPlayTime.value == 1) {
  32. const datTime = 60 * 60 * 1000;
  33. for (let i = 1; i < 24; i++) {
  34. const end = nowTime - datTime * (i - 1);
  35. const start = nowTime - datTime * i;
  36. resultArr.unshift({
  37. startTime: new Date(start).toLocaleString().replaceAll('/', '-'),
  38. endTime: new Date(end).toLocaleString().replaceAll('/', '-')
  39. });
  40. }
  41. } else if (autoPlayTime.value == 7) {
  42. const datTime = 24 * 60 * 60 * 1000;
  43. for (let i = 1; i < 7; i++) {
  44. const end = nowTime - datTime * (i - 1);
  45. const start = nowTime - datTime * i;
  46. resultArr.unshift({
  47. startTime: new Date(start).toLocaleDateString().replaceAll('/', '-'),
  48. endTime: new Date(end).toLocaleDateString().replaceAll('/', '-')
  49. });
  50. }
  51. } else if (autoPlayTime.value == 30) {
  52. const datTime = 24 * 60 * 60 * 1000;
  53. for (let i = 1; i < 30; i++) {
  54. const end = nowTime - datTime * (i - 1);
  55. const start = nowTime - datTime * i;
  56. resultArr.unshift({
  57. startTime: new Date(start).toLocaleDateString().replaceAll('/', '-'),
  58. endTime: new Date(end).toLocaleDateString().replaceAll('/', '-')
  59. });
  60. }
  61. }
  62. return resultArr;
  63. };
  64. const currentTimePoint = ref(0);
  65. //自动播放点位获取
  66. const getSprinkleSomeByType = (startTime, endTime) => {
  67. closePoint('autoPlay');
  68. sprinkleSomeByType({
  69. endTime: endTime,
  70. startTime: startTime,
  71. type: autoPlayType.value
  72. }).then((res) => {
  73. if (res.code == 200) {
  74. addImagePoint('autoPlay', res.data, {
  75. imageUrl: new URL(`@/assets/image/bidding.png`, import.meta.url).href
  76. });
  77. currentTimePoint.value = res?.data?.length || 0;
  78. }
  79. });
  80. };
  81. const intervalFlag = ref(false);
  82. const timeInterval = ref(null);
  83. const timeArr = ref([]);
  84. const autoNum = ref(0);
  85. // 自动播放事件
  86. const autoPlayFun = () => {
  87. timeArr.value = getTimeArray();
  88. intervalFlag.value = true;
  89. timeInterval.value = setInterval(() => {
  90. try {
  91. getSprinkleSomeByType(
  92. timeArr.value[autoNum.value].startTime,
  93. timeArr.value[autoNum.value].endTime
  94. );
  95. } catch (error) {
  96. console.log(error);
  97. }
  98. autoNum.value = autoNum.value + 1;
  99. if (autoNum.value >= timeArr.value.length) {
  100. autoNum.value = 0;
  101. }
  102. }, 5000);
  103. };
  104. // 地图地图类型
  105. const mapTheme = ref('dark');
  106. //区选择
  107. const selectPartKey = ref('松江区');
  108. //所有病例点位
  109. const currentAllPointList = ref([]);
  110. // 会商车绘制列表
  111. const flowCarList = ref([]);
  112. const pushFlowCarList = (value) => {
  113. flowCarList.value.push(value);
  114. };
  115. const delFlowCarList = () => {
  116. flowCarList.value = [];
  117. };
  118. const changeTheme = (is3D) => {
  119. change3DTheme(is3D);
  120. if (is3D) {
  121. currentToolSelectArray.value.push('3dChange');
  122. } else {
  123. currentToolSelectArray.value = currentToolSelectArray.value.filter(
  124. (item) => item != '3dChange'
  125. );
  126. }
  127. };
  128. //切换主题后加载初始化地图
  129. const initChangeMap = (is3D) => {
  130. changeTheme(is3D);
  131. currentToolSelectArray.value.forEach((item) => {
  132. if (item != '3dChange' && item != 'Bidding' && item != 'flowCar') {
  133. setCurrentToolSelectArray(item);
  134. if (selectPartKey.value?.length > 0) {
  135. if (selectPartKey.value == '浦东新区') {
  136. regionZone('浦东新区');
  137. } else {
  138. regionZone(selectPartKey.value);
  139. }
  140. }
  141. }
  142. });
  143. };
  144. //点亮地图工具图标
  145. const setCurrentToolSelectArray = async (value) => {
  146. currentToolSelectArray.value.push(value);
  147. try {
  148. switch (value) {
  149. case 'newAdress': {
  150. //新址图标
  151. addImagePoint('newAdress', [{ x: -14926.528171515301, y: -1705.2657878212942 }], {
  152. imageUrl: new URL(`@/assets/image/mapTools/new_icon.png`, import.meta.url).href
  153. });
  154. break;
  155. }
  156. case 'touch': {
  157. //密接图标
  158. addImagePoint(
  159. 'touch',
  160. [
  161. { x: 9604.191858692775, y: -19248.016463574288 },
  162. { x: 13799.47156001244, y: -11944.303054916069 },
  163. { x: 17672.277882889364, y: -9192.565371300574 }
  164. ],
  165. {
  166. imageUrl: new URL(`@/assets/image/mapTools/2.png`, import.meta.url).href
  167. }
  168. );
  169. // const res = await getTrajectorPointOnPeople({ type: 1 });
  170. // if (res?.code == 200) {
  171. // addJuHePoint(value, res?.data || []);
  172. // } else {
  173. // console.log('获取传染病数据错误');
  174. // }
  175. // addImagePoint(value, {
  176. // imageUrl: new URL(`@/assets/image/mapTools/2.png`, import.meta.url).href
  177. // });
  178. break;
  179. }
  180. case 'infectious': {
  181. //传染病图标
  182. const res = await getTrajectorPointOnPeople({ type: 1 });
  183. if (res?.code == 200) {
  184. addJuHePoint(value, res?.data || [], {
  185. label: '传染病',
  186. color: 'rgba(230, 162, 60, 0.5)',
  187. borderColor: 'rgba(230, 162, 60, 1)'
  188. });
  189. } else {
  190. console.log('获取传染病数据错误');
  191. }
  192. break;
  193. }
  194. case 'feverClinic': {
  195. //发热门诊图标
  196. const res = await getTrajectorPointOnPeople({ type: 2 });
  197. if (res?.code == 200) {
  198. addJuHePoint(value, res?.data || [], {
  199. label: '发热门诊',
  200. color: 'rgba(245, 108, 108, 0.5)',
  201. borderColor: 'rgba(245, 108, 108, 1)'
  202. });
  203. } else {
  204. console.log('获取发热数据错误');
  205. }
  206. break;
  207. }
  208. case 'breathe': {
  209. //呼吸图标
  210. const res = await getTrajectorPointOnPeople({ type: 3 });
  211. if (res?.code == 200) {
  212. addJuHePoint(value, res?.data || [], {
  213. label: '呼吸数据',
  214. color: 'rgba(148, 0, 211, 0.5)',
  215. borderColor: 'rgba(148, 0, 211, 1)'
  216. });
  217. } else {
  218. console.log('获取呼吸数据错误');
  219. }
  220. break;
  221. }
  222. case 'flowCar': {
  223. const res = await getTrajectorPointOnCar();
  224. if (res?.code == 200) {
  225. addImagePoint(value, res?.data || [], {
  226. imageUrl: new URL(`@/assets/image/mapTools/6.png`, import.meta.url).href
  227. });
  228. }
  229. initChangeMap(true);
  230. break;
  231. }
  232. case 'Bidding': {
  233. initChangeMap(true);
  234. //有轨迹点;
  235. const allShowHasPoint = currentAllPointList.value.filter((item) => {
  236. return item?.x && item?.y && item?.ty == '有轨迹';
  237. });
  238. //无轨迹点
  239. const allShowNoPoint = currentAllPointList.value.filter((item) => {
  240. return item?.x && item?.y && item?.ty == '无轨迹';
  241. });
  242. allShowHasPoint?.length > 0 &&
  243. addPoint(allShowHasPoint, 'hasPointView', {
  244. color: 'rgba(0, 128, 255, 0.4)',
  245. borderColor: 'rgba(0, 128, 255, 0.6)'
  246. });
  247. allShowNoPoint?.length > 0 &&
  248. addPoint(allShowNoPoint, 'noPointView', {
  249. color: 'rgba(255, 127, 0, 0.4)',
  250. borderColor: 'rgba(255, 127, 0, 0.6)'
  251. });
  252. //无轨迹点
  253. break;
  254. }
  255. case '3dChange': {
  256. initChangeMap(true);
  257. break;
  258. }
  259. case 'autoPlay': {
  260. autoPlayFun();
  261. break;
  262. }
  263. }
  264. } catch (error) {
  265. console.log(error);
  266. }
  267. };
  268. //关闭地图工具图标
  269. const delCurrentToolSelectArray = (value) => {
  270. currentToolSelectArray.value = currentToolSelectArray.value.filter((item) => item != value);
  271. if (value == 'Bidding') {
  272. startBidding(false);
  273. stopTrajectory('car_layerdrawLine');
  274. closePoint('car_layerdrawLine');
  275. closePoint('drawPoint');
  276. closePoint('clickView');
  277. closePoint('hasPointView');
  278. closePoint('noPointView');
  279. useDrawPointStore().modifyTrail = false;
  280. closeOutputPoint();
  281. initChangeMap(false);
  282. } else if (value == 'flowCar') {
  283. flowCarList.value.forEach((item) => {
  284. stopTrajectory(item);
  285. closePoint(item);
  286. });
  287. closePoint(value);
  288. delFlowCarList();
  289. initChangeMap(false);
  290. } else if (value == '3dChange') {
  291. change3DTheme(false);
  292. initChangeMap();
  293. } else if (value == 'autoPlay') {
  294. autoNum.value = 0;
  295. clearInterval(timeInterval.value);
  296. timeInterval.value = null;
  297. } else {
  298. closePoint(value);
  299. }
  300. fullExtent();
  301. };
  302. return {
  303. currentToolSelectArray,
  304. flowCarList,
  305. selectPartKey,
  306. currentAllPointList,
  307. pushFlowCarList,
  308. delFlowCarList,
  309. setCurrentToolSelectArray,
  310. delCurrentToolSelectArray,
  311. mapTheme,
  312. changeTheme,
  313. autoPlayType,
  314. autoPlayTime,
  315. getSprinkleSomeByType,
  316. autoPlayFun,
  317. timeInterval,
  318. intervalFlag,
  319. autoNum,
  320. timeArr,
  321. currentTimePoint
  322. };
  323. });