theme_ctl_worldCapitalsGraphBar.html 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <!--********************************************************************
  2. * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
  3. *********************************************************************-->
  4. <!DOCTYPE html>
  5. <html>
  6. <head>
  7. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  8. <title data-i18n="resources.title_worldCapitalsGraphBar"></title>
  9. <style type="text/css">
  10. .editPane {
  11. position: absolute;
  12. right: 60px;
  13. top: 50px;
  14. text-align: center;
  15. background: #FFF;
  16. z-index: 1000;
  17. }
  18. </style>
  19. </head>
  20. <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
  21. <div class='panel panel-primary editPane' id='editPane' style="z-index: 99999">
  22. <div class='panel-heading'>
  23. <h5 class='panel-title text-center' data-i18n="resources.title_worldCapitalsGraphBar"></h5>
  24. </div>
  25. <div class='panel-body' id='params'>
  26. <p></p>
  27. <div align='right' class='button-group'>
  28. <input type='button' id='btn1' class='btn btn-primary' data-i18n="[value]resources.btn_addThemeLayer"
  29. onclick="addThemeLayer()" style="padding: 6px 30px;"/>
  30. <input type='button' id='btn2' class='btn btn-primary' data-i18n="[value]resources.text_input_value_clear"
  31. onclick="clearThemeLayer()" style="padding: 6px 30px;"/>
  32. </div>
  33. </div>
  34. </div>
  35. <div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
  36. <script type="text/javascript" exclude="iclient-classic" include="Bar3D" src="../../dist/classic/include-classic.js"></script>
  37. <script type="text/javascript" include="bootstrap,widgets.alert" src="../js/include-web.js"></script>
  38. <script type="text/javascript">
  39. var map, layer, themeLayer, infowin;
  40. var host = window.isLocal ? window.server : "https://iserver.supermap.io",
  41. url = host + "/iserver/services/map-world/rest/maps/World";
  42. // 统计图模块要求浏览器支持 Canvas 渲染
  43. if (!document.createElement('canvas').getContext) {
  44. widgets.alert.showAlert(resources.msg_supportCanvas, false);
  45. }
  46. map = new SuperMap.Map("map", {
  47. controls: [
  48. new SuperMap.Control.LayerSwitcher(),
  49. new SuperMap.Control.ScaleLine(),
  50. new SuperMap.Control.Zoom(),
  51. new SuperMap.Control.Navigation({
  52. dragPanOptions: {
  53. enableKinetic: true
  54. }
  55. })]
  56. });
  57. layer = new SuperMap.Layer.TiledDynamicRESTLayer("World", url, {
  58. transparent: true,
  59. cacheEnabled: true
  60. }, {maxResolution: "auto"});
  61. layer.events.on({"layerInitialized": addLayer});
  62. // 创建一个三维柱状统计专题图图层
  63. themeLayer = new SuperMap.Layer.Graph("ThemeLayer", "Bar3D");
  64. // 指定用于专题图制作的属性字段
  65. themeLayer.themeFields = ["CAP_POP"];
  66. // 压盖处理权重
  67. themeLayer.overlayWeightField = "CAP_POP";
  68. // 配置图表参数
  69. themeLayer.chartsSetting = {
  70. // width,height,codomain 分别表示图表宽、高、数据值域;此三项参数为必设参数
  71. width: 30,
  72. height: 100,
  73. codomain: [0, 14000000], // 允许图表展示的值域范围,此范围外的数据将不制作图表
  74. xShapeBlank: [0, 0, 0], // 水平方向上的空白间距参数
  75. YOffset: -50, // 向上偏移 50 像素
  76. useAxis: false, // 不显示坐标轴
  77. useBackground: false // 不显示背景框
  78. };
  79. // 注册 click 事件
  80. themeLayer.on("click", moveToCapital);
  81. function addLayer() {
  82. map.addLayers([layer, themeLayer]);
  83. map.setCenter(new SuperMap.LonLat(0, 0), 0);
  84. }
  85. //获取 feature 数据, 专题图的数据必须是 SuperMap.Feature.Vector
  86. function addThemeLayer() {
  87. clearThemeLayer();
  88. var queryParam, queryBySQLParams, queryBySQLService;
  89. queryParam = new SuperMap.REST.FilterParameter({
  90. name: "Capitals@World#1",
  91. // 只统计人口 > 1000000 的首都城市
  92. attributeFilter: "CAP_POP > 1000000"
  93. });
  94. queryBySQLParams = new SuperMap.REST.QueryBySQLParameters({
  95. queryParams: [queryParam]
  96. });
  97. queryBySQLService = new SuperMap.REST.QueryBySQLService(url, {
  98. eventListeners: {"processCompleted": processCompleted, "processFailed": processFailed}
  99. });
  100. queryBySQLService.processAsync(queryBySQLParams);
  101. }
  102. function processCompleted(queryEventArgs) {
  103. var i, result = queryEventArgs.result;
  104. if (result && result.recordsets) {
  105. for (i = 0; i < result.recordsets.length; i++) {
  106. if (result.recordsets[i].features) {
  107. // 向专题图层添加用于制作专题图的feature数据
  108. themeLayer.addFeatures(result.recordsets[i].features);
  109. }
  110. }
  111. }
  112. }
  113. function processFailed(e) {
  114. widgets.alert.showAlert(e.error.errorMsg, false);
  115. }
  116. // 定位到首都城市
  117. function moveToCapital(e) {
  118. if (e.target && e.target.refDataID) {
  119. closeInfoWin();
  120. // 获取图形对应的 feature
  121. var fea = themeLayer.getFeatureById(e.target.refDataID);
  122. // feature 的 bounds 中心
  123. var geoCenter = fea.geometry.getBounds().getCenterLonLat();
  124. // 定位到 feature 的 bounds 中心
  125. var lonLat = new SuperMap.LonLat(geoCenter.lon, geoCenter.lat);
  126. map.setCenter(lonLat, 4);
  127. // 弹窗内容
  128. var contentHTML = "<div style='color: #000; background-color: #fff'>";
  129. contentHTML += "<strong><i>" + fea.attributes.CAPITAL_CH + "</i></strong>";
  130. contentHTML += "<hr style='margin: 3px'>";
  131. contentHTML += resources.text_population + "<strong>" + fea.attributes.CAP_POP + "</strong>";
  132. contentHTML += "</div>";
  133. infowin = new SuperMap.Popup(
  134. "infowin",
  135. lonLat,
  136. new SuperMap.Size(150, 60),
  137. contentHTML,
  138. true,
  139. false,
  140. null);
  141. infowin.setBackgroundColor("#fff");
  142. infowin.setOpacity(0.8);
  143. if (infowin) map.removePopup(infowin);
  144. map.addPopup(infowin);
  145. }
  146. }
  147. function clearThemeLayer() {
  148. themeLayer.clear();
  149. closeInfoWin();
  150. }
  151. // 移除地图弹窗
  152. function closeInfoWin() {
  153. if (infowin) {
  154. try {
  155. map.removePopup(infowin);
  156. }
  157. catch (e) {
  158. widgets.alert.showAlert(e.message, false);
  159. }
  160. }
  161. }
  162. </script>
  163. </body>
  164. </html>