map.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  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: 16,
  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. })
  310. .addTo(map);
  311. if (localStorage.getItem("user_latitude") != null && localStorage.getItem("user_longitude") != null) {
  312. let myIcon = L.icon({
  313. iconUrl: '../js/leaflet1.3.1/images/myMarker00000000.png',
  314. iconSize: [10, 10],
  315. iconAnchor: [12, 0],
  316. popupAnchor: [1, -34],
  317. tooltipAnchor: [16, -28],
  318. shadowSize: [41, 41],
  319. className: "my-div-icon2"
  320. })
  321. let localAddr = [parseFloat(localStorage.getItem("user_latitude")), parseFloat(localStorage
  322. .getItem(
  323. "user_longitude"))];
  324. L.marker(localAddr, {
  325. icon: myIcon
  326. }).addTo(map);
  327. }
  328. // 批量将markers中的点添加到地图中,并添加监听事件打开底部弹窗。
  329. markers.forEach(item => {
  330. item.on('click', function(item) {
  331. // 请求疑点数据和图片
  332. let markerData = item.target.options.data;
  333. let state = markerData.properties && markerData.properties.state ? markerData
  334. .properties
  335. .state : 0;
  336. let desc = markerData.properties && markerData.properties.desc ? markerData
  337. .properties.desc :
  338. '';
  339. localStorage.setItem("markerDataPropertiesFileList", JSON.stringify(markerData
  340. .properties &&
  341. markerData.properties.fileList ? markerData.properties.fileList :
  342. {}));
  343. // 我的标记和标记疑点
  344. if (markerData.properties && markerData.properties.title) {
  345. let mapBottomBoxInnerHtml = `<div></div><span class="title">${markerData.properties && markerData.properties.title ? markerData.properties.title : '自定义标记' }</span>
  346. <div class="arrowdown" data-state="1"><span class="mui-icon mui-icon-arrowdown"></span></div>
  347. <p>位置:${markerData.properties.localAddr ? markerData.properties.localAddr : '未知'}</p>
  348. <div id="mapImageList">`;
  349. if (markerData.properties && markerData.properties.fileList) {
  350. getFileListUrl2(markerData.properties.fileList).then(res => {
  351. if (res) {
  352. for (let fileBase in res) {
  353. mapBottomBoxInnerHtml +=
  354. `<div><img src="${res[fileBase]}"/></div>`;
  355. }
  356. }
  357. mapBottomBoxInnerHtml += `
  358. </div>
  359. <input id="myMarkerId" value="${markerData.id}" />
  360. <div>
  361. <p>描述:</p>
  362. <span>${desc}</span>
  363. </div>`;
  364. document.getElementById('mapBottomBox').innerHTML =
  365. mapBottomBoxInnerHtml;
  366. document.getElementById('mapBottomBox').style.bottom =
  367. "0";
  368. })
  369. } else {
  370. mapBottomBoxInnerHtml += `
  371. </div>
  372. <input id="myMarkerId" value="${markerData.id}" />
  373. <div>
  374. <p>描述:</p>
  375. <span>${desc}</span>
  376. </div>`;
  377. document.getElementById('mapBottomBox').innerHTML =
  378. mapBottomBoxInnerHtml;
  379. document.getElementById('mapBottomBox').style.bottom = "0";
  380. }
  381. } else {
  382. // 我的任务疑点
  383. let statusMap = {
  384. 0: {
  385. class: "mapWarning",
  386. title: "未核实"
  387. },
  388. 1: {
  389. class: "mapSuccessTag",
  390. title: "已核实"
  391. }
  392. }
  393. let mapBottomBoxInnerHtml = `<div class="${state ? statusMap[state].class : 'mapWarning'}">${state ? statusMap[state].title : '未核实'}</div>
  394. <span class="title">${markerData.dataTitle}</span>
  395. <div class="arrowdown" data-state="${state}"><span class="mui-icon mui-icon-arrowdown"></span></div>
  396. <p>位置:${markerData.properties && markerData.properties['镇域名称'] ? markerData.properties['镇域名称'] : '未知'}</p>
  397. <div id="mapImageList">
  398. `;
  399. if (markerData.properties && markerData.properties.fileList) {
  400. getFileListUrl2(markerData.properties.fileList).then(res => {
  401. if (res) {
  402. for (let fileBase in res) {
  403. mapBottomBoxInnerHtml +=
  404. `<div><img src="${res[fileBase]}"/></div>`;
  405. }
  406. }
  407. mapBottomBoxInnerHtml += `
  408. ${state == 0 ? `<div id="uploadImage">
  409. <div><span class="mui-icon mui-icon-plus"></span></div>
  410. <div><span>上传照片</span></div>
  411. </div>` : ``}
  412. </div>
  413. <input id="myMarkerId" value="${markerData.id}" />
  414. <div>
  415. <p>描述:</p>
  416. ${state == 1 ? `<span>${desc}</span>` : `<textarea name="" id="mapTextArea" placeholder="请添加描述" cols="30" rows="3" >${desc}</textarea>`}
  417. </div>
  418. ${state == 0 ? `
  419. <div class="displayFlex3">
  420. <div class="paperplaneMyMarker2 openMyPhoneMap" data-lat="${item.latlng.lat}" data-lng="${item.latlng.lng}">导航到这</div>
  421. <div class="paperplane"><span class="mui-icon mui-icon-paperplane"></span>提交</div>
  422. </div>
  423. ` : ``}`;
  424. document.getElementById('mapBottomBox').innerHTML =
  425. mapBottomBoxInnerHtml;
  426. document.getElementById('mapBottomBox').style.bottom =
  427. "0";
  428. })
  429. } else {
  430. mapBottomBoxInnerHtml += `
  431. ${state == 0 ? `<div id="uploadImage">
  432. <div><span class="mui-icon mui-icon-plus"></span></div>
  433. <div><span>上传照片</span></div>
  434. </div>` : ``}
  435. </div>
  436. <input id="myMarkerId" value="${markerData.id}" />
  437. <div>
  438. <p>描述:</p>
  439. ${state == 1 ? `<span>${desc}</span>` : `<textarea name="" id="mapTextArea" placeholder="请添加描述" cols="30" rows="3" >${desc}</textarea>`}
  440. </div>
  441. ${state == 0 ? `
  442. <div class="displayFlex3">
  443. <div class="paperplaneMyMarker2 openMyPhoneMap" data-lat="${item.latlng.lat}" data-lng="${item.latlng.lng}">导航到这</div>
  444. <div class="paperplane"><span class="mui-icon mui-icon-paperplane"></span>提交</div>
  445. </div>
  446. ` : ``}`;
  447. document.getElementById('mapBottomBox').innerHTML =
  448. mapBottomBoxInnerHtml;
  449. document.getElementById('mapBottomBox').style.bottom = "0";
  450. }
  451. }
  452. })
  453. if (item.options.data.name || item.options.data.properties.title || item.options.data
  454. .properties.desc) {
  455. item.addTo(map)
  456. .bindPopup(item.options.data.name || item.options.data.properties.title || item
  457. .options.data
  458. .properties.desc, {
  459. autoClose: false,
  460. closeOnClick: ""
  461. })
  462. .openPopup();
  463. } else {
  464. item.addTo(map);
  465. }
  466. });
  467. if (center_) {
  468. map.panTo(center_);
  469. }
  470. // 自定义标记页面事件
  471. if (localStorage.getItem("mapTitle") === "自定义标记") {
  472. localStorage.setItem('showMyMarkerBottomBox', 'false');
  473. document.getElementById('addMyMarker').style.display = "flex";
  474. let markerItem = "";
  475. // 地图的点击事件
  476. map.on('click', function(e) {
  477. if (!localStorage.getItem("showMyMarkerBottomBox") || localStorage.getItem(
  478. "showMyMarkerBottomBox") ==
  479. "false") {
  480. document.getElementById('taskName').innerHTML =
  481. `<p>lat:${e.latlng.lat}</p><p>lng:${e.latlng.lng}</p>`;
  482. document.getElementById('taskName').style.display = "block";
  483. localStorage.setItem("latlngLat", e.latlng.lat - 0.00011);
  484. localStorage.setItem("latlngLng", e.latlng.lng - 0.19195);
  485. if (markerItem) {
  486. markerItem.setLatLng([e.latlng.lat, e.latlng.lng]);
  487. } else {
  488. markerItem = L.marker([e.latlng.lat, e.latlng.lng]);
  489. markerItem.addTo(map);
  490. }
  491. }
  492. })
  493. }
  494. let myDivIconDoms = document.getElementsByClassName("my-div-icon");
  495. if (myDivIconDoms[0]) {
  496. myDivIconDoms[0].click();
  497. }
  498. // puls加载完成
  499. }
  500. })
  501. </script>
  502. </html>