theme_ctl_GraphBar3D.html 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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_GraphBar3D"></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_GraphBar3D"></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" onclick="addThemeLayer()"/>
  29. <input type='button' id='btn2' class='btn btn-primary' data-i18n="[value]resources.text_input_value_clear" onclick="clearThemeLayer()"/>
  30. </div>
  31. </div>
  32. </div>
  33. <div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
  34. <script type="text/javascript" exclude="iclient-classic" include="Bar3D" src="../../dist/classic/include-classic.js"></script>
  35. <script type="text/javascript" include="bootstrap,widgets.alert" src="../js/include-web.js"></script>
  36. <script src='../data/chinaConsumptionLevel.js'></script>
  37. <script type="text/javascript">
  38. var map, layer, themeLayer, infowin, infowinPosition;
  39. var host = window.isLocal ? window.server : "https://iserver.supermap.io",
  40. url = host + "/iserver/services/map-china400/rest/maps/China_4326";
  41. // 统计图模块要求浏览器支持 Canvas 渲染
  42. if (!document.createElement('canvas').getContext) {
  43. widgets.alert.showAlert(resources.msg_supportCanvas, false);
  44. }
  45. map = new SuperMap.Map("map", {
  46. controls: [
  47. new SuperMap.Control.LayerSwitcher(),
  48. new SuperMap.Control.ScaleLine(),
  49. new SuperMap.Control.Zoom(),
  50. new SuperMap.Control.Navigation({
  51. dragPanOptions: {
  52. enableKinetic: true
  53. }
  54. })]
  55. });
  56. layer = new SuperMap.Layer.TiledDynamicRESTLayer("China", url, {
  57. transparent: true,
  58. cacheEnabled: true
  59. }, {maxResolution: "auto"});
  60. layer.events.on({"layerInitialized": addLayer});
  61. // 创建一个三维柱状图(Bar3D)统计专题图图层
  62. themeLayer = new SuperMap.Layer.Graph("ThemeLayer", "Bar3D");
  63. // 指定用于专题图制作的属性字段
  64. themeLayer.themeFields = ["CON2009", "CON2010", "CON2011", "CON2012", "CON2013"];
  65. // 配置图表参数
  66. themeLayer.chartsSetting = {
  67. // width,height,codomain 分别表示图表宽、高、数据值域;此三项参数为必设参数
  68. width: 260,
  69. height: 120,
  70. codomain: [0, 40000], // 允许图表展示的值域范围,此范围外的数据将不制作图表
  71. // 3d 柱条正面样式(3d 柱条的侧面和顶面会以 3d 柱条正面样式为默认样式)
  72. barFaceStyle: {
  73. stroke: true
  74. },
  75. // 按字段设置 3d 柱条正面样式
  76. barFaceStyleByFields: [{fillColor: "#FFB980"}, {fillColor: "#5AB1EF"}, {fillColor: "#B6A2DE"}, {fillColor: "#2EC7C9"}, {fillColor: "#D87A80"}],
  77. // 3d 柱条正面 hover 样式(3d 柱条的侧面和顶面 hover 会以 3d 柱条正面 hover 样式为默认 hover 样式)
  78. barFaceHoverStyle: {
  79. stroke: true,
  80. strokeWidth: 1,
  81. strokeColor: "#ffff00"
  82. },
  83. xShapeBlank: [15, 15, 15], // 水平方向上的空白间距参数
  84. axisYTick: 4, // y 轴刻度数量
  85. useXReferenceLine: true, // 使用参考线
  86. xReferenceLineStyle: {strokeColor: "#008acd", strokeOpacity: 0.4}, // 参考线样式
  87. axisYLabels: ["4万", "3万", "2万", "1万", "0"], // y 轴标签
  88. axisXLabels: ["09年", "10年", "11年", "12年", "13年"], // x 轴标签
  89. backgroundStyle: { // 背景样式
  90. fillColor: "#d1eeee",
  91. shadowBlur: 12,
  92. shadowColor: "#d1eeee"
  93. },
  94. backgroundRadius: [5, 5, 5, 5] // 背景框圆角参数
  95. };
  96. // 注册专题图 mousemove, mouseout事件(注意:专题图图层对象自带 on 函数,没有 events 对象)
  97. themeLayer.on("mousemove", showInfoWin);
  98. themeLayer.on("mouseout", closeInfoWin);
  99. themeLayer.setOpacity(0.9);
  100. function addLayer() {
  101. map.addLayers([layer, themeLayer]);
  102. map.setCenter(new SuperMap.LonLat(104.067923, 34.679943), 2);
  103. }
  104. //构建 feature 数据, 专题图的数据必须是 SuperMap.Feature.Vector
  105. function addThemeLayer() {
  106. clearThemeLayer();
  107. var features = [];
  108. for (var i = 0, len = chinaConsumptionLevel.length; i < len; i++) {
  109. // 省居民消费水平(单位:元)信息
  110. var provinceInfo = chinaConsumptionLevel[i];
  111. var geo = new SuperMap.Geometry.Point(provinceInfo[1], provinceInfo[2]);
  112. var attrs = {};
  113. attrs.NAME = provinceInfo[0];
  114. attrs.CON2009 = provinceInfo[3];
  115. attrs.CON2010 = provinceInfo[4];
  116. attrs.CON2011 = provinceInfo[5];
  117. attrs.CON2012 = provinceInfo[6];
  118. attrs.CON2013 = provinceInfo[7];
  119. var fea = new SuperMap.Feature.Vector(geo, attrs);
  120. features.push(fea);
  121. }
  122. themeLayer.addFeatures(features);
  123. }
  124. // 清除专题图层中的内容
  125. function clearThemeLayer() {
  126. themeLayer.clear();
  127. closeInfoWin();
  128. }
  129. // 注册地图 mousemove,用于获取当前鼠标在地图中的像素位置
  130. map.events.on({
  131. "mousemove": function (e) {
  132. infowinPosition = e.xy.clone();
  133. // 偏移
  134. infowinPosition.x += 40;
  135. infowinPosition.y -= 25;
  136. }
  137. });
  138. // 显示地图弹窗
  139. function showInfoWin(e) {
  140. // e.target 是图形对象,即数据的可视化对象,三维柱状图中是指三维柱条;
  141. // 图形对象的 refDataID 属性是数据(feature)的 id 属性,它指明图形对象是由那个数据制作而来;
  142. // 图形对象的 dataInfo 属性是图形对象表示的具体数据,他有两个属性,field 和 value;
  143. if (e.target && e.target.refDataID && e.target.dataInfo) {
  144. closeInfoWin();
  145. // 获取图形对应的数据 (feature)
  146. var fea = themeLayer.getFeatureById(e.target.refDataID);
  147. var info = e.target.dataInfo;
  148. // 弹窗内容
  149. var contentHTML = "<div style='color: #000; background-color: #fff'>";
  150. contentHTML += "省级行政区名称:<br><strong>" + fea.attributes.NAME + "</strong>";
  151. contentHTML += "<hr style='margin: 3px'>";
  152. switch (info.field) {
  153. case "CON2009":
  154. contentHTML += "09年居民消费水平 <br/><strong>" + info.value + "</strong>(元)";
  155. break;
  156. case "CON2010":
  157. contentHTML += "10年居民消费水平 <br/><strong>" + info.value + "</strong>(元)";
  158. break;
  159. case "CON2011":
  160. contentHTML += "11年居民消费水平 <br/><strong>" + info.value + "</strong>(元)";
  161. break;
  162. case "CON2012":
  163. contentHTML += "12年居民消费水平 <br/><strong>" + info.value + "</strong>(元)";
  164. break;
  165. case "CON2013":
  166. contentHTML += "13年居民消费水平 <br/><strong>" + info.value + "</strong>(元)";
  167. break;
  168. default:
  169. contentHTML += "No Data";
  170. }
  171. contentHTML += "</div>";
  172. // 弹出框大小
  173. var infowinSize = (SuperMap.Browser.name == "firefox") ? new SuperMap.Size(150, 105) : new SuperMap.Size(140, 90);
  174. // 弹出窗地理位置
  175. var lonLat = map.getLonLatFromPixel(infowinPosition);
  176. infowin = new SuperMap.Popup(
  177. "infowin",
  178. lonLat,
  179. infowinSize,
  180. contentHTML,
  181. false,
  182. false,
  183. null);
  184. infowin.setBackgroundColor("#fff");
  185. infowin.setOpacity(0.8);
  186. if (infowin) map.removePopup(infowin);
  187. map.addPopup(infowin);
  188. }
  189. }
  190. // 移除和销毁地图弹窗
  191. function closeInfoWin() {
  192. if (infowin) {
  193. try {
  194. map.removePopup(infowin);
  195. }
  196. catch (e) {
  197. widgets.alert.showAlert(e.message,false);
  198. }
  199. }
  200. }
  201. </script>
  202. </body>
  203. </html>