coordination.html 22 KB

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