map.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  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. <link rel="stylesheet" href="../js/leaflet1.3.1/leaflet.css">
  12. <link rel="stylesheet" href="../js/leaflet1.3.1/leaflet.label.css">
  13. <link rel="stylesheet" href="../js/leaflet1.3.1/leaflet.measure.css">
  14. <!-- 自定义工具类 -->
  15. <script>
  16. var systemConfig = {
  17. assetsUrl: "http://localhost:8848",
  18. mapViewer: {
  19. center: [31.105589678244445, 121.72894516017521],
  20. zoom: 11
  21. },
  22. token: '65463DEE-620A-0ED5-2385-17ECD07CD351', //公共地图资源token
  23. mapService: 'http://121.43.55.7:10011/proxy/', //地图服务
  24. }
  25. //地图全局变量声明
  26. var map2DViewer = {
  27. markers: {},
  28. polygons: {},
  29. polylines: {},
  30. circles: {},
  31. map: null,
  32. layers: {},
  33. groups: {}
  34. }
  35. </script>
  36. <script src="../js/leaflet1.3.1/leaflet.js"></script>
  37. <script type="module" src="../js/leaflet1.3.1/leaflet-side-by-side.js"></script>
  38. <script src="../js/esri-leaflet-v3.0.4/esri-leaflet-debug.js"></script>
  39. <script type="module" src="../js/leaflet1.3.1/leaflet.measure.js"></script>
  40. <script type="module" src="../js/leaflet1.3.1/leaflet.label.js"></script>
  41. <!--标准mui.css-->
  42. <link rel="stylesheet" href="../css/mui.min.css">
  43. <link rel="stylesheet" href="../css/home.css">
  44. <style type="text/css">
  45. html,
  46. body,
  47. #map {
  48. position: relative;
  49. height: 100%;
  50. }
  51. .leaflet-touch .leaflet-control-layers-toggle {
  52. width: 22px !important;
  53. height: 22px !important;
  54. background-size: 20px 20px !important;
  55. }
  56. </style>
  57. </head>
  58. <body>
  59. <header class="mui-bar mui-bar-nav" style="z-index: 999;">
  60. <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
  61. <h1 class="mui-title" id="mapTitle"></h1>
  62. </header>
  63. <div id="map">
  64. <!-- 文件上传 -->
  65. <input id="uploadFileInput" type="file" style="z-index: -1;" value=""
  66. accept="image/png, image/jpeg, image/jpg" />
  67. <!-- 当前任务名称 -->
  68. <span id="taskName">老港镇林地审计-任务1</span>
  69. <!-- 地图底部弹窗 -->
  70. <div id="mapBottomBox">
  71. </div>
  72. <!-- 我的任务列表模式 -->
  73. <div class="changeType toBackPage">
  74. <span class="mui-icon mui-icon-list"></span>
  75. </div>
  76. <!-- 自定义标记添加事件 -->
  77. <div class="changeType" id="addMyMarker">
  78. <span class="mui-icon mui-icon-upload"></span>
  79. </div>
  80. </div>
  81. </body>
  82. <script src="../js/util.js"></script>
  83. <script type="text/javascript">
  84. let markers = [];
  85. let geometrys = [];
  86. // 地图默认中心位置
  87. //定义一些常量
  88. let center_ = [31.17361258762417, 121.51803731918336];
  89. function getOneLatLng(data, returnFunc) {
  90. if (typeof data[0] == "object") {
  91. getOneLatLng(data[0], returnFunc);
  92. } else {
  93. if (data[0] < data[1]) {
  94. returnFunc([data[0] + 0.00011, data[1] + 0.19195]);
  95. return;
  96. } else {
  97. returnFunc([data[1] + 0.00011, data[0] + 0.19195]);
  98. }
  99. }
  100. }
  101. let gotoOrtherPageState = false;
  102. // 得到定位数据
  103. if (localStorage.getItem("geometrys") && localStorage.getItem("mapTitle") !== "自定义标记") {
  104. let geometrysItem = JSON.parse(localStorage.getItem("geometrys"));
  105. // console.log(geometrysItem)
  106. let index = 1;
  107. if (geometrysItem != null) {
  108. if (geometrysItem[0]) {
  109. getOneLatLng(geometrysItem[0].coord ? geometrysItem[0].coord : geometrysItem[0].geometry.coordinates,
  110. function(res) {
  111. center_ = res;
  112. });
  113. }
  114. geometrysItem.forEach(item => {
  115. //创建多个icon
  116. var greenIcon = L.icon({
  117. iconUrl: '../js/leaflet1.3.1/images/marker-icon-2x-sc.png',
  118. iconSize: [25, 41],
  119. iconAnchor: [12, 41],
  120. popupAnchor: [1, -34],
  121. tooltipAnchor: [16, -28],
  122. shadowSize: [41, 41]
  123. }),
  124. redIcon = L.icon({
  125. iconUrl: '../js/leaflet1.3.1/images/marker-icon-2x-er.png',
  126. iconSize: [25, 41],
  127. iconAnchor: [12, 41],
  128. popupAnchor: [1, -34],
  129. tooltipAnchor: [16, -28],
  130. shadowSize: [41, 41]
  131. }),
  132. orangeIcon = L.icon({
  133. iconUrl: '../js/leaflet1.3.1/images/marker-icon-2x-wr.png',
  134. iconSize: [25, 41],
  135. iconAnchor: [12, 41],
  136. popupAnchor: [1, -34],
  137. tooltipAnchor: [16, -28],
  138. shadowSize: [41, 41]
  139. }),
  140. greenIconActive = L.icon({
  141. iconUrl: '../js/leaflet1.3.1/images/marker-icon-2x-sc.png',
  142. iconSize: [25, 41],
  143. iconAnchor: [12, 41],
  144. popupAnchor: [1, -34],
  145. tooltipAnchor: [16, -28],
  146. shadowSize: [41, 41],
  147. className: "my-div-icon"
  148. }),
  149. redIconActive = L.icon({
  150. iconUrl: '../js/leaflet1.3.1/images/marker-icon-2x-er.png',
  151. iconSize: [25, 41],
  152. iconAnchor: [12, 41],
  153. popupAnchor: [1, -34],
  154. tooltipAnchor: [16, -28],
  155. shadowSize: [41, 41],
  156. className: "my-div-icon"
  157. }),
  158. orangeIconActive = L.icon({
  159. iconUrl: '../js/leaflet1.3.1/images/marker-icon-2x-wr.png',
  160. iconSize: [25, 41],
  161. iconAnchor: [12, 41],
  162. popupAnchor: [1, -34],
  163. tooltipAnchor: [16, -28],
  164. shadowSize: [41, 41],
  165. className: "my-div-icon"
  166. });
  167. index++;
  168. // 先将点添加到markers对象中
  169. let centerItem = [];
  170. if (localStorage.getItem("markerId") && item.id == localStorage.getItem("markerId")) {
  171. gotoOrtherPageState = true;
  172. getOneLatLng(item.coord ? item.coord : item.geometry.coordinates, function(res) {
  173. center_ = res;
  174. if (center_[0] && center_[1]) {
  175. markers.push(L.marker(center_, {
  176. icon: localStorage.getItem("mapTitle") == "我的标记" || (item
  177. .properties && item.properties.state) ?
  178. greenIconActive : orangeIconActive,
  179. data: item
  180. }));
  181. }
  182. });
  183. } else {
  184. getOneLatLng(item.coord ? item.coord : item.geometry.coordinates, function(res) {
  185. centerItem = res;
  186. if (centerItem[0] && centerItem[1]) {
  187. markers.push(L.marker(centerItem, {
  188. icon: localStorage.getItem("mapTitle") == "我的标记" || (item
  189. .properties && item.properties.state) ? greenIcon :
  190. orangeIcon,
  191. data: item
  192. }));
  193. }
  194. });
  195. }
  196. })
  197. }
  198. };
  199. // 如果得到当前手机定位
  200. if (gotoOrtherPageState == false && localStorage.getItem("user_latitude") && localStorage.getItem("user_longitude")) {
  201. center_ = [parseFloat(localStorage.getItem("user_latitude")), parseFloat(localStorage.getItem("user_longitude"))];
  202. }
  203. // 地图初始化
  204. var map = L.map("map", {
  205. center: center_,
  206. zoom: 12,
  207. minZoom: 9,
  208. maxZoom: 16,
  209. zoomControl: true,
  210. attributionControl: false,
  211. doubleClickZoom: false,
  212. maxBounds: [
  213. [31.95, 120.86],
  214. [30.7, 122.12]
  215. ]
  216. })
  217. // 初始化地图底图
  218. var layer = L.esri
  219. .tiledMapLayer({
  220. url: "http://121.43.55.7:10011/proxy/?servertype=Street_Purplish_Blue&token=65463DEE-620A-0ED5-2385-17ECD07CD351"
  221. })
  222. .addTo(map);
  223. if (localStorage.getItem("user_latitude") != null && localStorage.getItem("user_longitude") != null) {
  224. let myIcon = L.icon({
  225. iconUrl: '../js/leaflet1.3.1/images/marker-icon-2x-sc.png',
  226. iconSize: [25, 41],
  227. iconAnchor: [12, 41],
  228. popupAnchor: [1, -34],
  229. tooltipAnchor: [16, -28],
  230. shadowSize: [41, 41]
  231. })
  232. let localAddr = [parseFloat(localStorage.getItem("user_latitude")), parseFloat(localStorage.getItem(
  233. "user_longitude"))];
  234. L.marker(localAddr, {
  235. icon: myIcon
  236. }).addTo(map);
  237. }
  238. // 批量将markers中的点添加到地图中,并添加监听事件打开底部弹窗。
  239. markers.forEach(item => {
  240. item.on('click', function(item) {
  241. // 请求疑点数据和图片
  242. let markerData = item.target.options.data;
  243. let state = markerData.properties && markerData.properties.state ? markerData.properties
  244. .state : 0;
  245. let desc = markerData.properties && markerData.properties.desc ? markerData.properties.desc :
  246. '';
  247. localStorage.setItem("markerDataPropertiesFileList", JSON.stringify(markerData.properties &&
  248. markerData.properties.fileList ? markerData.properties.fileList : {}));
  249. // 我的标记和标记疑点
  250. if (markerData.properties && markerData.properties.title) {
  251. let mapBottomBoxInnerHtml = `<div></div><span class="title">${markerData.properties && markerData.properties.title ? markerData.properties.title : '自定义标记' }</span>
  252. <div class="arrowdown" data-state="1"><span class="mui-icon mui-icon-arrowdown"></span></div>
  253. <p>位置:${markerData.properties.localAddr ? markerData.properties.localAddr : '未知'}</p>
  254. <div id="mapImageList">`;
  255. if (markerData.properties && markerData.properties.fileList) {
  256. getFileListUrl(markerData.properties.fileList).then(res => {
  257. if (res) {
  258. for (let fileBase in res) {
  259. mapBottomBoxInnerHtml +=
  260. `<div><img src="${res[fileBase]}"/></div>`;
  261. }
  262. }
  263. mapBottomBoxInnerHtml += `
  264. </div>
  265. <input id="myMarkerId" value="${markerData.id}" />
  266. <div>
  267. <p>描述:</p>
  268. <span>${desc}</span>
  269. </div>`;
  270. document.getElementById('mapBottomBox').innerHTML = mapBottomBoxInnerHtml;
  271. document.getElementById('mapBottomBox').style.bottom = "0";
  272. })
  273. } else {
  274. mapBottomBoxInnerHtml += `
  275. </div>
  276. <input id="myMarkerId" value="${markerData.id}" />
  277. <div>
  278. <p>描述:</p>
  279. <span>${desc}</span>
  280. </div>`;
  281. document.getElementById('mapBottomBox').innerHTML = mapBottomBoxInnerHtml;
  282. document.getElementById('mapBottomBox').style.bottom = "0";
  283. }
  284. } else {
  285. // 我的任务疑点
  286. let statusMap = {
  287. 0: {
  288. class: "mapWarning",
  289. title: "未核实"
  290. },
  291. 1: {
  292. class: "mapSuccessTag",
  293. title: "已核实"
  294. }
  295. }
  296. let mapBottomBoxInnerHtml = `<div class="${state ? statusMap[state].class : 'mapWarning'}">${state ? statusMap[state].title : '未核实'}</div>
  297. <span class="title">${markerData.dataTitle}</span>
  298. <div class="arrowdown" data-state="${state}"><span class="mui-icon mui-icon-arrowdown"></span></div>
  299. <p>位置:${markerData.properties && markerData.properties['镇域名称'] ? markerData.properties['镇域名称'] : '未知'}</p>
  300. <div id="mapImageList">
  301. `;
  302. if (markerData.properties && markerData.properties.fileList) {
  303. getFileListUrl(markerData.properties.fileList).then(res => {
  304. if (res) {
  305. for (let fileBase in res) {
  306. mapBottomBoxInnerHtml +=
  307. `<div><img src="${res[fileBase]}"/></div>`;
  308. }
  309. }
  310. mapBottomBoxInnerHtml += `
  311. ${state == 0 ? `<div id="uploadImage">
  312. <div><span class="mui-icon mui-icon-plus"></span></div>
  313. <div><span>上传照片</span></div>
  314. </div>` : ``}
  315. </div>
  316. <input id="myMarkerId" value="${markerData.id}" />
  317. <div>
  318. <p>描述:</p>
  319. ${state == 1 ? `<span>${desc}</span>` : `<textarea name="" id="mapTextArea" placeholder="请添加描述" cols="30" rows="3" >${desc}</textarea>`}
  320. </div>
  321. ${state == 0 ? `
  322. <div class="displayFlex3">
  323. <div class="paperplaneMyMarker2 openMyPhoneMap" data-lat="${item.latlng.lat}" data-lng="${item.latlng.lng}">导航到这</div>
  324. <div class="paperplane"><span class="mui-icon mui-icon-paperplane"></span>提交</div>
  325. </div>
  326. ` : ``}`;
  327. document.getElementById('mapBottomBox').innerHTML = mapBottomBoxInnerHtml;
  328. document.getElementById('mapBottomBox').style.bottom = "0";
  329. })
  330. } else {
  331. mapBottomBoxInnerHtml += `
  332. ${state == 0 ? `<div id="uploadImage">
  333. <div><span class="mui-icon mui-icon-plus"></span></div>
  334. <div><span>上传照片</span></div>
  335. </div>` : ``}
  336. </div>
  337. <input id="myMarkerId" value="${markerData.id}" />
  338. <div>
  339. <p>描述:</p>
  340. ${state == 1 ? `<span>${desc}</span>` : `<textarea name="" id="mapTextArea" placeholder="请添加描述" cols="30" rows="3" >${desc}</textarea>`}
  341. </div>
  342. ${state == 0 ? `
  343. <div class="displayFlex3">
  344. <div class="paperplaneMyMarker2 openMyPhoneMap" data-lat="${item.latlng.lat}" data-lng="${item.latlng.lng}">导航到这</div>
  345. <div class="paperplane"><span class="mui-icon mui-icon-paperplane"></span>提交</div>
  346. </div>
  347. ` : ``}`;
  348. document.getElementById('mapBottomBox').innerHTML = mapBottomBoxInnerHtml;
  349. document.getElementById('mapBottomBox').style.bottom = "0";
  350. }
  351. }
  352. })
  353. if (item.options.data.name || item.options.data.properties.title || item.options.data.properties.desc) {
  354. item.addTo(map)
  355. .bindPopup(item.options.data.name || item.options.data.properties.title || item.options.data
  356. .properties.desc, {
  357. autoClose: false,
  358. closeOnClick: ""
  359. })
  360. .openPopup();
  361. } else {
  362. item.addTo(map);
  363. }
  364. });
  365. if (center_) {
  366. map.panTo(center_);
  367. }
  368. // 自定义标记页面事件
  369. if (localStorage.getItem("mapTitle") === "自定义标记") {
  370. localStorage.setItem('showMyMarkerBottomBox', 'false');
  371. document.getElementById('addMyMarker').style.display = "flex";
  372. let markerItem = "";
  373. // 地图的点击事件
  374. map.on('click', function(e) {
  375. if (!localStorage.getItem("showMyMarkerBottomBox") || localStorage.getItem("showMyMarkerBottomBox") ==
  376. "false") {
  377. document.getElementById('taskName').innerHTML =
  378. `<p>lat:${e.latlng.lat}</p><p>lng:${e.latlng.lng}</p>`;
  379. document.getElementById('taskName').style.display = "block";
  380. localStorage.setItem("latlngLat", e.latlng.lat - 0.00011);
  381. localStorage.setItem("latlngLng", e.latlng.lng - 0.19195);
  382. if (markerItem) {
  383. markerItem.setLatLng([e.latlng.lat, e.latlng.lng]);
  384. } else {
  385. markerItem = L.marker([e.latlng.lat, e.latlng.lng]);
  386. markerItem.addTo(map);
  387. }
  388. }
  389. })
  390. }
  391. </script>
  392. </html>