leafletDraw2.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. let mousemove2Status = true;
  2. let LControlDraw = L.Control.extend({
  3. //是否初始化
  4. _initialized: false,
  5. //统计
  6. _lC: 0,
  7. //测量对象集合
  8. _measureObjs: {},
  9. //是否完成当前测绘
  10. _finished: true,
  11. //新测量
  12. isNewElevation: true,
  13. moveMarker: false,
  14. //测量参数
  15. options: {
  16. position: "topright",
  17. autoZIndex: true,
  18. offset: [0, 0],
  19. background: "#000",
  20. color: "#fff",
  21. size: 14,
  22. closeButton: true,
  23. iconUrl: "./images/marker-icon.png"
  24. },
  25. initialize: function (options) {
  26. L.setOptions(this, options);
  27. return this;
  28. },
  29. onAdd: function (map) {
  30. this._map = map;
  31. this._createControl();
  32. switch (this.options.position) {
  33. case "topleft":
  34. this._container.style.marginLeft = this.options.offset[0] + "px";
  35. this._container.style.marginTop = this.options.offset[1] + "px";
  36. break;
  37. case "topright":
  38. this._container.style.marginRight = this.options.offset[0] + "px";
  39. this._container.style.marginTop = this.options.offset[1] + "px";
  40. break;
  41. case "bottomleft":
  42. this._container.style.marginLeft = this.options.offset[0] + "px";
  43. this._container.style.marginBottom = this.options.offset[1] + "px";
  44. break;
  45. case "bottomright":
  46. this._container.style.marginRight = this.options.offset[0] + "px";
  47. this._container.style.marginBottom = this.options.offset[1] + "px";
  48. break;
  49. }
  50. return this._container;
  51. },
  52. _createControl: function () {
  53. var _this = this;
  54. this._container = L.DomUtil.create("div", "leaflet-bar leaflet-control-measure");
  55. var link = L.DomUtil.create("a", "leaflet-control-measure-link", this._container);
  56. link.title = "标记疑点";
  57. // L.DomUtil.create("span", "", link);
  58. L.DomEvent.on(this._container, "contextmenu", L.DomEvent.stopPropagation)
  59. .on(link, "click", L.DomEvent.stopPropagation)
  60. .on(link, "click", function () {
  61. if (_this._finished) {
  62. //开启新的测量
  63. _this.start();
  64. } else {
  65. _this._finished = true;
  66. }
  67. });
  68. // _this.start();
  69. },
  70. start: function () {
  71. var _this = this;
  72. _this._finished = false;
  73. L.DomUtil.addClass(_this._container, "active");
  74. _this._addMeasureGroup();
  75. },
  76. _addMeasureGroup: function () {
  77. var _this = this;
  78. if (!_this._initialized) {
  79. _this._measureGroup = new L.featureGroup();
  80. _this._measureGroup.addTo(this._map);
  81. _this._initialized = true;
  82. }
  83. if (_this.isNewElevation) {
  84. _this._lC++;
  85. _this._measureObjs[_this._lC] = new L.FeatureGroup();
  86. _this._measureObjs[_this._lC].addTo(_this._measureGroup);
  87. _this.isNewElevation = false;
  88. _this._measureObjs[_this._lC].measurePoints = [];
  89. }
  90. _this.tmpMarkers = [];
  91. //关闭地图双击事件
  92. _this._map.doubleClickZoom.disable();
  93. //监听地图单击事件
  94. _this._map.on("click", _this._onClickPoint, this);
  95. //监听鼠标移动事件
  96. _this._map.on("mousemove", _this._mousemove, this);
  97. },
  98. _mousemove: function (e) {
  99. if (mousemove2Status) {
  100. var _this = this;
  101. e.latlng = _this.latlngRectifying(e);
  102. if (_this.moveMarker) {
  103. _this.moveMarker.setLatLng(e.latlng);
  104. if (_this._measureObjs[_this._lC].polyline) {
  105. _this._measureObjs[_this._lC].measurePoints.push([e.latlng.lat, e.latlng.lng]);
  106. var points = _this._measureObjs[_this._lC].measurePoints;
  107. if (_this._measureObjs[_this._lC].measurePoints.length == 2) {
  108. var radius = L.latLng(points[1]).distanceTo(L.latLng(points[0]));
  109. _this._measureObjs[_this._lC].circle.setRadius(radius);
  110. } else if (_this._measureObjs[_this._lC].measurePoints.length == 3 && e.latlng.indexMarker == 1) {
  111. _this._measureObjs[_this._lC].circle.setStyle({
  112. opacity: 1
  113. });
  114. } else {
  115. _this._measureObjs[_this._lC].circle.setStyle({
  116. opacity: 0
  117. });
  118. }
  119. if (_this._measureObjs[_this._lC].measurePoints.length > 2) {
  120. var coors = _.clone(_this._measureObjs[_this._lC].measurePoints);
  121. coors.push(
  122. _this._measureObjs[_this._lC].measurePoints[_this._measureObjs[_this._lC].measurePoints.length - 1]
  123. );
  124. if (_this._measureObjs[_this._lC].polygon) {
  125. _this._measureObjs[_this._lC].polygon.setLatLngs([coors]);
  126. } else {
  127. _this._measureObjs[_this._lC].polygon = L.polygon([coors], {
  128. color: "#fff",
  129. weight: 0,
  130. fillColor: "#fff",
  131. fillOpacity: 0.3
  132. }).addTo(_this._measureObjs[_this._lC]);
  133. }
  134. }
  135. _this._measureObjs[_this._lC].polyline.setLatLngs(points);
  136. //实时计算测量数据
  137. var moveData = _.clone(points);
  138. _this._moveInfo(moveData);
  139. _this._measureObjs[_this._lC].measurePoints.pop();
  140. }
  141. } else {
  142. _this.moveMarker = L.circleMarker(e.latlng, {
  143. radius: 10,
  144. color: "#f00"
  145. }).addTo(_this._map);
  146. }
  147. } else {
  148. this._map.off("mousemove");
  149. // console.log("lmx");
  150. }
  151. },
  152. //测量时,根据鼠标移动点位信息
  153. _moveInfo: function (data) {
  154. var _this = this;
  155. var lineDistance = 0;
  156. for (var i = 1; i < data.length; i++) {
  157. var curcoor = data[i];
  158. var prePoint = data[i - 1];
  159. lineDistance = L.latLng(curcoor).distanceTo(prePoint);
  160. var lineDistanceStr =
  161. lineDistance > 1000 ? (lineDistance / 1000).toFixed(2) + "公里" : Math.ceil(lineDistance) + "米";
  162. if (i == data.length - 1) {
  163. var pointAngle = L.Util.getAngleByLatLng(prePoint[1], prePoint[0], curcoor[1], curcoor[0]);
  164. }
  165. }
  166. //添加分段信息
  167. var oLabelObj = L.DomUtil.create("div", "measure-content");
  168. var pointText = L.DomUtil.create("span", "measure-result-text");
  169. pointText.innerHTML = lineDistanceStr;
  170. oLabelObj.appendChild(pointText);
  171. if (data.length > 1) {
  172. if (_this.tmpMarkers[data.length - 2]) {
  173. //如果最后一个点存在,更新最后一个点信息
  174. _this.tmpMarkers[data.length - 2].setLatLng(data[data.length - 1]);
  175. _this.tmpMarkers[data.length - 2].label.setContent(oLabelObj);
  176. } else {
  177. //如果最后一个点不存在,创建点信息
  178. var marker = L.marker(data[data.length - 1], {
  179. icon: L.divIcon({ className: "measuremarker", iconSize: [4, 4] })
  180. });
  181. marker.bindLabel(oLabelObj, {
  182. noHide: true,
  183. clickable: true,
  184. className: "measure-tip",
  185. offset: [0, 0]
  186. });
  187. marker.addTo(_this._measureObjs[_this._lC]);
  188. _this.tmpMarkers.push(marker);
  189. }
  190. }
  191. },
  192. /**
  193. * 通过坐标点计算面积
  194. * @type {Function}
  195. * @returns {Number} 面积
  196. * @private
  197. */
  198. _getArea: function (_lc) {
  199. var _this = this;
  200. var latLngs = _this._measureObjs[_lc].measurePoints;
  201. var pointsCount = latLngs.length,
  202. area = 0.0,
  203. d2r = Math.PI / 180,
  204. p1,
  205. p2;
  206. if (pointsCount > 2) {
  207. for (var i = 0; i < pointsCount; i++) {
  208. p1 = latLngs[i];
  209. p2 = latLngs[(i + 1) % pointsCount];
  210. area += (p2[1] - p1[1]) * d2r * (2 + Math.sin(p1[0] * d2r) + Math.sin(p2[0] * d2r));
  211. }
  212. area = (area * 6378137.0 * 6378137.0) / 2.0;
  213. }
  214. area = Math.abs(area);
  215. if (area > 1000000) {
  216. area = (area * 0.000001).toFixed(2) + " 平方公里";
  217. } else {
  218. area = area.toFixed(2) + " 米&sup2;";
  219. }
  220. return area;
  221. },
  222. latlngRectifying: function (e) {
  223. var _this = this;
  224. var curLatlngs = [];
  225. var curpx = e.layerPoint;
  226. var length = _this._measureObjs[_this._lC] ? _this._measureObjs[_this._lC].measurePoints.length : 0;
  227. var latlng = e.latlng;
  228. if (length > 0) {
  229. curLatlngs.push({
  230. latlng: _this._measureObjs[_this._lC].measurePoints[0],
  231. px: _this._map.latLngToLayerPoint(_this._measureObjs[_this._lC].measurePoints[0])
  232. });
  233. curLatlngs.push({
  234. latlng: _this._measureObjs[_this._lC].measurePoints[length - 1],
  235. px: _this._map.latLngToLayerPoint(_this._measureObjs[_this._lC].measurePoints[length - 1])
  236. });
  237. }
  238. for (var i = 0; i < curLatlngs.length; i++) {
  239. var dispx = Math.sqrt(
  240. (curpx.x - curLatlngs[i].px.x) * (curpx.x - curLatlngs[i].px.x) +
  241. (curpx.y - curLatlngs[i].px.y) * (curpx.y - curLatlngs[i].px.y)
  242. );
  243. if (dispx < 10) {
  244. latlng = L.latLng(curLatlngs[i].latlng);
  245. latlng.reset = true;
  246. latlng.indexMarker = i;
  247. break;
  248. }
  249. }
  250. return latlng;
  251. },
  252. _onClickPoint: function (e) {
  253. var _this = this;
  254. e.latlng = _this.latlngRectifying(e);
  255. if (!e.latlng.reset) {
  256. _this._measureObjs[_this._lC].measurePoints.push([e.latlng.lat, e.latlng.lng]);
  257. } else {
  258. if (e.latlng.indexMarker == 0) {
  259. if (_this._measureObjs[_this._lC].polygon) {
  260. _this._measureObjs[_this._lC].measurePoints.push([e.latlng.lat, e.latlng.lng]);
  261. _this._measureObjs[_this._lC].polygon.setLatLngs(_this._measureObjs[_this._lC].measurePoints);
  262. _this._measureObjs[_this._lC].polygon.setStyle({
  263. fillColor: "#f00",
  264. color: "#f00",
  265. weight: 0,
  266. fillOpacity: 0.3
  267. });
  268. } else {
  269. _this._measureObjs[_this._lC].removeLayer(_this._measureObjs[_this._lC].circle);
  270. _this._measureObjs[_this._lC].removeLayer(_this._measureObjs[_this._lC].polyline);
  271. }
  272. } else {
  273. _this._measureObjs[_this._lC].removeLayer(_this._measureObjs[_this._lC].polygon);
  274. _this._measureObjs[_this._lC].polygon = null;
  275. }
  276. _this._onFinishClick();
  277. }
  278. if (_this._measureObjs[_this._lC].measurePoints.length == 1 && !_this._finished) {
  279. var latlngs = [
  280. [e.latlng.lat, e.latlng.lng],
  281. [e.latlng.lat, e.latlng.lng]
  282. ];
  283. _this._measureObjs[_this._lC].polyline = L.polyline(latlngs, {
  284. color: "red",
  285. dashArray: 10
  286. }).addTo(_this._measureObjs[_this._lC]);
  287. _this._measureObjs[_this._lC].circle = L.circle([e.latlng.lat, e.latlng.lng], {
  288. radius: 0,
  289. color: "red",
  290. fillOpacity: 0
  291. }).addTo(_this._measureObjs[_this._lC]);
  292. } else {
  293. // _this._measureObjs[_this._lC].removeLayer(_this._measureObjs[_this._lC].circle);
  294. }
  295. },
  296. _onFinishClick: function () {
  297. let _this = this;
  298. //关闭地图双击事件
  299. _this._map.doubleClickZoom.enable();
  300. //监听地图单击事件
  301. _this._map.off("click", _this._onClickPoint, this);
  302. //监听鼠标移动事件
  303. _this._map.off("mousemove", _this._mousemove, this);
  304. _this.isNewElevation = true;
  305. _this._finished = true;
  306. _this._map.removeLayer(_this.moveMarker);
  307. _this.moveMarker = null;
  308. for (var i = 0; i < _this.tmpMarkers.length; i++) {
  309. _this._measureObjs[_this._lC].removeLayer(_this.tmpMarkers[i]);
  310. }
  311. _this.tmpMarkers = [];
  312. //根据点集合渲染marker点
  313. var coorslength = _this._measureObjs[_this._lC].measurePoints.length;
  314. _this._measureObjs[_this._lC].markerObjs = [];
  315. var lineDistance = 0;
  316. if (coorslength > 1) {
  317. for (var i = 0; i < coorslength; i++) {
  318. var curcoor = _this._measureObjs[_this._lC].measurePoints[i];
  319. var marker = L.marker(curcoor, {
  320. draggable: true,
  321. icon: L.divIcon({ className: "measuremarker", iconSize: [10, 10] })
  322. });
  323. if (i > 0) {
  324. var prePoint = _this._measureObjs[_this._lC].measurePoints[i - 1];
  325. lineDistance = L.latLng(curcoor).distanceTo(prePoint);
  326. var lineDistanceStr =
  327. lineDistance > 1000 ? (lineDistance / 1000).toFixed(2) + "公里" : Math.ceil(lineDistance) + "米";
  328. var pointAngle = L.Util.getAngleByLatLng(prePoint[1], prePoint[0], curcoor[1], curcoor[0]);
  329. //添加分段信息
  330. var oLabelObj = L.DomUtil.create("div", "measure-content");
  331. var delLabel = L.DomUtil.create("div", "measure-ico-del");
  332. var saveLabel = L.DomUtil.create("div", "measure-ico-save");
  333. var listLabel = L.DomUtil.create("div", "measure-ico-list");
  334. var pointText = L.DomUtil.create("span", "measure-result-text");
  335. pointText.innerHTML = lineDistanceStr;
  336. delLabel.lC = _this._lC;
  337. saveLabel.lC = _this._lC;
  338. L.DomEvent.on(delLabel, "click", function (e) {
  339. L.DomEvent.stopPropagation(e);
  340. _this.del(delLabel.lC);
  341. });
  342. L.DomEvent.on(saveLabel, "click", function (e) {
  343. L.DomEvent.stopPropagation(e);
  344. _this._map.fire("draw2-result", {
  345. distance: _this._measureObjs[delLabel.lC].distance,
  346. points: _this._measureObjs[delLabel.lC].measurePoints,
  347. area: _this._measureObjs[delLabel.lC].area || 0,
  348. LC: delLabel.lC
  349. });
  350. });
  351. L.DomEvent.on(listLabel, "click", function (e) {
  352. L.DomEvent.stopPropagation(e);
  353. _this._map.fire("draw2-result", {
  354. distance: _this._measureObjs[delLabel.lC].distance,
  355. points: _this._measureObjs[delLabel.lC].measurePoints,
  356. area: _this._measureObjs[delLabel.lC].area || 0,
  357. LC: delLabel.lC,
  358. });
  359. });
  360. if (i == coorslength - 1) {
  361. //测量面积
  362. if (_this._measureObjs[_this._lC].polygon) {
  363. var area = _this._getArea(_this._lC);
  364. _this._measureObjs[_this._lC].area = area;
  365. pointText.innerHTML = lineDistanceStr + "<br/>" + area;
  366. }
  367. oLabelObj.appendChild(delLabel);
  368. oLabelObj.appendChild(saveLabel);
  369. }
  370. oLabelObj.appendChild(pointText);
  371. marker.bindLabel(oLabelObj, {
  372. noHide: true,
  373. clickable: true,
  374. className: "measure-tip",
  375. offset: [0, 0]
  376. });
  377. }
  378. marker.LC = _this._lC;
  379. marker.LIndex = i;
  380. marker.addTo(_this._measureObjs[_this._lC]);
  381. _this._measureObjs[_this._lC].markerObjs.push(marker);
  382. if (!(i == 0 && _this._measureObjs[_this._lC].polygon)) {
  383. marker.on("move", function (e) {
  384. _this._renderMeasure({
  385. LC: e.target.LC,
  386. LIndex: e.target.LIndex,
  387. latlng: e.latlng
  388. });
  389. });
  390. }
  391. }
  392. } else {
  393. var curcoor = _this._measureObjs[_this._lC].measurePoints[0];
  394. var myIcon = L.icon({
  395. iconUrl: this.options.iconUrl,
  396. iconSize: [25, 41],
  397. iconAnchor: [12, 41]
  398. });
  399. var marker = L.marker(curcoor, { draggable: true, icon: myIcon });
  400. var oLabelObj = L.DomUtil.create("div", "measure-content");
  401. var delLabel = L.DomUtil.create("div", "measure-ico-del");
  402. var saveLabel = L.DomUtil.create("div", "measure-ico-save");
  403. var listLabel = L.DomUtil.create("div", "measure-ico-list");
  404. delLabel.lC = _this._lC;
  405. saveLabel.lC = _this._lC;
  406. L.DomEvent.on(delLabel, "click", function (e) {
  407. L.DomEvent.stopPropagation(e);
  408. _this.del(delLabel.lC);
  409. });
  410. L.DomEvent.on(saveLabel, "click", function (e) {
  411. L.DomEvent.stopPropagation(e);
  412. _this._map.fire("draw2-result", {
  413. distance: _this._measureObjs[delLabel.lC].distance,
  414. points: _this._measureObjs[delLabel.lC].measurePoints,
  415. area: _this._measureObjs[delLabel.lC].area || 0,
  416. LC: delLabel.lC
  417. });
  418. });
  419. L.DomEvent.on(listLabel, "click", function (e) {
  420. L.DomEvent.stopPropagation(e);
  421. _this._map.fire("draw2-result", {
  422. distance: _this._measureObjs[delLabel.lC].distance,
  423. points: _this._measureObjs[delLabel.lC].measurePoints,
  424. area: _this._measureObjs[delLabel.lC].area || 0,
  425. LC: delLabel.lC,
  426. });
  427. });
  428. oLabelObj.appendChild(delLabel);
  429. oLabelObj.appendChild(saveLabel);
  430. marker.bindLabel(oLabelObj, {
  431. noHide: true,
  432. clickable: true,
  433. className: "measure-tip",
  434. offset: [0, 0]
  435. });
  436. marker.LC = _this._lC;
  437. marker.LIndex = i;
  438. marker.addTo(_this._measureObjs[_this._lC]);
  439. _this._measureObjs[_this._lC].markerObjs.push(marker);
  440. }
  441. _this._measureObjs[_this._lC].distance = lineDistance;
  442. },
  443. _renderMeasure: function (data) {
  444. var _this = this;
  445. var latlng = [data.latlng.lat, data.latlng.lng];
  446. if (_this._measureObjs[data.LC].measurePoints.length == 1) {
  447. return false;
  448. }
  449. _this._measureObjs[data.LC].measurePoints[data.LIndex] = latlng;
  450. var curlength = _this._measureObjs[data.LC].measurePoints.length;
  451. //如果是面,第一个点和最后一个点位置同时改变
  452. if (_this._measureObjs[data.LC].polygon) {
  453. if (data.LIndex == 0) {
  454. _this._measureObjs[data.LC].measurePoints[curlength - 1] = latlng;
  455. _this._measureObjs[_this._lC].markerObjs[curlength - 1].setLatLng(latlng);
  456. }
  457. if (data.LIndex == curlength - 1) {
  458. _this._measureObjs[data.LC].measurePoints[0] = latlng;
  459. _this._measureObjs[_this._lC].markerObjs[0].setLatLng(latlng);
  460. }
  461. }
  462. var points = _this._measureObjs[data.LC].measurePoints;
  463. //更新circle
  464. var radius = L.latLng(points[1]).distanceTo(L.latLng(points[0]));
  465. _this._measureObjs[data.LC].circle.setRadius(radius);
  466. _this._measureObjs[data.LC].circle.setLatLng(points[0]);
  467. if (points.length == 2) {
  468. _this._measureObjs[data.LC].circle.setStyle({
  469. opacity: 1
  470. });
  471. }
  472. //更新线
  473. _this._measureObjs[data.LC].polyline.setLatLngs(points);
  474. //更新面
  475. if (_this._measureObjs[data.LC].polygon) {
  476. _this._measureObjs[data.LC].polygon.setLatLngs([points]);
  477. }
  478. var lineDistance = 0;
  479. var coorslength = _this._measureObjs[data.LC].measurePoints.length;
  480. for (var i = 1; i < coorslength; i++) {
  481. var curcoor = _this._measureObjs[data.LC].measurePoints[i];
  482. var prePoint = _this._measureObjs[data.LC].measurePoints[i - 1];
  483. lineDistance = L.latLng(curcoor).distanceTo(prePoint);
  484. var lineDistanceStr =
  485. lineDistance > 1000 ? (lineDistance / 1000).toFixed(2) + "公里" : Math.ceil(lineDistance) + "米";
  486. var pointAngle = L.Util.getAngleByLatLng(prePoint[1], prePoint[0], curcoor[1], curcoor[0]);
  487. //添加分段信息
  488. var oLabelObj = L.DomUtil.create("div", "measure-content");
  489. var delLabel = L.DomUtil.create("div", "measure-ico-del");
  490. var saveLabel = L.DomUtil.create("div", "measure-ico-save");
  491. var listLabel = L.DomUtil.create("div", "measure-ico-list");
  492. var pointText = L.DomUtil.create("span", "measure-result-text");
  493. pointText.innerHTML = lineDistanceStr;
  494. delLabel.lC = _this._lC;
  495. saveLabel.lC = _this._lC;
  496. L.DomEvent.on(delLabel, "click", function (e) {
  497. L.DomEvent.stopPropagation(e);
  498. _this.del(delLabel.lC);
  499. });
  500. L.DomEvent.on(saveLabel, "click", function (e) {
  501. L.DomEvent.stopPropagation(e);
  502. _this._map.fire("draw2-result", {
  503. distance: _this._measureObjs[delLabel.lC].distance,
  504. points: _this._measureObjs[delLabel.lC].measurePoints,
  505. area: _this._measureObjs[delLabel.lC].area || 0,
  506. LC: delLabel.lC
  507. });
  508. });
  509. L.DomEvent.on(listLabel, "click", function (e) {
  510. L.DomEvent.stopPropagation(e);
  511. _this._map.fire("draw2-result", {
  512. distance: _this._measureObjs[delLabel.lC].distance,
  513. points: _this._measureObjs[delLabel.lC].measurePoints,
  514. area: _this._measureObjs[delLabel.lC].area || 0,
  515. LC: delLabel.lC,
  516. });
  517. });
  518. if (i == coorslength - 1) {
  519. oLabelObj.appendChild(delLabel);
  520. oLabelObj.appendChild(saveLabel);
  521. //测量面积
  522. try {
  523. if (_this._measureObjs[data.LC].polygon) {
  524. var area = _this._getArea(data.LC);
  525. _this._measureObjs[data.LC].area;
  526. pointText.innerHTML = lineDistanceStr + "<br/>" + area;
  527. }
  528. } catch (e) {
  529. // console.error("leaflet.draw.js 测量面积error:", e);
  530. }
  531. }
  532. oLabelObj.appendChild(pointText);
  533. _this._measureObjs[_this._lC].distance = lineDistance;
  534. _this._measureObjs[data.LC].markerObjs[i].label.setContent(oLabelObj);
  535. }
  536. },
  537. /**
  538. * 删除对应lC的测距
  539. */
  540. del: function (lC) {
  541. var _this = this;
  542. if (_this._measureObjs[lC]) {
  543. _this._measureGroup.removeLayer(_this._measureObjs[lC]);
  544. delete _this._measureObjs[lC];
  545. }
  546. }
  547. });