index.html 47 KB

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