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