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