pipe-map.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  1. "use strict"
  2. var keyValue = request('keyValue');
  3. var eOverlays = [];//覆盖物
  4. var showPolygon = [];
  5. var map;
  6. var drawingManager;
  7. var thisPipeLineId;//当前绘制管线ID
  8. var editOverlays;//编辑状态的 地图覆盖物
  9. // 新建管网区域
  10. function addPipeArea() {
  11. dialogOpen({
  12. id: "Form",
  13. title: '新建管网区域',
  14. url: '/PipeNetworkManage/PipeMap/PiPeMapForm?keyValue=',
  15. width: "750px",
  16. height: "500px",
  17. callBack: function (iframeId) {
  18. top.frames[iframeId].AcceptClick();
  19. }
  20. });
  21. }
  22. //初始化管网区域信息
  23. function InitialPipeArea() {
  24. var areaDate;
  25. $.ajax({
  26. type: "Get",
  27. async: false,
  28. url: "/PipeNetworkManage/PipeMap/GetPipeAreaList",
  29. success: function (data) {
  30. areaDate = data;
  31. },
  32. error: function (xhr, status, error) {
  33. }
  34. });
  35. $("#pipeAreaList").html(areaDate);
  36. //加载所有管线
  37. loadAllPipeLine();
  38. //页面文字信息初始化
  39. InitialPageText();
  40. }
  41. //页面文字信息初始化
  42. function InitialPageText() {
  43. var areaNum = $(".areaItem").length;
  44. var linNum = eOverlays.length;
  45. $("#areaNum").text("管网数量:" + areaNum);
  46. $("#lineNum").text("管线总数:" + linNum);
  47. }
  48. function loadAllPipeLine() {
  49. //加载所有管线
  50. var lineCoordinates;
  51. $.ajax({
  52. type: "Get",
  53. async: false,
  54. dataType: "json",
  55. url: "/PipeNetworkManage/PipeMap/GetAllPipeLine",
  56. success: function (data) {
  57. lineCoordinates = data;
  58. },
  59. error: function (xhr, status, error) {
  60. }
  61. });
  62. drawPloyLine(lineCoordinates);
  63. }
  64. //管网线 显示
  65. function showPipeLine(areaId) {
  66. $("#west_pipeArea").fadeOut("slow");
  67. $("#west_pipeLine").fadeIn("slow");
  68. //管线数据获取
  69. $("#hid_area_id").val(areaId);
  70. pipeLineShow(areaId);//左侧栏 管线信息加载
  71. showAreaPipeLine(areaId);
  72. }
  73. //加载某一管网区域 所有管线信息
  74. function showAreaPipeLine(areaId) {
  75. //var lineCoordinates;
  76. //$.ajax({
  77. // type: "Get",
  78. // async: false,
  79. // dataType: "json",
  80. // url: "/PipeNetworkManage/PipeMap/GetPipeLineCoordinates?areaId=" + areaId,
  81. // success: function (data) {
  82. // lineCoordinates = data;
  83. // },
  84. // error: function (xhr, status, error) {
  85. // }
  86. //});
  87. //drawPloyLine(lineCoordinates);
  88. //清空覆盖物
  89. for (var i = 0 ; i < eOverlays.length;i++) {
  90. var overLay = eOverlays[i];
  91. map.removeOverlay(overLay.overLay);
  92. }
  93. //加载这一区域的管线
  94. for (var i = 0 ; i < eOverlays.length; i++) {
  95. var overLay = eOverlays[i];
  96. var thisAreaId = overLay.areaId;
  97. if (thisAreaId == areaId) {
  98. map.addOverlay(overLay.overLay);
  99. }
  100. }
  101. }
  102. //左侧栏 管线信息加载
  103. function pipeLineShow(areaId) {
  104. var lineDate;
  105. $.ajax({
  106. type: "Get",
  107. async: false,
  108. url: "/PipeNetworkManage/PipeMap/GetPipeLineList?areaId=" + areaId,
  109. success: function (data) {
  110. lineDate = data;
  111. },
  112. error: function (xhr, status, error) {
  113. }
  114. });
  115. $("#pipeLineList").html(lineDate);
  116. }
  117. // 绘制管线
  118. function drawPloyLine(data) {
  119. eOverlays.length = 0;//初始化
  120. //地图覆盖物增加
  121. for (var i = 0; i < data.length; i++) {
  122. var lineId = data[i]["PipeLineId"];//管线ID
  123. var Coordinates = data[i]["Coordinates"];//管线坐标
  124. //var lineStyle = data[i]["PipeLineStyle"];//管线样式
  125. var areaId = data[i].PipeAreaId;
  126. if (Coordinates.length > 0) {
  127. var points = Coordinates.split("|");
  128. var paths = [];
  129. for (var j = 0 ; j < points.length; j++) {
  130. paths.push(new BMap.Point(points[j].split(",")[0], points[j].split(",")[1]));
  131. }
  132. //console.log(lineStyle);
  133. //var styles = lineStyle.split("-");
  134. //var polyLine = new BMap.Polyline(paths, { strokeColor: styles[0], strokeWeight: styles[2], strokeOpacity: 0.5, strokeStyle: styles[1] == 0 ? "solid" : "dashed" });
  135. var polyLine = new BMap.Polyline(paths, { strokeColor: "#FF0000", strokeWeight: "2", strokeOpacity: 1, strokeStyle: "solid" });
  136. map.addOverlay(polyLine);
  137. //信息存储
  138. var thisLine = {};
  139. thisLine.lineId = lineId;
  140. thisLine.overLay = polyLine;
  141. thisLine.areaId = areaId;
  142. eOverlays.push(thisLine);
  143. }
  144. }
  145. }
  146. //新建管线
  147. function addPipeLine() {
  148. var areaId = $("#hid_area_id").val();
  149. dialogOpen({
  150. id: "Form",
  151. title: '新建管线',
  152. url: '/PipeNetworkManage/PipeMap/PiPeLineForm?areaId=' + areaId + '&keyValue=',
  153. width: "750px",
  154. height: "500px",
  155. callBack: function (iframeId) {
  156. top.frames[iframeId].AcceptClick();
  157. }
  158. });
  159. }
  160. // 编辑管网区域
  161. function editPipeArea(id) {
  162. dialogOpen({
  163. id: "Form",
  164. title: '编辑管网区域',
  165. url: '/PipeNetworkManage/PipeMap/PiPeMapForm?keyValue=' + id,
  166. width: "750px",
  167. height: "500px",
  168. callBack: function (iframeId) {
  169. top.frames[iframeId].AcceptClick();
  170. }
  171. });
  172. }
  173. function editPipeLine(id) {
  174. dialogOpen({
  175. id: "Form",
  176. title: '编辑管线信息',
  177. url: '/PipeNetworkManage/PipeMap/PipeLineForm?keyValue=' + id,
  178. width: "750px",
  179. height: "500px",
  180. callBack: function (iframeId) {
  181. top.frames[iframeId].AcceptClick();
  182. }
  183. });
  184. }
  185. //// 新建管线
  186. //function addPipeLine() {
  187. // dialogOpen({
  188. // id: "Form",
  189. // title: '新建管网区域',
  190. // url: '/PipeNetworkManage/PipeMap/PiPeLineForm?keyValue=',
  191. // width: "750px",
  192. // height: "500px",
  193. // callBack: function (iframeId) {
  194. // top.frames[iframeId].AcceptClick();
  195. // }
  196. // });
  197. //}
  198. function hideShowArea(id) {
  199. var nowClass = $(this).eq(0).attr("class");
  200. if (nowClass.indexOf("glyphicon-eye-open") > 0) {
  201. $(this).removeClass("glyphicon-eye-open");
  202. $(this).addClass("glyphicon-eye-close");
  203. } else {
  204. $(this).addClass("glyphicon-eye-open");
  205. $(this).removeClass("glyphicon-eye-close");
  206. }
  207. }
  208. // checkbox change事件监听
  209. function checkBoxChange() {
  210. // dma分区是否展示
  211. $("#cdma").change(function (e) {
  212. if ($('#cdma').is(':checked')) {
  213. showAllDMA();
  214. } else {
  215. for (var overlay in overlays) {
  216. map.removeOverlay(overlays[overlay]);
  217. }
  218. if (showPolygon) {
  219. map.removeOverlay(showPolygon);
  220. }
  221. }
  222. });
  223. }
  224. // 获取中心点
  225. function getCenterPoint(path) {
  226. var x = 0.0;
  227. var y = 0.0;
  228. for (var i = 0; i < path.length; i++) {
  229. x = x + parseFloat(path[i].lng);
  230. y = y + parseFloat(path[i].lat);
  231. }
  232. x = x / path.length;
  233. y = y / path.length;
  234. return { lng: x, lat: y }
  235. }
  236. // 设置单个区域
  237. function addOnePolygon() {
  238. var paths = overlays[PointTreeCode].getPath();
  239. var polygon = new BMap.Polygon(paths, { strokeColor: "red", strokeWeight: 2, strokeOpacity: 1, FillOpacity: "0.0", fillColor: "none" });
  240. map.addOverlay(polygon);
  241. showPolygon = polygon;
  242. var center = getCenterPoint(paths);
  243. map.setZoom(12);
  244. map.panTo(new BMap.Point(center.lng, center.lat), 2000);
  245. }
  246. //点击划线
  247. function DrowOrEditPipeLine(lineId) {
  248. //编辑区域出现
  249. $("#btnWrapper").show();
  250. thisPipeLineId = lineId;
  251. //样式--选中区域变色--后期增加
  252. }
  253. function drow() {
  254. drawOne(thisPipeLineId);
  255. drawingManager.open();//开启绘制
  256. drawingManager.setDrawingMode(BMAP_DRAWING_POLYLINE);//绘制折线模式
  257. }
  258. // 绘制具体界面区域
  259. function drawOne(lineId) {
  260. //保存图标显示
  261. $("#btnWrapper .save").show();
  262. var isExists = false;
  263. var nowOverlay;
  264. //判断此管线是否绘制过
  265. for (var i = 0 ; i < eOverlays.length; i++) {
  266. var overLay = eOverlays[i];
  267. if (overLay.lineId == lineId) {
  268. isExists = true;
  269. nowOverlay = overLay.overLay;
  270. }
  271. }
  272. if (!isExists) {
  273. $("#btnWrapper").show();
  274. // 绘制完成调用
  275. var overlaycomplete = function (e) {
  276. //$("#drawmap").attr("disabled", "disabled");
  277. var path = e.overlay.getPath();//获取所有点集合
  278. eOverlays.push(e.overlay);
  279. var paths = [];
  280. for (var i = 0; i < path.length; i++) {
  281. paths.push(new BMap.Point(path[i].lng, path[i].lat));
  282. }
  283. //var polyLine = new BMap.Polyline(paths, { strokeColor: $("#FillColor").val(), strokeWeight: 2, strokeOpacity: 0.5 });
  284. var polyLine = new BMap.Polyline(paths, { strokeColor: "#FF0000", strokeWeight: 2, strokeOpacity: 1 });
  285. map.addOverlay(polyLine);
  286. polyLine.enableEditing();
  287. polyLine.isEdit = true;
  288. clearNoEdit(eOverlays);
  289. editOverlays = polyLine;
  290. };
  291. //var styleOptions = {
  292. // strokeColor: "rgb(46, 207, 3)", //边线颜色。
  293. // fillColor: "rgb(46, 207, 3)", //填充颜色。当参数为空时,圆形将没有填充效果。
  294. // strokeWeight: 3, //边线的宽度,以像素为单位。
  295. // strokeOpacity: 0.8, //边线透明度,取值范围0 - 1。
  296. // fillOpacity: 0.6, //填充的透明度,取值范围0 - 1。
  297. // strokeStyle: 'solid' //边线的样式,solid或dashed。
  298. //}
  299. //实例化鼠标绘制工具
  300. drawingManager = new BMapLib.DrawingManager(map, {
  301. isOpen: false, //是否开启绘制模式
  302. enableDrawingTool: false, //是否显示工具栏
  303. drawingMode: BMAP_DRAWING_POLYLINE,//绘制模式 线
  304. drawingToolOptions: {
  305. anchor: BMAP_ANCHOR_TOP_RIGHT, //位置
  306. offset: new BMap.Size(5, 5), //偏离值
  307. drawingModes: [
  308. BMAP_DRAWING_POLYLINE
  309. ]
  310. },
  311. //polygonOptions: styleOptions //多边形的样式
  312. });
  313. //添加鼠标绘制工具监听事件,用于获取绘制结果
  314. drawingManager.addEventListener('overlaycomplete', overlaycomplete);
  315. } else {
  316. nowOverlay.enableEditing();
  317. editOverlays = nowOverlay;
  318. }
  319. }
  320. // 清除拖拽区域
  321. function clearNoEdit(overlays) {
  322. for (var i = 0; i < overlays.length; i++) {
  323. map.removeOverlay(overlays[i]);
  324. }
  325. overlays.length = 0
  326. }
  327. // 获取坐标点
  328. function getlinepoints(polygon) {
  329. var pts = polygon.getPath();
  330. var points = "";
  331. for (var i = 0; i < pts.length; i++) {
  332. points += pts[i].lng + "," + pts[i].lat;
  333. if (i < pts.length - 1) {
  334. points += "|"
  335. }
  336. }
  337. return points;
  338. }
  339. //保存管线坐标
  340. function save() {
  341. var linePoints = getlinepoints(editOverlays);
  342. editOverlays.isEdit = false;
  343. $.ajax({
  344. type: "POST",
  345. async: false,
  346. url: "/PipeNetworkManage/PipeMap/SavePipeLinePoints",
  347. data: { lineId: thisPipeLineId, points: linePoints },
  348. dataType:"json",
  349. success: function (data) {
  350. dialogMsg(data.message,1);
  351. //alert(data);
  352. editOverlays.disableEditing();
  353. //保存图标隐藏
  354. $("#btnWrapper .save").hide();
  355. $("#btnWrapper").hide();
  356. },
  357. error: function (xhr, status, error) {
  358. }
  359. });
  360. }
  361. //返回按钮
  362. function showPipeArea() {
  363. //管线区域隐藏
  364. $("#west_pipeLine").fadeOut("slow");
  365. $("#west_pipeArea").fadeIn("slow");
  366. //地图管线重新加载
  367. map.clearOverlays();
  368. loadAllPipeLine();
  369. }
  370. // 初始化颜色
  371. function InitialColor() {
  372. $('.fill_Color').each(function () {
  373. $(this).minicolors({
  374. control: $(this).attr('data-control') || 'hue',
  375. defaultValue: $(this).attr('data-defaultValue') || '',
  376. inline: $(this).attr('data-inline') === 'true',
  377. letterCase: $(this).attr('data-letterCase') || 'lowercase',
  378. opacity: $(this).attr('data-opacity'),
  379. position: $(this).attr('data-position') || 'bottom left',
  380. change: function (hex, opacity) {
  381. if (!hex) return;
  382. if (opacity) hex += ', ' + opacity;
  383. try {
  384. console.log(hex);
  385. } catch (e) { }
  386. },
  387. theme: 'bootstrap'
  388. });
  389. });
  390. }
  391. //初始化页面
  392. function InitialPage() {
  393. // 设置
  394. $(".partitionsContainer").css({ "height": ($(window).height() - 80) + "px" });
  395. //layout布局
  396. $('#layout').layout({
  397. applyDemoStyles: true,
  398. onresize: function () {
  399. $(window).resize();
  400. }
  401. });
  402. // resize重设(表格、树形)宽高
  403. $(window).resize(function (e) {
  404. window.setTimeout(function () {
  405. $("#itemTree").css("min-height", $(window).height() - 100);
  406. $("#itemTree_line").css("min-height", $(window).height() - 100);
  407. $(".partitionsContainer").css({ "height": ($(window).height() - 80) + "px" });
  408. }, 200);
  409. e.stopPropagation();
  410. });
  411. $("#itemTree").css("min-height", $(window).height() - 100);
  412. $("#itemTree_line").css("min-height", $(window).height() - 100);
  413. //布局宽度重新设置
  414. $(".ui-layout-west").css("width", "300px");
  415. var centerWidht = $(".ui-layout-center").width();
  416. $(".ui-layout-center").css({ "width": centerWidht - 100, "left": "305px" });
  417. $(".ui-layout-resizer").css("display", "none");
  418. }
  419. // 初始化百度地图
  420. function initBaiduMap(lat, lgt,zoom) {
  421. map = new BMap.Map("allmap");
  422. var geoc = new BMap.Geocoder(); //地址解析对象
  423. var point = new BMap.Point(lat, lgt);
  424. map.centerAndZoom(point, zoom); // 中心点
  425. map.enableScrollWheelZoom(true); //开启鼠标滚轮缩放
  426. var bottom_left_control = new BMap.ScaleControl({ anchor: BMAP_ANCHOR_BOTTOM_LEFT });// 左上角,添加比例尺
  427. map.addControl(bottom_left_control);
  428. map.addControl(new BMap.MapTypeControl({
  429. mapTypes: [
  430. BMAP_NORMAL_MAP,
  431. BMAP_HYBRID_MAP
  432. //BMAP_PERSPECTIVE_MAP
  433. ],
  434. anchor: BMAP_ANCHOR_TOP_LEFT
  435. }));
  436. }
  437. //删除管网区域
  438. function deletePipeArea(areaId) {
  439. if (areaId) {
  440. $.RemoveForm({
  441. url: "/PipeNetworkManage/PipeMap/DeletePipeArea",
  442. param: { areaId: areaId },
  443. success: function (data) {
  444. InitialPipeArea();
  445. map.clearOverlays()
  446. loadAllPipeLine();
  447. }
  448. })
  449. }
  450. }
  451. //删除管网区域
  452. function deletePipeLine(lineId,areaId) {
  453. if (lineId) {
  454. $.RemoveForm({
  455. url: "/PipeNetworkManage/PipeMap/DeltePipeLine",
  456. param: { lineId: lineId },
  457. success: function (data) {
  458. showAreaPipeLine(areaId);
  459. map.clearOverlays()
  460. loadAllPipeLine();
  461. pipeLineShow(areaId);
  462. }
  463. })
  464. }
  465. }