index.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <template>
  2. <div class="map-content">
  3. <div id="mapChart"></div>
  4. <div class="map-tools">
  5. <div :class="{'map-tool-item':mapToolName!='测距','map-tool-itemActive':mapToolName=='测距'}"
  6. @click="handleMapTools('测距')">
  7. <img v-if="mapToolName!='测距'" src="@/assets/yujing/map/measure-deactive.png"/>
  8. <img v-else src="@/assets/yujing/map/measure-active.png"/>
  9. </div>
  10. <div :class="{'map-tool-item':mapToolName!='测面','map-tool-itemActive':mapToolName=='测面'}"
  11. @click="handleMapTools('测面')">
  12. <img v-if="mapToolName!='测面'" src="@/assets/yujing/map/area-deactive.png"/>
  13. <img v-else src="@/assets/yujing/map/area-active.png"/>
  14. </div>
  15. </div>
  16. <!-- 地图站点信息弹框 -->
  17. <div ref="popupRefs" class="map-popup" v-show="showPopup">
  18. <div class="map-popup-top">
  19. <img src="@/assets/yujing/map/取消.png" @click="closePopup"/>
  20. </div>
  21. <div class="map-popup-content">
  22. <div class="popup-content-left">
  23. <span>测站名称:</span>
  24. <span>所在河流:</span>
  25. <span>最新监测时间:</span>
  26. <span>溶解氧(mg/L):</span>
  27. <span>高锰酸盐指数(mg/L):</span>
  28. <span>氨氮(mg/L):</span>
  29. <span>总磷(mg/L):</span>
  30. <span>锑(μg/L):</span>
  31. </div>
  32. <div class="popup-content-right">
  33. <span
  34. style="color: #4a93f5;cursor: pointer;"
  35. @click="handleStnmDialog(mapPopupData,'stnm')"
  36. >{{ mapPopupData.stnm }}</span>
  37. <span
  38. style="color: #4a93f5;cursor: pointer;"
  39. @click="handleStnmDialog(mapPopupData,'river')"
  40. >{{ mapPopupData.river }}</span>
  41. <span>{{ mapPopupData.tm }}</span>
  42. <span>{{ mapPopupData.cod }}</span>
  43. <span></span>
  44. <span></span>
  45. <span></span>
  46. <span></span>
  47. </div>
  48. </div>
  49. <div class="popup-trangle"></div>
  50. </div>
  51. <StnmDialog :showStnmDialog="stnmDialogVisible" :stnmData="stnmDialogData" @closeDialog="closeStnmDialog"/>
  52. </div>
  53. </template>
  54. <script setup>
  55. import {ElMessage} from 'element-plus';
  56. import 'ol/css';
  57. import {ScaleLine, defaults as defaultControls} from 'ol/control';
  58. import Map from 'ol/Map';
  59. import View from 'ol/View';
  60. import TileLayer from "ol/layer/Tile";
  61. import { XYZ, Vector as VectorSource } from 'ol/source.js';
  62. import VectorLayer from "ol/layer/Vector";
  63. import { LineString, Point } from "ol/geom";
  64. import { Icon, Style, Text,Circle } from 'ol/style';
  65. import Fill from "ol/style/Fill";
  66. import Feature from 'ol/Feature';
  67. import Stroke from "ol/style/Stroke";
  68. import Overlay from 'ol/Overlay';
  69. import StnmDialog from "./components/StnmDialog.vue";
  70. import imgⅣ from "@/assets/yujing/map/Ⅳ.png";
  71. const mapChart = ref(null);
  72. const mapCenter = ref([120.745, 31.120]);
  73. const mapZoom = ref(10.6);
  74. const mapToolName = ref("");
  75. const mapPointData = [
  76. {
  77. stnm: "太浦闸下",
  78. river: "太浦河干流",
  79. tm: "2025-08-21 13:51",
  80. lgtd: 120.745,
  81. lttd: 31.120,
  82. cod:10.87,
  83. },
  84. {
  85. stnm: "太浦闸上",
  86. river: "太浦河干流",
  87. tm: "2025-09-05 15:48",
  88. lgtd: 120.545,
  89. lttd: 31.020,
  90. cod:8.87,
  91. },
  92. ];
  93. const popupRefs = ref(null);
  94. const showPopup = ref(false);
  95. const mapPopupData = ref({});
  96. const stnmDialogVisible = ref(false);
  97. const stnmDialogData = ref({});
  98. onMounted(() => {
  99. });
  100. const initMap = (mapObj) => {
  101. let vecLayer = new TileLayer({
  102. source: new XYZ({
  103. url: "http://t0.tianditu.gov.cn/vec_w/wmts?" +
  104. "SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=vec&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles" +
  105. "&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}" +
  106. "&tk=9bb941214f10fbf9a3eab43f45cb2b7e",
  107. }),
  108. });
  109. let cvaLayer = new TileLayer({
  110. source: new XYZ({
  111. url: "http://t0.tianditu.gov.cn/cva_w/wmts?" +
  112. "SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=cva&STYLE=default&TILEMATRIXSET=w&FORMAT=tiles" +
  113. "&TILEMATRIX={z}&TILEROW={y}&TILECOL={x}" +
  114. "&tk=9bb941214f10fbf9a3eab43f45cb2b7e",
  115. }),
  116. });
  117. mapChart.value= new Map({
  118. target: 'mapChart',
  119. view: new View({
  120. center: mapObj.center,
  121. zoom: mapObj.zoom,
  122. minZoom: 3,
  123. maxZoom: 16,
  124. projection: 'EPSG:4326',
  125. }),
  126. layers: [vecLayer, cvaLayer],
  127. controls: defaultControls({
  128. zoom: false,//不显示放大放小按钮
  129. rotate: false,//不显示指北针控件
  130. attribution: false,//不显示右下角的地图信息控件
  131. scaleLine:false,//不显示比例尺控件
  132. })
  133. });
  134. // 添加地图站点
  135. let featuresData = [];
  136. mapPointData.forEach((item) => {
  137. let iconFeature = new Feature({
  138. geometry: new Point([item.lgtd,item.lttd]),
  139. properties: item,
  140. });
  141. iconFeature.setStyle(
  142. new Style({
  143. image: new Icon({
  144. src: imgⅣ,
  145. anchor: [0.5, 0.5],
  146. scale: 0.08,
  147. }),
  148. })
  149. );
  150. featuresData.push(iconFeature);
  151. })
  152. var polygonLayer = new VectorLayer({
  153. source:new VectorSource({
  154. features: featuresData,
  155. }),
  156. zIndex:5,
  157. visible:true,
  158. })
  159. mapChart.value.addLayer(polygonLayer);
  160. if(mapObj.pageName == '首页'){
  161. singleclick();
  162. }
  163. };
  164. // 地图点击事件
  165. const singleclick = () => {
  166. let elpopup = popupRefs.value;
  167. let popupOverlay = new Overlay({
  168. element: elpopup,
  169. positioning: "bottom-center",
  170. stopEvent: false,
  171. offset: [220, 110],
  172. });
  173. mapChart.value.on("singleclick", (e) => {
  174. let feature = mapChart.value.forEachFeatureAtPixel(e.pixel, (feature) => feature);
  175. if (feature) {
  176. showPopup.value = true;
  177. mapPopupData.value = feature.values_.properties;
  178. let position = [mapPopupData.value.lgtd, mapPopupData.value.lttd];
  179. popupOverlay.setPosition(position);
  180. }
  181. });
  182. // 设置弹窗位置
  183. mapChart.value.addOverlay(popupOverlay);
  184. };
  185. // 关闭站点信息弹框
  186. const closePopup = () => {
  187. showPopup.value = false;
  188. };
  189. const handleStnmDialog = (data,type) => {
  190. stnmDialogData.value = {
  191. ...data,
  192. type
  193. };
  194. stnmDialogVisible.value = true;
  195. };
  196. const closeStnmDialog = (status) => {
  197. stnmDialogVisible.value = status;
  198. };
  199. const mapToolsRefs = ref(null);
  200. const handleMapTools = (name) => {
  201. mapToolName.value = name;
  202. if(name == '测距'){
  203. mapToolsRefs.value.distance(mapChart.value);
  204. }
  205. }
  206. defineExpose({
  207. initMap,
  208. });
  209. </script>
  210. <style scoped lang="scss">
  211. .map-content{
  212. height: 100%;
  213. width: 100%;
  214. position: relative;
  215. #mapChart{
  216. height: 100%;
  217. width: 100%;
  218. }
  219. .map-tools{
  220. position: absolute;
  221. top: 8%;
  222. left: 1%;
  223. width: 30px;
  224. height: 80px;
  225. display: flex;
  226. flex-direction: column;
  227. .map-tool-item{
  228. width: 100%;
  229. height: 30px;
  230. background: rgba(255,255,255,0.9);
  231. border-radius: 3px;
  232. margin: 5px 0;
  233. display:flex;
  234. flex-direction: column;
  235. justify-content: center;
  236. align-items: center;
  237. cursor: pointer;
  238. img{
  239. width: 18px;
  240. height: 18px;
  241. }
  242. }
  243. .map-tool-itemActive{
  244. width: 100%;
  245. height: 30px;
  246. background: rgba(74, 147, 245,0.9);
  247. border-radius: 3px;
  248. margin: 5px 0;
  249. display:flex;
  250. flex-direction: column;
  251. justify-content: center;
  252. align-items: center;
  253. cursor: pointer;
  254. img{
  255. width: 18px;
  256. height: 18px;
  257. }
  258. }
  259. .map-tool-item:hover{
  260. background: rgba(74, 147, 245,0.9);
  261. }
  262. }
  263. }
  264. .map-popup {
  265. width:400px;
  266. height: 220px;
  267. background-color: rgba(255, 255, 255,0.9);
  268. border-radius: 5px;
  269. position: relative;
  270. .map-popup-top{
  271. width: 100%;
  272. height: 20px;
  273. background: url("@/assets/images/lefttitle-bg.png");
  274. background-size: 100% 100%;
  275. border-radius: 5px 5px 0 0;
  276. img{
  277. position: absolute;
  278. top: 2px;
  279. right: 2px;
  280. width: 16px;
  281. height: 16px;
  282. cursor: pointer;
  283. }
  284. }
  285. .map-popup-content{
  286. width: 95%;
  287. height: 82%;
  288. margin: 2.5%;
  289. background-color: #fff;
  290. border: 1px solid #e9e9e9;
  291. display: flex;
  292. .popup-content-left{
  293. display: flex;
  294. flex-direction: column;
  295. font-size: 14px;
  296. font-weight: bolder;
  297. color: #444444;
  298. line-height: 22px;
  299. margin-left: 5PX;
  300. }
  301. .popup-content-right{
  302. display: flex;
  303. flex-direction: column;
  304. font-size: 14px;
  305. color: #444444;
  306. line-height: 22px;
  307. }
  308. }
  309. .popup-trangle{
  310. width:0;
  311. height:0;
  312. content:'';
  313. border-right:10px solid rgba(255,255,255,0.9);
  314. border-top:10px solid transparent;
  315. border-bottom:10px solid transparent;
  316. position:absolute;
  317. left:-10px;
  318. bottom:100px;
  319. }
  320. }
  321. </style>