theme_ctl_RankSymbol.html 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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_RankSymbol"></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_RankSymbol"></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="addThemeFeatures()"/>
  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="Circle" 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,alertDiv;
  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. // 创建一个圆形符号专题图层
  62. themeLayer = new SuperMap.Layer.RankSymbol("RankSymbolLayer", "Circle");
  63. // 指定用于专题图制作的属性字段 详看下面 addThemeLayer()中的feature.attrs.CON2009
  64. themeLayer.themeField = "CON2009";
  65. // 配置图表参数
  66. themeLayer.symbolSetting = {
  67. //必设参数
  68. codomain: [0, 40000], // 允许图形展示的值域范围,此范围外的数据将不制作图图形
  69. //圆最大半径 默认100
  70. maxR: 100,
  71. //圆最小半径 默认0
  72. minR: 0,
  73. // 圆形样式
  74. circleStyle: {fillOpacity: 0.8},
  75. // 符号专题图填充颜色
  76. fillColor: "#FFA500",
  77. // 专题图hover 样式
  78. circleHoverStyle: {fillOpacity: 1}
  79. };
  80. // 注册专题图 mousemove, mouseout事件(注意:专题图图层对象自带 on 函数,没有 events 对象)
  81. themeLayer.on("mousemove", showInfoWin);
  82. themeLayer.on("mouseout", closeInfoWin);
  83. // 注册地图 mousemove,用于获取当前鼠标在地图中的像素位置
  84. map.events.on({
  85. "mousemove": function (e) {
  86. infowinPosition = e.xy.clone();
  87. }
  88. });
  89. function addLayer() {
  90. map.addLayers([layer, themeLayer]);
  91. map.setCenter(new SuperMap.LonLat(104.067923, 34.679943), 2);
  92. }
  93. //构建 feature 数据, 专题图的数据必须是 SuperMap.Feature.Vector
  94. function addThemeFeatures() {
  95. clearThemeLayer();
  96. var features = [];
  97. for (var i = 0, len = chinaConsumptionLevel.length; i < len; i++) {
  98. // 省居民消费水平(单位:元)信息
  99. var provinceInfo = chinaConsumptionLevel[i];
  100. var geo = new SuperMap.Geometry.Point(provinceInfo[1], provinceInfo[2]);
  101. var attrs = {};
  102. attrs.NAME = provinceInfo[0];
  103. attrs.CON2009 = provinceInfo[3];
  104. var fea = new SuperMap.Feature.Vector(geo, attrs);
  105. features.push(fea);
  106. }
  107. themeLayer.addFeatures(features);
  108. }
  109. // 清除专题图层中的内容
  110. function clearThemeLayer() {
  111. themeLayer.clear();
  112. closeInfoWin();
  113. }
  114. // 显示地图弹窗
  115. function showInfoWin(e) {
  116. // e.target 是图形对象,即数据的可视化对象。
  117. // 图形对象的 refDataID 属性是数据(feature)的 id 属性,它指明图形对象是由那个数据制作而来;
  118. // 图形对象的 dataInfo 属性是图形对象表示的具体数据,他有两个属性,field、R 和 value;
  119. if (e.target && e.target.refDataID && e.target.dataInfo) {
  120. closeInfoWin();
  121. // 获取图形对应的数据 (feature)
  122. var fea = themeLayer.getFeatureById(e.target.refDataID);
  123. var info = e.target.dataInfo;
  124. // 弹窗内容
  125. var contentHTML = "<div style='color: #000; background-color: #fff'>";
  126. contentHTML += "省级行政区名称:<br><strong>" + fea.attributes.NAME + "</strong>";
  127. contentHTML += "<hr style='margin: 3px'>";
  128. switch (info.field) {
  129. case "CON2009":
  130. contentHTML += "09年居民消费水平 <br/><strong>" + info.value + "</strong>(元)";
  131. break;
  132. default:
  133. contentHTML += "No Data";
  134. }
  135. contentHTML += "</div>";
  136. // 弹出框大小
  137. var infowinSize = (SuperMap.Browser.name == "firefox") ? new SuperMap.Size(150, 105) : new SuperMap.Size(140, 90);
  138. // 弹出窗地理位置 向右偏移R
  139. infowinPosition.x += info.r;
  140. var lonLat = map.getLonLatFromPixel(infowinPosition);
  141. infowin = new SuperMap.Popup(
  142. "infowin",
  143. lonLat,
  144. infowinSize,
  145. contentHTML,
  146. false,
  147. false,
  148. null);
  149. infowin.setBackgroundColor("#fff");
  150. infowin.setOpacity(0.8);
  151. if (infowin) map.removePopup(infowin);
  152. map.addPopup(infowin);
  153. }
  154. }
  155. // 移除和销毁地图弹窗
  156. function closeInfoWin() {
  157. if (infowin) {
  158. try {
  159. map.removePopup(infowin);
  160. }
  161. catch (e) {
  162. widgets.alert.showAlert(e.message,false);
  163. }
  164. }
  165. }
  166. </script>
  167. </body>
  168. </html>