viewMap.html 25 KB

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