others_SM_OSMBuildings_RestData.html 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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>Supermap OSM BUildings Draw Data</title>
  9. </head>
  10. <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
  11. <div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
  12. <script type="text/javascript" include="bootstrap,widgets.alert" src="../js/include-web.js"></script>
  13. <script type="text/javascript" exclude="iclient-classic" include="OSMBuildings-SuperMap" src="../../dist/classic/include-classic.js"></script>
  14. <script type="text/javascript">
  15. var map, layer, osm, dataurl,alertDiv,
  16. host = window.isLocal ? window.server : "https://iserver.supermap.io";
  17. url = host + "/iserver/services/map-china400/rest/maps/China";
  18. dataurl = host + "/iserver/services/data-jingjin/rest/data";
  19. //检测浏览器是啥支持canves Buildings 需要Canvas绘制
  20. if (!document.createElement('canvas').getContext) {
  21. widgets.alert.showAlert(resources.msg_supportCanvas, false);
  22. }
  23. //初始化地图
  24. map = new SuperMap.Map("map", {
  25. controls: [
  26. new SuperMap.Control.Navigation(),
  27. new SuperMap.Control.MousePosition(),
  28. new SuperMap.Control.LayerSwitcher(),
  29. new SuperMap.Control.Zoom()
  30. ]
  31. });
  32. //初始化图层
  33. layer = new SuperMap.Layer.TiledDynamicRESTLayer("China", url, null, {maxResolution: "auto"});
  34. //监听图层信息加载完成事件
  35. layer.events.on({"layerInitialized": addLayer});
  36. //异步加载图层
  37. function addLayer() {
  38. map.addLayers([layer]);
  39. //显示地图范围
  40. map.setCenter(new SuperMap.LonLat(12957186.36784, 4852711.53595), 8);
  41. // SQL 查询方式从服务器端获取数据
  42. getFeatureBySQL();
  43. }
  44. function getFeatureBySQL() {
  45. //vectorlayer.removeAllFeatures();
  46. var getFeatureParam, getFeatureBySQLService, getFeatureBySQLParam;
  47. //查询参数设置
  48. getFeatureParam = new SuperMap.REST.FilterParameter({
  49. name: "Capital",
  50. atrributeFilter: "SMID<15"
  51. });
  52. getFeatureBySQLParam = new SuperMap.REST.GetFeaturesBySQLParameters({
  53. queryParameter: getFeatureParam,
  54. datasetNames: ["Jingjin:BaseMap_R"]
  55. });
  56. //实例化Service 并且设置监听函数
  57. getFeatureBySQLService = new SuperMap.REST.GetFeaturesBySQLService(dataurl, {
  58. eventListeners: {
  59. "processCompleted": processCompleted,
  60. "processFailed": processFailed
  61. }
  62. });
  63. //向服务发送操作参数
  64. getFeatureBySQLService.processAsync(getFeatureBySQLParam);
  65. }
  66. //查询成功后的处理方法
  67. function processCompleted(getFeatureEventArgs) {
  68. var i, len, features, result = getFeatureEventArgs.result;
  69. if (result && result.features) {
  70. features = result.features;
  71. for (i = 0, len = features.length; i < len; i++) {
  72. //var feature = features[i];
  73. FeatureToOSMBuildingsGeojson(features[i]);
  74. }
  75. //构建OSMBuildings
  76. OSMBuildingsInit();
  77. }
  78. }
  79. //查询失败
  80. function processFailed(e) {
  81. widgets.alert.showAlert(e.error.errorMsg,false);
  82. }
  83. var Draw_geoJSON = {
  84. "type": "FeatureCollection",
  85. "features": []
  86. };
  87. var featureID = 0;
  88. //处理服务器端返回的feature数据
  89. function FeatureToOSMBuildingsGeojson(e) {
  90. featureID++;
  91. var feature = {
  92. "type": "Feature",
  93. "id": 0,
  94. "geometry": {
  95. "type": "Polygon",
  96. "coordinates": []
  97. },
  98. "properties": {
  99. "wallColor": "rgb(111,168,220)",
  100. "roofColor": "rgb(207,226,243)",
  101. "height": 0,
  102. "minHeight": 0
  103. }
  104. };
  105. feature.id = featureID;
  106. feature.properties.height = e.attributes.POP_DENSITY99 * 800;
  107. feature.properties.wallColor = getWallColorByPoP(e.attributes.POP_DENSITY99);
  108. feature.properties.roofColor = getRootColorByPoP(e.attributes.POP_DENSITY99);
  109. var components1 = e.geometry.components;
  110. var geometry_coordinates = [];
  111. for (var i = 0; i < components1.length; i++) {
  112. var components2 = components1[i];
  113. for (var j = 0; j < components2.components.length; j++) {
  114. var components3 = components2.components[j];
  115. for (var k = 0; k < components3.components.length; k++) {
  116. var component = components3.components[k];
  117. var lonlat = new SuperMap.LonLat(component.x, component.y);
  118. geometry_coordinates.push([lonlat.lon, lonlat.lat]);
  119. }
  120. //起点终点相同 闭合
  121. geometry_coordinates.push(geometry_coordinates[0]);
  122. feature.geometry.coordinates = [geometry_coordinates];
  123. Draw_geoJSON.features.push(feature);
  124. }
  125. }
  126. }
  127. function getWallColorByPoP(pop) {
  128. var color = "#00eeee"
  129. if (pop >= 0 && pop < 0.02) {
  130. color = "#FDE2CA"
  131. } else if (pop >= 0.02 && pop < 0.04) {
  132. color = "#FACE9C";
  133. } else if (pop >= 0.04 && pop < 0.06) {
  134. color = "#F09C42";
  135. } else if (pop >= 0.06 && pop < 0.1) {
  136. color = "#D0770B";
  137. } else if (pop >= 0.1 && pop < 0.2) {
  138. color = "#945305";
  139. }
  140. return color;
  141. }
  142. function getRootColorByPoP(pop) {
  143. var color = "#00eeee"
  144. if (pop >= 0 && pop < 0.02) {
  145. color = "#F5E0CD"
  146. } else if (pop >= 0.02 && pop < 0.04) {
  147. color = "#F7D1A6";
  148. } else if (pop >= 0.04 && pop < 0.06) {
  149. color = "#F3A755";
  150. } else if (pop >= 0.06 && pop < 0.1) {
  151. color = "#DA861F";
  152. } else if (pop >= 0.1 && pop < 0.2) {
  153. color = "#A96411";
  154. }
  155. return color;
  156. }
  157. //OSMBuildings 构建
  158. function OSMBuildingsInit() {
  159. osm = new OSMBuildings(map);
  160. osm.load();
  161. osm.date(new Date()); //设置当前时间 计算OSMBuildings 阴影
  162. osm.set(Draw_geoJSON);
  163. osm.click(function (e) {
  164. // 返回当前点击的feature ID 和 当前的经纬度
  165. widgets.alert.showAlert("FeatureID:" + e.feature,true);
  166. });
  167. }
  168. </script>
  169. </body>
  170. </html>