leaflet.measureDistance.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. L.Control.MeasureDistance = L.Control.extend({
  2. //是否初始化
  3. _initialized:false,
  4. //统计
  5. _lC:0,
  6. //测
  7. _measureObjs:{},
  8. //是否完成当前测绘
  9. _finished:true,
  10. isNewElevation:true,
  11. options:{
  12. position:'topright',
  13. autoZIndex:true,
  14. offset:[10,10],
  15. background:"#000",
  16. color:"#fff",
  17. size:14,
  18. closeButton:true
  19. },
  20. initialize:function(options){
  21. L.setOptions(this, options);
  22. return this;
  23. },
  24. onAdd:function(map){
  25. this._map = map;
  26. this._createControl();
  27. this._map.on('measure-area-start',this.stop,this);
  28. switch(this.options.position){
  29. case 'topleft':
  30. this._container.style.marginLeft = this.options.offset[0]+'px';
  31. this._container.style.marginTop = this.options.offset[1]+'px';
  32. break;
  33. case 'topright':
  34. this._container.style.marginRight = this.options.offset[0]+'px';
  35. this._container.style.marginTop = this.options.offset[1]+'px';
  36. break;
  37. case 'bottomleft':
  38. this._container.style.marginLeft = this.options.offset[0]+'px';
  39. this._container.style.marginBottom = this.options.offset[1]+'px';
  40. break;
  41. case 'bottomright':
  42. this._container.style.marginRight = this.options.offset[0]+'px';
  43. this._container.style.marginBottom = this.options.offset[1]+'px';
  44. break;
  45. }
  46. return this._container;
  47. },
  48. _createControl:function(){
  49. var _this = this;
  50. this._container = L.DomUtil.create('div','leaflet-bar leaflet-control-measure-distance');
  51. var link = L.DomUtil.create('a','leaflet-control-measure-distance-link',this._container);
  52. link.title = '两点测量距离';
  53. L.DomUtil.create('span','',link);
  54. L.DomEvent
  55. .on(this._container,'contextmenu',L.DomEvent.stopPropagation)
  56. .on(link,'click', L.DomEvent.stopPropagation)
  57. .on(link,'click',function(){
  58. if(!_this._finished){
  59. if(_this._measureObjs[_this._lC].distancePoints.length > 0){
  60. _this._onFinishClick();
  61. }
  62. _this._finished = true;
  63. L.DomUtil.removeClass(_this._container,'active');
  64. _this._removeMeasureGroup();
  65. map2DViewer.map.fire('measure-distance-stop');
  66. map2DViewer.map.getContainer().style.cursor = 'auto';
  67. }else {
  68. _this._finished = false;
  69. L.DomUtil.addClass(_this._container,'active');
  70. _this._addMeasureGroup();
  71. map2DViewer.map.fire('measure-distance-start');
  72. if(L.Browser.ie || L.Browser.firefox){
  73. _this._map.getContainer().style.cursor = 'url('+L.DefaultImagePath+'/cur-ruler.cur),auto';
  74. }else{
  75. _this._map.getContainer().style.cursor = 'url('+L.DefaultImagePath+'/cur-ruler.cur) 5 5,auto';
  76. }
  77. }
  78. })
  79. _this.start();
  80. },
  81. start:function(){
  82. var _this = this;
  83. if(!_this._finished){
  84. if(_this._measureObjs[_this._lC].distancePoints.length > 0){
  85. _this._onFinishClick();
  86. }
  87. _this._finished = true;
  88. L.DomUtil.removeClass(_this._container,'active');
  89. _this._removeMeasureGroup();
  90. map2DViewer.map.fire('measure-distance-stop');
  91. }
  92. _this._finished = false;
  93. L.DomUtil.addClass(_this._container,'active');
  94. _this._addMeasureGroup();
  95. map2DViewer.map.fire('measure-distance-start');
  96. if(L.Browser.ie || L.Browser.firefox){
  97. _this._map.getContainer().style.cursor = 'url('+L.DefaultImagePath+'/cur-ruler.cur),auto';
  98. }else{
  99. _this._map.getContainer().style.cursor = 'url('+L.DefaultImagePath+'/cur-ruler.cur) 5 5,auto';
  100. }
  101. _this._map.doubleClickZoom.disable();
  102. },
  103. stopMasuring:function(){
  104. var _this = this;
  105. _this._finished = true;
  106. L.DomUtil.removeClass(_this._container,'active');
  107. _this._removeMeasureGroup();
  108. map2DViewer.map.getContainer().style.cursor = 'auto';
  109. },
  110. stop:function(){
  111. var _this = this;
  112. if(!_this._finished){
  113. if(_this._measureObjs[_this._lC].distancePoints.length > 0){
  114. _this._onFinishClick();
  115. }
  116. _this._finished = true;
  117. L.DomUtil.removeClass(_this._container,'active');
  118. _this._removeMeasureGroup();
  119. map2DViewer.map.fire('measure-distance-stop');
  120. map2DViewer.map.getContainer().style.cursor = 'auto';
  121. }
  122. },
  123. measurePoints:function(startPoint,endPoint){
  124. var _this = this;
  125. _this.start();
  126. _this._onClickPoint({latlng:startPoint});
  127. _this._onClickPoint({latlng:endPoint});
  128. },
  129. updatelC:function(lC,startPoint,endPoint){
  130. var _this = this;
  131. _this._measureObjs[lC].distancePoints = [startPoint,endPoint];
  132. _this._measureObjs[lC].linePoints = [startPoint,endPoint];
  133. _this._measureObjs[lC].lineDistance = new L.LatLng(startPoint[0],startPoint[1]).distanceTo(new L.LatLng(endPoint[0],endPoint[1]));
  134. var newPos = _this._getCurvePoints([new L.LatLng(startPoint[0],startPoint[1]),new L.LatLng(endPoint[0],endPoint[1])]);
  135. _this._measureObjs[lC].polyLine.setLatLngs(newPos);
  136. _this._measureObjs[lC].polyLine.redraw();
  137. _this._measureObjs[lC].resultMarker.setLatLng(new L.LatLng(endPoint[0],endPoint[1]));
  138. var lineDistance = _this._measureObjs[lC].lineDistance;
  139. var lineDistanceStr = lineDistance > 1000 ? (lineDistance / 1000).toFixed(2) + '公里' : Math.ceil(lineDistance) + '米';
  140. var pointAngle = L.Util.getAngleByLatLng(startPoint[1],startPoint[0],endPoint[1],endPoint[0]);
  141. pointAngle += '度';
  142. //添加结束信息
  143. var pointText = L.DomUtil.create('div','measure-distance-result-text');
  144. pointText.innerHTML = lineDistanceStr+'<br/>'+pointAngle;
  145. pointText.lC = _this._lC;
  146. L.DomEvent.on(pointText, 'dblclick', function(e) {
  147. L.DomEvent.stopPropagation(e);
  148. _this.del(pointText.lC)
  149. });
  150. _this._measureObjs[lC].removeLayer(_this._measureObjs[lC].resultMarker);
  151. _this._measureObjs[lC].resultMarker = L.marker(endPoint,{icon:L.divIcon({iconSize: [5, 5]})}).bindLabel(pointText,
  152. {noHide: true,clickable: true,className:'measure-distance-tip',offset:[0,0]}
  153. ).addTo(_this._measureObjs[lC]);
  154. map2DViewer.map.fire('measure-distance-result',{lC:lC,distance:lineDistanceStr,angle:pointAngle,distancePoints:_this._measureObjs[lC].distancePoints});
  155. },
  156. /**
  157. * 清除所有的量算
  158. * @return {[type]} [description]
  159. */
  160. cleanAllMeasure:function(){
  161. var _this = this;
  162. for(var item in _this._measureObjs){
  163. _this.del(item);
  164. }
  165. },
  166. _addMeasureGroup:function(){
  167. var _this = this;
  168. if(!_this._initialized){
  169. _this._measureGroup = new L.featureGroup();
  170. _this._measureGroup.addTo(map2DViewer.map);
  171. _this._initialized = true;
  172. }
  173. map2DViewer.map.doubleClickZoom.disable();
  174. map2DViewer.map.on('click',_this._onClickPoint,this);
  175. },
  176. _removeMeasureGroup:function(){
  177. var _this = this;
  178. // map2DViewer.map.getContainer().style.cursor = 'auto';
  179. map2DViewer.map.off('mousemove',_this._onMoveLine,this);
  180. map2DViewer.map.off('click',_this._onClickPoint,this);
  181. },
  182. _restartMearing:function(){
  183. var _this = this;
  184. map2DViewer.map.doubleClickZoom.disable();
  185. map2DViewer.map.on('click',_this._onClickPoint,this);
  186. if (L.Browser.ie || L.Browser.firefox) {
  187. _this._map.getContainer().style.cursor = 'url(' + L.DefaultImagePath + '/cur-ruler.cur),auto';
  188. } else {
  189. _this._map.getContainer().style.cursor = 'url(' + L.DefaultImagePath + '/cur-ruler.cur) 5 5,auto';
  190. }
  191. },
  192. /**
  193. * 鼠标单击事件,如果是第一次,则设置为初始点 如果产生第二个点表示测量完成
  194. * @param e
  195. * @returns {boolean}
  196. * @private
  197. */
  198. _onClickPoint:function(e){
  199. var _this = this;
  200. e.latlng = L.Util.formatEarthLatLng(e.latlng);
  201. if(_this.isNewElevation){
  202. _this._lC++;
  203. _this._measureObjs[_this._lC] = new L.FeatureGroup();
  204. _this._measureObjs[_this._lC].tempLine = new L.Polyline([[0,0],[0,0]],{clickable:false,color:'#ff0000',weight:2,opacity:1}).addTo(_this._measureObjs[_this._lC]);
  205. _this._measureObjs[_this._lC].addTo(_this._measureGroup);
  206. _this._measureObjs[_this._lC].distancePoints = [];
  207. _this._measureObjs[_this._lC].linePoints = [];
  208. _this._measureObjs[_this._lC].lineDistance = 0;
  209. _this.isNewElevation = false;
  210. }
  211. if(_this._measureObjs[_this._lC].distancePoints.length > 0){
  212. _this.dblclickFirst = true;
  213. _this._measureObjs[_this._lC].distancePoints.push(e.latlng);
  214. var _sPoint = _this._measureObjs[_this._lC].distancePoints[_this._measureObjs[_this._lC].distancePoints.length-2];
  215. var qPoints = _this._getCurvePoints([_sPoint, e.latlng]);
  216. _this._measureObjs[_this._lC].linePoints.push(qPoints);
  217. var lineDistance = _sPoint.distanceTo(e.latlng) + _this._measureObjs[_this._lC].lineDistance;
  218. _this._measureObjs[_this._lC].lineDistance = lineDistance;
  219. var _lastPoint = _this._measureObjs[_this._lC].distancePoints[_this._measureObjs[_this._lC].distancePoints.length-1];
  220. _this._measureObjs[_this._lC].lineDistance = lineDistance;
  221. var lineDistanceStr = lineDistance > 1000 ? (lineDistance / 1000).toFixed(2) + '公里' : Math.ceil(lineDistance) + '米';
  222. var pointAngle = L.Util.getAngleByLatLng(_sPoint.lng,_sPoint.lat,_lastPoint.lng,_lastPoint.lat);
  223. //添加结束信息
  224. var oLabelObj = L.DomUtil.create('div','measure-distance-content');
  225. var delLabel = L.DomUtil.create('span','distance-ico-del');
  226. var pointText = L.DomUtil.create('span','measure-distance-result-text');
  227. delLabel.innerHTML = '删除';
  228. delLabel.lC = _this._lC;
  229. L.DomEvent.on(delLabel, 'click', function(e) {
  230. L.DomEvent.stopPropagation(e);
  231. _this.del(delLabel.lC)
  232. });
  233. pointText.innerHTML = lineDistanceStr+'<br/>'+pointAngle+'度';
  234. pointText.lC = _this._lC;
  235. oLabelObj.appendChild(pointText);
  236. _this._measureObjs[_this._lC].resultMarker = _this._buildMarker(_lastPoint).bindLabel(oLabelObj,
  237. {noHide: true,clickable: true,className:'measure-distance-tip',offset:[0,0]}
  238. ).addTo(_this._measureObjs[_this._lC]);
  239. _this._onMoveLine(e)
  240. }else {
  241. _this._measureObjs[_this._lC].resultMarker = _this._buildMarker(e.latlng).addTo(_this._measureObjs[_this._lC]);
  242. _this._measureObjs[_this._lC].distancePoints.push(e.latlng);
  243. map2DViewer.map.on('mousemove',_this._onMoveLine,this);
  244. }
  245. _this.editerCSS();
  246. },
  247. /**
  248. * 创建一个marker 并返回该marker
  249. * @type {Function}
  250. * @param obj {Object} {latlng}
  251. * @returns {L.Marker}
  252. * @private
  253. */
  254. _buildMarker:function(obj){
  255. var _this = this;
  256. var marker = L.marker(
  257. obj,
  258. {icon: L.divIcon({
  259. iconSize: [5, 5]
  260. })}
  261. );
  262. marker.on('click',function(e){
  263. if(_this._measureObjs[_this._lC].distancePoints.length<2){
  264. return false;
  265. }
  266. //与上一个点相同,测量完成
  267. if(e.latlng == _this._measureObjs[_this._lC].distancePoints[_this._measureObjs[_this._lC].distancePoints.length-1] ){
  268. _this._onFinishClick(e);
  269. return false;
  270. }
  271. });
  272. return marker;
  273. },
  274. /**
  275. * 给起始点和目的点的鼠标画线
  276. * @type {Function}
  277. * @param e
  278. * @private
  279. */
  280. _onMoveLine:function(e){
  281. var _this = this;
  282. if(_this._measureObjs[_this._lC].distancePoints.length > 0){
  283. var length = _this._measureObjs[_this._lC].distancePoints.length;
  284. var _startPoint = _this._measureObjs[_this._lC].distancePoints[length-2];
  285. var _endPoint = e.latlng;
  286. _this._drawLine(_startPoint,_endPoint);
  287. }
  288. },
  289. /**
  290. * 更新画线
  291. * @type {Function}
  292. * @param start {Object} 开始点
  293. * @param end {Object} 结束点
  294. * @private
  295. */
  296. _drawLine:function(start,end){
  297. var _this = this;
  298. _this._measureObjs[_this._lC].distancePoints.push(end);
  299. var newPos = _this._measureObjs[_this._lC].distancePoints;
  300. _this._measureObjs[_this._lC].tempLine.setLatLngs(newPos);
  301. _this._measureObjs[_this._lC].tempLine.redraw();
  302. var length = _this._measureObjs[_this._lC].distancePoints.length;
  303. _this._measureObjs[_this._lC].distancePoints.splice(length-1,1);
  304. },
  305. _upDateLine:function(lC){
  306. var _this = this;
  307. var linePoints = _this._measureObjs[_this._lC].linePoints;
  308. var allPoints = [];
  309. for(var i = 0,l=linePoints.length;i<l;i++){
  310. allPoints = allPoints.concat(linePoints[i]);
  311. }
  312. if(_this._measureObjs[lC].polyLine){
  313. _this._measureObjs[lC].polyLine.setLatLngs(allPoints);
  314. }else {
  315. _this._measureObjs[lC].polyLine = L.polyline(allPoints,{color:'#ff0000',weight:2, opacity:1,clickable:false})
  316. .addTo(_this._measureObjs[lC]);
  317. }
  318. },
  319. /**
  320. * 结束当前线条画线测距
  321. * @param e
  322. * @private
  323. */
  324. _onFinishClick:function(e){
  325. var _this = this;
  326. map2DViewer.map.off('click',_this._onClickPoint,this);
  327. if(e && _this.dblclickFirst){
  328. _this.dblclickFirst = false;
  329. _this._measureObjs[_this._lC].distancePoints.push(e.latlng);
  330. var _sPoint = _this._measureObjs[_this._lC].distancePoints[_this._measureObjs[_this._lC].distancePoints.length-3];
  331. var qPoints = _this._getCurvePoints([_sPoint, e.latlng]);
  332. _this._measureObjs[_this._lC].linePoints.push(qPoints);
  333. //var lineDistance = _sPoint.distanceTo(e.latlng) + _this._measureObjs[_this._lC].lineDistance;
  334. var lineDistance = _this._measureObjs[_this._lC].lineDistance;
  335. _this._measureObjs[_this._lC].lineDistance = lineDistance;
  336. var _lastPoint = _this._measureObjs[_this._lC].distancePoints[_this._measureObjs[_this._lC].distancePoints.length-2];
  337. _this._measureObjs[_this._lC].lineDistance = lineDistance;
  338. var lineDistanceStr = lineDistance > 1000 ? (lineDistance / 1000).toFixed(2) + '公里' : Math.ceil(lineDistance) + '米';
  339. var pointAngle = L.Util.getAngleByLatLng(_sPoint.lng,_sPoint.lat,_lastPoint.lng,_lastPoint.lat);
  340. //添加结束信息
  341. var oLabelObj = L.DomUtil.create('div','measure-distance-content');
  342. var delLabel = L.DomUtil.create('div','distance-ico-del');
  343. var pointText = L.DomUtil.create('span','measure-distance-result-text');
  344. //delLabel.innerHTML = '删除';
  345. delLabel.lC = _this._lC;
  346. L.DomEvent.on(delLabel, 'click', function(e) {
  347. L.DomEvent.stopPropagation(e);
  348. _this.del(delLabel.lC)
  349. });
  350. pointText.innerHTML = lineDistanceStr+'<br/>'+pointAngle+'度';
  351. pointText.lC = _this._lC;
  352. L.DomEvent.on(pointText, 'dblclick', function(e) {
  353. L.DomEvent.stopPropagation(e);
  354. _this.del(pointText.lC)
  355. });
  356. oLabelObj.appendChild(pointText);
  357. if(_this.options.closeButton){
  358. oLabelObj.appendChild(delLabel);
  359. }
  360. _this._measureObjs[_this._lC].resultMarker.unbindLabel();
  361. _this._measureObjs[_this._lC].resultMarker = L.marker(_lastPoint,{icon:L.divIcon({iconSize: [5, 5]})}).bindLabel(oLabelObj,
  362. {noHide: true,clickable: true,className:'measure-distance-tip',offset:[0,0]}
  363. ).addTo(_this._measureObjs[_this._lC]);
  364. }
  365. map2DViewer.map.off('mousemove',_this._onMoveLine,this);
  366. _this.isNewElevation = true;
  367. _this.editerCSS();
  368. _this.stopMasuring();
  369. _this.start();
  370. },
  371. /**
  372. * 修改测距样式
  373. */
  374. editerCSS:function(){
  375. var _this = this;
  376. $(".measure-distance-content span").css({
  377. "color":_this.options.color,
  378. })
  379. $(".measure-distance-content span").css({
  380. "font-size":_this.options.font_size,
  381. })
  382. $(".measure-distance-content").css({
  383. // "background":_this.options.background
  384. "background":'rgba(255,255,255,0.5)'
  385. });
  386. },
  387. /**
  388. * 合并样式
  389. */
  390. addCss:function(options){
  391. var _this = this;
  392. _.merge(this.options, options);
  393. _this.editerCSS();
  394. },
  395. /**
  396. * 删除对应lC的测距
  397. */
  398. del:function(lC){
  399. var _this = this;
  400. if(_this._measureObjs[lC]){
  401. _this._measureGroup.removeLayer(_this._measureObjs[lC]);
  402. delete _this._measureObjs[lC];
  403. map2DViewer.map.fire('measure-distance-delete',{lC:lC});
  404. }
  405. },
  406. /**
  407. * 获取弧线的节点坐标数组
  408. * @type {Function}
  409. * @param points
  410. * @returns {Array}
  411. * @private
  412. */
  413. _getCurvePoints:function(points){
  414. var _this = this;
  415. var curvePoints = [];
  416. for(var i = 0; i < points.length-1;i++){
  417. if(points[i]['lat'] == points[i+1]['lat'] && points[i]['lng'] == points[i+1]['lng']){
  418. curvePoints = curvePoints.concat(points[i]);
  419. }else {
  420. var p = _this._getCurve(points[i],points[i+1],20);
  421. if(p && p.length > 0){
  422. curvePoints = curvePoints.concat(p);
  423. }
  424. }
  425. }
  426. return curvePoints;
  427. },
  428. /**
  429. * 根据两点获取曲线坐标点数组
  430. * @type {Function}
  431. * @param start {Object} 起点
  432. * @param finish {Object} 终点
  433. * @param segments {Number} 拐点数量
  434. * @returns {*}
  435. * @private
  436. */
  437. _getCurve:function(start,finish,segments){
  438. var startlat = start.lat;
  439. var startlon = start.lng;
  440. var finishlat = finish.lat;
  441. var finishlon = finish.lng;
  442. var segments = segments;
  443. var curveAry = [];
  444. var lat1 = startlat * (Math.PI / 180);
  445. var lon1 = startlon * (Math.PI / 180);
  446. var lat2 = finishlat * (Math.PI / 180);
  447. var lon2 = finishlon * (Math.PI / 180);
  448. 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)));
  449. for(var n= 0; n<segments+1;n++){
  450. var f = (1/segments)*n;
  451. var A = Math.sin((1-f)*d)/Math.sin(d);
  452. var B = Math.sin(f*d)/Math.sin(d);
  453. var x = A * Math.cos(lat1)*Math.cos(lon1) + B*Math.cos(lat2)*Math.cos(lon2);
  454. var y = A * Math.cos(lat1)*Math.sin(lon1) + B*Math.cos(lat2)*Math.sin(lon2);
  455. var z = A * Math.sin(lat1) + B * Math.sin(lat2);
  456. var lat = Math.atan2(z,Math.sqrt(Math.pow(x,2)+Math.pow(y,2)));
  457. var lon = Math.atan2(y,x);
  458. try{
  459. var temp = L.latLng(lat/(Math.PI/180),lon/(Math.PI/180));
  460. curveAry.push(temp);
  461. }catch (e){
  462. }
  463. }
  464. return curveAry;
  465. },
  466. onRemove: function(map) {
  467. return this;
  468. }
  469. });
  470. L.control.measureDistance = function(options){
  471. return new L.Control.MeasureDistance(options);
  472. }
  473. /**
  474. * 测量工具
  475. */
  476. map2DViewer.distanceToolFire = function(data) {};
  477. map2DViewer.distanceToolDelFire = function(data) {};
  478. map2DViewer.setDistanceTool = function(options) {
  479. var defaultData = {
  480. action: 'add',
  481. position: 'topleft',
  482. offset: [10, 10],
  483. background:"#fff",
  484. color:"#000",
  485. font_size:"14px",
  486. closeButton:true
  487. }
  488. _.merge(defaultData, options);
  489. switch (defaultData.action) {
  490. case 'add':
  491. this.distanceTool = new L.Control.MeasureDistance({
  492. position: defaultData.position,
  493. offset: defaultData.offset,
  494. background:defaultData.background,
  495. color:defaultData.color,
  496. font_size:defaultData.font_size,
  497. closeButton:defaultData.closeButton
  498. }).addTo(this.map);
  499. this.map.on('measure-distance-result', map2DViewer.distanceToolFire);
  500. this.map.on('measure-distance-delete', map2DViewer.distanceToolDelFire);
  501. return this.distanceTool;
  502. break;
  503. case 'remove':
  504. if(this.distanceTool){
  505. this.distanceTool._removeMeasureGroup();
  506. map2DViewer.map.doubleClickZoom.enable();
  507. this.map.off('measure-distance-result', map2DViewer.distanceToolFire);
  508. this.map.off('measure-distance-delete', map2DViewer.distanceToolDelFire);
  509. }
  510. break;
  511. case 'clear':
  512. if(this.distanceTool){
  513. this.distanceTool.cleanAllMeasure();
  514. this.distanceTool._removeMeasureGroup();
  515. map2DViewer.map.doubleClickZoom.enable();
  516. this.map.removeControl(this.distanceTool);
  517. }
  518. break;
  519. case 'restart':
  520. if(this.distanceTool){
  521. this.distanceTool._restartMearing();
  522. }
  523. }
  524. }