viewMHIMap.html 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8"/>
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  6. <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  7. <title>重大风险点分布图</title>
  8. <link rel="stylesheet" href="../../../../assets/libs/layui/css/layui.css"/>
  9. <link rel="stylesheet" href="../../../../assets/module/admin.css?v=312"/>
  10. <link rel="stylesheet" href="../../../../assets/css/editormap.css?v=312"/>
  11. <link rel="stylesheet" type="text/css" href="../../../../assets/libs/leaflet/leaflet-draw/leaflet.draw-src.css">
  12. <link rel="stylesheet" type="text/css" href="../../../../assets/libs/leaflet/leaflet.css">
  13. <link rel="stylesheet" href="../../../../assets/module/formSelects/formSelects-v4.css"/>
  14. <!--[if lt IE 9]>
  15. <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  16. <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  17. <![endif]-->
  18. <style>
  19. .risk_point_dot {
  20. width: 30px;
  21. height: 30px;
  22. border-radius: 15px !important;
  23. text-align: center;
  24. color: #fff;
  25. vertical-align: middle;
  26. display: table-cell;
  27. }
  28. .level_ {
  29. background-color: #0b0b0b;
  30. }
  31. .level1_ {
  32. background-color: red;
  33. }
  34. .level2_ {
  35. background-color: #FB7437;
  36. }
  37. .level3_ {
  38. background-color: #FFDC44;
  39. }
  40. .level4_ {
  41. background-color: #14C2FB;
  42. }
  43. .risk_point_text {
  44. display: table-cell;
  45. vertical-align: middle;
  46. height: 30px;
  47. padding-left: 10px;
  48. }
  49. .info li {
  50. font-size: 15px;
  51. color: #222;
  52. line-height: 29px;
  53. margin-top: 10px;
  54. }
  55. .divIcon {
  56. width: 15px;
  57. height: 15px;
  58. border-radius: 50%;
  59. animation: myfirst 0.8s infinite;
  60. }
  61. @keyframes myfirst {
  62. 0% {
  63. border: 5px solid rgba(255, 0, 0, 1);
  64. }
  65. 25% {
  66. border: 5px solid rgba(255, 0, 0, 0.8);
  67. }
  68. 50% {
  69. border: 7px solid rgba(255, 0, 0, 0.6);
  70. }
  71. 75% {
  72. border: 9px solid rgba(255, 0, 0, 0.4);
  73. }
  74. 100% {
  75. border: 10px solid rgba(255, 0, 0, 0);
  76. }
  77. }
  78. </style>
  79. </head>
  80. <body>
  81. <!-- 页面加载loading -->
  82. <div class="page-loading">
  83. <div class="ball-loader">
  84. <span></span><span></span><span></span><span></span>
  85. </div>
  86. </div>
  87. <!-- 正文开始 -->
  88. <div class="layui-fluid">
  89. <div class="layui-card">
  90. <div class="layui-card-header">
  91. 重大危险源分布图
  92. </div>
  93. <div class="layui-card-body">
  94. <div class="layui-form toolbar" lay-filter="formFilter">
  95. <div class="layui-row">
  96. <div class="layui-col-md4">
  97. <div class="layui-form-item">
  98. <div class="layui-inline">
  99. <label class="layui-form-label w-auto w-padding">部门:</label>
  100. <div class="layui-input-inline mr0">
  101. <input type="text" id="groupName" name="groupName" value=""
  102. placeholder="点击选择"
  103. class="layui-input" readonly>
  104. <input type="hidden" id="groupId" name="groupId">
  105. <div id="menuContent" class="menuContent">
  106. <ul id="groupTree" class="ztree" style="margin-top:0;"></ul>
  107. </div>
  108. </div>
  109. <div class="layui-inline mr0">
  110. <label class="layui-form-label w-auto w-padding">选择背景图:</label>
  111. <div class="layui-input-inline mr0">
  112. <select id="entMapList" name="entMapList" lay-filter="entMapList" lay-verType="tips" class="layui-input-block">
  113. <option value="">选择背景图</option>
  114. </select>
  115. </div>
  116. </div>
  117. </div>
  118. </div>
  119. </div>
  120. <div class="layui-col-md1">
  121. <span class="risk_point_text">总计&nbsp;&nbsp;</span>
  122. <div class="risk_point_dot level_">0</div>
  123. </div>
  124. <div class="layui-col-md1">
  125. <span class="risk_point_text">重大&nbsp;&nbsp;</span>
  126. <div class="risk_point_dot level1_">0</div>
  127. </div>
  128. <div class="layui-col-md1">
  129. <span class="risk_point_text">较大&nbsp;&nbsp;</span>
  130. <div class="risk_point_dot level2_">0</div>
  131. </div>
  132. <div class="layui-col-md1">
  133. <span class="risk_point_text">一般&nbsp;&nbsp;</span>
  134. <div class="risk_point_dot level3_">0</div>
  135. </div>
  136. <div class="layui-col-md1">
  137. <span class="risk_point_text">较低&nbsp;&nbsp;</span>
  138. <div class="risk_point_dot level4_">0</div>
  139. </div>
  140. </div>
  141. </div>
  142. <div class="layui-row">
  143. <input type="hidden" name="entMapId" id="entMapId">
  144. <div class="layui-col-xs6 layui-col-sm6 layui-col-md12">
  145. <div class="layui-tab layui-tab-card" lay-filter="dangerSource">
  146. <input type="hidden" name="riskPointType" id="riskPointType">
  147. <div class="layui-tab-content">
  148. <div class="layui-hide" id="imgDiv">
  149. </div>
  150. <div class="layui-tab-item layui-show" id="mapDiv">
  151. <div class="right-map" style="height: 700px">
  152. <div class="map-container" id="map"></div>
  153. </div>
  154. </div>
  155. </div>
  156. </div>
  157. </div>
  158. </div>
  159. </div>
  160. </div>
  161. </div>
  162. <!-- js部分 -->
  163. <script type="text/javascript" src="../../../../assets/libs/layui/layui.js"></script>
  164. <script type="text/javascript" src="../../../../assets/js/common.js?v=312"></script>
  165. <script type="text/javascript" src="../../../../assets/libs/jquery/jquery-3.2.1.min.js"></script>
  166. <script src="../../../../assets/libs/leaflet/leaflet.js"></script>
  167. <script src="../../../../assets/libs/leaflet/leaflet-draw/leaflet.draw-src.js"></script>
  168. <script src="../../../../assets/libs/leaflet/leaflet-draw/local.js"></script>
  169. <script src="../../../../assets/libs/leaflet/proj4-compressed.js"></script>
  170. <script src="../../../../assets/libs/leaflet/proj4leaflet.js"></script>
  171. <script>
  172. var imgPath, viewImgPath, map;
  173. var entMapList;
  174. var loadFlag = true;
  175. layui.use(['layer', 'form', 'table', 'util', 'admin', 'zTree', 'uParas', '_groupTree', 'element', 'laydate', 'notice', '_zTree'], function () {
  176. var $ = layui.jquery;
  177. var layer = layui.layer;
  178. var element = layui.element;
  179. var form = layui.form;
  180. var admin = layui.admin;
  181. var uParas = layui.uParas;
  182. var _groupTree = layui._groupTree;
  183. var laydate = layui.laydate;
  184. var notice = layui.notice;
  185. var _zTree = layui._zTree;
  186. var insTb = {
  187. reload: function (obj, p) {
  188. $.getJSON(uParas.baseUrl + "/ent/riskPoint/riskPointLvCount", {gId: $("#groupId").val()}, function (result) {
  189. if (result.code == 1) {
  190. var allCount = 0, lv1Count = 0, lv2Count = 0, lv3Count = 0, lv4Count = 0;
  191. $.each(result.data, function (i, field) {
  192. if (field.riskPointLevel == 1) {
  193. lv1Count = field.lvCount;
  194. }
  195. if (field.riskPointLevel == 2) {
  196. lv2Count = field.lvCount;
  197. }
  198. if (field.riskPointLevel == 3) {
  199. lv3Count = field.lvCount;
  200. }
  201. if (field.riskPointLevel == 4) {
  202. lv4Count = field.lvCount;
  203. }
  204. if (field.riskPointLevel != null) {
  205. allCount += field.lvCount;
  206. }
  207. });
  208. $(".risk_point_dot.level1_").html(lv1Count);
  209. $(".risk_point_dot.level2_").html(lv2Count);
  210. $(".risk_point_dot.level3_").html(lv3Count);
  211. $(".risk_point_dot.level4_").html(lv4Count);
  212. $(".risk_point_dot.level_").html(allCount);
  213. setTimeout(function () {
  214. loadMapData.init(0, uParas, riskPointLevelFunc, _zTree);
  215. }, 1000)
  216. }
  217. });
  218. }
  219. }
  220. _groupTree.init(insTb);
  221. insTb.reload();
  222. var entMapId = uParas.getUrlParam("entMapId");
  223. if (entMapId != null && entMapId != undefined) {
  224. $("#entMapId").val(entMapId);
  225. }
  226. $.getJSON(uParas.baseUrl + "/ent/map/getList", {mapType: 2}, function (result) {
  227. var entMap;
  228. if (result.data != null) {
  229. entMapList = result.data;
  230. if (entMapId != null && entMapId != undefined) {
  231. $.each(result.data, function (i, field) {
  232. if (field.mapId.toString() === entMapId) {
  233. imgPath = field.mapRasterLayer;
  234. uParas.initSimpleSelectX("entMapList", "formFilter", result, "mapName", "mapId", entMapId);
  235. return;
  236. }
  237. });
  238. } else {
  239. entMap = result.data[0];
  240. imgPath = entMap.mapRasterLayer;
  241. uParas.initSimpleSelectX("entMapList", "formFilter", result, "mapName", "mapId", entMap.mapId);
  242. $("#entMapId").val(entMap.mapId);
  243. }
  244. }
  245. });
  246. //监听下拉选择
  247. form.on('select(entMapList)', function (data) {
  248. if (data.value != "") {
  249. $.each(entMapList, function (i, field) {
  250. if (field.mapId.toString() === data.value) {
  251. imgPath = field.mapRasterLayer;
  252. return;
  253. }
  254. });
  255. $("#entMapId").val(data.value);
  256. myBmap.init(form, uParas, riskPointLevelFunc, _zTree);
  257. loadMapData.init("1", uParas, riskPointLevelFunc, _zTree);
  258. }
  259. });
  260. //监听Tab切换,以改变地址hash值
  261. element.on('tab(dangerSource)', function (data) {
  262. var riskPointType = this.getAttribute('lay-id');
  263. if (riskPointType === "1") {
  264. $("#imgDiv").removeClass("layui-show");
  265. $("#imgDiv").addClass("layui-hide");
  266. loadMapData.init("0", uParas, riskPointLevelFunc, _zTree);
  267. $("#riskPointType").val("0");
  268. }
  269. if (riskPointType === "3") {
  270. loadMapData.init("1", uParas, riskPointLevelFunc, _zTree);
  271. $("#mapDiv").addClass("layui-show");
  272. $("#imgDiv").removeClass("layui-show");
  273. $("#imgDiv").addClass("layui-hide");
  274. $("#riskPointType").val("1");
  275. }
  276. });
  277. function riskPointLevelFunc(value) {
  278. var opts = '<div class="riskPointLevel">';
  279. if (value == 1) {
  280. opts += "<div class='notify'><span class='heartbit'></span><span><img src='../../../../assets/images/lv/red.png' style='width: 28px;height: 28px;'/></span></div>";
  281. } else if (value == 2) {
  282. opts += "<img src='../../../../assets/images/lv/orange.png' style='width: 28px;height: 28px;'/>";
  283. } else if (value == 3) {
  284. opts += "<img src='../../../../assets/images/lv/yellow.png' style='width: 28px;height: 28px;'/>";
  285. } else if (value == 4) {
  286. opts += "<img src='../../../../assets/images/lv/blue.png' style='width: 28px;height: 28px;'/>";
  287. } else {
  288. opts += "无";
  289. }
  290. opts += "</div>"
  291. return opts;
  292. }
  293. setTimeout(function () {
  294. myBmap.init(form, uParas, riskPointLevelFunc, _zTree);
  295. }, 1000);
  296. });
  297. var myBmap = {
  298. mapContainer: "map", //地图容器
  299. mapTile: "http://online{s}.map.bdimg.com/tile/?qt=vtile&x={x}&y={y}&z={z}&styles=pl&scaler=2&udt=20181205", //切片图层
  300. myIcon: null, //保存创建的icon
  301. myMarker: null, //保存自己创建marker
  302. myMarkerType: 0, //marker类型
  303. myMarkerId: null, //markerId
  304. isSave: true, //是否保存标记
  305. checkedIcon: null, //保存选中的icon
  306. title: null,
  307. deleteMarkerId: null, //保存删除得markerId
  308. myMarkerGroup: L.layerGroup(),
  309. myMarkerGroupInit: L.layerGroup(),
  310. data: {},
  311. init: function (form, uParas, riskPointLevelFunc, _zTree) {
  312. _form = form;
  313. var _this = this;
  314. //初始化地图
  315. var map_type = 3;
  316. if (map_type == 4) {
  317. baidu_map();
  318. } else {
  319. image_map();
  320. }
  321. // 增加区域绘制工具栏
  322. plotLayer = L.featureGroup(), map.addLayer(plotLayer);
  323. var e = {
  324. position: "topright",
  325. draw: {
  326. polyline: {shapeOptions: {color: "#0000ff", weight: 3}},
  327. polygon: {allowIntersection: !0, showArea: !0, shapeOptions: {color: "#0000ff", weight: 2}},
  328. rectangle: {shapeOptions: {color: "#0000ff", weight: 2}},
  329. circle: false,
  330. circlemarker: false,
  331. marker: false
  332. },
  333. edit: {
  334. featureGroup: plotLayer,
  335. remove: !0,
  336. edit: false
  337. }
  338. }, n = new L.Control.Draw(e);
  339. function draw_createdHandler(t) {
  340. t.layerType;
  341. var o = t.layer;
  342. plotLayer.addLayer(o)
  343. var all = o.toGeoJSON();
  344. var drawIds = $("#drawIds").val();
  345. $("#drawIds").remove();
  346. if (drawIds != undefined) {
  347. drawIds = drawIds + "#" + JSON.stringify(all.geometry.coordinates) + ";" + all.geometry.type;
  348. } else {
  349. drawIds = JSON.stringify(all.geometry.coordinates) + ";" + all.geometry.type
  350. }
  351. $(".my-marker-type").append('<input type="hidden" id="drawIds" name="drawIds" value="' + drawIds + '">');
  352. }
  353. function draw_deletedHandler(t) {
  354. $("#drawIds").remove();
  355. }
  356. //底图为图片
  357. // function image_map() {
  358. // // 地图更换背景图 crs设置
  359. // var yx = L.latLng;
  360. // var xy = function xy(x, y) {
  361. // if (L.Util.isArray(x)) {
  362. // return yx(x[1], x[0]);
  363. // }
  364. // return yx(y, x);
  365. // };
  366. // var bounds = [xy(-600, -600), xy(300, 300)];
  367. // var imgTile = L.imageOverlay(imgPath, bounds);
  368. // map = L.map(_this.mapContainer, {
  369. // crs: L.CRS.Simple,
  370. // center: L.latLng(50.5, 30.5),
  371. // minZoom: 0,
  372. // zoom: 4,
  373. // layers: [imgTile, _this.myMarkerGroup, _this.myMarkerGroupInit],
  374. // attributionControl: true
  375. // });
  376. // map.fitBounds(bounds);
  377. // }
  378. function image_map() {
  379. if (map == undefined || map._loaded == undefined) {
  380. map = L.map(_this.mapContainer, {crs: L.CRS.Simple, center: L.latLng(50.5, 30.5), minZoom: 0, zoom: 4, attributionControl: false});
  381. } else {
  382. loadFlag = false;
  383. }
  384. var yx = L.latLng;
  385. var xy = function xy(x, y) {
  386. if (L.Util.isArray(x)) {
  387. return yx(x[1], x[0]);
  388. }
  389. return yx(y, x);
  390. };
  391. map.eachLayer(function (layer) {
  392. map.removeLayer(layer);
  393. });
  394. map.addLayer(_this.myMarkerGroupInit);
  395. var bounds = [xy(-600, -600), xy(300, 300)];
  396. L.imageOverlay(imgPath, bounds).addTo(map);
  397. map.fitBounds(bounds);
  398. }
  399. //底图为百度地图
  400. function baidu_map() {
  401. var maxZoom = 26;
  402. var crs = new L.Proj.CRS('EPSG:3395',
  403. '+proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs', {
  404. resolutions: function () {
  405. level = 19;
  406. var res = [];
  407. res[0] = Math.pow(2, 18);
  408. for (var i = 1; i < level; i++) {
  409. res[i] = Math.pow(2, (18 - i))
  410. }
  411. return res;
  412. }(),
  413. origin: [0, 0],
  414. bounds: L.bounds([20037508.342789244, 0], [0, 20037508.342789244])
  415. });
  416. var image = new L.TileLayer(_this.mapTile, {
  417. maxZoom: maxZoom,
  418. minZoom: 10,
  419. subdomains: [0, 1, 2],
  420. tms: true
  421. });
  422. map = L.map(_this.mapContainer, {
  423. crs: crs,
  424. layers: [image]
  425. });
  426. map.setView([34.474387, 109.490437], 14);
  427. }
  428. }
  429. }
  430. var loadMapData = {
  431. jobPng: "../../../../assets/images/icon/job.png",
  432. facilityPng: "../../../../assets/images/icon/facility.png",
  433. colorList: [
  434. "rgb(255, 75, 40)",
  435. "rgb(253, 116, 35)",
  436. "rgb(255, 223, 16)",
  437. "rgb(0, 192, 255)",
  438. "rgb(255, 75, 40)",
  439. "rgb(253, 116, 35)"
  440. ],
  441. init: function (type, uParas, riskPointLevelFunc, _zTree) {
  442. var _uParas = uParas;
  443. var riskPointLevelFunc = riskPointLevelFunc;
  444. var _zTree = _zTree;
  445. function icon(imgUrl) {
  446. return L.icon({
  447. iconUrl: imgUrl,
  448. iconSize: [38, 45],
  449. popupAnchor: [0, -16]
  450. });
  451. }
  452. initMapData(type, uParas);
  453. function initMapData(type, uParas) {
  454. var groupId = $("#groupId").val();
  455. // myBmap.myMarkerGroupInit.clearLayers();
  456. var httpUrl = uParas.baseUrl + "/ent/riskPointMap/getRiskPointMap";
  457. if (type == "1") {
  458. httpUrl += "?isWeightyDangerSrc=1";
  459. httpUrl += "&entMapId=" + $("#entMapId").val();
  460. } else {
  461. httpUrl += "?entMapId=" + $("#entMapId").val();
  462. }
  463. myBmap.myMarkerGroupInit.clearLayers();
  464. $.getJSON(httpUrl, {gId: groupId}, function (result) {
  465. if (result.code == 1) {
  466. $.each(result.data, function (index, item) {
  467. var markerData = item.markerData;
  468. if (markerData != null) {
  469. var optionsData = {
  470. mapId: item.id,
  471. riskPointId: item.riskPointId,
  472. title: item.markerTitle
  473. };
  474. optionsData.iconUrl = imgPathFun(item.riskPointLevel);
  475. optionsData.icon = icon(optionsData.iconUrl);
  476. if (item.markerType == 3) {
  477. var data = new Array();
  478. $.each($.parseJSON(markerData), function (index, item) {
  479. data[index] = new Array(item[1], item[0]);
  480. });
  481. optionsData.color = loadMapData.colorList[item.riskPointLevel - 1];
  482. optionsData.fillColor = loadMapData.colorList[item.riskPointLevel - 1];
  483. L.polygon(data, optionsData).addTo(myBmap.myMarkerGroupInit).bindPopup(item.markerTitle).on('click', onMapClick);
  484. } else if (item.markerType == 1) {
  485. if (item.isWeightyDangerSrc == 1) {
  486. optionsData.icon = L.divIcon({
  487. className: "divIcon1",
  488. iconSize: [38, 45],
  489. html: `<div style="width: 100px;height: 100px; margin-top: -27px;margin-left: -31px; display: flex;justify-content: center;align-items: center">
  490. <img class="divIcon" src="../../../../assets/images/icon/zdwxy.png" style="background-color: red" alt="">
  491. </div>`
  492. });
  493. }
  494. L.marker($.parseJSON(markerData), optionsData).addTo(myBmap.myMarkerGroupInit).bindPopup(item.markerTitle).on('click', onMapClick);
  495. } else if (item.markerType == 2) {
  496. var data = new Array();
  497. $.each($.parseJSON(markerData), function (index, item) {
  498. data[index] = new Array(item[1], item[0]);
  499. });
  500. optionsData.color = loadMapData.colorList[item.riskPointLevel - 1];
  501. L.polyline(data, optionsData).addTo(myBmap.myMarkerGroupInit).bindPopup(item.markerTitle).on('click', onMapClick);
  502. }
  503. }
  504. });
  505. }
  506. });
  507. }
  508. function imgPathFun(lv) {
  509. return "../../../../assets/images/lv/lv" + lv + ".png";
  510. }
  511. function onMapClick(e) {
  512. var riskPointId = e.target.options.riskPointId;
  513. var index = layer.open({
  514. type: 2,
  515. zIndex: 1000,
  516. title: "风险点详情",
  517. shadeClose: true,
  518. area: ['650px', '768px'],
  519. content: "../details.html?riskPointId=" + riskPointId + "&type=open",
  520. fixed: false,
  521. maxmin: true
  522. });
  523. layer.full(index);
  524. }
  525. }
  526. }
  527. function iconClick(e) {
  528. $(e).toggleClass('icon-active')
  529. }
  530. </script>
  531. </body>
  532. </html>