coordination.html 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
  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="https://a.amap.com/jsapi_demos/static/demo-center/css/demo-center.css" />
  9. <link rel="stylesheet" type="text/css" href="./js/M_select/M_select.css">
  10. <link rel="stylesheet" type="text/css" href="./js/notification/index.css">
  11. <style>
  12. html,
  13. body,
  14. #mapF {
  15. height: 100%;
  16. width: 100%;
  17. }
  18. </style>
  19. </head>
  20. <body>
  21. <div id="mapF" class="map" tabindex="0"></div>
  22. <div style="padding: 0 10px;">
  23. <div style="position: absolute;top: 0;display:inline-block;width: 50%;padding-top: 10px;">
  24. <select id="selectId" class="select02">
  25. </select>
  26. </div>
  27. </div>
  28. <div id="notification" style="display: none;">
  29. <div class="mask"> </div>
  30. <div class="content"> </div>
  31. </div>
  32. <script src="https://a.amap.com/jsapi_demos/static/china.js"></script>
  33. <script type="text/javascript">
  34. window._AMapSecurityConfig = {
  35. securityJsCode: 'ce0e44758ad6b69607e23bf8e6a6ac11',
  36. }
  37. </script>
  38. <script type="text/javascript" src="https://webapi.amap.com/maps?v=2.0&key=14aefebea926bb958032d5daf836fadf">
  39. </script>
  40. <!-- <script type="text/javascript" src="https://webapi.amap.com/maps?v=2.0&key=8e266e1ac2ad2383c7773ff504ac248f">
  41. </script> -->
  42. <!-- <script src="https://webapi.amap.com/loader.js"></script> -->
  43. <script type="text/javascript" src="https://webapi.amap.com/ui/1.1/main.js"></script>
  44. <script type="text/javascript" src="./js/jquery-2.2.1.min.js"></script>
  45. <script src="./js/M_select/M_select.js"></script>
  46. <script type="text/javascript" src="http://172.16.120.165:13200/assets/map-data.js.js"></script>
  47. <script type="text/javascript" src="./js/map-text.js"></script>
  48. <script type="text/javascript">
  49. var checkedArray = {
  50. checkedData: 1,
  51. checkedList: [{
  52. value: 1,
  53. label: "消防站"
  54. }, {
  55. value: 2,
  56. label: "消防车"
  57. }, {
  58. value: 3,
  59. label: "监控"
  60. }, {
  61. value: 4,
  62. label: "重点单位"
  63. }, {
  64. value: 5,
  65. label: "消火栓/天然水源"
  66. }, ],
  67. } //类型筛选
  68. $.each(checkedArray.checkedList, function(i, item) {
  69. $("#selectId").append(`<option value="${item.value}">${item.label}</option>`)
  70. })
  71. $(function() {
  72. $(".select02").M_select({
  73. // 手动添加下拉款图片(以html页面为起始位置写路径)
  74. "Img": "./js/M_select/up4.png",
  75. "Img2": "./js/M_select/down4.png",
  76. "radius": "15px",
  77. "Title": "--请选择--",
  78. "inputName": "selected_value",
  79. // 默认选中的值(参数值写需要选中的select的value值)
  80. "selected": "1",
  81. Succee: function() {
  82. checkedArray.checkedData = parseInt($(".inputHidden").val())
  83. mapCluster();
  84. }
  85. });
  86. });
  87. //点击遮罩层关闭
  88. $('#notification .mask').on('click', function(e) {
  89. $('#notification').css('display', 'none')
  90. $('#notification .content #xxxx').remove()
  91. })
  92. </script>
  93. <script type="text/javascript">
  94. var cluster, markers = [];
  95. var map = [];
  96. var mapPolList = [];
  97. var colorList = [
  98. ['#99e', "#F33"],
  99. ['#ee6', "#c38"],
  100. ['#c38', "#F33"],
  101. ['#6E7', '#F33'],
  102. ['#6A7', "#F33"],
  103. ['#EF7', "#F33"],
  104. ['#AF7', "#F33"],
  105. ['#BAC', "#F33"],
  106. ['#BEF', "#F33"],
  107. ['#BBB', "#F33"],
  108. ['#EFA', "#F33"],
  109. ['#FE6', "#F33"],
  110. ['#7F6', "#F33"],
  111. ['#7dc', "#F33"],
  112. ];
  113. var colorIndList = [-1, 7, 21, 26, 31, 37, 46, 52, 57, 66, 68, 71, 74, 100]
  114. var polygon1 = null //选中地图区域数据存储
  115. var textList = [] //地图文字数据存储
  116. var streetTown = "" //街镇信息存储
  117. var streetTownList = [{
  118. value: "",
  119. label: "全区"
  120. }, {
  121. value: "华漕镇",
  122. label: "华漕镇"
  123. }, {
  124. value: "虹桥镇",
  125. label: "虹桥镇"
  126. }, {
  127. value: "梅陇镇",
  128. label: "梅陇镇"
  129. }, {
  130. value: "七宝镇",
  131. label: "七宝镇"
  132. }, {
  133. value: "颛桥镇",
  134. label: "颛桥镇"
  135. }, {
  136. value: "马桥镇",
  137. label: "马桥镇"
  138. }, {
  139. value: "吴泾镇",
  140. label: "吴泾镇"
  141. }, {
  142. value: "浦江镇",
  143. label: "浦江镇"
  144. }, {
  145. value: "新虹街道",
  146. label: "新虹街道"
  147. }, {
  148. value: "古美路街道",
  149. label: "古美路街道"
  150. }, {
  151. value: "江川路街道",
  152. label: "江川路街道"
  153. }, {
  154. value: "浦锦街道",
  155. label: "浦锦街道"
  156. }, {
  157. value: "莘庄镇",
  158. label: "莘庄镇"
  159. }, ]
  160. var tankuangXY = {} //撒点弹框坐标
  161. var arrayList = {} //撒点弹框数据存储
  162. function initMap() {
  163. map = new AMap.Map("mapF", {
  164. // mapStyle: 'amap://styles/d0ddc09bd7cbd7331a8e8fa691e5b0da', //设置地图的显示样式
  165. resizeEnable: true,
  166. zoom: 13,
  167. zooms: [3, 16],
  168. });
  169. AMap.plugin(["AMap.Geolocation"], () => {
  170. var geolocation = new AMap.Geolocation({
  171. showButton: false, //是否显示定位按钮
  172. buttonPosition: "RT", //定位按钮的位置
  173. /* LT LB RT RB */
  174. buttonOffset: new AMap.Pixel(10, 20), //定位按钮距离对应角落的距离
  175. zoomToAccuracy: false, //定位成功后调整地图视野范围使定位位置及精度范围视野内可见,默认:false
  176. showMarker: true, //是否显示定位点
  177. markerOptions: {
  178. //自定义定位点样式,同Marker的Options
  179. offset: new AMap.Pixel(-18, -36),
  180. content: '<img src="https://a.amap.com/jsapi_demos/static/resource/img/user.png" style="width:36px;height:36px"/>',
  181. },
  182. convert: true,
  183. showCircle: true, //是否显示定位精度圈
  184. circleOptions: {
  185. //定位精度圈的样式
  186. strokeColor: "#0093FF",
  187. noSelect: true,
  188. strokeOpacity: 0.5,
  189. strokeWeight: 1,
  190. fillColor: "#02B0FF",
  191. fillOpacity: 0.25,
  192. },
  193. });
  194. map.addControl(geolocation);
  195. // geolocation.getCurrentPosition();
  196. });
  197. mapPolList = mapData.map((el, ind) => {
  198. // console.log(val)
  199. let color = colorList[0];
  200. let polygon = new AMap.Polygon({
  201. map: this.map,
  202. zIndex: 2,
  203. fillOpacity: 0.5,
  204. path: el.value,
  205. fillColor: color[0],
  206. strokeColor: color[1],
  207. });
  208. //插入覆盖物自定义数据
  209. polygon.setExtData(el);
  210. //鼠标移入覆盖物事件
  211. polygon.on("mouseover", () => {
  212. polygon.setOptions({
  213. fillOpacity: 0.4,
  214. fillColor: color[1],
  215. });
  216. });
  217. //鼠标移出覆盖物事件
  218. polygon.on("mouseout", (val) => {
  219. if (streetTown) {
  220. if (streetTown == polygon.getExtData().name) {
  221. polygon.setOptions({
  222. fillOpacity: 0.4,
  223. fillColor: color[1],
  224. });
  225. } else {
  226. polygon.setOptions({
  227. fillOpacity: 0.5,
  228. fillColor: color[0],
  229. });
  230. }
  231. } else {
  232. polygon.setOptions({
  233. fillOpacity: 0.5,
  234. fillColor: color[0],
  235. });
  236. }
  237. });
  238. polygon.on("click", (handler, context) => {
  239. if (polygon1) {
  240. //修改上一次选中样式
  241. polygon1.setOptions({
  242. fillOpacity: 0.5,
  243. fillColor: color[0],
  244. });
  245. }
  246. //存储点击区域元素
  247. polygon1 = polygon;
  248. if (streetTown === polygon.getExtData().name) {
  249. //修改全局街镇数据
  250. streetTown = "";
  251. //修改上一次选中样式
  252. polygon1.setOptions({
  253. fillOpacity: 0.5,
  254. fillColor: color[0],
  255. });
  256. polygon1 = null;
  257. } else {
  258. //修改全局街镇数据
  259. streetTown = polygon.getExtData().name;
  260. //修改上一次选中样式
  261. polygon1.setOptions({
  262. fillOpacity: 0.4,
  263. fillColor: color[1],
  264. });
  265. }
  266. mapCluster()
  267. //销毁点位信息弹窗
  268. map.clearInfoWindow();
  269. });
  270. })
  271. mapText.map((val, ind) => {
  272. let text = new AMap.Text({
  273. zIndex: 1,
  274. style: {
  275. color: "black",
  276. backgroundColor: "transparent",
  277. border: "none",
  278. },
  279. position: val.position,
  280. text: val.name,
  281. angle: val.angle,
  282. });
  283. text.setMap(map);
  284. textList.push(text);
  285. });
  286. map.setFitView();
  287. var logMapinfo = function() {
  288. var zoom = map.getZoom(); //获取当前地图级别
  289. var dom = document.getElementsByClassName("amap-overlay-text-container");
  290. for (let i = 0; i <= 13; i++) {
  291. if (zoom > 12) {
  292. dom[i].style.cssText = "display: block;font-size:13px !important;background: transparent;border: 0px;";
  293. } else if (zoom > 10.5 || zoom > 11) {
  294. dom[i].style.cssText = "display: block;font-size:11px !important;background: transparent;border: 0px;";
  295. } else if (zoom < 10) {
  296. dom[i].style.cssText = "display:none !important;font-size:11px;background: transparent;border: 0px;";
  297. }
  298. }
  299. };
  300. map.on("zoomstart", logMapinfo);
  301. }
  302. /**
  303. * @聚合撒点
  304. * @param {数据list} data
  305. * @param {页面类型} pageType
  306. * @param {类型} type
  307. */
  308. function initMarkers(data, pageType, type) {
  309. var _this = this;
  310. var tag = 1; //1.自定义图标 2.完全自定义 3.默认
  311. var style = ""; //地图最大化小图标
  312. var points = []; //地图撒点处理数据存储
  313. if (pageType === "警情综合处置") {
  314. data.forEach((val) => {
  315. points.push({
  316. lnglat: [val.longitude, val.latitude],
  317. array: val
  318. });
  319. });
  320. if (type) {
  321. if (type == 1) {
  322. //消防站
  323. style = `background: url('./img/map1.png') no-repeat; height: 53px; width: 47px; border: 0px !important; border-radius: 0px !important; box-shadow: 0 0 0 0 !important;`;
  324. } else if (type == 2) {
  325. //消防车
  326. style = `background: url('./img/map2.png') no-repeat; height: 53px; width: 47px; border: 0px !important; border-radius: 0px !important; box-shadow: 0 0 0 0 !important;`;
  327. } else if (type == 3) {
  328. //监控
  329. style = `background: url('./img/map3.png') no-repeat; height: 53px; width: 47px; border: 0px !important; border-radius: 0px !important; box-shadow: 0 0 0 0 !important;`;
  330. } else if (type == 4) {
  331. //重点单位
  332. style = `background: url('./img/map4.png') no-repeat; height: 53px; width: 47px; border: 0px !important; border-radius: 0px !important; box-shadow: 0 0 0 0 !important;`;
  333. } else if (type == 5) {
  334. //消火栓/天然水源
  335. style = `background: url('./img/map5.png') no-repeat; height: 53px; width: 47px; border: 0px !important; border-radius: 0px !important; box-shadow: 0 0 0 0 !important;`;
  336. } else if (type == 6) {
  337. //实时告警
  338. style = `background: url('./img/map6.png') no-repeat; height: 53px; width: 47px; border: 0px !important; border-radius: 0px !important; box-shadow: 0 0 0 0 !important;`;
  339. }
  340. } else {
  341. style = `background-color: hsla(180, 100%, 50%, 0.5); height: 24px; width: 24px; border: 1px solid hsl(180, 100%, 40%); border-radius: 12px; box-shadow: hsl(180, 100%, 50%) 0px 0px 1px;`;
  342. }
  343. }
  344. var _renderMarker = function(context) {
  345. var content = `<div style="${style}"></div>`;
  346. var offset = new AMap.Pixel(-9, -9);
  347. context.marker.setContent(content);
  348. context.marker.setOffset(offset);
  349. // 给每个点坐标绑定鼠标经过事件,这里是实现点击功能的重点
  350. context.marker.on("mouseover", (e) => {
  351. tankuangXY = {
  352. x: e.pixel.x,
  353. y: e.pixel.y
  354. };
  355. if (pageType === "警情综合处置") {
  356. if (type !== 6) {
  357. // console.log(context.data[0].array);
  358. }
  359. }
  360. });
  361. context.marker.on("click", (e) => {
  362. if (pageType === "警情综合处置") {
  363. if (type == 1) {
  364. $("#notification .content").append(
  365. `
  366. <div id="xxxx">
  367. <div class="title">${context.data[0].array.stationName}</div>
  368. <div class="borderBottom"></div>
  369. <div class="ctn">
  370. <div style="text-align: center;">经度:${context.data[0].array.longitude}</div>
  371. <div style="text-align: center;">纬度:${context.data[0].array.latitude}</div>
  372. </div>
  373. </div>
  374. `)
  375. $('#notification').css('display', 'block')
  376. } else if (type == 4) {
  377. $("#notification .content").append(
  378. `
  379. <div id="xxxx">
  380. <div class="title">${context.data[0].array.companyName}</div>
  381. <div class="borderBottom"></div>
  382. <div class="ctn">
  383. <div style="width:100%">地址:${context.data[0].array.address}</div>
  384. <div style="width:100%">单位性质:${context.data[0].array.companyTypeName}</div>
  385. </div>
  386. <div class="ctn">
  387. <div >所属街镇:${context.data[0].array.streetTown}</div>
  388. </div>
  389. </div>
  390. `)
  391. $('#notification').css('display', 'block')
  392. } else if (type == 5) {
  393. $("#notification .content").append(
  394. `
  395. <div id="xxxx">
  396. <div class="title">${context.data[0].array.waterName}</div>
  397. <div class="borderBottom"></div>
  398. <div class="ctn">
  399. <div style="width:100%">水源所在位置:${context.data[0].array.waterAddress}</div>
  400. </div>
  401. </div>
  402. `)
  403. $('#notification').css('display', 'block')
  404. } else if (type == 6) {
  405. //实时告警
  406. console.log(context.data[0].array);
  407. }
  408. console.log(context.data[0].array);
  409. }
  410. });
  411. };
  412. if (cluster) {
  413. cluster.setMap(null);
  414. }
  415. if (tag == 2) {
  416. //完全自定义
  417. this.map.plugin(["AMap.MarkerClusterer"], function() {
  418. cluster = new AMap.MarkerCluster(map, points, {
  419. gridSize: 80, // 设置网格像素大小
  420. renderClusterMarker: function(context) {
  421. var factor = Math.pow(context.count / points.length, 1 / 18);
  422. var div = document.createElement("div");
  423. var Hue = 180 - factor * 180;
  424. var bgColor = "hsla(" + Hue + ",100%,40%,0.7)";
  425. var fontColor = "hsla(" + Hue + ",100%,90%,1)";
  426. var borderColor = "hsla(" + Hue + ",100%,40%,1)";
  427. var shadowColor = "hsla(" + Hue + ",100%,90%,1)";
  428. div.style.backgroundColor = bgColor;
  429. var size = Math.round(30 + Math.pow(context.count / points.length, 1 / 5) * 20);
  430. div.style.width = div.style.height = size + "px";
  431. div.style.border = "solid 1px " + borderColor;
  432. div.style.borderRadius = size / 2 + "px";
  433. div.style.boxShadow = "0 0 5px " + shadowColor;
  434. div.innerHTML = context.count;
  435. div.style.lineHeight = size + "px";
  436. div.style.color = fontColor;
  437. div.style.fontSize = "14px";
  438. div.style.textAlign = "center";
  439. context.marker.setOffset(new AMap.Pixel(-size / 2, -size / 2));
  440. context.marker.setContent(div);
  441. }, // 自定义聚合点样式
  442. renderMarker: _renderMarker, // 自定义非聚合点样式
  443. });
  444. });
  445. } else if (tag == 1) {
  446. //自定义图标
  447. var sts = [{
  448. url: "https://a.amap.com/jsapi_demos/static/images/blue.png",
  449. size: new AMap.Size(32, 32),
  450. offset: new AMap.Pixel(-16, -16),
  451. }, {
  452. url: "https://a.amap.com/jsapi_demos/static/images/green.png",
  453. size: new AMap.Size(32, 32),
  454. offset: new AMap.Pixel(-16, -16),
  455. }, {
  456. url: "https://a.amap.com/jsapi_demos/static/images/orange.png",
  457. size: new AMap.Size(36, 36),
  458. offset: new AMap.Pixel(-18, -18),
  459. }, {
  460. url: "https://a.amap.com/jsapi_demos/static/images/red.png",
  461. size: new AMap.Size(48, 48),
  462. offset: new AMap.Pixel(-24, -24),
  463. }, {
  464. url: "https://a.amap.com/jsapi_demos/static/images/darkRed.png",
  465. size: new AMap.Size(48, 48),
  466. offset: new AMap.Pixel(-24, -24),
  467. }, ];
  468. map.plugin(["AMap.MarkerCluster"], function() {
  469. cluster = new AMap.MarkerCluster(map, points, {
  470. styles: sts,
  471. gridSize: 80,
  472. renderMarker: _renderMarker, // 自定义非聚合点样式
  473. });
  474. });
  475. } else {
  476. //默认样式
  477. map.plugin(["AMap.MarkerCluster"], function() {
  478. cluster = new AMap.MarkerCluster(map, points, {
  479. gridSize: 80
  480. });
  481. });
  482. }
  483. }
  484. /**
  485. * @高德地图聚合撒点
  486. */
  487. function mapCluster() {
  488. var label = "";
  489. checkedArray.checkedList.forEach((val) => {
  490. if (val.value == checkedArray.checkedData) {
  491. label = val.label;
  492. }
  493. });
  494. $.get('http://xf.usky.cn:13203/prod-api/service-fire/demPoliceInfo/synthesizePoliceSituationScatterer', {
  495. streetTown: streetTown,
  496. scattererType: label
  497. }, function(res) {
  498. console.log(res)
  499. if (res.data.length > 0) {
  500. initMarkers(res.data, "警情综合处置", checkedArray.checkedData);
  501. } else {
  502. initMarkers([], "警情综合处置", checkedArray.checkedData);
  503. }
  504. })
  505. //
  506. }
  507. initMap();
  508. mapCluster();
  509. </script>
  510. <style>
  511. .amap-logo,
  512. .amap-copyright {
  513. display: none !important;
  514. }
  515. </style>
  516. </body>
  517. </html>