mapFacilitiesView.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
  7. <title>设施查看</title>
  8. <link rel="stylesheet" href="./css/input.css" />
  9. <link rel="stylesheet" href="./css/common.css" />
  10. <link rel="stylesheet" type="text/css" href="./js/M_select/M_select.css">
  11. <link rel="stylesheet" type="text/css" href="./js/notification/index.css">
  12. <style>
  13. html,
  14. body,
  15. #mapF {
  16. height: 100%;
  17. width: 100%;
  18. }
  19. </style>
  20. <style>
  21. @font-face {
  22. font-family: "iconfont";
  23. /* Project id 3620854 */
  24. src: url('https://at.alicdn.com/t/c/font_3620854_18olo3dgg2h.woff2?t=1691473656726') format('woff2'),
  25. url('https://at.alicdn.com/t/c/font_3620854_18olo3dgg2h.woff?t=1691473656726') format('woff'),
  26. url('https://at.alicdn.com/t/c/font_3620854_18olo3dgg2h.ttf?t=1691473656726') format('truetype');
  27. }
  28. /* 定义使用的样式 iconfont */
  29. .iconfont {
  30. font-family: "iconfont" !important;
  31. font-size: 1rem;
  32. font-style: normal;
  33. -webkit-font-smoothing: antialiased;
  34. -moz-osx-font-smoothing: grayscale;
  35. }
  36. </style>
  37. </head>
  38. <body>
  39. <div id="mapF" class="map" tabindex="0"></div>
  40. <div id="myPageTop">
  41. <!-- <div class="ui-input">
  42. <i class="iconfont icon">&#xe60d;</i>
  43. <input id="uiInput" placeholder="请输入设施名称" />
  44. </div> -->
  45. <div id="myPageRight">
  46. <div class="myPageType" style="text-align: center;">
  47. <i class="iconfont icon" style="font-size: 1.5rem;">&#xe60e;</i>
  48. <div style="font-size: 12px;">设施</div>
  49. </div>
  50. <div style="margin: 5px 0 5px 0;border-bottom: 1px solid #eaeef1;"></div>
  51. <div class="myPageLabel" style="text-align: center;">
  52. <i class="iconfont icon" style="font-size: 1.5rem;">&#xe60e;</i>
  53. <div style="font-size: 12px;">标签</div>
  54. </div>
  55. </div>
  56. <div id="myPageDialog">
  57. <div class="title">设施汇总(0)</div>
  58. <div class="center"></div>
  59. <div class="bottom" style="text-align: center;">
  60. <i class="iconfont icon" style="color: #a8abb2; font-size: 18px;">&#xe63d;</i>
  61. </div>
  62. </div>
  63. </div>
  64. <div class="drawer">
  65. <div class="header">
  66. <div class="title"></div>
  67. <i class="iconfont icon close" style="color: #a8abb2; font-size: 12px;">&#xe695;</i>
  68. </div>
  69. <div class="center">
  70. <img src="" alt="">
  71. <div class="model">
  72. <div class="content">
  73. <i class="iconfont icon" style="color:#0C83FA;font-size: 16px;">&#xe60f;</i>
  74. <div class="address"></div>
  75. </div>
  76. <div class="content">
  77. <i class="iconfont icon" style="color:#01b713;font-size: 16px;">&#xe616;</i>
  78. <div class="facilityType"></div>
  79. </div>
  80. <div class="content">
  81. <i class="iconfont icon" style="color:#ed480e;font-size: 16px;">&#xe617;</i>
  82. <div class="branch"></div>
  83. </div>
  84. </div>
  85. </div>
  86. </div>
  87. <script src="https://a.amap.com/jsapi_demos/static/china.js"></script>
  88. <script type="text/javascript">
  89. window._AMapSecurityConfig = {
  90. securityJsCode: 'ce0e44758ad6b69607e23bf8e6a6ac11',
  91. }
  92. </script>
  93. <script type="text/javascript" src="https://webapi.amap.com/maps?v=2.0&key=14aefebea926bb958032d5daf836fadf">
  94. </script>
  95. <script type="text/javascript" src="https://webapi.amap.com/ui/1.1/main.js"></script>
  96. <script type="text/javascript" src="./js/jquery-2.2.1.min.js"></script>
  97. <!-- uni 的 SDK -->
  98. <!-- 需要把 uni.webview.1.5.4.js 下载到自己的服务器 -->
  99. <script type="text/javascript" src="./js/uni.webview.1.5.4.js"></script>
  100. <script type="text/javascript">
  101. var dataList = [];//初始化数据存储
  102. var dataListCheckBox = [];//初始化数据选中数据存储
  103. var facilityNum = 0;//设施汇总数据存储
  104. var map = [];
  105. var marker = null;//创建点标记
  106. var myPageRight = {
  107. myPageTypeBool: 'none',//设施类型
  108. myPageLabelBool: 'none',//标签
  109. };//右侧小按钮绑定值存储
  110. /**
  111. * 初始化
  112. */
  113. function initMap() {
  114. map = new AMap.Map("mapF", {
  115. // mapStyle: 'amap://styles/d0ddc09bd7cbd7331a8e8fa691e5b0da', //设置地图的显示样式
  116. resizeEnable: true,
  117. center: [121.4737021, 31.2303904],
  118. zoom: 13,
  119. zooms: [3, 16],
  120. });
  121. map.setFitView();
  122. }
  123. /**
  124. * 撒点
  125. */
  126. function handleMarker(data) {
  127. AMap.plugin(["AMap.PolygonEditor,AMap.PolylineEditor", "AMap.Marker"], function () {
  128. map.clearMap(); // 清除地图覆盖物
  129. if (data.length > 0) {
  130. marker = new AMap.Marker({});//初始化点标记
  131. var markerData = data.map((item) => {
  132. return {
  133. position: [Number(item.longitude), Number(item.latitude)],
  134. icon: new AMap.Icon({
  135. image: item.icon || item.typeImg,
  136. size: new AMap.Size(28, 35), //图标大小
  137. imageSize: new AMap.Size(28, 35),
  138. }),
  139. data: item
  140. };
  141. })
  142. for (var i = 0, marker; i < markerData.length; i++) {
  143. marker = new AMap.Marker({
  144. map: map,
  145. icon: markerData[i].icon,
  146. position: markerData[i].position,
  147. offset: new AMap.Pixel(-10, -10),
  148. });
  149. marker.data = markerData[i]
  150. marker.setLabel({
  151. direction: 'top-left',
  152. offset: new AMap.Pixel(-5, -10), //设置文本标注偏移量
  153. content: `<div class='infoLabel'>${marker.data.data.facilityName}</div>`, //设置文本标注内容
  154. });
  155. marker.on('click', function (e) {
  156. var data = e.target.data.data
  157. handleDrawer(data)
  158. });
  159. }
  160. handleRightBtn();
  161. marker.setMap(map);
  162. map.setFitView(null, false, [150, 60, 100, 60]);
  163. }
  164. })
  165. }
  166. /**
  167. * 初始化数据
  168. */
  169. function initData() {
  170. $('#myPageDialog .title').html(`设施汇总(${facilityNum})`)
  171. var html = ``
  172. dataList.forEach(el => {
  173. html += `
  174. <div id="${el.typeCode}" class="center-col" onclick="checkbox(${el.typeCode})">
  175. <div class="image">
  176. <img style="max-width:40px;height:40px;margin: auto;"
  177. src="${el.typeImg}" />
  178. <div class="badge"> ${el.typeFacilityNum >= 100 ? '99+' : el.typeFacilityNum || 0} </div>
  179. </div>
  180. <div style="text-align: center;font-size: 12px;margin-bottom: 5px;">${el.typeName}</div>
  181. </div>
  182. `
  183. });
  184. $('#myPageDialog .center').append(html)
  185. $('#myPageRight .myPageLabel').on('click', function (e) {
  186. if (myPageRight.myPageLabelBool == "none") {
  187. myPageRight.myPageLabelBool = "block";
  188. $('#myPageRight .myPageLabel').css('color', '#2a98ff')
  189. } else {
  190. myPageRight.myPageLabelBool = "none";
  191. $('#myPageRight .myPageLabel').css('color', '#000000')
  192. }
  193. $('.amap-marker-label').css('display', myPageRight.myPageLabelBool)
  194. })
  195. $('#myPageRight .myPageType').on('click', function (e) {
  196. if (myPageRight.myPageTypeBool == "none") {
  197. myPageRight.myPageTypeBool = "block";
  198. $('#myPageRight .myPageType').css('color', '#2a98ff')
  199. } else {
  200. myPageRight.myPageTypeBool = "none";
  201. $('#myPageRight .myPageType').css('color', '#000000')
  202. }
  203. $('#myPageDialog').css('display', myPageRight.myPageTypeBool)
  204. })
  205. var display = "flex"
  206. $('#myPageDialog .bottom').on('click', function (e) {
  207. if (display == "none") {
  208. $('#myPageDialog .bottom').css('transform', 'rotate(-180deg)')
  209. display = "flex"
  210. } else {
  211. $('#myPageDialog .bottom').css('transform', 'rotate(0deg)')
  212. display = "none"
  213. }
  214. $('#myPageDialog .center').css('display', display)
  215. })
  216. initMap()
  217. }
  218. /**
  219. * 校验右侧小按钮
  220. */
  221. function handleRightBtn() {
  222. if (myPageRight.myPageLabelBool == 'block') {
  223. // $('#myPageRight .myPageLabel').trigger('click')
  224. $('.amap-marker-label').css('display', myPageRight.myPageLabelBool)
  225. }
  226. }
  227. /**
  228. * 复选事件
  229. */
  230. function checkbox(typeCode) {
  231. if (dataListCheckBox.includes(typeCode)) {
  232. dataListCheckBox.splice(dataListCheckBox.indexOf(typeCode), 1);
  233. $(`#${typeCode}`).attr('class', 'center-col')
  234. } else {
  235. dataListCheckBox.push(typeCode)
  236. $(`#${typeCode}`).attr('class', 'center-col mask')
  237. }
  238. parentMessage("撒点", dataListCheckBox.join(','));
  239. }
  240. /*
  241. * 抽屉事件
  242. */
  243. function handleDrawer(data) {
  244. $(`.drawer`).attr('class', 'drawer open')
  245. $(`.drawer .header .title`).html(data.facilityName)
  246. $(`.drawer .center img`).attr("src", data.imagesUrl ? data.imagesUrl : "../images/404.png")
  247. $(`.drawer .center .model .content .address`).html(data.address)
  248. $(`.drawer .center .model .content .facilityType`).html(data.typeName)
  249. $(`.drawer .center .model .content .branch`).html(data.deptId)
  250. $(`.drawer .header .close`).on('click', function (e) {
  251. $(`.drawer`).attr('class', 'drawer')
  252. })
  253. }
  254. /**
  255. * 向父页面发送数据
  256. */
  257. function parentMessage(type, data) {
  258. var message = {
  259. funcName: type,
  260. param: data,
  261. };
  262. //APP-PLUS
  263. uni.postMessage({
  264. data: message
  265. });
  266. //H5
  267. if (window.parent) {
  268. window.parent.postMessage(message, '*');
  269. }
  270. }
  271. /**
  272. * APP-PLUS || H5
  273. * 接收父页面传过来的值
  274. */
  275. window.receiveData = function (msg) {
  276. analysisData(msg)
  277. }
  278. window.addEventListener("message", function (event) {
  279. analysisData(event.data)
  280. });
  281. /**
  282. * 解析数据
  283. */
  284. function analysisData(data) {
  285. if ("funcName" in data) {
  286. if (data.funcName == "初始化") {
  287. var param = JSON.parse(data.param);
  288. dataList = param.baseGgpFacilityTypeNumVO;
  289. facilityNum = param.facilityNum;
  290. initData();
  291. } else if (data.funcName == "撒点") {
  292. var param = JSON.parse(data.param);
  293. param.forEach((e) => {
  294. dataList.forEach(el => {
  295. if (e.facilityType === el.typeCode) {
  296. e.typeImg = el.typeImg
  297. e.typeName = el.typeName
  298. }
  299. });
  300. })
  301. handleMarker(param)
  302. }
  303. }
  304. }
  305. </script>
  306. <style>
  307. #myPageTop {
  308. position: absolute;
  309. left: 8px;
  310. top: 8px;
  311. background: transparent;
  312. font-family: "Microsoft Yahei", "微软雅黑", "Pinghei";
  313. font-size: 13px;
  314. width: calc(100% - 16px);
  315. }
  316. #myPageRight {
  317. position: absolute;
  318. right: 0px;
  319. background-color: #fff;
  320. margin-top: 8px;
  321. padding: 5px;
  322. border-radius: 10px;
  323. box-shadow: 0px 0px 5px 0px rgba(141, 141, 141, 0.4);
  324. }
  325. #myPageTop #myPageDialog {
  326. position: absolute;
  327. right: calc(34px + 8px);
  328. width: 14rem;
  329. width: calc(100% - 34px - 8px);
  330. padding: 10px 10px 5px 10px;
  331. margin-top: 8px;
  332. background: #fff;
  333. box-shadow: 0px 0px 5px 0px rgba(141, 141, 141, 0.4);
  334. display: none;
  335. }
  336. #myPageTop #myPageDialog .title {
  337. font-weight: 600;
  338. text-align: center;
  339. margin-bottom: 10px;
  340. }
  341. #myPageTop #myPageDialog .center {
  342. display: flex;
  343. max-height: 260px;
  344. overflow: auto;
  345. flex-wrap: wrap;
  346. }
  347. #myPageTop #myPageDialog .center .mask {
  348. border-radius: 4px;
  349. background: #c2ddf6;
  350. }
  351. #myPageTop #myPageDialog .center .center-col {
  352. /* max-width: calc(25% - 2.5px);
  353. flex: 0 0 calc(25% - 2.5px); */
  354. max-width: calc(25% - 3.75px);
  355. flex: 0 0 calc(25% - 3.75px);
  356. margin: 0px 5px 5px 0;
  357. }
  358. #myPageTop #myPageDialog .center .center-col:nth-child(4n) {
  359. margin-right: 0;
  360. }
  361. #myPageTop #myPageDialog .center .center-col .image {
  362. position: relative;
  363. display: flex;
  364. margin: 15px 0 5px 0;
  365. }
  366. #myPageTop #myPageDialog .bottom {
  367. transform: rotate(-180deg);
  368. }
  369. </style>
  370. </body>
  371. </html>