turf_classificationAnalysis.html 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <!--********************************************************************
  2. * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
  3. *********************************************************************-->
  4. <!DOCTYPE html>
  5. <html lang="en">
  6. <head>
  7. <meta charset="UTF-8">
  8. <title data-i18n="resources.title_turfClassificationAnalysis"></title>
  9. <script type="text/javascript" include="bootstrap,widgets.alert" src="../js/include-web.js"></script>
  10. <script type="text/javascript" include="turf,leaflet.draw" src="../../dist/leaflet/include-leaflet.js"></script>
  11. <style>
  12. .leaflet-tooltip, .leaflet-tooltip:before {
  13. color: white;
  14. border: none;
  15. background: rgba(0, 0, 0, 0.5);
  16. }
  17. </style>
  18. </head>
  19. <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
  20. <div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
  21. <script>
  22. var host = window.isLocal ? window.server : "https://iserver.supermap.io",
  23. nearestDataUrl = host + "/iserver/services/map-china400/rest/maps/China_4326",
  24. mapUrl = host + "/iserver/services/map-china400/rest/maps/ChinaDark",
  25. turfLayer, nearestQueryResultLayer,
  26. turfAnalyzeType = 'Interpolation_tin',
  27. map = L.map('map', {
  28. crs: L.CRS.EPSG4326,
  29. preferCanvas: true,
  30. center: [36, 106],
  31. maxZoom: 18,
  32. mixZoom: 2,
  33. zoom: 4
  34. });
  35. L.supermap.tiledMapLayer(mapUrl, {
  36. noWrap: true,
  37. prjCoordSys: {"epsgCode": "4326"},
  38. minZoom: 3
  39. }).addTo(map);
  40. //创建dom
  41. initEditView();
  42. function initEditView() {
  43. var infoView = L.control({position: 'topright'});
  44. infoView.onAdd = function () {
  45. var me = this;
  46. me._div = L.DomUtil.create('div');
  47. me._div.style.width = '420px';
  48. me._div.innerHTML = "<div class='panel panel-primary editPane' id='editPane'>"+
  49. "<div class='panel-heading'>"+
  50. "<h5 class='panel-title text-center'>" + resources.text_classificationAnalysis + "</h5></div>"+
  51. "<div class='panel-body content' id='classificationBody' >"+
  52. "<div class='panel'>"+
  53. "<div class='input-group'>"+
  54. "<span class='input-group-addon'>" + resources.text_classificationAnalysisType + "<span data-i18n='[title]resources.text_requiredField' style='color: red;'> * </span></span>"+
  55. "<select class='form-control' id='classificationAnalyzeType' name='interpolationAnalyzeType'>"+
  56. "<option value='nearestOption' selected>nearestAnalyze</option>"+
  57. "</select>"+
  58. "</div>"+
  59. "</div>"+
  60. "<div class='input-group' id='nearestBody'></div>"+
  61. "</div>";
  62. handleMapEvent(me._div, me._map);
  63. return me._div;
  64. };
  65. infoView.addTo(map);
  66. }
  67. //设置图标
  68. var airportIcon = L.Icon.extend({
  69. options: {
  70. iconSize: [25, 25],
  71. iconAnchor: [10, 10],
  72. popupAnchor: [2, -10]
  73. }
  74. });
  75. var pointIcon = L.Icon.extend({
  76. options: {
  77. iconSize: [35, 35],
  78. iconAnchor: [5, 35],
  79. popupAnchor: [2, -25]
  80. }
  81. });
  82. var airportBlueIcon = new airportIcon({iconUrl: '../img/airportBlue.png'});
  83. var airportRedIcon = new airportIcon({iconUrl: '../img/airportRed.png'});
  84. var selectPointIcon = new pointIcon({iconUrl: '../img/position.png'});
  85. var pointIcon = L.icon({
  86. iconUrl: '../img/marker-gold.png',
  87. iconSize: [25, 25],
  88. });
  89. var bounds = L.latLngBounds(L.latLng(90, 180), L.latLng(-90, -180));
  90. function mapOnClickListener(e) {
  91. if (!bounds.contains(e.latlng)) {
  92. widgets.alert.showAlert(resources.msg_beyondScope, false);
  93. return;
  94. }
  95. if (!classificationAnalyst.sourcePoints || classificationAnalyst.sourcePoints.features.length === 0) {
  96. widgets.alert.showAlert(resources.text_loadingData, true);
  97. return;
  98. }
  99. clearLayer();
  100. classificationAnalyst.selectPointMarker = L.marker(e.latlng, {icon: selectPointIcon}).bindPopup(resources.text_querypoint).addTo(map);
  101. classificationAnalyst.nearestAnalyze(classificationAnalyst.sourcePoints, e.latlng);
  102. }
  103. //添加鼠标滑动事件
  104. var tooltip = L.tooltip({
  105. direction: 'right'
  106. });
  107. var pointerMoveHandler = function (evt) {
  108. var helpMsg = resources.msg_findAirport;
  109. if (helpMsg) {
  110. tooltip.setContent(helpMsg);
  111. tooltip.setLatLng(evt.latlng);
  112. }
  113. tooltip.addTo(map);
  114. };
  115. map.on('mousemove', pointerMoveHandler);
  116. //创建邻近分析对象:
  117. var classificationAnalyst = {
  118. sourcePoints: null,
  119. line: null,
  120. selectPointMarker: null,
  121. loadAnalystLayer: function () {
  122. var center = L.latLng(36, 106);
  123. map.flyTo(center, 4);
  124. //初始化turfLayer
  125. turfLayer = L.supermap.turfLayer({
  126. pointToLayer: function (feature, latlng) {
  127. return L.marker(latlng, {
  128. icon: airportRedIcon, zIndexOffset: 1000
  129. }
  130. );
  131. }
  132. }).addTo(map);
  133. var airportsParam = new SuperMap.QueryBySQLParameters({
  134. queryParams: {
  135. name: "Airport_pt@China.1",
  136. }
  137. });
  138. //只发送一次请求
  139. if (!nearestQueryResultLayer) {
  140. L.supermap
  141. .queryService(nearestDataUrl)
  142. .queryBySQL(airportsParam, function (serviceResult) {
  143. classificationAnalyst.sourcePoints = serviceResult.result.recordsets[0].features;
  144. nearestQueryResultLayer = L.geoJSON(classificationAnalyst.sourcePoints, {
  145. pointToLayer: function (feature, latlng) {
  146. return L.marker(latlng, {icon: airportBlueIcon}).bindPopup(feature.properties.NAME);
  147. }
  148. }).addTo(map);
  149. });
  150. } else {
  151. nearestQueryResultLayer.addTo(map);
  152. }
  153. //点击地图进行最近飞机场分析
  154. map.on('click', mapOnClickListener);
  155. },
  156. nearestAnalyze: function (sourcePoints, pointLnglat) {
  157. turfLayer.process("Classification.nearestPoint", {
  158. "targetPoint": [pointLnglat.lng, pointLnglat.lat],
  159. "points": sourcePoints
  160. }, function (result) {
  161. var latlng = L.latLng(result.geometry.coordinates[1], result.geometry.coordinates[0]);
  162. turfLayer.bindPopup(resources.msg_nearestAirport + result.properties.NAME).openPopup(latlng);
  163. classificationAnalyst.line = L.polyline([pointLnglat, latlng], {
  164. color: "red",
  165. dashArray: '5',
  166. weight: 1
  167. }).addTo(map);
  168. map.fire("viewreset");
  169. });
  170. },
  171. };
  172. classificationAnalyst.loadAnalystLayer();
  173. function clearLayer() {
  174. if (turfLayer) {
  175. turfLayer.clearLayers();
  176. }
  177. if (classificationAnalyst.line) {
  178. classificationAnalyst.line.removeFrom(map);
  179. }
  180. if (classificationAnalyst.selectPointMarker) {
  181. classificationAnalyst.selectPointMarker.removeFrom(map);
  182. }
  183. }
  184. //避免画图事件与地图事件冲突
  185. function handleMapEvent(div, map) {
  186. if (!div || !map) {
  187. return;
  188. }
  189. div.addEventListener('mouseover', function () {
  190. map.dragging.disable();
  191. map.scrollWheelZoom.disable();
  192. map.doubleClickZoom.disable();
  193. map.off('mousemove', pointerMoveHandler);
  194. tooltip.removeFrom(map);
  195. });
  196. div.addEventListener('click', function () {
  197. map.off('click', mapOnClickListener);
  198. });
  199. div.addEventListener('mouseout', function () {
  200. map.dragging.enable();
  201. map.scrollWheelZoom.enable();
  202. map.doubleClickZoom.enable();
  203. map.on('click', mapOnClickListener);
  204. });
  205. }
  206. </script>
  207. </body>
  208. </html>