theme_ctl_GraphBar.html 9.3 KB

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