turf_measurement.html 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882
  1. <!--********************************************************************
  2. * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
  3. *********************************************************************-->
  4. <!DOCTYPE html>
  5. <html>
  6. <head>
  7. <meta charset="UTF-8">
  8. <title data-i18n="resources.title_turfMeasurement"></title>
  9. <script type="text/javascript" include="bootstrap,bootstrap-select,widgets.alert"
  10. src="../js/include-web.js"></script>
  11. </head>
  12. <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
  13. <div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
  14. <script type="text/javascript" include="turf,leaflet.draw" src="../../dist/leaflet/include-leaflet.js"></script>
  15. <script type="text/javascript">
  16. var host = window.isLocal ? window.server : "https://iserver.supermap.io",
  17. url = host + "/iserver/services/map-jingjin/rest/maps/京津地区地图",
  18. turfLayer, resultLayer, urlWorld,
  19. totalLat = 0, totalLng = 0, averageLat, averageLng, distance, geo, coordinate,
  20. choose, marker1, marker2, marker3, editableLayers, drawControl,
  21. bearing, baseLayer, result, val,
  22. radius, steps, point;
  23. var map = L.map('map', {
  24. crs: L.CRS.EPSG4326,
  25. center: {lon: 116.383572, lat: 39.914714},
  26. maxZoom: 18,
  27. zoom: 10
  28. });
  29. //底图
  30. baseLayer = L.supermap.tiledMapLayer(url, {prjCoordSys: {"epsgCode": 4326}}).addTo(map);
  31. initEditView();
  32. bindEvents();
  33. $('#menuSelect').change();
  34. function initEditView() {
  35. var infoView = L.control({position: 'topright'});
  36. infoView.onAdd = function () {
  37. var me = this;
  38. me._div = L.DomUtil.create('div');
  39. me._div.style.width = '350px';
  40. me._div.innerHTML = "<div class='panel panel-primary editPane' id='editPane'>"+
  41. "<div class='panel-heading'>"+
  42. "<h5 class='panel-title text-center'>"+ resources.text_Jingshen + "</h5>"+
  43. "</div>"+
  44. "<div class='panel panel-body chooseItems' style='margin-bottom:0px;padding-bottom: 0px'>"+
  45. "<select class='form-control' id='menuSelect' >"+
  46. "<option value='along' selected='selected'>along</option>"+
  47. "<option value='area'>area</option>"+
  48. "<option value='bbox'>bbox</option>"+
  49. "<option value='center'>center</option>"+
  50. "<option value='destination'>destination</option>"+
  51. "<option value='distance'>distance</option>"+
  52. "<option value='midpoint'>midpoint</option>"+
  53. "<option value='square'>square</option>"+
  54. "<option value='greatCircle'>greatCircle</option>"+
  55. "<option value='bezierSpline'>bezierSpline</option>"+
  56. "<option value='buffer'>buffer</option>"+
  57. "<option value='circle'>circle</option>"+
  58. "</select>"+
  59. "</div>"+
  60. "<hr/>"+
  61. "<div class='panel-body' id='params' style='padding-top: 0px'>"+
  62. "<div class='input-group'>"+
  63. "<span class='input-group-addon'>" + resources.text_distanceUnit + "</span>"+
  64. "<select class='form-control' id='unitSelect' name='unitSelect'>"+
  65. "<option value='kilometers' selected = 'selected'>kilometers</option>"+
  66. "<option value='miles'>miles</option>"+
  67. "<option value='degrees'>degrees</option>"+
  68. "<option value='radians'>radians</option>"+
  69. "</select>"+
  70. "</div>"+
  71. "<p></p>"+
  72. "<div class='input-group'>"+
  73. "<span class='input-group-addon'>" + resources.text_distanceToStart + "</span>"+
  74. "<input id='distance' type='text' class='form-control' placeholder=" + resources.text_distance + " val='0.5'/>"+
  75. "</div>"+
  76. "<p></p>"+
  77. "<div class='input-group'>"+
  78. "<span class='input-group-addon'>" + resources.text_position + "</span>"+
  79. "<input id='bearing' type='text' class='form-control' placeholder=" + resources.text_positionRange + "/>"+
  80. "</div>"+
  81. "<p></p>"+
  82. "<div align='right' class='input-group'>"+
  83. "<input type='button' id='calc' class='btn btn-primary' value=" + resources.btn_getResult + "/>"+
  84. "</div>"+
  85. "</div>"+
  86. "</div>";
  87. handleMapEvent(me._div, me._map);
  88. return me._div;
  89. };
  90. infoView.addTo(map);
  91. hidePanel();
  92. reset();
  93. }
  94. //初始化事件
  95. function bindEvents() {
  96. // //获取单位
  97. // $('#unitSelect').change(function () {
  98. // unit = $('#unitSelect').children('option:selected').val();
  99. // });
  100. //控件栏取消地图事件
  101. $("#editPane").mouseover(function (e) {
  102. map.dragging.disable();
  103. });
  104. $("#editPane").mouseout(function () {
  105. map.dragging.enable();
  106. });
  107. $('#menuSelect').change(function () {
  108. widgets.alert.clearAlert();
  109. //初始化图层
  110. removeLayer();
  111. //初始化图层
  112. resetLayers();
  113. url = host + "/iserver/services/map-jingjin/rest/maps/京津地区地图";
  114. baseLayer = L.supermap.tiledMapLayer(url, {prjCoordSys: {"epsgCode": 4326}}).addTo(map);
  115. //第一个隐藏右侧菜单
  116. choose = $('#menuSelect').children('option:selected').val();
  117. reset();
  118. //对应菜单显示
  119. if (choose === 'along') {
  120. $('.panel-heading>h5').text(resources.text_Jingshen);
  121. drawLine();
  122. setCenter();
  123. setAlongIcon();
  124. clearControl();
  125. $('.input-group:eq(0)').show();
  126. $('.input-group:eq(1)').show();
  127. $('.input-group:eq(2)').hide();
  128. $('.input-group:eq(3)').show();
  129. $('.input-group:eq(1)>span').text(resources.text_distanceToStart);
  130. $('.input-group:eq(1)>input').val("0.5");
  131. $('.input-group:eq(1)>input').focusout(function () {
  132. val = $('.input-group:eq(1)>input').val();
  133. var unit = $('#unitSelect').children('option:selected').val();
  134. if ((unit === 'kilometers' && val > 1.1753172567467551) || (unit === 'miles' && val > 0.7303085417726581) || (unit === 'degrees' && val > 0.010566564943528475) || (unit === 'radians' && val > 0.00018442134893248942)) {
  135. widgets.alert.showAlert(resources.text_beyondDistance, false, 260);
  136. $('.input-group:eq(1)>input').val('');
  137. }
  138. else {
  139. widgets.alert.clearAlert();
  140. }
  141. });
  142. $('#calc').val(resources.text_getPoint);
  143. }
  144. else if (choose === 'area') {
  145. widgets.alert.showAlert(resources.msg_drawTurfPolygon, true, 500);
  146. $('.panel-heading>h5').text(resources.text_measureArea);
  147. clearControl();
  148. setDefaultCenter(39.90455699411283, 116.407283, 11);
  149. drawController(false, false, true);
  150. drawing();
  151. $('.input-group:eq(0)').hide();
  152. $('.input-group:eq(1)').hide();
  153. $('.input-group:eq(2)').hide();
  154. $('.input-group:eq(3)').show();
  155. $('#calc').val(resources.text_getArea);
  156. }
  157. else if (choose === 'bbox') {
  158. $('.panel-heading>h5').text(resources.text_JingshenBounds);
  159. setDefaultCenter(39.70182899926848, 116.11948400050001, 11);
  160. drawLine();
  161. setCenter();
  162. clearControl();
  163. $('.input-group:eq(0)').hide();
  164. $('.input-group:eq(1)').hide();
  165. $('.input-group:eq(2)').hide();
  166. $('.input-group:eq(3)').show();
  167. $('#calc').val(resources.text_getBounds);
  168. }
  169. else if (choose === 'destination') {
  170. $('.panel-heading>h5').text(resources.text_pointToTarget);
  171. setDefaultCenter(39.90455699411283, 116.407283, 7);
  172. $('.input-group:eq(0)').show();
  173. $('.input-group:eq(1)').show();
  174. $('.input-group:eq(2)').show();
  175. $('.input-group:eq(3)').show();
  176. $('.input-group:eq(1)>span').text(resources.text_distanceToStart);
  177. $('.input-group:eq(1)>input').unbind('focusout').val("0.5");
  178. $('.input-group:eq(2)>span').text(resources.text_position);
  179. $('.input-group:eq(2)>input').attr('placeholder', resources.text_positionRange);
  180. setDestinationIcon();
  181. clearControl();
  182. $('#calc').val(resources.text_getTargetPoint);
  183. }
  184. else if (choose === 'distance') {
  185. $('.panel-heading>h5').text(resources.text_distanceBetween);
  186. setDefaultCenter(39.80771500024742, 116.72499999899998, 8);
  187. clearControl();
  188. setDistanceIcon();
  189. $('.input-group:eq(0)').show();
  190. $('.input-group:eq(1)').hide();
  191. $('.input-group:eq(2)').hide();
  192. $('.input-group:eq(3)').show();
  193. $('#calc').val(resources.text_getDistance);
  194. }
  195. else if (choose === 'midpoint') {
  196. $('.panel-heading>h5').text(resources.text_middlePointBetween);
  197. setDefaultCenter(39.90455699411283, 116.407283, 7);
  198. clearControl();
  199. setMidpointIcon();
  200. $('.input-group:eq(0)').hide();
  201. $('.input-group:eq(1)').hide();
  202. $('.input-group:eq(2)').hide();
  203. $('.input-group:eq(3)').show();
  204. $('#calc').val(resources.text_getMiddlePoint);
  205. }
  206. else if (choose === 'greatCircle') {
  207. $('.panel-heading>h5').text(resources.text_bigRoundRoute);
  208. isUseWorldMap(1);
  209. clearControl();
  210. setDefaultCenter(40, 112, 3);
  211. setGreatCircleIcon();
  212. $('.input-group:eq(0)').hide();
  213. $('.input-group:eq(1)').hide();
  214. $('.input-group:eq(2)').hide();
  215. $('.input-group:eq(3)').show();
  216. $('#calc').val(resources.text_getRoute);
  217. }
  218. else if (choose === 'square') {
  219. widgets.alert.showAlert(resources.msg_externalTangentSquare, true, 500);
  220. $('.panel-heading>h5').text(resources.text_externalTangentSquare);
  221. setDefaultCenter(39.70914100034369, 116.11697300062501, 14);
  222. clearControl();
  223. drawController(false, false, false, false, true);
  224. drawing();
  225. $('.input-group:eq(0)').hide();
  226. $('.input-group:eq(1)').hide();
  227. $('.input-group:eq(2)').hide();
  228. $('.input-group:eq(3)').show();
  229. $('#calc').val(resources.text_getExternalTangentSquare);
  230. }
  231. else if (choose === 'center') {
  232. $('.panel-heading>h5').text(resources.text_scenicSpotsCenter);
  233. setDefaultCenter(39.93393099410061, 116.38035099999959, 12);
  234. clearControl();
  235. setCenterIcon();
  236. $('.input-group:eq(0)').hide();
  237. $('.input-group:eq(1)').hide();
  238. $('.input-group:eq(2)').hide();
  239. $('.input-group:eq(3)').show();
  240. $('#calc').val(resources.text_getScenicSpotCenter);
  241. }
  242. else if (choose === 'bezierSpline') {
  243. $('.panel-heading>h5').text(resources.text_bezier);
  244. setDefaultCenter(40.676116230453765, 116.55439124389999, 12);
  245. clearControl();
  246. whiteRiver();
  247. $('.input-group:eq(0)').hide();
  248. $('.input-group:eq(1)').hide();
  249. $('.input-group:eq(2)').hide();
  250. $('.input-group:eq(3)').show();
  251. $('#calc').val(resources.text_getBezier);
  252. }
  253. else if (choose === 'buffer') {
  254. $('.panel-heading>h5').text(resources.text_buffer);
  255. widgets.alert.showAlert(resources.msg_markPoint, true);
  256. clearControl();
  257. setDefaultCenter(40, 116.83, 9);
  258. drawController(false, false, false, false, false, false, true);
  259. drawing();
  260. $('.input-group:eq(0)').show();//单位
  261. $('.input-group:eq(1)').show();//步长
  262. $('.input-group:eq(2)').show();//半径
  263. $('.input-group:eq(3)').show();
  264. $('.input-group:eq(1)>span').text(resources.text_step);//步长
  265. $('.input-group:eq(1)>input').unbind('focusout').val("1");
  266. $('.input-group:eq(2)>span').text(resources.text_radius);//半径
  267. $('.input-group:eq(2)>input').val("10");
  268. $('#calc').val(resources.text_getBuffer);
  269. }
  270. else if (choose === 'circle') {
  271. $('.panel-heading>h5').text(resources.text_polygon);
  272. widgets.alert.showAlert(resources.msg_markPoint, true);
  273. clearControl();
  274. setDefaultCenter(40, 116.83, 9);
  275. drawController(false, false, false, false, false, false, true);
  276. drawing();
  277. $('.title').show();
  278. $('.title>span').text('circle');
  279. $('.area').hide();
  280. $('.input-group:eq(0)').show();//单位
  281. $('.input-group:eq(1)').show();//步长
  282. $('.input-group:eq(2)').show();//半径
  283. $('.input-group:eq(3)').show();
  284. $('.input-group:eq(1)>span').text(resources.text_step);//步长
  285. $('.input-group:eq(1)>input').unbind('focusout').val("10");
  286. $('.input-group:eq(2)>span').text(resources.text_radius);//半径
  287. $('.input-group:eq(2)>input').val("10");
  288. $('#calc').val(resources.text_getPolygon);
  289. }
  290. else {
  291. widgets.alert.showAlert(resources.msg_noMethod, false);
  292. }
  293. showPanel();
  294. });
  295. //生成对应距离点点击事件
  296. $('#calc').click(function () {
  297. //获取自定义距离
  298. distance = $('#distance').val();
  299. //获取自定方位
  300. bearing = $('#bearing').val();
  301. //步长
  302. steps = distance;
  303. //半径
  304. radius = bearing;
  305. //角度
  306. angle = distance;
  307. meths = {
  308. "along": along,
  309. "area": area,
  310. "bbox": bbox,
  311. "destination": destination,
  312. "distance": turf_Distance,
  313. "midpoint": midpoint,
  314. "greatCircle": greatCircle,
  315. "square": square,
  316. "center": center,
  317. "bezierSpline": bezierSpline,
  318. "buffer": buffer,
  319. "circle": circle,
  320. };
  321. if (!meths[choose]) {
  322. widgets.alert.showAlert(resources.msg_illegal, false);
  323. }
  324. meths[choose]();
  325. });
  326. }
  327. //添加draw的控件
  328. function drawController(toolbar, polyline, polygon, circle, rectangle, circlemarker, marker) {
  329. editableLayers = new L.FeatureGroup();
  330. map.addLayer(editableLayers);
  331. var options = {
  332. position: 'topleft',
  333. draw: {
  334. toolbar: toolbar,
  335. polyline: polyline,
  336. polygon: polygon,
  337. circle: circle,
  338. rectangle: rectangle,
  339. circlemarker: circlemarker,
  340. marker: marker,
  341. remove: {},
  342. }
  343. };
  344. drawControl = new L.Control.Draw(options);
  345. map.addControl(drawControl);
  346. handleMapEvent(drawControl.getContainer(), map);
  347. }
  348. //开始画图
  349. function drawing() {
  350. map.on(L.Draw.Event.CREATED, function (e) {
  351. var type = e.layerType,
  352. layer = e.layer;
  353. geo = layer.toGeoJSON();
  354. coordinate = geo.geometry.coordinates;
  355. editableLayers.addLayer(layer);
  356. });
  357. }
  358. //京深路数据
  359. function drawLine() {
  360. roadLine = L.polyline([
  361. [39.70771500024742, 116.12499999899998],
  362. [39.70738300038022, 116.124684999625],
  363. [39.70738300038022, 116.124684999625],
  364. [39.70630000081341, 116.12366300000001],
  365. [39.70630000081341, 116.12366300000001],
  366. [39.70526299956156, 116.122695000875],
  367. [39.70182899926848, 116.11948400050001],
  368. [39.70182899926848, 116.11948400050001],
  369. [39.70001099999569, 116.117782000875],
  370. [39.70001099999569, 116.117782000875],
  371. [39.69914100034369, 116.11697300062501]
  372. ]).addTo(map);
  373. marker1 = L.marker([39.70771500024742, 116.12499999899998]), marker2 = L.marker([39.69914100034369, 116.11697300062501]);
  374. coordinate = roadLine.toGeoJSON().geometry.coordinates;
  375. }
  376. //白河
  377. function whiteRiver() {
  378. riverLine = L.polyline([
  379. [40.675731250349635, 116.44468018273878],
  380. [40.67514041485476, 116.45764286288912],
  381. [40.675374865714495, 116.47234517561137],
  382. [40.68284917168584, 116.4864209475681],
  383. [40.6926826346566, 116.50806547030137],
  384. [40.701383778180805, 116.51490194761084],
  385. [40.68381460602459, 116.54403108790551],
  386. [40.676116230453765, 116.55439124389999],
  387. [40.67476948501498, 116.56406552077725],
  388. [40.68296164868846, 116.58188801112561],
  389. [40.70683026321353, 116.5925083591713],
  390. [40.72097728359635, 116.59861159022633],
  391. [40.71945202953016, 116.61194828377546],
  392. [40.71459183686403, 116.6157779223366]
  393. ]).addTo(map);
  394. coordinate = riverLine.toGeoJSON().geometry.coordinates;
  395. }
  396. //设置中心点
  397. function setCenter() {
  398. //初始化
  399. totalLng = 0, totalLat = 0;
  400. for (var i = 0; i < coordinate.length; i++) {
  401. totalLat += coordinate[i][0];
  402. }
  403. averageLat = totalLat / coordinate.length;
  404. for (var j = 0; j < coordinate.length; j++) {
  405. totalLng += coordinate[j][1];
  406. }
  407. averageLng = totalLng / coordinate.length;
  408. map.setView(L.latLng(averageLng, averageLat), 15);
  409. }
  410. //设置自定义中心
  411. function setDefaultCenter(lng, lat, zoom) {
  412. var options = {
  413. "animate": true,
  414. "duration": 0.15,
  415. "easeLinearity": 0.25,
  416. "noMoveStart": false,
  417. };
  418. map.flyTo(L.latLng(lng, lat), zoom, options);
  419. }
  420. //判断底图
  421. function isUseWorldMap(bool) {
  422. if (bool) {
  423. urlWorld = host + "/iserver/services/map-world/rest/maps/World";
  424. url = urlWorld;
  425. baseLayer = L.supermap.tiledMapLayer(url, {prjCoordSys: {"epsgCode": 4326}}).addTo(map);
  426. }
  427. else {
  428. url = host + "/iserver/services/map-jingjin/rest/maps/京津地区地图";
  429. baseLayer = L.supermap.tiledMapLayer(url, {prjCoordSys: {"epsgCode": 4326}}).addTo(map);
  430. }
  431. }
  432. //设置along方法的icon
  433. function setAlongIcon() {
  434. var startIcon = L.icon({
  435. iconUrl: '../img/start_trans.png',
  436. iconSize: [20, 20],
  437. });
  438. var endIcon = L.icon({
  439. iconUrl: '../img/end_trans.png',
  440. iconSize: [20, 20],
  441. });
  442. L.marker(marker1.getLatLng(), {icon: startIcon}).addTo(map);
  443. L.marker(marker2.getLatLng(), {icon: endIcon}).addTo(map);
  444. }
  445. //设置center方法的icon
  446. function setCenterIcon() {
  447. turfLayer.process("Helper.multiPoint", {
  448. //北京周边景区
  449. "coordinates": ([[116.38035099999959, 39.93393099410061], [116.34482800000002, 39.914760994108605], [116.40732099999964, 39.916013994108134], [116.44748600000042, 39.93767799409907]]),
  450. });
  451. }
  452. //设置distance方法的Icon
  453. function setDistanceIcon() {
  454. turfLayer.process("Helper.multiPoint", {
  455. //北京2天津
  456. "coordinates": ([[116.407283, 39.90455699411283], [117.215268, 39.12096299445415]]),
  457. });
  458. }
  459. //设置destination方法的Icon.
  460. function setDestinationIcon() {
  461. marker3 = L.marker([39.90455699411283, 116.407283]);
  462. var startIcon = L.icon({
  463. iconUrl: '../img/start_trans.png',
  464. iconSize: [20, 20],
  465. });
  466. L.marker(marker3.getLatLng(), {icon: startIcon}).addTo(map);
  467. }
  468. //设置midpoint方法的Icon
  469. function setMidpointIcon() {
  470. turfLayer.process("Helper.multiPoint", {
  471. //北京2天津
  472. "coordinates": ([[116.407283, 39.90455699411283], [117.215268, 39.12096299445415]]),
  473. });
  474. }
  475. //设置greatCircle方法的Icon
  476. function setGreatCircleIcon() {
  477. turfLayer.process("Helper.multiPoint", {
  478. //北京2布拉格
  479. "coordinates": ([[116.407283, 39.90455699411283], [51.052494, 18.852219]])
  480. });
  481. }
  482. //右侧panel显示
  483. function showPanel() {
  484. $('#params').show();
  485. }
  486. //右侧panel隐藏
  487. function hidePanel() {
  488. $('#params').hide();
  489. }
  490. //初始化页面
  491. function reset() {
  492. $('.chooseItems').show();
  493. hidePanel();
  494. $('.panel-heading>h5').text(resources.text_measure);
  495. $('#unitSelect option:first').prop("selected", 'selected');
  496. $('#distance').val('');
  497. $('#bearing').val('');
  498. coordinate = 0;
  499. }
  500. function clearControl() {
  501. if (drawControl) {
  502. map.removeControl(drawControl);
  503. }
  504. }
  505. //清空当前图层
  506. function removeLayer() {
  507. map.eachLayer(function (layer) {
  508. if (layer !== baseLayer) {
  509. layer.removeFrom(map);
  510. }
  511. });
  512. }
  513. //初始化生成图层
  514. function resetLayers() {
  515. turfLayer = L.supermap.turfLayer({
  516. attribution: " <span>© <a href='https://turfjs.org/' target='_blank'>turfjs</a></span>",
  517. style: function (feature) {
  518. return {
  519. color: "rgb(0,153,255)",
  520. opacity: 1,
  521. fillColor: "rgb(0,153,255)",
  522. fillOpacity: 0.1,
  523. weight: 6
  524. };
  525. }
  526. }).addTo(map);
  527. resultLayer = L.supermap.turfLayer({
  528. attribution: "",
  529. style: function (feature) {
  530. return {
  531. color: "rgb(255,0,0)",
  532. opacity: 1,
  533. fillColor: "rgb(255,0,0)",
  534. fillOpacity: 0.1,
  535. weight: 6
  536. };
  537. }
  538. }).addTo(map);
  539. }
  540. // 判断input是否是数字
  541. function checkIsNum(num) {
  542. var reg = /^\d+(\.\d+)?$/g;
  543. if (reg.test(num)) {
  544. return 1;
  545. } else {
  546. widgets.alert.showAlert(resources.msg_illegalFillIn, false, 260)
  547. }
  548. }
  549. //判断是否在[-180,180]范围内
  550. function isInRange(val) {
  551. // return val >= -180 && val <= 180;
  552. if (val < -180 || val > 180) {
  553. widgets.alert.showAlert(resources.msg_inputValue, false, 260);
  554. }
  555. else {
  556. return 1;
  557. }
  558. }
  559. function greatThanZero(steps) {
  560. var reg = /^[1-9]\d*(\.\d+)?$/g;
  561. if (!reg.test(steps)) {
  562. widgets.alert.showAlert(resources.msg_stepSize, false);
  563. }
  564. }
  565. //turf along方法
  566. function along() {
  567. var unit = $('#unitSelect').children('option:selected').val();
  568. if (unit != 'null' && unit != undefined) {
  569. if (checkIsNum(distance) && coordinate) {
  570. turfLayer.process("Helper.lineString", {
  571. "coordinates": coordinate,
  572. }, function (line) {
  573. resultLayer.process("Measurement.along", {
  574. "line": line,
  575. "distance": distance,
  576. "units": unit,
  577. });
  578. });
  579. }
  580. }
  581. else {
  582. widgets.alert.showAlert(resources.msg_selectUnit, false, 260);
  583. }
  584. }
  585. //turf area方法
  586. function area() {
  587. if (coordinate) {
  588. turfLayer.process("Helper.polygon", {
  589. "coordinates": coordinate,
  590. }, function (polygon) {
  591. resultLayer.process("Measurement.area", {
  592. "geojson": polygon
  593. }, function (e) {
  594. result = e + resources.msg_sqm;
  595. widgets.alert.showAlert(result, true);
  596. $(" input[ id='area' ] ").val(result);
  597. });
  598. });
  599. }
  600. else {
  601. widgets.alert.showAlert(resources.msg_drawLayer, false, 260);
  602. }
  603. }
  604. //turf bbox方法
  605. function bbox() {
  606. if (coordinate) {
  607. turfLayer.process("Helper.lineString", {
  608. "coordinates": coordinate,
  609. }, function (e) {
  610. resultLayer.process("Measurement.bbox", {
  611. "geojson": e
  612. }, function (bbox) {
  613. resultLayer.process("Measurement.bboxPolygon", {
  614. "bbox": bbox
  615. });
  616. });
  617. });
  618. }
  619. }
  620. //turf destination方法
  621. function destination() {
  622. var unit = $('#unitSelect').children('option:selected').val();
  623. if (unit != 'null' && unit != undefined) {
  624. widgets.alert.clearAlert();
  625. if (checkIsNum(distance) && isInRange(bearing)) {
  626. coordinates = [116.407283, 39.90455699411283];
  627. resultLayer.process("Measurement.destination", {
  628. "origin": coordinates,
  629. "distance": distance,
  630. "bearing": bearing,
  631. "units": unit,
  632. });
  633. }
  634. }
  635. else {
  636. widgets.alert.showAlert(resources.msg_selectUnit, false, 260)
  637. }
  638. }
  639. //turf distance方法
  640. function turf_Distance() {
  641. var disUnits = {
  642. "kilometers": "千米",
  643. "miles": "英里",
  644. "degrees": "角度",
  645. "radians": "弧度",
  646. };
  647. var inUnits = {
  648. "千米": "kilometers",
  649. "英里": "miles",
  650. "角度": "degrees",
  651. "弧度": "radians",
  652. };
  653. var unit = $('#unitSelect').children('option:selected').val();
  654. if (unit != 'null' && unit != undefined) {
  655. resultLayer.process("Measurement.distance", {
  656. "from": turfLayer.toGeoJSON().features[0].geometry.coordinates[0],
  657. "to": turfLayer.toGeoJSON().features[0].geometry.coordinates[1],
  658. "units": unit,
  659. }, function (e) {
  660. resultNum = e;
  661. });
  662. unit = disUnits[unit];
  663. result = resultNum + unit;
  664. widgets.alert.showAlert(result, true, 260);
  665. $(" input[ id='area' ] ").val(result);
  666. unit = inUnits[unit];
  667. }
  668. else {
  669. widgets.alert.showAlert(resources.msg_selectUnit, false, 260)
  670. }
  671. }
  672. //turf midpoint
  673. function midpoint() {
  674. resultLayer.process("Measurement.midpoint", {
  675. "point1": turfLayer.toGeoJSON().features[0].geometry.coordinates[0],
  676. "point2": turfLayer.toGeoJSON().features[0].geometry.coordinates[1],
  677. });
  678. resultLayer.eachLayer(function (layer) {
  679. layer.setIcon(L.icon({
  680. iconUrl: '../img/marker-gold.png',
  681. iconSize: [20, 20],
  682. })).bindPopup(resources.text_center);
  683. })
  684. }
  685. //turf greatCircle
  686. function greatCircle() {
  687. resultLayer.process("Measurement.greatCircle", {
  688. "start": turfLayer.toGeoJSON().features[0].geometry.coordinates[0],
  689. "end": turfLayer.toGeoJSON().features[0].geometry.coordinates[1],
  690. "properties": {'name': '北京 to 布拉格'},
  691. "npoints": 100,
  692. "offset": 10
  693. });
  694. }
  695. //turf square
  696. function square() {
  697. if (!coordinate) {
  698. return;
  699. }
  700. turfLayer.process("Helper.polygon", {
  701. "coordinates": coordinate,
  702. }, function (e) {
  703. turfLayer.process("Measurement.bbox", {
  704. "geojson": e
  705. }, function (box) {
  706. resultLayer.process("Measurement.square", {
  707. "bbox": box
  708. }, function (bbox) {
  709. resultLayer.process("Measurement.bboxPolygon", {
  710. "bbox": bbox
  711. });
  712. }, null, false);
  713. }, null, false);
  714. }, null, false);
  715. }
  716. //turf center
  717. function center() {
  718. resultLayer.process("Measurement.center", {
  719. "geojson": turfLayer.toGeoJSON()
  720. });
  721. resultLayer.eachLayer(function (layer) {
  722. layer.setIcon(L.icon({
  723. iconUrl: '../img/marker-gold.png',
  724. iconSize: [30, 30],
  725. })).bindPopup(resources.text_center);
  726. });
  727. }
  728. //turf bezierSpline
  729. function bezierSpline() {
  730. if (coordinate) {
  731. turfLayer.process("Helper.lineString", {
  732. "coordinates": coordinate,
  733. }, function (line) {
  734. resultLayer.process("Transformation.bezierSpline", {
  735. "line": line,
  736. "resolution": 10000,
  737. "sharpness": 0.85
  738. });
  739. });
  740. }
  741. }
  742. //turf buffer
  743. //先draw一个点 再在此点上进行缓冲区分析,默认单位killo
  744. function buffer() {
  745. var unit = $('#unitSelect').children('option:selected').val();
  746. if (unit != 'null') {
  747. widgets.alert.clearAlert();
  748. greatThanZero(steps);
  749. if (coordinate && checkIsNum(distance) && checkIsNum(radius) && steps > 0) {
  750. turfLayer.process("Helper.point", {
  751. "coordinates": coordinate,
  752. }, function (point) {
  753. resultLayer.process("Transformation.buffer", {
  754. "geojson": point,
  755. "radius": radius,
  756. "steps": parseFloat(steps),
  757. "units": unit,
  758. });
  759. });
  760. } else {
  761. widgets.alert.showAlert(resources.msg_incorrectInfo, false, 260);
  762. }
  763. }
  764. else {
  765. widgets.alert.showAlert(resources.msg_selectUnit, false, 260);
  766. }
  767. }
  768. //turf circle
  769. //先draw一个点 再在此点上画圆多边形
  770. //有默认单位kilometer
  771. function circle() {
  772. var unit = $('#unitSelect').children('option:selected').val();
  773. widgets.alert.clearAlert();
  774. greatThanZero(steps);
  775. if (coordinate && checkIsNum(distance) && checkIsNum(radius) && steps > 0) {
  776. turfLayer.process("Helper.point", {
  777. "coordinates": coordinate,
  778. }, function (point) {
  779. resultLayer.process("Transformation.circle", {
  780. "center": point,
  781. "radius": radius,
  782. "steps": parseFloat(steps),
  783. "units": unit,
  784. "properties": {},
  785. });
  786. });
  787. }
  788. else {
  789. widgets.alert.showAlert(resources.msg_incorrectInfo, false, 260);
  790. }
  791. }
  792. function handleMapEvent(div, map) {
  793. if (!div || !map) {
  794. return;
  795. }
  796. div.addEventListener('mouseover', function () {
  797. map.scrollWheelZoom.disable();
  798. map.doubleClickZoom.disable();
  799. });
  800. div.addEventListener('mouseout', function () {
  801. map.scrollWheelZoom.enable();
  802. map.doubleClickZoom.enable();
  803. });
  804. }
  805. </script>
  806. </body>
  807. </html>