index.html 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093
  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. <style>
  15. .risk_point_dot {
  16. width: 30px;
  17. height: 30px;
  18. border-radius: 15px !important;
  19. text-align: center;
  20. color: #fff;
  21. vertical-align: middle;
  22. display: table-cell;
  23. }
  24. .level_ {
  25. background-color: #0b0b0b;
  26. }
  27. .level1_ {
  28. background-color: red;
  29. }
  30. .level2_ {
  31. background-color: #FB7437;
  32. }
  33. .level3_ {
  34. background-color: #FFDC44;
  35. }
  36. .level4_ {
  37. background-color: #14C2FB;
  38. }
  39. .risk_point_text {
  40. display: table-cell;
  41. vertical-align: middle;
  42. height: 30px;
  43. padding-left: 10px;
  44. }
  45. .info li {
  46. font-size: 15px;
  47. color: #222;
  48. line-height: 29px;
  49. margin-top: 10px;
  50. }
  51. .layui-layer-content {
  52. overflow: auto !important;
  53. }
  54. </style>
  55. </head>
  56. <body>
  57. <!-- 页面加载loading -->
  58. <div class="page-loading">
  59. <div class="ball-loader">
  60. <span></span><span></span><span></span><span></span>
  61. </div>
  62. </div>
  63. <!-- 正文开始 -->
  64. <div class="layui-fluid">
  65. <div class="layui-card">
  66. <div class="layui-card-header">
  67. 可视化编辑
  68. </div>
  69. <div class="layui-card-body">
  70. <div class="layui-form toolbar" lay-filter="formFilter">
  71. <div class="layui-row">
  72. <div class="layui-col-md5">
  73. <div class="layui-form-item">
  74. <div class="layui-inline">
  75. <label class="layui-form-label w-auto w-padding">选择背景图:</label>
  76. <div class="layui-input-inline mr0">
  77. <select id="entMapList" name="entMapList" lay-filter="entMapList" lay-verType="tips"
  78. class="layui-input-block">
  79. <option value="">选择背景图</option>
  80. </select>
  81. </div>
  82. </div>
  83. </div>
  84. </div>
  85. <div class="col-md-2 pull-right">
  86. <a id="showUploadDlg1" class="layui-link" href="javascript:;">➕更换地图背景</a>
  87. </div>
  88. </div>
  89. </div>
  90. <div class="layui-row">
  91. <div class="layui-col-xs6 layui-col-sm6 layui-col-md2">
  92. <div class="layui-tab layui-tab-card" lay-filter="dangerSource" style="height: 715px;overflow:auto">
  93. <!-- <ul class="layui-tab-title">-->
  94. <!-- <li class="layui-this" lay-id="1">设备设施</li>-->
  95. <!-- <li lay-id="2">作业活动</li>-->
  96. <!-- </ul>-->
  97. <div class="layui-tab-content" style="height: 655px;">
  98. <div class="layui-tab-item layui-show">
  99. <ul id="facilityIconList" class="icon-box-ul">
  100. </ul>
  101. </div>
  102. <div class="layui-tab-item">
  103. <ul id="jobIconList" class="icon-box-ul">
  104. </ul>
  105. </div>
  106. </div>
  107. </div>
  108. </div>
  109. <div class="layui-col-xs6 layui-col-sm6 layui-col-md8">
  110. <div class="right-map" style="height: 715px">
  111. <div class="map-container" id="map"></div>
  112. </div>
  113. </div>
  114. <div class="layui-col-xs4 layui-col-sm12 layui-col-md2">
  115. <div class="icon-form-box" style="display: none">
  116. <form class="layui-form">
  117. <input type="hidden" name="entMapId" id="entMapId">
  118. <div class="my-form-group">
  119. <h3 class="riskp-detail">风险点基本信息:</h3>
  120. <div class="my-form-item">
  121. <label>站点信息:</label>
  122. <div id="my-marker">
  123. </div>
  124. <div id="my-marker-title">
  125. </div>
  126. </div>
  127. <div class="my-form-item">
  128. <label for="riskPointName" class="marker-name">名称:</label>
  129. <input type="text" id="riskPointName" name="riskPointName" placeholder="请输入风险点名称">
  130. </div>
  131. </div>
  132. <div class="layui-btn-group my-btn-group">
  133. <a href="javascript:;" class="layui-btn " id="saveMarker" lay-filter="saveMarker"
  134. lay-submit>保存</a>
  135. <a href="javascript:;" class="layui-btn layui-btn-primary " id="deleteMarker">撤销</a>
  136. <a href="javascript:;" class="layui-btn layui-btn-danger " id="deleteMarker_"
  137. style="display: none">删除</a>
  138. </div>
  139. </form>
  140. </div>
  141. <div id="info" class="info">
  142. <fieldset class="layui-elem-field">
  143. <legend>使用说明</legend>
  144. <div class="layui-field-box">
  145. <ul>
  146. <li>1.点击选中设备设施或者作业活动分组下面的图标</li>
  147. <li>2.点击地图绘制点</li>
  148. <li>3.编辑信息保存风险点</li>
  149. </ul>
  150. </div>
  151. </fieldset>
  152. </div>
  153. </div>
  154. </div>
  155. </div>
  156. </div>
  157. </div>
  158. <!-- js部分 -->
  159. <script type="text/javascript" src="../../../../assets/libs/layui/layui.js"></script>
  160. <script type="text/javascript" src="../../../../assets/js/common.js?v=312"></script>
  161. <script type="text/javascript" src="../../../../assets/libs/jquery/jquery-3.2.1.min.js"></script>
  162. <script src="../../../../assets/libs/leaflet/leaflet.js"></script>
  163. <script src="../../../../assets/libs/leaflet/leaflet-draw/leaflet.draw-src.js"></script>
  164. <script src="../../../../assets/libs/leaflet/leaflet-draw/local.js"></script>
  165. <script src="../../../../assets/libs/leaflet/proj4-compressed.js"></script>
  166. <script src="../../../../assets/libs/leaflet/proj4leaflet.js"></script>
  167. <script type="text/html" id="upTpl">
  168. <form id="modelUserForm" lay-filter="modelUserForm" class="layui-form model-form">
  169. <div class="layui-form-item">
  170. <label class="layui-form-label w-padding">名称:</label>
  171. <div class="layui-input-block">
  172. <input name="entMapName" id="entMapName" placeholder="请输入名称" type="text" class="layui-input"/>
  173. </div>
  174. </div>
  175. <div class="layui-form-item">
  176. <label class="layui-form-label w-padding">背景图:</label>
  177. <div class="layui-input-block" id="uploadImg">
  178. <div class="layui-upload-drag">
  179. <i class="layui-icon"></i>
  180. <p>点击上传,或将文件拖拽到此处</p>
  181. </div>
  182. <img src="" id="vMapImg" width="100px">
  183. </div>
  184. <input name="mapImg" id="mapImg" type="hidden" class="layui-input">
  185. </div>
  186. <div class="layui-form-item text-right">
  187. <button class="layui-btn" lay-filter="modelSubmit" lay-submit>保存</button>
  188. <button class="layui-btn layui-btn-primary" type="button" ew-event="closePageDialog">取消</button>
  189. </div>
  190. </form>
  191. </script>
  192. <script>
  193. var resultData;
  194. var imgPath, viewImgPath, map;
  195. var entMapList;
  196. var loadFlag = true;
  197. layui.use(['index', 'layer', 'form', 'table', 'util', 'admin', 'zTree', 'uParas', '_groupTree', 'element', 'laydate', 'notice', '_zTree', 'upload'], function () {
  198. var $ = layui.jquery;
  199. var layer = layui.layer;
  200. var element = layui.element;
  201. var form = layui.form;
  202. var index = layui.index;
  203. var table = layui.table;
  204. var util = layui.util;
  205. var admin = layui.admin;
  206. var uParas = layui.uParas;
  207. var _groupTree = layui._groupTree;
  208. var laydate = layui.laydate;
  209. var notice = layui.notice;
  210. var _zTree = layui._zTree;
  211. var upload = layui.upload;
  212. date = new Date();
  213. // _groupTree.init(insTb);
  214. // insTb.reload();
  215. var entMapId = uParas.getUrlParam("entMapId");
  216. if (entMapId != null && entMapId != undefined) {
  217. $("#entMapId").val(entMapId);
  218. }
  219. $.getJSON(uParas.baseUrl + "/ent/map/getList", {mapType: 2}, function (result) {
  220. var entMap;
  221. if (result.data != null) {
  222. entMapList = result.data;
  223. if (entMapId != null && entMapId != undefined) {
  224. $.each(result.data, function (i, field) {
  225. if (field.mapId.toString() === entMapId) {
  226. imgPath = field.mapRasterLayer;
  227. uParas.initSimpleSelectX("entMapList", "formFilter", result, "mapName", "mapId", entMapId);
  228. return;
  229. }
  230. });
  231. } else {
  232. entMap = result.data[0];
  233. imgPath = entMap.mapRasterLayer;
  234. uParas.initSimpleSelectX("entMapList", "formFilter", result, "mapName", "mapId", entMap.mapId);
  235. $("#entMapId").val(entMap.mapId);
  236. }
  237. }
  238. });
  239. // var url = uParas.baseUrl + "/ent/dangerSource/query?limit=1000";
  240. var url = uParas.baseUrl + "/ent/parkConf/query?limit=1000";
  241. /*初始化危险源数据*/
  242. $.getJSON(url, function (result) {
  243. resultData = result;
  244. loadDangerSource(result, 1);
  245. uParas.cache("dangerSourceList", result.data);
  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.clearMapController();
  258. myBmap.init(form, uParas, riskPointLevelFunc, _zTree);
  259. loadMapData.init(_riskPointType, uParas, riskPointLevelFunc, _zTree);
  260. }
  261. });
  262. // 渲染laydate
  263. var myDate = new Date();
  264. laydate.render({
  265. elem: '#activeStartTime',
  266. format: 'yyyy-MM-dd HH:mm:ss',
  267. type: 'datetime',
  268. min: myDate.toLocaleString()
  269. });
  270. laydate.render({
  271. elem: '#activeEndTime',
  272. format: 'yyyy-MM-dd HH:mm:ss',
  273. type: 'datetime',
  274. min: myDate.toLocaleString()
  275. });
  276. //监听Tab切换,以改变地址hash值
  277. var _riskPointType;
  278. element.on('tab(dangerSource)', function () {
  279. var riskPointType = this.getAttribute('lay-id');
  280. loadDangerSource(resultData, riskPointType);
  281. });
  282. //监听是否激活
  283. form.on('radio(isActive)', function (data) {
  284. if (data.value == 0) {
  285. $("#activeTime").hide();
  286. } else {
  287. $("#activeTime").show();
  288. }
  289. });
  290. function loadDangerSource(result, riskPointType) {
  291. var out = {};
  292. var array = new Array();
  293. $.each(result.data, function (i, field) {
  294. // if (field.riskPointType == riskPointType) {
  295. array.push(field);
  296. // }
  297. });
  298. out.data = array;
  299. loadIcon(out, riskPointType);
  300. loadMapData.init(riskPointType, uParas, riskPointLevelFunc, _zTree);
  301. _riskPointType = riskPointType;
  302. }
  303. $('#showUploadDlg1').on('click', function () {
  304. saveMap(2);
  305. });
  306. $('#showUploadDlg2').on('click', function () {
  307. saveMap(3);
  308. });
  309. function saveMap(type) {
  310. admin.open({
  311. type: 1,
  312. title: '上传图片',
  313. content: $('#upTpl').html(),
  314. success: function (layero, index) {
  315. upload.render({
  316. elem: '#uploadImg'
  317. , url: uParas.baseUrl + '/admin/uploadImages'
  318. , done: function (res) {
  319. $("#mapImg").val(res.data[0]);
  320. $("#vMapImg").attr("src", uParas.baseUrl + res.data[0]);
  321. }
  322. });
  323. var url = uParas.baseUrl + '/ent/map/save';
  324. form.on('submit(modelSubmit)', function (data) {
  325. layer.load();
  326. var obj = data.field;
  327. obj.mapRasterLayer = $("#mapImg").val();
  328. obj.mapType = type;
  329. obj.mapName = $("#entMapName").val();
  330. admin.req(url, obj, function (resp) {
  331. layer.closeAll('loading');
  332. if (resp.code == 1) {
  333. layer.close(index);
  334. layer.msg(resp.msg);
  335. } else {
  336. layer.msg(resp.msg);
  337. }
  338. }, 'POST');
  339. return false;
  340. });
  341. }
  342. });
  343. }
  344. /**
  345. * 1f 2J
  346. * @param resp
  347. * @param type
  348. * @param ulDivName
  349. */
  350. function loadIcon(resp, type) {
  351. var defImgPath = '../../../../assets/images/icon/facility.png';
  352. var li = "";
  353. $.each(resp.data, function (i, field) {
  354. var riskPointLevel = riskPointLevelFunc(field.dangerSourceLevel);
  355. var imgPath = field.dangerImg;
  356. if (imgPath == null || imgPath == "") {
  357. imgPath = defImgPath;
  358. } else {
  359. imgPath = imgPath;
  360. }
  361. if (field.parkParentId == 0) {
  362. li += '<li class="iconCategory">' + field.parkName + '</li>';
  363. $.each(resp.data, function (i, _field) {
  364. if (field.parkId == _field.parkParentId) {
  365. riskPointLevel = riskPointLevelFunc(_field.dangerSourceLevel);
  366. li += `<li><a href="javascript:;" id="${_field.parkId}" class="marker-icon">
  367. <img src="${imgPath}" id="${_field.parkId}" type="${type}" lv="${_field.dangerSourceLevel}" name="${_field.parkName}"></a>
  368. <span>${_field.parkName}</span></li>`;
  369. }
  370. });
  371. }
  372. });
  373. $("#facilityIconList").html('');
  374. $("#facilityIconList").append(li);
  375. }
  376. function riskPointLevelFunc(value) {
  377. var opts = '<div class="riskPointLevel">';
  378. if (value == 1) {
  379. opts += "<div class='notify'><span class='heartbit'></span><span><img src='../../../../assets/images/lv/red.png' style='width: 28px;height: 28px;'/></span></div>";
  380. } else if (value == 2) {
  381. opts += "<img src='../../../../assets/images/lv/orange.png' style='width: 28px;height: 28px;'/>";
  382. } else if (value == 3) {
  383. opts += "<img src='../../../../assets/images/lv/yellow.png' style='width: 28px;height: 28px;'/>";
  384. } else if (value == 4) {
  385. opts += "<img src='../../../../assets/images/lv/blue.png' style='width: 28px;height: 28px;'/>";
  386. } else {
  387. opts += "无";
  388. }
  389. opts += "</div>"
  390. return opts;
  391. }
  392. $("#deleteMarker_").click(function () {
  393. layer.confirm('确定要删除么?', {
  394. skin: 'layui-layer-admin',
  395. shade: .1
  396. }, function (i) {
  397. $.getJSON(uParas.baseUrl + "/ent/riskPoint/delete/" + $("#riskPointId").val(), {}, function (result) {
  398. layer.closeAll();
  399. if (result.code == 1) {
  400. notice.msg(result.msg, {icon: 1});
  401. $(".icon-form-box").hide();
  402. $("#info").show();
  403. setTimeout(function () {
  404. loadMapData.init(_riskPointType, uParas, riskPointLevelFunc, _zTree);
  405. }, 1000)
  406. }
  407. });
  408. });
  409. })
  410. setTimeout(function () {
  411. myBmap.init(form, uParas, riskPointLevelFunc, _zTree);
  412. }, 1000);
  413. });
  414. var myBmap = {
  415. mapContainer: "map", //地图容器
  416. mapTile: "http://online{s}.map.bdimg.com/tile/?qt=vtile&x={x}&y={y}&z={z}&styles=pl&scaler=2&udt=20181205", //切片图层
  417. myIcon: null, //保存创建的icon
  418. myMarker: null, //保存自己创建marker
  419. myMarkerType: 0, //marker类型
  420. myMarkerId: null, //markerId
  421. isSave: true, //是否保存标记
  422. checkedIcon: null, //保存选中的icon
  423. title: null,
  424. deleteMarkerId: null, //保存删除得markerId
  425. myMarkerGroup: L.layerGroup(),
  426. myMarkerGroupInit: L.layerGroup(),
  427. mapControl: null, // 地图控制器,用来清除叠加控制
  428. data: {},
  429. plotLayer: null,
  430. init: function (form, uParas, riskPointLevelFunc, _zTree) {
  431. _form = form;
  432. var _this = this;
  433. // 初始化默认操作
  434. this.clearPlotLayer() // 默认清空绘制点位
  435. this.myMarkerGroup.clearLayers(); // 图层
  436. this.isSave = true
  437. clearForm()
  438. //初始化地图
  439. var map_type = 2;
  440. if (map_type == 4) {
  441. baidu_map();
  442. } else {
  443. image_map();
  444. }
  445. // 增加区域绘制工具栏
  446. this.plotLayer = plotLayer = this.plotLayer != null ? this.plotLayer : L.featureGroup(), map.addLayer(plotLayer);
  447. var e = {
  448. position: "topright",
  449. draw: {
  450. polyline: {shapeOptions: {color: "#0000ff", weight: 3}},
  451. polygon: {allowIntersection: !0, showArea: !0, shapeOptions: {color: "#0000ff", weight: 2}},
  452. rectangle: {shapeOptions: {color: "#0000ff", weight: 2}},
  453. circle: false,
  454. circlemarker: false,
  455. marker: false
  456. },
  457. edit: {
  458. featureGroup: plotLayer,
  459. remove: !0,
  460. edit: false
  461. }
  462. }, n = mapControl = new L.Control.Draw(e);
  463. map.addControl(n)
  464. function draw_createdHandler(t) {
  465. t.layerType;
  466. var o = t.layer;
  467. plotLayer.addLayer(o)
  468. var all = o.toGeoJSON();
  469. var drawIds = $("#drawIds").val();
  470. $("#drawIds").remove();
  471. if (drawIds != undefined) {
  472. drawIds = drawIds + "#" + JSON.stringify(all.geometry.coordinates) + ";" + all.geometry.type;
  473. } else {
  474. drawIds = JSON.stringify(all.geometry.coordinates) + ";" + all.geometry.type
  475. }
  476. $(".my-marker-type").append('<input type="hidden" id="drawIds" name="drawIds" value="' + drawIds + '">');
  477. }
  478. function draw_deletedHandler(t) {
  479. $("#drawIds").remove();
  480. }
  481. // baidu_map()
  482. //地图鼠标事件
  483. map.off('click').on('click', function (e) {
  484. var point = [];
  485. if (_this.myIcon != null) {
  486. var myIcon1 = L.icon({
  487. iconUrl: _this.myIcon,
  488. iconSize: [40, 40],
  489. // iconAnchor: [0, 0]
  490. })
  491. // console.log(myIcon1);
  492. _this.myIcon = null; //将myIcon 置为null 防止鼠标在地图上移动或者点击再次做绘制
  493. point.push(e.latlng.lat, e.latlng.lng);
  494. _this.myMarker = L.marker([e.latlng.lat, e.latlng.lng], {icon: myIcon1});
  495. _this.myMarker.on('click', markerClick); //标记点击事件
  496. //_this.myMarker.addTo(map); //添加marker到地图上
  497. _this.myMarkerGroup.addLayer(_this.myMarker);
  498. _this.myMarkerGroup.addTo(map);
  499. _this.deleteMarkerId = _this.myMarker._leaflet_id; //保存当前markerId
  500. clearForm(); //清空函数
  501. $("#my-marker").append(_this.checkedIcon); //在表单中进行回显
  502. $("#my-marker-title").append(_this.title); //在表单中进行回显
  503. var latlngArray = "[" + e.latlng.lat + "," + e.latlng.lng + "]";
  504. $("#my-marker-title").append('<input type="hidden" id="latlng" name="latlng" value="' + latlngArray + '">');
  505. $("#my-marker-title").append('<input type="hidden" id="dangerSourceId" name="dangerSourceId" value="' + _this.myMarkerId + '">');
  506. map.on(L.Draw.Event.CREATED, draw_createdHandler), map.on(L.Draw.Event.DELETED, draw_deletedHandler)
  507. $(".icon-form-box").show();
  508. $("#info").hide();
  509. $("#deleteMarker_").hide();
  510. $("#deleteMarker").show();
  511. var inGroupNumber = {
  512. reload: function (obj) {
  513. uParas.initFormSelects("liablePerson", uParas.baseUrl + '/admin/common/getUsersByGroupId?gId=' + obj.where.groupId, "accountRealName", "aId");
  514. }
  515. }
  516. _zTree._init('/admin/common/getGroupLists', 'gId', 'groupParent', 'groupName', 'gId', 0, 'groupTree_', inGroupNumber, 'menuContent_', 'liableGroupIdName', 'liableGroupId');
  517. }
  518. })
  519. //左侧icon得点击事件
  520. $(".icon-box-ul").off('click').on('click', 'a', function (event) {
  521. if (_this.isSave) {
  522. _this.isSave = false;
  523. var curParent = $(event.currentTarget).parent();
  524. var tarSrc = $(event.target).attr('src');
  525. var title = $(event.target).attr('name');
  526. var id = $(event.target).attr('id');
  527. var type = $(event.target).attr('type');
  528. var riskPointMinLevel = $(event.target).attr('lv');
  529. _this.data.riskPointMinLevel = riskPointMinLevel;
  530. _this.data.type = type;
  531. $('.icon-active').removeClass('icon-active');
  532. $(event.currentTarget).addClass('icon-active');
  533. _this.myIcon = tarSrc;
  534. //复制icon进行拖动
  535. _this.myMarkerId = id;
  536. // _this.myMarkerType = type;
  537. _this.checkedIcon = '<img src="' + tarSrc + '" width="40px" height="40px"/>';
  538. // //console.log(_this.checkedIcon)
  539. _this.title = title;
  540. } else {
  541. layer.msg('请先保存标记!');
  542. }
  543. })
  544. _form.on('submit(saveMarker)', function (data) {
  545. var sendData = data.field;
  546. if (sendData.riskPointName == "") {
  547. layer.msg("请输入名称!");
  548. return;
  549. }
  550. sendData.riskPointType = sendData.type;
  551. $.ajax({
  552. type: "post",
  553. url: uParas.baseUrl + "/ent/riskPointMap/saveDangerSourceMap",
  554. data: sendData,
  555. dataType: "json",
  556. success: function (result) {
  557. if (result.code === 1) {
  558. layer.msg("保存成功");
  559. _this.isSave = true;
  560. $(".my-marker-box>ul>li:not(:last-child)").remove();
  561. if (map._layers[_this.deleteMarkerId] != null) {
  562. map.removeLayer(map._layers[_this.deleteMarkerId]);
  563. }
  564. clearForm(); //清空函数
  565. setTimeout(function () {
  566. loadMapData.init(sendData.type, uParas, riskPointLevelFunc, _zTree);
  567. }, 1000)
  568. $(".icon-form-box").hide();
  569. $("#info").show();
  570. } else {
  571. layer.msg(result.msg);
  572. }
  573. }
  574. });
  575. });
  576. // 标记click事件
  577. function markerClick(e) {
  578. _this.deleteMarkerId = e.target._leaflet_id;
  579. }
  580. //删除marker事件
  581. $("#deleteMarker").click(function () {
  582. _this.isSave = true;
  583. $(".my-marker-box>ul>li:not(:last-child)").remove();
  584. if (map._layers[_this.deleteMarkerId] != null) {
  585. map.removeLayer(map._layers[_this.deleteMarkerId]);
  586. }
  587. plotLayer.clearLayers();
  588. clearForm(); //清空函数
  589. });
  590. // 添加标注
  591. $("#addMarker").click(function () {
  592. layerOpen();
  593. })
  594. // 删除单个标记
  595. $(".my-marker-box>ul").on('click', 'span', function (e) {
  596. $(e.target).parent().remove();
  597. var eles = $(".my-marker-box>ul>li");
  598. var ids = '';
  599. var lv = 4;
  600. $.each(eles, function (index, item) {
  601. var id = $(item).find('img').attr('id');
  602. var lvSon = $(item).find('img').attr('lv');
  603. if (id != undefined) {
  604. ids += id + ",";
  605. if (Number(lvSon) < Number(lv)) {
  606. lv = lvSon;
  607. }
  608. }
  609. });
  610. $("#dangerSourceIds").remove();
  611. $("#riskPointMinLevelSon").remove();
  612. $(".my-marker-type").append('<input type="hidden" id="riskPointMinLevelSon" name="riskPointMinLevelSon" value="' + lv + '">');
  613. $(".my-marker-type").append('<input type="hidden" id="dangerSourceIds" name="dangerSourceIds" value="' + ids + '">');
  614. })
  615. //底图为图片
  616. function image_map() {
  617. if (map == undefined || map._loaded == undefined) {
  618. map = L.map(_this.mapContainer, {
  619. crs: L.CRS.Simple,
  620. center: L.latLng(50.5, 30.5),
  621. minZoom: 0,
  622. zoom: 0,
  623. attributionControl: false
  624. });
  625. } else {
  626. loadFlag = false;
  627. }
  628. var yx = L.latLng;
  629. var xy = function xy(x, y) {
  630. if (L.Util.isArray(x)) {
  631. return yx(x[1], x[0]);
  632. }
  633. return yx(y, x);
  634. };
  635. // map.eachLayer(function (layer) {
  636. // map.removeLayer(layer);
  637. // });
  638. map.addLayer(_this.myMarkerGroupInit);
  639. map.addLayer(_this.myMarkerGroup);
  640. var bounds = [xy(-600, -600), xy(300, 300)];
  641. L.imageOverlay(imgPath, bounds).addTo(map);
  642. map.fitBounds(bounds);
  643. }
  644. //底图为百度地图
  645. function baidu_map() {
  646. var maxZoom = 26;
  647. var crs = new L.Proj.CRS('EPSG:3395',
  648. '+proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs', {
  649. resolutions: function () {
  650. level = 19;
  651. var res = [];
  652. res[0] = Math.pow(2, 18);
  653. for (var i = 1; i < level; i++) {
  654. res[i] = Math.pow(2, (18 - i))
  655. }
  656. return res;
  657. }(),
  658. origin: [0, 0],
  659. bounds: L.bounds([20037508.342789244, 0], [0, 20037508.342789244])
  660. });
  661. var image = new L.TileLayer(_this.mapTile, {
  662. maxZoom: maxZoom,
  663. minZoom: 10,
  664. subdomains: [0, 1, 2],
  665. tms: true
  666. });
  667. map = L.map(_this.mapContainer, {
  668. crs: crs,
  669. layers: [image]
  670. });
  671. map.setView([34.474387, 109.490437], 14);
  672. }
  673. function clearForm() {
  674. $("#my-marker").html(""); //清除icon;
  675. $('.icon-active').removeClass('icon-active'); //移除已选class
  676. $(".my-marker-type>input").remove(); //移除标记类型中得input
  677. $("#markerType").html(""); //清空标记类型
  678. $("#riskPointName").val(""); //清空标记类型
  679. $(".my-marker-box>ul>li:not(:last-child)").remove();
  680. $("#drawIds").remove();
  681. $("#drawType").remove();
  682. $("#my-marker-title").html("");
  683. $("#riskPointDesc").val('');
  684. $("#activeStartTime").val('');
  685. $("#activeEndTime").val('');
  686. $("#riskPointPlaces").val('');
  687. $('#liableGroupIdName').val('');
  688. $('#liablePerson').html('');
  689. }
  690. function layerOpen() {
  691. var outIds = $("#dangerSourceId").val();
  692. if ($("#dangerSourceIds").val() != undefined) {
  693. outIds += "," + $("#dangerSourceIds").val();
  694. }
  695. if (outIds == undefined) {
  696. outIds = new Array();
  697. }
  698. var defImgPath = "";
  699. var jobPng = "../../../../assets/images/icon/job.png";
  700. var facilityPng = "../../../../assets/images/icon/facility.png";
  701. //var dangerSourceList = layui.data(uParas.tableName).dangerSourceList;
  702. var html = '<div class="">';
  703. html += '<div class="danger-src-date popup-icon-box" style="width: 550px;float: left;margin-left: 20px;"><ul>';
  704. $.each(resultData.data, function (i, field) {
  705. var type = field.riskPointType;
  706. var riskPointLevel = riskPointLevelFunc(field.dangerSourceLevel);
  707. var imgPath = field.dangerImg;
  708. if (type == 1) {
  709. defImgPath = facilityPng;
  710. } else {
  711. defImgPath = jobPng;
  712. }
  713. if (imgPath == null || imgPath == "") {
  714. imgPath = defImgPath;
  715. } else {
  716. imgPath = uParas.baseUrl + imgPath;
  717. }
  718. var id = field.dangerSrcId;
  719. if (field.riskPointType == 1) {
  720. // if (outIds.indexOf(id) == -1) {
  721. if (field.parentDangerSrcId == -1) {
  722. // if (field.riskCount == field.riskCountParent) {
  723. if (field.riskCountParent == 0) {
  724. html += '<li class="iconCategory_">' + field.dangerSrcName + '</li>';
  725. html += `<li onclick="iconClick(this)"><a href="javascript:;" id="${field.dangerSrcId}" class="marker-icon"><span style='font-size: 18px;margin-top: 10px;'>✦ </span>
  726. <img src="${imgPath}" id="${field.dangerSrcId}" type="${type}" lv="${field.dangerSourceLevel}" name="${field.dangerSrcName}" style='width: 25px;height: 25px;'></a>
  727. <span style="margin-left: 10px;color: #0c5df1;">${field.dangerSrcName}</span>${riskPointLevel}</li>`;
  728. } else {
  729. html += '<li class="iconCategory_">' + field.dangerSrcName + '</li>';
  730. $.each(resultData.data, function (i, _field) {
  731. var _id = _field.dangerSrcId;
  732. if (outIds.indexOf(_id) == -1) {
  733. if (field.dangerSrcId == _field.parentDangerSrcId) {
  734. var _type = _field.riskPointType;
  735. var _riskPointLevel = riskPointLevelFunc(_field.dangerSourceLevel);
  736. var _imgPath = _field.dangerImg;
  737. if (_type == 1) {
  738. defImgPath = facilityPng;
  739. } else {
  740. defImgPath = jobPng;
  741. }
  742. if (_imgPath == null || _imgPath == "") {
  743. _imgPath = defImgPath;
  744. } else {
  745. _imgPath = uParas.baseUrl + _imgPath
  746. }
  747. // li += `<li><a href="javascript:;" id="${_field.dangerSrcId}" class="marker-icon">
  748. // <img src="${imgPath}" id="${_field.dangerSrcId}" type="${type}" lv="${_field.dangerSourceLevel}" name="${_field.dangerSrcName}"></a>
  749. // <span>${_field.dangerSrcName}</span>${riskPointLevel}</li>`;
  750. html += `<li onclick="iconClick(this)"><a href="javascript:;" id="${_field.dangerSrcId}" class="marker-icon"><span style='font-size: 18px;margin-top: 10px;'>✦ </span>
  751. <img src="${_imgPath}" id="${_field.dangerSrcId}" type="${_type}" lv="${_field.dangerSourceLevel}" name="${_field.dangerSrcName}" style='width: 25px;height: 25px;'></a>
  752. <span style="margin-left: 10px;color: #0c5df1;">${_field.dangerSrcName}</span>${_riskPointLevel}</li>`;
  753. }
  754. }
  755. });
  756. }
  757. // }
  758. }
  759. // else {
  760. // html += `<li onclick="iconClick(this)"><a href="javascript:;" id="${field.dangerSrcId}" class="marker-icon"><span style='font-size: 18px;margin-top: 10px;'>✦ </span>
  761. // <img src="${imgPath}" id="${field.dangerSrcId}" type="${type}" lv="${field.dangerSourceLevel}" name="${field.dangerSrcName}" style='width: 25px;height: 25px;'></a>
  762. // <span style="margin-left: 10px;color: #0c5df1;">${field.dangerSrcName}</span>${riskPointLevel}</li>`;
  763. // }
  764. // }
  765. }
  766. });
  767. html += '</ul></div>';
  768. html += '<div class="danger-src-date popup-icon-box" style="float: left;width: 550px;"><ul>';
  769. $.each(resultData.data, function (i, field) {
  770. var type = field.riskPointType;
  771. var riskPointLevel = riskPointLevelFunc(field.dangerSourceLevel);
  772. var imgPath = field.dangerImg;
  773. if (type == 1) {
  774. defImgPath = facilityPng;
  775. } else {
  776. defImgPath = jobPng;
  777. }
  778. if (imgPath == null || imgPath == "") {
  779. imgPath = defImgPath;
  780. } else {
  781. imgPath = uParas.baseUrl + imgPath;
  782. }
  783. var id = field.dangerSrcId;
  784. if (field.riskPointType == 2) {
  785. if (field.parentDangerSrcId == -1) {
  786. if (field.riskCount == field.riskCountParent) {
  787. html += '<li class="iconCategory_">' + field.dangerSrcName + '</li>';
  788. html += `<li onclick="iconClick(this)"><a href="javascript:;" id="${field.dangerSrcId}" class="marker-icon"><span style='font-size: 18px;margin-top: 10px;'>✦ </span>
  789. <img src="${imgPath}" id="${field.dangerSrcId}" type="${type}" lv="${field.dangerSourceLevel}" name="${field.dangerSrcName}" style='width: 25px;height: 25px;'></a>
  790. <span style="margin-left: 10px;color: #0c5df1;">${field.dangerSrcName}</span>${riskPointLevel}</li>`;
  791. } else {
  792. html += '<li class="iconCategory_">' + field.dangerSrcName + '</li>';
  793. $.each(resultData.data, function (i, _field) {
  794. var _id = _field.dangerSrcId;
  795. if (outIds.indexOf(_id) == -1) {
  796. if (field.dangerSrcId == _field.parentDangerSrcId) {
  797. var _type = _field.riskPointType;
  798. var _riskPointLevel = riskPointLevelFunc(_field.dangerSourceLevel);
  799. var _imgPath = _field.dangerImg;
  800. if (_type == 1) {
  801. defImgPath = facilityPng;
  802. } else {
  803. defImgPath = jobPng;
  804. }
  805. if (_imgPath == null || _imgPath == "") {
  806. _imgPath = defImgPath;
  807. } else {
  808. _imgPath = uParas.baseUrl + _imgPath
  809. }
  810. // li += `<li><a href="javascript:;" id="${_field.dangerSrcId}" class="marker-icon">
  811. // <img src="${imgPath}" id="${_field.dangerSrcId}" type="${type}" lv="${_field.dangerSourceLevel}" name="${_field.dangerSrcName}"></a>
  812. // <span>${_field.dangerSrcName}</span>${riskPointLevel}</li>`;
  813. html += `<li onclick="iconClick(this)"><a href="javascript:;" id="${_field.dangerSrcId}" class="marker-icon"><span style='font-size: 18px;margin-top: 10px;'>✦ </span>
  814. <img src="${_imgPath}" id="${_field.dangerSrcId}" type="${_type}" lv="${_field.dangerSourceLevel}" name="${_field.dangerSrcName}" style='width: 25px;height: 25px;'></a>
  815. <span style="margin-left: 10px;color: #0c5df1;">${_field.dangerSrcName}</span>${_riskPointLevel}</li>`;
  816. }
  817. }
  818. });
  819. }
  820. // }
  821. }
  822. }
  823. });
  824. html += '</ul></div></div>';
  825. layer.open({
  826. title: '【设备设施】' + '<span style="margin-left: 470px;">【作业活动】</span>',
  827. btn: ['确定', '取消'],
  828. type: 1,
  829. area: ['1200px', '60%'], //宽高
  830. content: html,
  831. yes: yes
  832. });
  833. }
  834. function yes(index) {
  835. var eles = $(".popup-icon-box>ul>li");
  836. var li = '';
  837. var ids = '';
  838. var lv = 4;
  839. $.each(eles, function (index, item) {
  840. if ($(item).hasClass('icon-active')) {
  841. var imgSrc = $(item).find('img').attr('src');
  842. var id = $(item).find('img').attr('id');
  843. var title = $(item).find('img').attr('name');
  844. var div = $(item).find('div').html();
  845. var lvSon = $(item).find('img').attr('lv');
  846. li += '<li><img src="' + imgSrc + '" id="' + id + '"lv=' + lvSon + ' ><span>x</span><p>' + title + '</p><div class="riskPointLevel">' + div + '</div></li>';
  847. if (id != undefined) {
  848. ids += id + ",";
  849. if (Number(lvSon) < lv) {
  850. lv = lvSon;
  851. }
  852. }
  853. }
  854. });
  855. $("#myMarkerBox>ul").prepend(li);
  856. if ($("#dangerSourceIds").val() != undefined) {
  857. ids += $("#dangerSourceIds").val();
  858. }
  859. $("#dangerSourceIds").remove();
  860. $("#riskPointMinLevelSon").remove();
  861. $(".my-marker-type").append('<input type="hidden" id="riskPointMinLevelSon" name="riskPointMinLevelSon" value="' + lv + '">');
  862. $(".my-marker-type").append('<input type="hidden" id="dangerSourceIds" name="dangerSourceIds" value="' + ids + '">');
  863. layer.close(index);
  864. }
  865. },
  866. clearPlotLayer: function () {
  867. if (this.plotLayer != null) {
  868. this.plotLayer.clearLayers()
  869. }
  870. },
  871. clearMapController() { // 清除地图控制器
  872. map.removeControl(mapControl)
  873. }
  874. }
  875. var loadMapData = {
  876. jobPng: "../../../../assets/images/icon/job.png",
  877. facilityPng: "../../../../assets/images/icon/facility.png",
  878. init: function (type, uParas, riskPointLevelFunc, _zTree) {
  879. var _uParas = uParas;
  880. var riskPointLevelFunc = riskPointLevelFunc;
  881. var _zTree = _zTree;
  882. var jobIcon = L.icon({
  883. iconUrl: loadMapData.jobPng,
  884. iconSize: [38, 45],
  885. popupAnchor: [0, -16]
  886. });
  887. var facilityIcon = L.icon({
  888. iconUrl: loadMapData.facilityPng,
  889. iconSize: [38, 45],
  890. popupAnchor: [0, -16]
  891. });
  892. function icon(imgUrl) {
  893. return L.icon({
  894. iconUrl: imgUrl,
  895. iconSize: [38, 45],
  896. popupAnchor: [0, -16]
  897. });
  898. }
  899. initMapData(type, uParas);
  900. function initMapData(type, uParas) {
  901. var groupId = $("#groupId").val();
  902. if (type == undefined) {
  903. type = 1
  904. } else {
  905. myBmap.myMarkerGroupInit.clearLayers();
  906. }
  907. myBmap.myMarkerGroupInit.clearLayers();
  908. var entMapId = $("#entMapId").val();
  909. $.getJSON(uParas.baseUrl + "/ent/parkQr/getRiskPointMap", {
  910. entMapId: entMapId
  911. }, function (result) {
  912. if (result.code == 1) {
  913. $.each(result.data, function (index, item) {
  914. var markerData = item.markerData;
  915. if (markerData != null) {
  916. var optionsData = {
  917. mapId: item.id,
  918. riskPointId: item.riskPointId,
  919. type: type,
  920. title: item.markerTitle
  921. };
  922. if (item.dangerImg != null && item.dangerImg != "") {
  923. optionsData.iconUrl = imgPathFun(item.dangerImg, type);
  924. } else {
  925. if (type === 2) {
  926. optionsData.iconUrl = loadMapData.jobPng;
  927. } else {
  928. optionsData.iconUrl = loadMapData.facilityPng;
  929. }
  930. }
  931. if (item.markerType == 3) {
  932. var data = new Array();
  933. $.each($.parseJSON(markerData), function (index, item) {
  934. data[index] = new Array(item[1], item[0]);
  935. });
  936. L.polygon(data, optionsData).addTo(myBmap.myMarkerGroupInit).bindPopup(item.markerTitle).on('click', onMapClick);
  937. } else if (item.markerType == 1) {
  938. if (item.dangerImg != null && item.dangerImg != "") {
  939. optionsData.icon = icon(uParas.baseUrl + item.dangerImg);
  940. } else {
  941. if (type == 2) {
  942. optionsData.icon = jobIcon;
  943. } else {
  944. optionsData.icon = facilityIcon;
  945. }
  946. }
  947. L.marker($.parseJSON(markerData), optionsData).addTo(myBmap.myMarkerGroupInit).bindPopup(item.markerTitle).on('click', onMapClick);
  948. } else if (item.markerType == 2) {
  949. var data = new Array();
  950. $.each($.parseJSON(markerData), function (index, item) {
  951. data[index] = new Array(item[1], item[0]);
  952. });
  953. L.polyline(data, optionsData).addTo(myBmap.myMarkerGroupInit).bindPopup(item.markerTitle).on('click', onMapClick);
  954. }
  955. }
  956. });
  957. }
  958. });
  959. }
  960. function imgPathFun(imgPath, type) {
  961. var defImgPath = "";
  962. var jobPng = "../../../../assets/images/icon/job.png";
  963. var facilityPng = "../../../../assets/images/icon/facility.png";
  964. if (type == "1") {
  965. defImgPath = facilityPng;
  966. } else {
  967. defImgPath = jobPng;
  968. }
  969. if (imgPath == null || imgPath == "") {
  970. return defImgPath;
  971. } else {
  972. if (imgPath.indexOf("http:") != -1) {
  973. defImgPath = imgPath;
  974. } else {
  975. defImgPath = uParas.baseUrl + imgPath;
  976. }
  977. }
  978. return defImgPath;
  979. }
  980. function onMapClick(e) {
  981. $(".icon-form-box").show();
  982. $("#info").hide();
  983. var options = e.target.options;
  984. var data = {};
  985. data.mapId = options.mapId;
  986. data.riskPointId = options.riskPointId;
  987. $("#deleteMarker").hide();
  988. $("#deleteMarker_").show();
  989. $("#my-marker").html('<img src="' + options.iconUrl + '"/>');
  990. $("#markerType").html(options.type == 2 ? '作业活动' : '设备设施');
  991. $("#riskPointName").val(options.title);
  992. $.getJSON("/ent/parkQr/findMapDataById", data, function (result) {
  993. if (result.code == 1) {
  994. var item = result.data[0];
  995. var index = item.dangerSourceIds;
  996. var arr = new Array();
  997. if (index != null) {
  998. if (index.indexOf(',') != -1) {
  999. arr = index.split(',');
  1000. } else {
  1001. arr = [index];
  1002. }
  1003. }
  1004. $("#my-marker-title").html("");
  1005. $("#my-marker-title").append(item.dangerSrcName);
  1006. $("#type").remove();
  1007. $("#my-marker-title").append('<input type="hidden" id="type" name="type" value="' + options.type + '">');
  1008. $("#riskPointId").remove();
  1009. $("#my-marker-title").append('<input type="hidden" id="riskPointId" name="riskPointId" value="' + item.riskPointId + '">');
  1010. $("#dangerSourceId").remove();
  1011. $("#my-marker-title").append('<input type="hidden" id="dangerSourceId" name="dangerSourceId" value="' + item.dangerSrcId + '">');
  1012. }
  1013. });
  1014. }
  1015. }
  1016. }
  1017. function iconClick(e) {
  1018. $(e).toggleClass('icon-active')
  1019. }
  1020. </script>
  1021. </body>
  1022. </html>