toolElevation.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. /**
  2. * @fileoverview 工具 剖面量算 模块
  3. * @author Song.Huang
  4. * @version 1.0.0
  5. */
  6. define([
  7. 'html!templates/tools/toolElevation',
  8. 'vendorDir/map23dlib/leaflet.eleation',
  9. 'vendorDir/map23dlib/d3.v3.min',
  10. 'css!styles/tools/toolElevation'
  11. ],
  12. function (tpcLayout) {
  13. /**
  14. * 状态值
  15. * @type {Boolean}
  16. * @default false
  17. * @private
  18. */
  19. var status = {
  20. initialized: false, //是否初始化
  21. firstEle: true
  22. };
  23. /**
  24. * 模块数据 用于数据存储和外部调用
  25. * @type {Object}
  26. * 数据存放
  27. */
  28. var modValue = {
  29. elevationGroup: null, //电和线容器
  30. lineGuide: null, //初始线
  31. lC: 0, //线条统计
  32. elevationObjs: {}, //量算线条集合
  33. curElevIC: null, //正在进行的量算
  34. isNewelevation: true, //是否是新的画线事件
  35. iCData: {} //剖面量算数据保存
  36. };
  37. /**
  38. * 页面初始化
  39. * 添加监听
  40. * @type {Function}
  41. */
  42. function init() {
  43. if (L.Browser.ie || L.Browser.firefox) {
  44. map2DViewer.map.getContainer().style.cursor = 'url(/scripts/vendor/map23dlib/images/cur-ruler.cur),auto';
  45. } else {
  46. map2DViewer.map.getContainer().style.cursor = 'url(/scripts/vendor/map23dlib/images/cur-ruler.cur) 5 5,auto';
  47. }
  48. ONEMAP.M.mapHolder.removeMouseHand();
  49. if (!status.initialized) {
  50. modValue.elevationGroup = map23DControl.group({
  51. action: 'add'
  52. });
  53. $('#wrapper').append(tpcLayout);
  54. subscribe();
  55. status.initialized = true;
  56. $(window).resize(function () {
  57. layoutResize("sideBarStatus");
  58. });
  59. }
  60. afac()
  61. };
  62. function afac() {
  63. ONEMAP.C.publisher.publish({
  64. modName: 'toolElevation'
  65. }, 'tools:active');
  66. }
  67. function layoutResize(options) {
  68. if (!status.firstEle) {
  69. $("#elevationContent").css({
  70. 'left': 0,
  71. 'width': '100%'
  72. })
  73. $(".leaflet-control-elevation").css({
  74. 'position': 'absolute',
  75. 'left': 0,
  76. 'bottom': 0
  77. })
  78. run(null, modValue.lC);
  79. }
  80. };
  81. /**
  82. * 添加至我的图层 量算
  83. */
  84. function addMyLayerControl() {
  85. // ONEMAP.C.publisher.publish('add::elevation','mearsuring');
  86. }
  87. function controlMeasuring(options) {
  88. if (options.action == 'clear') {
  89. clearAllMap();
  90. } else if (options.action == 'hide') {
  91. map2DViewer.group({
  92. action: "hide",
  93. guid: modValue.elevationGroup
  94. })
  95. $("#elevationContent").hide();
  96. } else if (options.action == 'show') {
  97. map2DViewer.group({
  98. action: "show",
  99. guid: modValue.elevationGroup
  100. })
  101. if ($(".elevationList li").length > 0) {
  102. $("#elevationContent").show();
  103. }
  104. }
  105. };
  106. /**
  107. * 鼠标单击事件,如果是第一次,则设置为初始点
  108. * @type {Function}
  109. * @param e {Event}
  110. * @returns {boolean}
  111. * @private
  112. */
  113. function onClickPoint(e) {
  114. addMyLayerControl();
  115. var labelObj = L.DomUtil.create('p', 'eleStyle');
  116. var tipText = '起点';
  117. if (modValue.isNewelevation) {
  118. modValue.lC++;
  119. modValue.elevationObjs[modValue.lC] = new L.FeatureGroup();
  120. modValue.elevationObjs[modValue.lC].addTo(map2DViewer.groups[modValue.elevationGroup]);
  121. modValue.elevationObjs[modValue.lC].rangPoints = [];
  122. modValue.elevationObjs[modValue.lC].lineDistance = 0;
  123. modValue.elevationObjs[modValue.lC].linePoints = [];
  124. modValue.isNewelevation = false;
  125. };
  126. if (modValue.elevationObjs[modValue.lC].rangPoints.length > 0) {
  127. if (e.latlng === modValue.elevationObjs[modValue.lC].rangPoints[modValue.elevationObjs[modValue.lC].rangPoints.length - 1]) {
  128. return false;
  129. }
  130. modValue.elevationObjs[modValue.lC].rangPoints.push(e.latlng);
  131. var _sPoint = modValue.elevationObjs[modValue.lC].rangPoints[modValue.elevationObjs[modValue.lC].rangPoints.length - 2];
  132. var numP = parseInt(_sPoint.distanceTo(e.latlng) / 600) > 2 ? parseInt(_sPoint.distanceTo(e.latlng) / 600) : 2;
  133. var qPoints = getCurvePoints([_sPoint, e.latlng], numP);
  134. modValue.elevationObjs[modValue.lC].linePoints.push(qPoints);
  135. var tem = L.polyline(qPoints, {
  136. color: '#edad00',
  137. weight: 3,
  138. opacity: 1
  139. });
  140. tem.addTo(modValue.elevationObjs[modValue.lC]);
  141. tem.redraw();
  142. var lineDistance = _sPoint.distanceTo(e.latlng) + modValue.elevationObjs[modValue.lC].lineDistance;
  143. modValue.elevationObjs[modValue.lC].lineDistance = lineDistance;
  144. var lineDistanceStr = lineDistance > 1000 ? (lineDistance / 1000).toFixed(2) + '公里' : Math.ceil(lineDistance) + '米';
  145. tipText = lineDistanceStr;
  146. labelObj.innerHTML = tipText;
  147. } else {
  148. modValue.elevationObjs[modValue.lC].rangPoints.push(e.latlng);
  149. labelObj.innerHTML = tipText;
  150. map2DViewer.map.on('mousemove', onMoveLine);
  151. }
  152. modValue.elevationObjs[modValue.lC]._lastMarker = buildMarker({
  153. latlng: e.latlng
  154. }).bindLabel(labelObj, {
  155. noHide: true
  156. });
  157. modValue.elevationObjs[modValue.lC]._lastMarker.showLabel();
  158. modValue.elevationObjs[modValue.lC]._lastMarker.addTo(modValue.elevationObjs[modValue.lC]);
  159. };
  160. /**
  161. * 获取弧线的节点坐标数组 //todo 有误
  162. * @type {Function}
  163. * @param points
  164. * @returns {Array}
  165. * @private
  166. */
  167. function getCurvePoints(points, num) {
  168. var curvePoints = [];
  169. for (var i = 0; i < points.length - 1; i++) {
  170. var p = getCurve(points[i], points[i + 1], num);
  171. if (p && p.length > 0) {
  172. curvePoints = curvePoints.concat(p);
  173. }
  174. }
  175. return curvePoints;
  176. };
  177. /**
  178. * 根据两点获取曲线坐标点数组
  179. * @type {Function}
  180. * @param start {Object} 起点
  181. * @param finish {Object} 终点
  182. * @param segments {Number} 拐点数量
  183. * @returns {*}
  184. * @private
  185. */
  186. function getCurve(start, finish, segments) {
  187. var startlat = start.lat;
  188. var startlon = start.lng;
  189. var finishlat = finish.lat;
  190. var finishlon = finish.lng;
  191. var segments = segments;
  192. var curveAry = [];
  193. var lat1 = startlat * (Math.PI / 180);
  194. var lon1 = startlon * (Math.PI / 180);
  195. var lat2 = finishlat * (Math.PI / 180);
  196. var lon2 = finishlon * (Math.PI / 180);
  197. var d = 2 * Math.asin(Math.sqrt(Math.pow((Math.sin((lat1 - lat2) / 2)), 2) + Math.cos(lat1) * Math.cos(lat2) * Math.pow((Math.sin((lon1 - lon2) / 2)), 2)));
  198. for (var n = 0; n < segments + 1; n++) {
  199. var f = (1 / segments) * n;
  200. var A = Math.sin((1 - f) * d) / Math.sin(d);
  201. var B = Math.sin(f * d) / Math.sin(d);
  202. var x = A * Math.cos(lat1) * Math.cos(lon1) + B * Math.cos(lat2) * Math.cos(lon2);
  203. var y = A * Math.cos(lat1) * Math.sin(lon1) + B * Math.cos(lat2) * Math.sin(lon2);
  204. var z = A * Math.sin(lat1) + B * Math.sin(lat2);
  205. var lat = Math.atan2(z, Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)));
  206. var lon = Math.atan2(y, x);
  207. try {
  208. var temp = L.latLng(lat / (Math.PI / 180), lon / (Math.PI / 180));
  209. curveAry.push(temp);
  210. } catch (e) {}
  211. }
  212. return curveAry;
  213. };
  214. /**
  215. * 给起始点和目的点的鼠标画线
  216. * @type {Function}
  217. * @param e
  218. * @private
  219. */
  220. function onMoveLine(e) {
  221. if (modValue.elevationObjs[modValue.lC].rangPoints.length > 0) {
  222. var _startPoint = modValue.elevationObjs[modValue.lC].rangPoints[modValue.elevationObjs[modValue.lC].rangPoints.length - 1];
  223. var _endPoint = e.latlng;
  224. drawLine(_startPoint, _endPoint);
  225. }
  226. };
  227. /**
  228. * 更新画线
  229. * @type {Function}
  230. * @param start {Object} 开始点
  231. * @param end {Object} 结束点
  232. * @private
  233. */
  234. function drawLine(start, end) {
  235. var numP = parseInt(start.distanceTo(end) / 600) > 2 ? parseInt(start.distanceTo(end) / 600) : 2;
  236. var newPos = getCurvePoints([start, end], numP);
  237. var pointArry = [];
  238. for (var i = 0; i < newPos.length; i++) {
  239. pointArry.push([newPos[i].lng, newPos[i].lat]);
  240. }
  241. map3DViewer.polyline({
  242. action: 'update',
  243. geojson: {
  244. "geometry": {
  245. "coordinates": pointArry
  246. }
  247. },
  248. guid: modValue.lineGuide
  249. });
  250. };
  251. /**
  252. * 创建冒泡窗
  253. */
  254. function creatPopupHtml(options) {
  255. var popupHtml = '<div class="popup_html marker">' +
  256. ' <div class="popup-lt"></div>' +
  257. ' <div class="popup-lb"></div>' +
  258. ' <div class="popup-rt"></div>' +
  259. ' <div class="popup-rb"></div>' +
  260. ' <div class="popup-ct" style="text-indent:15px;line-height:48px">' +
  261. ' </div>' +
  262. ' <div class="popup-cb" style="padding-bottom:20px;color:#666666 !important">' + options.content + '</div>' +
  263. '</div>'
  264. return popupHtml;
  265. }
  266. /**
  267. * 双击事件,结束当前线条画线测距
  268. * @type {Function}
  269. * @param e
  270. * @private
  271. */
  272. function onFinishClick(e) {
  273. map3DViewer.polyline({
  274. action: 'update',
  275. geojson: {
  276. "geometry": {
  277. "coordinates": [
  278. [0, 0],
  279. [0, 0]
  280. ]
  281. }
  282. },
  283. guid: modValue.lineGuide
  284. })
  285. map2DViewer.map.off('mousemove', onMoveLine);
  286. var _lastPoint = modValue.elevationObjs[modValue.lC].rangPoints[modValue.elevationObjs[modValue.lC].rangPoints.length - 1];
  287. var lineDistance = modValue.elevationObjs[modValue.lC].lineDistance;
  288. modValue.elevationObjs[modValue.lC].lineDistance = lineDistance;
  289. var lineDistanceStr = lineDistance > 1000 ? (lineDistance / 1000).toFixed(2) + '公里' : Math.ceil(lineDistance) + '米';
  290. var lid = modValue.lC;
  291. var oLabelObj = '<div class="ele_popup_html"><a class="sure" href="javascript:ONEMAP.M.toolElevation.run(\'' + e + '\',\'' + lid + '\')">剖面量算</a><a class="del" href="javascript:ONEMAP.M.toolElevation.del(\'' + e + '\',\'' + lid + '\')">删除</a></div>';
  292. // $("#elevationContent .close").bind('click',function(){
  293. // ONEMAP.M.toolElevation.del(e, modValue.lC);
  294. // })
  295. var options_popup = {
  296. name: '剖面量算',
  297. content: oLabelObj
  298. }
  299. oLabelObj = creatPopupHtml(options_popup);
  300. modValue.elevationObjs[modValue.lC]._lastMarker.bindPopup(oLabelObj, {
  301. closeButton: false,
  302. maxWidth: 60,
  303. minWidth: 40
  304. });
  305. modValue.elevationObjs[modValue.lC]._lastMarker.on('mouseover', function () {
  306. this.openPopup();
  307. setTimeout(function () {
  308. if (modValue.elevationObjs[modValue.lC]) {
  309. modValue.elevationObjs[modValue.lC]._lastMarker.closePopup()
  310. }
  311. }, 200000)
  312. });
  313. var curLiHtml = $('<li class="listItem cur"><a cid="' + lid + '" href="javascript:ONEMAP.M.toolElevation.runData(\'' + e + '\',\'' + lid + '\')">量算' + modValue.lC + '</a></li>')
  314. curLiHtml.bind('click', function () {
  315. modValue.elevationObjs[lid]._lastMarker.openPopup();
  316. setTimeout(function () {
  317. if (modValue.elevationObjs[lid]) {
  318. modValue.elevationObjs[lid]._lastMarker.closePopup()
  319. }
  320. }, 2000);
  321. var latlng = modValue.elevationObjs[lid]._lastMarker.getLatLng();
  322. map2DViewer.setView({
  323. center: {
  324. lat: latlng.lat,
  325. lng: latlng.lng
  326. },
  327. zoom: map23DData.view.zoom
  328. });
  329. $(this).siblings().removeClass('cur');
  330. $(this).addClass('cur');
  331. });
  332. $("#elevationContent .elevationList").append(curLiHtml);
  333. curLiHtml.siblings().removeClass('cur');
  334. run(null, JSON.stringify(modValue.lC));
  335. };
  336. /**
  337. * 进行剖面量算
  338. * @param {[type]} event [description]
  339. * @param {[type]} iC [description]
  340. * @return {[type]} [description]
  341. */
  342. function run(event, iC) {
  343. modValue.curElevIC = iC;
  344. $.each(modValue.elevationObjs, function (i, t) {
  345. if (i === iC) {
  346. modValue.elevationObjs[i].setStyle({
  347. color: "red"
  348. });
  349. } else {
  350. modValue.elevationObjs[i].setStyle({
  351. color: "#edad00"
  352. });
  353. }
  354. })
  355. $("#elevationContent .elevationList .listItem").eq(iC - 1).addClass('cur');
  356. $("#elevationContent .elevationList .listItem").eq(iC - 1).siblings().removeClass('cur');
  357. var coordinates = [];
  358. // if (modValue.elevationObjs[iC])
  359. // return
  360. for (var i = 0, l = modValue.elevationObjs[iC].linePoints.length; i < l; i++) {
  361. var pointsLatLngs = modValue.elevationObjs[iC].linePoints[i];
  362. for (var ii = 0, ll = pointsLatLngs.length; ii < ll; ii++) {
  363. coordinates.push(pointsLatLngs[ii]['lng']);
  364. coordinates.push(pointsLatLngs[ii]['lat']);
  365. }
  366. }
  367. if (coordinates.length < 2) {
  368. ONEMAP.C.publisher.publish({
  369. type: 'error',
  370. message: '量算点数过少,无法进行剖面量算!'
  371. }, 'noteBar::add');
  372. return false;
  373. }
  374. var ajaxUrl = onemapUrlConfig.elevationDataUrl + onemapUrlConfig.elevationVertion;
  375. var ajaxData = {
  376. points: '[' + coordinates.join(',') + ']',
  377. count: 8,
  378. zoom: map23DData.view.zoom,
  379. delta_zoom: 0
  380. };
  381. $.ajax({
  382. type: "post",
  383. dataType: 'json',
  384. data: ajaxData,
  385. url: ajaxUrl,
  386. beforeSend: ONEMAP.V.loading.load(),
  387. success: function (data) {
  388. if (data.code == 0) {
  389. if (data.data.length > 0) {
  390. var coordinatesAll = [];
  391. var coordinatesTemp = [];
  392. var gap = 1;
  393. for (var i = 0, l = data.data.length; i < l; i++) {
  394. coordinatesTemp = [data.data[i + 2], data.data[i + 3], data.data[i + 1]];
  395. coordinatesAll.push(coordinatesTemp);
  396. i = i + 3;
  397. }
  398. var geojson = {
  399. "name": "NewFeatureType",
  400. "type": "FeatureCollection",
  401. "features": [{
  402. "type": "Feature",
  403. "geometry": {
  404. "type": "LineString",
  405. "coordinates": coordinatesAll
  406. },
  407. "properties": null
  408. }]
  409. };
  410. modValue.iCData[modValue.curElevIC] = geojson;
  411. if (ONEMAP.M.toolElevation.elevationControl) {
  412. map2DViewer.map.removeControl(ONEMAP.M.toolElevation.elevationControl);
  413. ONEMAP.M.toolElevation.elevationControl = null;
  414. }
  415. ONEMAP.M.toolElevation['elevationControl'] = L.control.elevation();
  416. ONEMAP.M.toolElevation['elevationControl'].addTo(map2DViewer.map);
  417. var gjl = L.geoJson(geojson, {
  418. onEachFeature: ONEMAP.M.toolElevation.elevationControl.addData.bind(ONEMAP.M.toolElevation.elevationControl)
  419. });
  420. $(".leaflet-control-elevation").appendTo($("#elevationContent .itemElevation"));
  421. $("#elevationContent").show();
  422. $(".leaflet-control-elevation").css({
  423. 'position': 'absolute',
  424. 'left': 0,
  425. 'bottom': 0
  426. })
  427. } else {
  428. ONEMAP.C.publisher.publish({
  429. type: 'error',
  430. message: '无量算数据显示'
  431. }, 'noteBar::add');
  432. }
  433. } else {
  434. ONEMAP.C.publisher.publish({
  435. type: 'error',
  436. message: data.message
  437. }, 'noteBar::add');
  438. }
  439. },
  440. completer: ONEMAP.V.loading.loaded()
  441. });
  442. status.firstEle = false;
  443. };
  444. /**
  445. * 外部添加量算
  446. */
  447. function addElevation() {
  448. }
  449. function runData(event, iC) {
  450. modValue.curElevIC = iC;
  451. $.each(modValue.elevationObjs, function (i, t) {
  452. if (i === iC) {
  453. modValue.elevationObjs[i].setStyle({
  454. color: "red"
  455. });
  456. } else {
  457. modValue.elevationObjs[i].setStyle({
  458. color: "#edad00"
  459. });
  460. }
  461. })
  462. $.each($(".elevationList .listItem"), function (i, t) {
  463. if ($(t).find('a').attr("cid") === iC) {
  464. $(t).addClass('cur');
  465. $(t).siblings().removeClass('cur');
  466. }
  467. })
  468. //$("#elevationContent .elevationList .listItem").eq(iC - 1).addClass('cur');
  469. //$("#elevationContent .elevationList .listItem").eq(iC - 1).siblings().removeClass('cur');
  470. if (ONEMAP.M.toolElevation.elevationControl) {
  471. map2DViewer.map.removeControl(ONEMAP.M.toolElevation.elevationControl);
  472. ONEMAP.M.toolElevation.elevationControl = null;
  473. }
  474. var geojson = modValue.iCData[modValue.curElevIC];
  475. ONEMAP.M.toolElevation['elevationControl'] = L.control.elevation();
  476. ONEMAP.M.toolElevation['elevationControl'].addTo(map2DViewer.map);
  477. var gjl = L.geoJson(geojson, {
  478. onEachFeature: ONEMAP.M.toolElevation.elevationControl.addData.bind(ONEMAP.M.toolElevation.elevationControl)
  479. });
  480. $(".leaflet-control-elevation").appendTo($("#elevationContent .itemElevation"));
  481. $("#elevationContent").show();
  482. $(".leaflet-control-elevation").css({
  483. 'position': 'absolute',
  484. 'left': 0,
  485. 'bottom': 0
  486. })
  487. };
  488. /**
  489. * 删除对应iC的测距
  490. * @type {Function}
  491. * @param event {Event}
  492. * @param iC {String} IC
  493. */
  494. function del(event, iC) {
  495. var event = event || window.event;
  496. L.DomEvent.stop(event);
  497. map2DViewer.groups[modValue.elevationGroup].removeLayer(modValue.elevationObjs[iC]);
  498. delete modValue.elevationObjs[iC];
  499. if (modValue.curElevIC == iC) {
  500. if (ONEMAP.M.toolElevation.elevationControl) {
  501. map2DViewer.map.removeControl(ONEMAP.M.toolElevation.elevationControl);
  502. ONEMAP.M.toolElevation.elevationControl = null;
  503. }
  504. }
  505. $.each($(".elevationList li"), function (i, t) {
  506. if ($(t).find('a').attr("cid") === iC) {
  507. if ($(t).index() === 0) {
  508. var cueCid = $(".elevationList li").eq(i + 1).find('a').attr("cid");
  509. } else {
  510. var cueCid = $(".elevationList li").eq(i - 1).find('a').attr("cid");
  511. }
  512. runData(null, cueCid);
  513. $(t).remove();
  514. }
  515. });
  516. if ($(".elevationList li").length === 0) {
  517. $("#elevationContent").hide();
  518. }
  519. };
  520. /**
  521. * 创建一个marker 并返回该marker
  522. * @type {Function}
  523. * @param obj {Object} marker对象
  524. * @returns {L.Marker}
  525. * @private
  526. */
  527. function buildMarker(obj) {
  528. var markerId = map23DControl.marker({
  529. action: 'add',
  530. groupId: modValue.elevationGroup,
  531. geojson: {
  532. "properties": {
  533. iconUrl: map23DConfig.map23DAssetsUrl + '/images/layout/ico_linePoint.png',
  534. iconSize: [15, 15],
  535. iconAnchor: [7, 7],
  536. popupAnchor: [0, -7]
  537. },
  538. "geometry": {
  539. "coordinates": [obj.latlng.lng, obj.latlng.lat]
  540. }
  541. }
  542. })
  543. map2DViewer.markers[markerId].on('click', function (e) {
  544. if (modValue.elevationObjs[modValue.lC].rangPoints.length < 2) {
  545. return false;
  546. }
  547. //与上一个点相同,测量完成
  548. if (e.latlng.lat == modValue.elevationObjs[modValue.lC].rangPoints[modValue.elevationObjs[modValue.lC].rangPoints.length - 1].lat ||
  549. e.latlng.lng == modValue.elevationObjs[modValue.lC].rangPoints[modValue.elevationObjs[modValue.lC].rangPoints.length - 1].lng) {
  550. modValue.isNewelevation = true;
  551. map2DViewer.markers[markerId].off('click');
  552. onFinishClick({
  553. latlng: modValue.elevationObjs[modValue.lC].rangPoints[modValue.elevationObjs[modValue.lC].rangPoints.length - 1],
  554. curMarker: this
  555. });
  556. return false;
  557. }
  558. });
  559. return map2DViewer.markers[markerId];
  560. };
  561. function subscribe() {
  562. ONEMAP.C.publisher.subscribe(remove, 'tools:active');
  563. ONEMAP.C.publisher.subscribe(clearAllMap, 'cleanMap');
  564. ONEMAP.C.publisher.subscribe(remove, 'change23D');
  565. ONEMAP.C.publisher.subscribe(layoutResize, 'sideBarStatus');
  566. ONEMAP.C.publisher.subscribe(controlMeasuring, 'controlMearsuring');
  567. };
  568. function remove(options) {
  569. if (options.modName == "cleanMap") {
  570. clearAllMap();
  571. }
  572. if (options.modName != 'toolElevation') {
  573. $(".tools-elevation").removeClass('cur');
  574. removeEvent();
  575. } else {
  576. if ($(".tools-elevation").hasClass('cur')) {
  577. $(".tools-elevation").removeClass('cur');
  578. removeEvent();
  579. } else {
  580. $(".tools-elevation").addClass('cur');
  581. map2DViewer.map.doubleClickZoom.disable();
  582. map2DViewer.map.on('click', onClickPoint);
  583. modValue.lineGuide = map3DViewer.polyline({
  584. action: 'add',
  585. groupId: modValue.elevationGroup,
  586. geojson: {
  587. "properties": {
  588. color: '#edad00',
  589. weight: 3,
  590. opacity: 0.5,
  591. altitudeMode: 0,
  592. },
  593. "geometry": {
  594. "coordinates": [
  595. [0, 0],
  596. [0, 0]
  597. ]
  598. }
  599. }
  600. })
  601. }
  602. }
  603. };
  604. /**
  605. * 移除剖面量算事件
  606. */
  607. function removeEvent() {
  608. if (L.Browser.ie || L.Browser.firefox) {
  609. map2DViewer.map.getContainer().style.cursor = 'url(/scripts/vendor/map23dlib/images/cur-none.cur),auto';
  610. } else {
  611. map2DViewer.map.getContainer().style.cursor = 'url(/scripts/vendor/map23dlib/images/cur-none.cur) 5 5,auto';
  612. }
  613. if (modValue.isNewelevation === false) {
  614. if (modValue.elevationObjs[modValue.lC]) {
  615. onFinishClick({
  616. latlng: modValue.elevationObjs[modValue.lC].rangPoints[modValue.elevationObjs[modValue.lC].rangPoints.length - 1]
  617. });
  618. }
  619. }
  620. modValue.isNewelevation = true;
  621. ONEMAP.M.mapHolder.mouseHand();
  622. map2DViewer.map.off('click', onClickPoint);
  623. map2DViewer.map.off('mousemove', onMoveLine);
  624. };
  625. function clearAllMap() {
  626. // map2DViewer.groups[modValue.elevationGroup].clearLayers();
  627. map23DControl.group({
  628. action: 'remove',
  629. guid: modValue.elevationGroup
  630. })
  631. map23DControl.group({
  632. action: 'add',
  633. guid: modValue.elevationGroup
  634. })
  635. // map3DViewer.polyline({
  636. // action: 'remove',
  637. // guid: modValue.lineGuide
  638. // })
  639. modValue.elevationObjs = {};
  640. modValue.lC = 0;
  641. $("#elevationContent").hide();
  642. $("#elevationContent .elevationList").empty();
  643. $("#elevationContent .itemElevation").empty();
  644. if (ONEMAP.M.toolElevation.elevationControl) {
  645. map2DViewer.map.removeControl(ONEMAP.M.toolElevation.elevationControl);
  646. ONEMAP.M.toolElevation.elevationControl = null;
  647. }
  648. if ($(".tools-elevation").hasClass('cur')) {
  649. $(".tools-elevation").removeClass('cur');
  650. }
  651. removeEvent();
  652. // modValue.elevationGroup = null
  653. // status.initialized = false
  654. };
  655. return ONEMAP.M.toolElevation = {
  656. init: init,
  657. run: run,
  658. runData: runData,
  659. addElevation: addElevation,
  660. del: del
  661. }
  662. })