map.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title></title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
  7. <meta name="apple-mobile-web-app-capable" content="yes">
  8. <meta name="apple-mobile-web-app-status-bar-style" content="black">
  9. <script src="../js/imageConversion.js"></script>
  10. <script src="../js/mui.js"></script>
  11. <script src="../js/util.js"></script>
  12. <link rel="stylesheet" href="../js/leaflet1.3.1/leaflet.css">
  13. <link rel="stylesheet" href="../js/leaflet1.3.1/leaflet.label.css">
  14. <link rel="stylesheet" href="../js/leaflet1.3.1/leaflet.measure.css">
  15. <!-- 自定义工具类 -->
  16. <script>
  17. var systemConfig = {
  18. assetsUrl: "http://localhost:8848",
  19. mapViewer: {
  20. center: [31.105589678244445, 121.72894516017521],
  21. zoom: 11
  22. },
  23. token: '65463DEE-620A-0ED5-2385-17ECD07CD351', //公共地图资源token
  24. mapService: 'http://121.43.55.7:10011/proxy/', //地图服务
  25. }
  26. //地图全局变量声明
  27. var map2DViewer = {
  28. markers: {},
  29. polygons: {},
  30. polylines: {},
  31. circles: {},
  32. map: null,
  33. layers: {},
  34. groups: {}
  35. }
  36. </script>
  37. <script src="../js/leaflet1.3.1/leaflet.js"></script>
  38. <script type="module" src="../js/leaflet1.3.1/leaflet-side-by-side.js"></script>
  39. <script src="../js/esri-leaflet-v3.0.4/esri-leaflet-debug.js"></script>
  40. <script type="module" src="../js/leaflet1.3.1/leaflet.measure.js"></script>
  41. <script type="module" src="../js/leaflet1.3.1/leaflet.label.js"></script>
  42. <!--标准mui.css-->
  43. <link rel="stylesheet" href="../css/mui.min.css">
  44. <link rel="stylesheet" href="../css/home.css">
  45. <style type="text/css">
  46. html,
  47. body,
  48. #map {
  49. position: relative;
  50. height: 100%;
  51. }
  52. .leaflet-touch .leaflet-control-layers-toggle {
  53. width: 22px !important;
  54. height: 22px !important;
  55. background-size: 20px 20px !important;
  56. }
  57. </style>
  58. </head>
  59. <body>
  60. <header class="mui-bar mui-bar-nav" style="z-index: 999;">
  61. <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
  62. <h1 class="mui-title" id="mapTitle"></h1>
  63. </header>
  64. <div id="map">
  65. <!-- 文件上传 -->
  66. <input id="uploadFileInput" type="file" style="z-index: -1;" value=""
  67. accept="image/png, image/jpeg, image/jpg" />
  68. <!-- 当前任务名称 -->
  69. <span id="taskName"></span>
  70. <!-- 地图底部弹窗 -->
  71. <div id="mapBottomBox">
  72. </div>
  73. <!-- 我的任务列表模式 -->
  74. <div class="changeType toBackPage">
  75. <span class="mui-icon mui-icon-list"></span>
  76. </div>
  77. <!-- 自定义标记添加事件 -->
  78. <div class="changeType" id="addMyMarker">
  79. <span class="mui-icon mui-icon-upload"></span>
  80. </div>
  81. </div>
  82. </body>
  83. <script type="text/javascript">
  84. mui.plusReady(function() {
  85. if (plus) {
  86. function newPostRequest2(setting, funSuccess, funError) {
  87. var xhr = new XMLHttpRequest();
  88. // 请求成功回调函数
  89. xhr.onload = e => {
  90. console.log('request success');
  91. };
  92. // 请求结束
  93. xhr.onloadend = e => {
  94. console.log('request loadend');
  95. };
  96. // 请求出错
  97. xhr.onerror = e => {
  98. console.log('request error');
  99. funError("request error");
  100. };
  101. // 请求超时
  102. xhr.ontimeout = e => {
  103. console.log('request timeout');
  104. funError("request timeout");
  105. };
  106. xhr.open('POST', "http://117.131.26.69:10081/proxy_dms/content/selectContentList", true);
  107. if (localStorage.getItem("token")) {
  108. xhr.setRequestHeader("token", localStorage.getItem("token"))
  109. }
  110. xhr.onreadystatechange = function() {
  111. if (xhr.readyState == 4 && xhr.status == 200) {
  112. funSuccess(JSON.parse(xhr.responseText));
  113. }
  114. }
  115. xhr.send(setting.data);
  116. }
  117. // 动态获取图片(点击疑点或标记marker时)
  118. function getFileListUrl2(fileList) {
  119. return new Promise((resolve, reject) => {
  120. if (fileList) {
  121. let fileUrlList = [];
  122. let index = 0;
  123. for (let fileName in fileList) {
  124. index++;
  125. }
  126. for (let fileName in fileList) {
  127. let paramData2 = new FormData();
  128. paramData2.append("columnId", 1793);
  129. paramData2.append("states", "0,1,2");
  130. paramData2.append("pageSize", 10);
  131. paramData2.append("page", 0);
  132. let searchParam = [];
  133. let paramItem = {
  134. field: "title",
  135. searchType: "1",
  136. content: {
  137. value: fileList[fileName]
  138. }
  139. };
  140. searchParam.push(paramItem);
  141. if (searchParam.length > 0) {
  142. paramData2.append("search", JSON.stringify(searchParam));
  143. }
  144. newPostRequest2({
  145. data: paramData2
  146. }, function funSuccess(res, textStatus, xhr) {
  147. let resJson2 = res;
  148. if (resJson2.code == 200) {
  149. let fileBase = resJson2.content
  150. .data[0].c_file_base64;
  151. fileUrlList.push(fileBase);
  152. if (fileUrlList.length == index) {
  153. resolve(fileUrlList);
  154. }
  155. }
  156. }, function funerror(res, textStatus, xhr) {});
  157. }
  158. } else {
  159. resolve();
  160. }
  161. });
  162. }
  163. let markers = [];
  164. let geometrys = [];
  165. // 地图默认中心位置
  166. //定义一些常量
  167. let center_ = [31.17361258762417, 121.51803731918336];
  168. function getOneLatLng(data, returnFunc) {
  169. if (typeof data[0] == "object") {
  170. getOneLatLng(data[0], returnFunc);
  171. } else {
  172. if (data[0] < data[1]) {
  173. returnFunc([data[0] + 0.00011, data[1] + 0.19195]);
  174. return;
  175. } else {
  176. returnFunc([data[1] + 0.00011, data[0] + 0.19195]);
  177. }
  178. }
  179. }
  180. let gotoOrtherPageState = false;
  181. // 得到定位数据
  182. if (localStorage.getItem("geometrys") && localStorage.getItem("mapTitle") !== "自定义标记") {
  183. let geometrysItem = JSON.parse(localStorage.getItem("geometrys"));
  184. // console.log(geometrysItem)
  185. let index = 1;
  186. if (geometrysItem != null) {
  187. if (geometrysItem[0]) {
  188. getOneLatLng(geometrysItem[0].coord ? geometrysItem[0].coord : geometrysItem[0].geometry
  189. .coordinates,
  190. function(res) {
  191. center_ = res;
  192. });
  193. }
  194. geometrysItem.forEach(item => {
  195. //创建多个icon
  196. var greenIcon = L.icon({
  197. iconUrl: '../js/leaflet1.3.1/images/marker-icon-2x-sc.png',
  198. iconSize: [25, 41],
  199. iconAnchor: [12, 41],
  200. popupAnchor: [1, -34],
  201. tooltipAnchor: [16, -28],
  202. shadowSize: [41, 41]
  203. }),
  204. redIcon = L.icon({
  205. iconUrl: '../js/leaflet1.3.1/images/marker-icon-2x-er.png',
  206. iconSize: [25, 41],
  207. iconAnchor: [12, 41],
  208. popupAnchor: [1, -34],
  209. tooltipAnchor: [16, -28],
  210. shadowSize: [41, 41]
  211. }),
  212. orangeIcon = L.icon({
  213. iconUrl: '../js/leaflet1.3.1/images/marker-icon-2x-wr.png',
  214. iconSize: [25, 41],
  215. iconAnchor: [12, 41],
  216. popupAnchor: [1, -34],
  217. tooltipAnchor: [16, -28],
  218. shadowSize: [41, 41]
  219. }),
  220. greenIconActive = L.icon({
  221. iconUrl: '../js/leaflet1.3.1/images/marker-icon-2x-sc.png',
  222. iconSize: [25, 41],
  223. iconAnchor: [12, 41],
  224. popupAnchor: [1, -34],
  225. tooltipAnchor: [16, -28],
  226. shadowSize: [41, 41],
  227. className: "my-div-icon"
  228. }),
  229. redIconActive = L.icon({
  230. iconUrl: '../js/leaflet1.3.1/images/marker-icon-2x-er.png',
  231. iconSize: [25, 41],
  232. iconAnchor: [12, 41],
  233. popupAnchor: [1, -34],
  234. tooltipAnchor: [16, -28],
  235. shadowSize: [41, 41],
  236. className: "my-div-icon"
  237. }),
  238. orangeIconActive = L.icon({
  239. iconUrl: '../js/leaflet1.3.1/images/marker-icon-2x-wr.png',
  240. iconSize: [25, 41],
  241. iconAnchor: [12, 41],
  242. popupAnchor: [1, -34],
  243. tooltipAnchor: [16, -28],
  244. shadowSize: [41, 41],
  245. className: "my-div-icon"
  246. });
  247. index++;
  248. // 先将点添加到markers对象中
  249. let centerItem = [];
  250. if (localStorage.getItem("markerId") && item.id == localStorage.getItem(
  251. "markerId")) {
  252. gotoOrtherPageState = true;
  253. getOneLatLng(item.coord ? item.coord : item.geometry.coordinates, function(
  254. res) {
  255. center_ = res;
  256. if (center_[0] && center_[1]) {
  257. markers.push(L.marker(center_, {
  258. icon: localStorage.getItem("mapTitle") ==
  259. "我的标记" || (item
  260. .properties && item.properties.state
  261. ) ?
  262. greenIconActive : orangeIconActive,
  263. data: item
  264. }));
  265. }
  266. });
  267. } else {
  268. getOneLatLng(item.coord ? item.coord : item.geometry.coordinates, function(
  269. res) {
  270. centerItem = res;
  271. if (centerItem[0] && centerItem[1]) {
  272. markers.push(L.marker(centerItem, {
  273. icon: localStorage.getItem("mapTitle") ==
  274. "我的标记" || (item
  275. .properties && item.properties.state
  276. ) ? greenIcon : orangeIcon,
  277. data: item
  278. }));
  279. }
  280. });
  281. }
  282. })
  283. }
  284. };
  285. // 如果得到当前手机定位
  286. if (gotoOrtherPageState == false && localStorage.getItem("user_latitude") && localStorage.getItem(
  287. "user_longitude")) {
  288. center_ = [parseFloat(localStorage.getItem("user_latitude")), parseFloat(localStorage.getItem(
  289. "user_longitude"))];
  290. }
  291. // 地图初始化
  292. var map = L.map("map", {
  293. center: center_,
  294. zoom: 12,
  295. minZoom: 9,
  296. maxZoom: 18,
  297. zoomControl: true,
  298. attributionControl: false,
  299. doubleClickZoom: false,
  300. maxBounds: [
  301. [31.95, 120.86],
  302. [30.7, 122.12]
  303. ]
  304. })
  305. // 初始化地图底图
  306. // var layer = L.esri
  307. // .tiledMapLayer({
  308. // // url: "http://121.43.55.7:10011/proxy/?servertype=Street_Purplish_Blue&token=65463DEE-620A-0ED5-2385-17ECD07CD351"
  309. // url: "http://t0.tianditu.gov.cn/vec_c/wmts?tk=7e55f62d7d46488299e8caa8d6f0dcf4"
  310. // })
  311. // .addTo(map);
  312. var layer = L.tileLayer(
  313. "http://webrd0{s}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}", {
  314. attribution: '&copy; 高德地图',
  315. maxZoom: 19,
  316. minZoom: 3,
  317. subdomains: "1234",
  318. zoom: 3
  319. }).addTo(map);
  320. if (localStorage.getItem("user_latitude") != null && localStorage.getItem("user_longitude") != null) {
  321. let myIcon = L.icon({
  322. iconUrl: '../js/leaflet1.3.1/images/myMarker00000000.png',
  323. iconSize: [10, 10],
  324. iconAnchor: [12, 0],
  325. popupAnchor: [1, -34],
  326. tooltipAnchor: [16, -28],
  327. shadowSize: [41, 41],
  328. className: "my-div-icon2"
  329. })
  330. let localAddr = [parseFloat(localStorage.getItem("user_latitude")), parseFloat(localStorage
  331. .getItem(
  332. "user_longitude"))];
  333. L.marker(localAddr, {
  334. icon: myIcon
  335. }).addTo(map);
  336. }
  337. // 批量将markers中的点添加到地图中,并添加监听事件打开底部弹窗。
  338. markers.forEach(item => {
  339. item.on('click', function(item) {
  340. // 请求疑点数据和图片
  341. let markerData = item.target.options.data;
  342. let state = markerData.properties && markerData.properties.state ? markerData
  343. .properties
  344. .state : 0;
  345. let desc = markerData.properties && markerData.properties.desc ? markerData
  346. .properties.desc :
  347. '';
  348. localStorage.setItem("markerDataPropertiesFileList", JSON.stringify(markerData
  349. .properties &&
  350. markerData.properties.fileList ? markerData.properties.fileList : {}));
  351. // 我的标记和标记疑点
  352. if (markerData.properties && markerData.properties.title) {
  353. let mapBottomBoxInnerHtml = `<div></div><span class="title">${markerData.properties && markerData.properties.title ? markerData.properties.title : '自定义标记' }</span>
  354. <div class="arrowdown" data-state="1"><span class="mui-icon mui-icon-arrowdown"></span></div>
  355. <p>位置:${markerData.properties.localAddr ? markerData.properties.localAddr : '未知'}</p>
  356. <div id="mapImageList">`;
  357. if (markerData.properties && markerData.properties.fileList) {
  358. getFileListUrl2(markerData.properties.fileList).then(res => {
  359. if (res) {
  360. for (let fileBase in res) {
  361. mapBottomBoxInnerHtml +=
  362. `<div><img src="${res[fileBase]}"/></div>`;
  363. }
  364. }
  365. mapBottomBoxInnerHtml += `
  366. </div>
  367. <input id="myMarkerId" value="${markerData.id}" />
  368. <div>
  369. <p>描述:</p>
  370. <span>${desc}</span>
  371. </div>`;
  372. document.getElementById('mapBottomBox').innerHTML =
  373. mapBottomBoxInnerHtml;
  374. document.getElementById('mapBottomBox').style.bottom =
  375. "0";
  376. })
  377. } else {
  378. mapBottomBoxInnerHtml += `
  379. </div>
  380. <input id="myMarkerId" value="${markerData.id}" />
  381. <div>
  382. <p>描述:</p>
  383. <span>${desc}</span>
  384. </div>`;
  385. document.getElementById('mapBottomBox').innerHTML =
  386. mapBottomBoxInnerHtml;
  387. document.getElementById('mapBottomBox').style.bottom = "0";
  388. }
  389. } else {
  390. // 我的任务疑点
  391. let statusMap = {
  392. 0: {
  393. class: "mapWarning",
  394. title: "未核实"
  395. },
  396. 1: {
  397. class: "mapSuccessTag",
  398. title: "已核实"
  399. }
  400. }
  401. let mapBottomBoxInnerHtml = `<div class="${state ? statusMap[state].class : 'mapWarning'}">${state ? statusMap[state].title : '未核实'}</div>
  402. <span class="title">${markerData.dataTitle}</span>
  403. <div class="arrowdown" data-state="${state}"><span class="mui-icon mui-icon-arrowdown"></span></div>
  404. <p>位置:${markerData.properties && markerData.properties['镇域名称'] ? markerData.properties['镇域名称'] : '未知'}</p>
  405. <div id="mapImageList">
  406. `;
  407. if (markerData.properties && markerData.properties.fileList) {
  408. getFileListUrl2(markerData.properties.fileList).then(res => {
  409. if (res) {
  410. for (let fileBase in res) {
  411. mapBottomBoxInnerHtml +=
  412. `<div><img src="${res[fileBase]}"/></div>`;
  413. }
  414. }
  415. mapBottomBoxInnerHtml += `
  416. ${state == 0 ? `<div id="uploadImage">
  417. <div><span class="mui-icon mui-icon-plus"></span></div>
  418. <div><span>上传照片</span></div>
  419. </div>` : ``}
  420. </div>
  421. <input id="myMarkerId" value="${markerData.id}" />
  422. <div>
  423. <p>描述:</p>
  424. ${state == 1 ? `<span>${desc}</span>` : `<textarea name="" id="mapTextArea" placeholder="请添加描述" cols="30" rows="3" >${desc}</textarea>`}
  425. </div>
  426. ${state == 0 ? `
  427. <div class="displayFlex3">
  428. <div class="paperplaneMyMarker2 openMyPhoneMap" data-lat="${item.latlng.lat}" data-lng="${item.latlng.lng}">导航到这</div>
  429. <div class="paperplane"><span class="mui-icon mui-icon-paperplane"></span>提交</div>
  430. </div>
  431. ` : ``}`;
  432. document.getElementById('mapBottomBox').innerHTML =
  433. mapBottomBoxInnerHtml;
  434. document.getElementById('mapBottomBox').style.bottom =
  435. "0";
  436. })
  437. } else {
  438. mapBottomBoxInnerHtml += `
  439. ${state == 0 ? `<div id="uploadImage">
  440. <div><span class="mui-icon mui-icon-plus"></span></div>
  441. <div><span>上传照片</span></div>
  442. </div>` : ``}
  443. </div>
  444. <input id="myMarkerId" value="${markerData.id}" />
  445. <div>
  446. <p>描述:</p>
  447. ${state == 1 ? `<span>${desc}</span>` : `<textarea name="" id="mapTextArea" placeholder="请添加描述" cols="30" rows="3" >${desc}</textarea>`}
  448. </div>
  449. ${state == 0 ? `
  450. <div class="displayFlex3">
  451. <div class="paperplaneMyMarker2 openMyPhoneMap" data-lat="${item.latlng.lat}" data-lng="${item.latlng.lng}">导航到这</div>
  452. <div class="paperplane"><span class="mui-icon mui-icon-paperplane"></span>提交</div>
  453. </div>
  454. ` : ``}`;
  455. document.getElementById('mapBottomBox').innerHTML =
  456. mapBottomBoxInnerHtml;
  457. document.getElementById('mapBottomBox').style.bottom = "0";
  458. }
  459. }
  460. })
  461. if (item.options.data.name || item.options.data.properties.title || item.options.data
  462. .properties.desc) {
  463. item.addTo(map)
  464. .bindPopup(item.options.data.name || item.options.data.properties.title || item
  465. .options.data
  466. .properties.desc, {
  467. autoClose: false,
  468. closeOnClick: ""
  469. })
  470. .openPopup();
  471. } else {
  472. item.addTo(map);
  473. }
  474. });
  475. if (center_) {
  476. map.panTo(center_);
  477. }
  478. // 自定义标记页面事件
  479. if (localStorage.getItem("mapTitle") === "自定义标记") {
  480. localStorage.setItem('showMyMarkerBottomBox', 'false');
  481. document.getElementById('addMyMarker').style.display = "flex";
  482. let markerItem = "";
  483. // 地图的点击事件
  484. map.on('click', function(e) {
  485. if (!localStorage.getItem("showMyMarkerBottomBox") || localStorage.getItem(
  486. "showMyMarkerBottomBox") ==
  487. "false") {
  488. document.getElementById('taskName').innerHTML =
  489. `<p>lat:${e.latlng.lat}</p><p>lng:${e.latlng.lng}</p>`;
  490. document.getElementById('taskName').style.display = "block";
  491. localStorage.setItem("latlngLat", e.latlng.lat - 0.00011);
  492. localStorage.setItem("latlngLng", e.latlng.lng - 0.19195);
  493. if (markerItem) {
  494. markerItem.setLatLng([e.latlng.lat, e.latlng.lng]);
  495. } else {
  496. markerItem = L.marker([e.latlng.lat, e.latlng.lng]);
  497. markerItem.addTo(map);
  498. }
  499. }
  500. })
  501. }
  502. let myDivIconDoms = document.getElementsByClassName("my-div-icon");
  503. if (myDivIconDoms[0]) {
  504. myDivIconDoms[0].click();
  505. }
  506. // puls加载完成
  507. }
  508. })
  509. </script>
  510. </html>