viewMap.html 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583
  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. <ul class="layui-tab-title">
  148. <li class="layui-this" lay-id="1">风险点分布图</li>
  149. <li lay-id="3">重大危险源</li>
  150. </ul>
  151. <div class="layui-tab-content">
  152. <div class="layui-hide" id="imgDiv">
  153. </div>
  154. <div class="layui-tab-item layui-show" id="mapDiv">
  155. <div class="right-map" style="height: 700px">
  156. <div class="map-container" id="map"></div>
  157. </div>
  158. </div>
  159. </div>
  160. </div>
  161. </div>
  162. </div>
  163. </div>
  164. </div>
  165. </div>
  166. <!-- js部分 -->
  167. <script type="text/javascript" src="../../../../assets/libs/layui/layui.js"></script>
  168. <script type="text/javascript" src="../../../../assets/js/common.js?v=312"></script>
  169. <script type="text/javascript" src="../../../../assets/libs/jquery/jquery-3.2.1.min.js"></script>
  170. <script src="../../../../assets/libs/leaflet/leaflet.js"></script>
  171. <script src="../../../../assets/libs/leaflet/leaflet-draw/leaflet.draw-src.js"></script>
  172. <script src="../../../../assets/libs/leaflet/leaflet-draw/local.js"></script>
  173. <script src="../../../../assets/libs/leaflet/proj4-compressed.js"></script>
  174. <script src="../../../../assets/libs/leaflet/proj4leaflet.js"></script>
  175. <script>
  176. var imgPath, viewImgPath, map;
  177. var entMapList;
  178. var loadFlag = true;
  179. layui.use(['layer', 'form', 'table', 'util', 'admin', 'zTree', 'uParas', '_groupTree', 'element', 'laydate', 'notice', '_zTree'], function () {
  180. var $ = layui.jquery;
  181. var layer = layui.layer;
  182. var element = layui.element;
  183. var form = layui.form;
  184. var admin = layui.admin;
  185. var uParas = layui.uParas;
  186. var _groupTree = layui._groupTree;
  187. var laydate = layui.laydate;
  188. var notice = layui.notice;
  189. var _zTree = layui._zTree;
  190. var insTb = {
  191. reload: function (obj, p) {
  192. $.getJSON(uParas.baseUrl + "/ent/riskPoint/riskPointLvCount", {gId: $("#groupId").val()}, function (result) {
  193. if (result.code == 1) {
  194. var allCount = 0, lv1Count = 0, lv2Count = 0, lv3Count = 0, lv4Count = 0;
  195. $.each(result.data, function (i, field) {
  196. if (field.riskPointLevel == 1) {
  197. lv1Count = field.lvCount;
  198. }
  199. if (field.riskPointLevel == 2) {
  200. lv2Count = field.lvCount;
  201. }
  202. if (field.riskPointLevel == 3) {
  203. lv3Count = field.lvCount;
  204. }
  205. if (field.riskPointLevel == 4) {
  206. lv4Count = field.lvCount;
  207. }
  208. if (field.riskPointLevel != null) {
  209. allCount += field.lvCount;
  210. }
  211. });
  212. $(".risk_point_dot.level1_").html(lv1Count);
  213. $(".risk_point_dot.level2_").html(lv2Count);
  214. $(".risk_point_dot.level3_").html(lv3Count);
  215. $(".risk_point_dot.level4_").html(lv4Count);
  216. $(".risk_point_dot.level_").html(allCount);
  217. setTimeout(function () {
  218. loadMapData.init(0, uParas, riskPointLevelFunc, _zTree);
  219. }, 1000)
  220. }
  221. });
  222. }
  223. }
  224. _groupTree.init(insTb);
  225. insTb.reload();
  226. var entMapId = uParas.getUrlParam("entMapId");
  227. if (entMapId != null && entMapId != undefined) {
  228. $("#entMapId").val(entMapId);
  229. }
  230. $.getJSON(uParas.baseUrl + "/ent/map/getList", {mapType: 2}, function (result) {
  231. var entMap;
  232. if (result.data != null) {
  233. entMapList = result.data;
  234. if (entMapId != null && entMapId != undefined) {
  235. $.each(result.data, function (i, field) {
  236. if (field.mapId.toString() === entMapId) {
  237. imgPath = field.mapRasterLayer;
  238. uParas.initSimpleSelectX("entMapList", "formFilter", result, "mapName", "mapId", entMapId);
  239. return;
  240. }
  241. });
  242. } else {
  243. entMap = result.data[0];
  244. imgPath = entMap.mapRasterLayer;
  245. uParas.initSimpleSelectX("entMapList", "formFilter", result, "mapName", "mapId", entMap.mapId);
  246. $("#entMapId").val(entMap.mapId);
  247. }
  248. }
  249. });
  250. //监听下拉选择
  251. form.on('select(entMapList)', function (data) {
  252. if (data.value != "") {
  253. $.each(entMapList, function (i, field) {
  254. if (field.mapId.toString() === data.value) {
  255. imgPath = field.mapRasterLayer;
  256. return;
  257. }
  258. });
  259. $("#entMapId").val(data.value);
  260. myBmap.init(form, uParas, riskPointLevelFunc, _zTree);
  261. if ($("#riskPointType").val() == null || $("#riskPointType").val() == "") {
  262. loadMapData.init("0", uParas, riskPointLevelFunc, _zTree);
  263. } else {
  264. loadMapData.init($("#riskPointType").val(), uParas, riskPointLevelFunc, _zTree);
  265. }
  266. }
  267. });
  268. //监听Tab切换,以改变地址hash值
  269. element.on('tab(dangerSource)', function (data) {
  270. var riskPointType = this.getAttribute('lay-id');
  271. if (riskPointType === "1") {
  272. $("#imgDiv").removeClass("layui-show");
  273. $("#imgDiv").addClass("layui-hide");
  274. loadMapData.init("0", uParas, riskPointLevelFunc, _zTree);
  275. $("#riskPointType").val("0");
  276. }
  277. if (riskPointType === "3") {
  278. loadMapData.init("1", uParas, riskPointLevelFunc, _zTree);
  279. $("#mapDiv").addClass("layui-show");
  280. $("#imgDiv").removeClass("layui-show");
  281. $("#imgDiv").addClass("layui-hide");
  282. $("#riskPointType").val("1");
  283. }
  284. });
  285. function riskPointLevelFunc(value) {
  286. var opts = '<div class="riskPointLevel">';
  287. if (value == 1) {
  288. opts += "<div class='notify'><span class='heartbit'></span><span><img src='../../../../assets/images/lv/red.png' style='width: 28px;height: 28px;'/></span></div>";
  289. } else if (value == 2) {
  290. opts += "<img src='../../../../assets/images/lv/orange.png' style='width: 28px;height: 28px;'/>";
  291. } else if (value == 3) {
  292. opts += "<img src='../../../../assets/images/lv/yellow.png' style='width: 28px;height: 28px;'/>";
  293. } else if (value == 4) {
  294. opts += "<img src='../../../../assets/images/lv/blue.png' style='width: 28px;height: 28px;'/>";
  295. } else {
  296. opts += "无";
  297. }
  298. opts += "</div>"
  299. return opts;
  300. }
  301. setTimeout(function(){
  302. myBmap.init(form, uParas, riskPointLevelFunc, _zTree);
  303. }, 1000);
  304. });
  305. var myBmap = {
  306. mapContainer: "map", //地图容器
  307. mapTile: "http://online{s}.map.bdimg.com/tile/?qt=vtile&x={x}&y={y}&z={z}&styles=pl&scaler=2&udt=20181205", //切片图层
  308. myIcon: null, //保存创建的icon
  309. myMarker: null, //保存自己创建marker
  310. myMarkerType: 0, //marker类型
  311. myMarkerId: null, //markerId
  312. isSave: true, //是否保存标记
  313. checkedIcon: null, //保存选中的icon
  314. title: null,
  315. deleteMarkerId: null, //保存删除得markerId
  316. myMarkerGroup: L.layerGroup(),
  317. myMarkerGroupInit: L.layerGroup(),
  318. data: {},
  319. init: function (form, uParas, riskPointLevelFunc, _zTree) {
  320. _form = form;
  321. var _this = this;
  322. //初始化地图
  323. var map_type = 3;
  324. if (map_type == 4) {
  325. baidu_map();
  326. } else {
  327. image_map();
  328. }
  329. // 增加区域绘制工具栏
  330. plotLayer = L.featureGroup(), map.addLayer(plotLayer);
  331. var e = {
  332. position: "topright",
  333. draw: {
  334. polyline: {shapeOptions: {color: "#0000ff", weight: 3}},
  335. polygon: {allowIntersection: !0, showArea: !0, shapeOptions: {color: "#0000ff", weight: 2}},
  336. rectangle: {shapeOptions: {color: "#0000ff", weight: 2}},
  337. circle: false,
  338. circlemarker: false,
  339. marker: false
  340. },
  341. edit: {
  342. featureGroup: plotLayer,
  343. remove: !0,
  344. edit: false
  345. }
  346. }, n = new L.Control.Draw(e);
  347. function draw_createdHandler(t) {
  348. t.layerType;
  349. var o = t.layer;
  350. plotLayer.addLayer(o)
  351. var all = o.toGeoJSON();
  352. var drawIds = $("#drawIds").val();
  353. $("#drawIds").remove();
  354. if (drawIds != undefined) {
  355. drawIds = drawIds + "#" + JSON.stringify(all.geometry.coordinates) + ";" + all.geometry.type;
  356. } else {
  357. drawIds = JSON.stringify(all.geometry.coordinates) + ";" + all.geometry.type
  358. }
  359. $(".my-marker-type").append('<input type="hidden" id="drawIds" name="drawIds" value="' + drawIds + '">');
  360. }
  361. function draw_deletedHandler(t) {
  362. $("#drawIds").remove();
  363. }
  364. //底图为图片
  365. // function image_map() {
  366. // // 地图更换背景图 crs设置
  367. // var yx = L.latLng;
  368. // var xy = function xy(x, y) {
  369. // if (L.Util.isArray(x)) {
  370. // return yx(x[1], x[0]);
  371. // }
  372. // return yx(y, x);
  373. // };
  374. // var bounds = [xy(-600, -600), xy(300, 300)];
  375. // var imgTile = L.imageOverlay(imgPath, bounds);
  376. // map = L.map(_this.mapContainer, {
  377. // crs: L.CRS.Simple,
  378. // center: L.latLng(50.5, 30.5),
  379. // minZoom: 0,
  380. // zoom: 4,
  381. // layers: [imgTile, _this.myMarkerGroup, _this.myMarkerGroupInit],
  382. // attributionControl: true
  383. // });
  384. // map.fitBounds(bounds);
  385. // }
  386. function image_map() {
  387. if (map == undefined || map._loaded == undefined) {
  388. map = L.map(_this.mapContainer, {crs: L.CRS.Simple, center: L.latLng(50.5, 30.5), minZoom: 0, zoom: 4, attributionControl: false});
  389. } else {
  390. loadFlag = false;
  391. }
  392. var yx = L.latLng;
  393. var xy = function xy(x, y) {
  394. if (L.Util.isArray(x)) {
  395. return yx(x[1], x[0]);
  396. }
  397. return yx(y, x);
  398. };
  399. map.eachLayer(function (layer) {
  400. map.removeLayer(layer);
  401. });
  402. map.addLayer(_this.myMarkerGroupInit);
  403. var bounds = [xy(-600, -600), xy(300, 300)];
  404. L.imageOverlay(imgPath, bounds).addTo(map);
  405. map.fitBounds(bounds);
  406. }
  407. //底图为百度地图
  408. function baidu_map() {
  409. var maxZoom = 26;
  410. var crs = new L.Proj.CRS('EPSG:3395',
  411. '+proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs', {
  412. resolutions: function () {
  413. level = 19;
  414. var res = [];
  415. res[0] = Math.pow(2, 18);
  416. for (var i = 1; i < level; i++) {
  417. res[i] = Math.pow(2, (18 - i))
  418. }
  419. return res;
  420. }(),
  421. origin: [0, 0],
  422. bounds: L.bounds([20037508.342789244, 0], [0, 20037508.342789244])
  423. });
  424. var image = new L.TileLayer(_this.mapTile, {
  425. maxZoom: maxZoom,
  426. minZoom: 10,
  427. subdomains: [0, 1, 2],
  428. tms: true
  429. });
  430. map = L.map(_this.mapContainer, {
  431. crs: crs,
  432. layers: [image]
  433. });
  434. map.setView([34.474387, 109.490437], 14);
  435. }
  436. }
  437. }
  438. var loadMapData = {
  439. jobPng: "../../../../assets/images/icon/job.png",
  440. facilityPng: "../../../../assets/images/icon/facility.png",
  441. colorList: [
  442. "rgb(255, 75, 40)",
  443. "rgb(253, 116, 35)",
  444. "rgb(255, 223, 16)",
  445. "rgb(0, 192, 255)",
  446. "rgb(255, 75, 40)",
  447. "rgb(253, 116, 35)"
  448. ],
  449. init: function (type, uParas, riskPointLevelFunc, _zTree) {
  450. var _uParas = uParas;
  451. var riskPointLevelFunc = riskPointLevelFunc;
  452. var _zTree = _zTree;
  453. function icon(imgUrl) {
  454. return L.icon({
  455. iconUrl: imgUrl,
  456. iconSize: [38, 45],
  457. popupAnchor: [0, -16]
  458. });
  459. }
  460. initMapData(type, uParas);
  461. function initMapData(type, uParas) {
  462. var groupId = $("#groupId").val();
  463. // myBmap.myMarkerGroupInit.clearLayers();
  464. var httpUrl = uParas.baseUrl + "/ent/riskPointMap/getRiskPointMap";
  465. if (type == "1") {
  466. httpUrl += "?isWeightyDangerSrc=1";
  467. httpUrl += "&entMapId=" + $("#entMapId").val();
  468. } else {
  469. httpUrl += "?entMapId=" + $("#entMapId").val();
  470. }
  471. myBmap.myMarkerGroupInit.clearLayers();
  472. $.getJSON(httpUrl, {gId: groupId}, function (result) {
  473. if (result.code == 1) {
  474. $.each(result.data, function (index, item) {
  475. var markerData = item.markerData;
  476. if (markerData != null) {
  477. var optionsData = {
  478. mapId: item.id,
  479. riskPointId: item.riskPointId,
  480. title: item.markerTitle
  481. };
  482. optionsData.iconUrl = imgPathFun(item.riskPointLevel);
  483. optionsData.icon = icon(optionsData.iconUrl);
  484. if (item.markerType == 3) {
  485. var data = new Array();
  486. $.each($.parseJSON(markerData), function (index, item) {
  487. data[index] = new Array(item[1], item[0]);
  488. });
  489. optionsData.color = loadMapData.colorList[item.riskPointLevel - 1];
  490. optionsData.fillColor = loadMapData.colorList[item.riskPointLevel - 1];
  491. L.polygon(data, optionsData).addTo(myBmap.myMarkerGroupInit).bindPopup(item.markerTitle).on('click', onMapClick);
  492. } else if (item.markerType == 1) {
  493. if (item.isWeightyDangerSrc == 1) {
  494. optionsData.icon = L.divIcon({
  495. className: "divIcon1",
  496. iconSize: [38, 45],
  497. html: `<div style="width: 100px;height: 100px; margin-top: -27px;margin-left: -31px; display: flex;justify-content: center;align-items: center">
  498. <img class="divIcon" src="../../../../assets/images/icon/zdwxy.png" style="background-color: red" alt="">
  499. </div>`
  500. });
  501. }
  502. L.marker($.parseJSON(markerData), optionsData).addTo(myBmap.myMarkerGroupInit).bindPopup(item.markerTitle).on('click', onMapClick);
  503. } else if (item.markerType == 2) {
  504. var data = new Array();
  505. $.each($.parseJSON(markerData), function (index, item) {
  506. data[index] = new Array(item[1], item[0]);
  507. });
  508. optionsData.color = loadMapData.colorList[item.riskPointLevel - 1];
  509. L.polyline(data, optionsData).addTo(myBmap.myMarkerGroupInit).bindPopup(item.markerTitle).on('click', onMapClick);
  510. }
  511. }
  512. });
  513. }
  514. });
  515. }
  516. function imgPathFun(lv) {
  517. return "../../../../assets/images/lv/lv" + lv + ".png";
  518. }
  519. function onMapClick(e) {
  520. var riskPointId = e.target.options.riskPointId;
  521. var index = layer.open({
  522. type: 2,
  523. zIndex: 1000,
  524. title: "风险点详情",
  525. shadeClose: true,
  526. area: ['650px', '768px'],
  527. content: "../details.html?riskPointId=" + riskPointId + "&type=open",
  528. fixed: false,
  529. maxmin: true
  530. });
  531. layer.full(index);
  532. }
  533. }
  534. }
  535. function iconClick(e) {
  536. $(e).toggleClass('icon-active')
  537. }
  538. </script>
  539. </body>
  540. </html>