turf_interpolationAnalysis.html 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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_turfInterpolationAnalysis"></title>
  9. <style>
  10. .editPane {
  11. position: absolute;
  12. right: 10px;
  13. top: 10px;
  14. width: 400px;
  15. text-align: center;
  16. background: #FFF;
  17. z-index: 1000;
  18. }
  19. .dragBoxCss {
  20. border: 1px solid #33CCFF;
  21. }
  22. .tooltip {
  23. position: relative;
  24. background: rgba(0, 0, 0, 0.5);
  25. border-radius: 4px;
  26. color: white;
  27. padding: 4px 8px;
  28. opacity: 0.7;
  29. white-space: nowrap;
  30. }
  31. </style>
  32. </head>
  33. <body style='margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;'>
  34. <div id='map' style='margin:0 auto;width: 100%;height: 100%'></div>
  35. <div id='info' class='ol-popup'>
  36. <a href='#' id='popup-closer' class='ol-popup-closer'></a>
  37. <div id='info-content'></div>
  38. </div>
  39. <div class='panel panel-primary editPane' id='editPane'>
  40. <div class='panel-heading'>
  41. <h5 class='panel-title text-center' data-i18n="resources.text_interpolationAnalysis"></h5></div>
  42. <div class='panel-body content' id='interpolationBody'>
  43. <div class='panel'>
  44. <div class='input-group'>
  45. <span class='input-group-addon'><span data-i18n="resources.text_interpolationAnalysisType"></span><span
  46. data-i18n="[title]resources.text_requiredField" style='color: red;'> * </span></span>
  47. <select class='form-control' id='interpolationAnalyzeType' name='interpolationAnalyzeType'>
  48. <option value='tinOption' selected>tin</option>
  49. </select>
  50. </div>
  51. </div>
  52. <div class='input-group' id="tinBody">
  53. <input type='button' class='btn btn-primary' id='createTinBtn' data-i18n="[value]resources.btn_createTin"/>&nbsp;
  54. <input type='button' class='btn btn-primary' id='clearTinBtn' data-i18n="[value]resources.btn_clearTin"/>&nbsp;
  55. </div>
  56. </div>
  57. </div>
  58. </body>
  59. <script type="text/javascript" include="bootstrap,widgets.alert" src="../js/include-web.js"></script>
  60. <script type="text/javascript" include="turf" src="../../dist/ol/include-ol.js"></script>
  61. <script>
  62. var host = window.isLocal ? window.server : "https://iserver.supermap.io",
  63. tinDataUrl = host + "/iserver/services/map-jingjin/rest/maps/京津地区地图",
  64. mapUrl = host + "/iserver/services/map-china400/rest/maps/ChinaDark",
  65. turfLayer,
  66. tinQueryResultLayer,
  67. map = new ol.Map({
  68. target: 'map',
  69. maxExtent: [-180.0, -85.05, 180.0, 85.05],
  70. controls: ol.control.defaults({attributionOptions: {collapsed: false}})
  71. .extend([new ol.supermap.control.Logo()]),
  72. view: new ol.View({
  73. center: [106, 36],
  74. zoom: 5,
  75. projection: 'EPSG:4326'
  76. })
  77. });
  78. map.addLayer(new ol.layer.Tile({
  79. source: new ol.source.TileSuperMapRest({
  80. url: mapUrl,
  81. prjCoordSys: {"epsgCode": 4326}
  82. }),
  83. projection: 'EPSG:4326'
  84. }));
  85. //添加turf 图层
  86. var turfSource = new ol.source.Turf({
  87. wrapX: false,
  88. attributions: ""
  89. });
  90. bindEvent();
  91. function bindEvent() {
  92. $("#createTinBtn").click(function () {
  93. //是否有需要删除的提示框
  94. widgets.alert.clearAlert();
  95. if (interpolationAnalyst.resultFeatures) {
  96. interpolationAnalyst.createTin();
  97. } else {
  98. widgets.alert.showAlert(resources.text_loadingData, true);
  99. return;
  100. }
  101. });
  102. $("#clearTinBtn").click(function () {
  103. //是否有需要删除的提示框
  104. widgets.alert.clearAlert();
  105. clearLayer();
  106. });
  107. }
  108. //创建插值分析对象
  109. var interpolationAnalyst = {
  110. resultFeatures: null,
  111. loadAnalystLayer: function () {
  112. map.getView().animate({zoom: 9}, {center: [116.8, 39.8]});
  113. turfLayer = new ol.layer.Vector({
  114. source: turfSource,
  115. opacity: 0.5,
  116. style: function (feature) {
  117. feature.setStyle(new ol.style.Style({
  118. stroke: new ol.style.Stroke(({
  119. color: 'rgba(51,204,255,0.8)',
  120. weight: 0.1,
  121. })),
  122. fill: new ol.style.Fill({
  123. color: '#' + feature.getProperties().a + feature.getProperties().b + feature.getProperties().c,
  124. })
  125. }));
  126. }
  127. });
  128. var param = new SuperMap.QueryBySQLParameters({
  129. queryParams: {
  130. name: "Town_P@Jingjin.2",
  131. }
  132. });
  133. //只请求一次数据:
  134. if (!tinQueryResultLayer) {
  135. new ol.supermap.QueryService(tinDataUrl).queryBySQL(param, function (serviceResult) {
  136. interpolationAnalyst.resultFeatures = serviceResult.result.recordsets[0].features;
  137. for (var i = 0; i < interpolationAnalyst.resultFeatures.features.length; i++) {
  138. interpolationAnalyst.resultFeatures.features[i].properties.z = ~~(Math.random() * 9);
  139. }
  140. var features = (new ol.format.GeoJSON()).readFeatures(interpolationAnalyst.resultFeatures);
  141. var vectorSource = new ol.source.Vector({
  142. features: features,
  143. wrapX: false
  144. });
  145. tinQueryResultLayer = new ol.layer.Vector({
  146. source: vectorSource,
  147. style: new ol.style.Style({
  148. image: new ol.style.Circle({
  149. radius: 6,
  150. fill: new ol.style.Fill({color: 'rgba(255, 0, 0, 0.2)'}),
  151. })
  152. })
  153. });
  154. map.addLayer(tinQueryResultLayer);
  155. map.addLayer(turfLayer);
  156. });
  157. } else {
  158. map.addLayer(tinQueryResultLayer);
  159. map.addLayer(turfLayer);
  160. }
  161. },
  162. createTin: function () {
  163. if (turfSource.getFeatures().length > 0) {
  164. widgets.alert.showAlert(resources.msg_layerCreated, false);
  165. return;
  166. }
  167. turfSource.process("Interpolation.tin", {
  168. "points": interpolationAnalyst.resultFeatures,
  169. "z": 'z'
  170. });
  171. },
  172. };
  173. //页面默认首先加载“创建不规则三角网”:
  174. interpolationAnalyst.loadAnalystLayer();
  175. function clearLayer() {
  176. if (turfSource.getFeatures().length > 0) {
  177. turfSource.clear();
  178. }
  179. }
  180. </script>
  181. </html>