echarts_pie.html 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <!--********************************************************************
  2. * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
  3. *********************************************************************-->
  4. <html>
  5. <head>
  6. <meta charset='utf-8'/>
  7. <title data-i18n="resources.title_GraphPie"></title>
  8. <meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no'/>
  9. <style>
  10. body {
  11. margin: 0;
  12. padding: 0;
  13. }
  14. #map {
  15. position: absolute;
  16. top: 0;
  17. bottom: 0;
  18. width: 100%;
  19. }
  20. #map .mapboxgl-popup-content {
  21. padding: 10px 16px 15px;
  22. }
  23. </style>
  24. </head>
  25. <body>
  26. <div id='map'></div>
  27. <script type="text/javascript" include="bootstrap" src="../js/include-web.js"></script>
  28. <script type="text/javascript" include="echarts" src="../../dist/mapboxgl/include-mapboxgl.js"></script>
  29. <script type="text/javascript">
  30. var data;
  31. var attribution = "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox </a>" +
  32. " with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
  33. " Image <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a> | </span>" +
  34. " <a href='https://echarts.baidu.com' target='_blank'>© 2018 " + resources.title_3baidu + " ECharts</a>";
  35. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  36. var tileURL = host + '/iserver/services/map-world/rest/maps/世界地图_Gray/zxyTileImage.png?prjCoordSys='+encodeURIComponent('{"epsgCode":3857}')+'&z={z}&x={x}&y={y}';
  37. var url = host + "/iserver/services/map-china400/rest/maps/China_4326";
  38. var chart, div, popup = '';
  39. var map = new mapboxgl.Map({
  40. container: 'map',
  41. style: {
  42. "version": 8,
  43. "sources": {
  44. "raster-tiles": {
  45. "attribution": attribution,
  46. "type": "raster",
  47. "tiles": [tileURL],
  48. "tileSize": 256,
  49. },
  50. },
  51. "layers": [{
  52. "id": "simple-tiles",
  53. "type": "raster",
  54. "source": "raster-tiles",
  55. "minzoom": 0,
  56. "maxzoom": 18
  57. }]
  58. },
  59. center: [116.402, 39.905],
  60. zoom: 3.5
  61. });
  62. map.addControl(new mapboxgl.NavigationControl(), 'top-left');
  63. map.loadImage('../img/marker-icon.png', function (error, image) {
  64. if (error) throw error;
  65. map.addImage('positionPoint', image);
  66. });
  67. var categoryDataMap = {
  68. "北京市": [
  69. {value: 335, name: resources.text_class + 'A'},
  70. {value: 679, name: resources.text_class + 'B'},
  71. {value: 1299, name: resources.text_class + 'C'}
  72. ],
  73. "广州市": [
  74. {value: 117, name: resources.text_class + 'A'},
  75. {value: 1267, name: resources.text_class + 'B'},
  76. {value: 1048, name: resources.text_class + 'C'}
  77. ], "上海市": [
  78. {value: 475, name: resources.text_class + 'A'},
  79. {value: 1450, name: resources.text_class + 'B'},
  80. {value: 875, name: resources.text_class + 'C'}
  81. ]
  82. };
  83. var dataMap = {
  84. "北京市": [
  85. {value: 335, name: resources.text_commodity + 'A'},
  86. {value: 310, name: resources.text_commodity + 'B'},
  87. {value: 234, name: resources.text_commodity + 'C'},
  88. {value: 135, name: resources.text_commodity + 'D'},
  89. {value: 1048, name: resources.text_commodity + 'E'},
  90. {value: 251, name: resources.text_commodity + 'F'}
  91. ],
  92. "广州市": [
  93. {value: 117, name: resources.text_commodity + 'A'},
  94. {value: 284, name: resources.text_commodity + 'B'},
  95. {value: 768, name: resources.text_commodity + 'C'},
  96. {value: 215, name: resources.text_commodity + 'D'},
  97. {value: 901, name: resources.text_commodity + 'E'},
  98. {value: 148, name: resources.text_commodity + 'F'}
  99. ], "上海市": [
  100. {value: 475, name: resources.text_commodity + 'A'},
  101. {value: 29, name: resources.text_commodity + 'B'},
  102. {value: 430, name: resources.text_commodity + 'C'},
  103. {value: 981, name: resources.text_commodity + 'D'},
  104. {value: 732, name: resources.text_commodity + 'E'},
  105. {value: 143, name: resources.text_commodity + 'F'}
  106. ]
  107. };
  108. var option = {
  109. title: {
  110. text: resources.text_beijingCommoditySales,
  111. subtext: resources.text_fictitiouData,
  112. textStyle: {
  113. color: '#fff',
  114. fontSize: 16
  115. }
  116. },
  117. backgroundColor: '#404a59',
  118. tooltip: {
  119. trigger: 'item',
  120. formatter: "{a} <br/>{b}: {c} ({d}%)"
  121. },
  122. legend: {
  123. orient: 'vertical',
  124. x: 'right',
  125. y: 'bottom',
  126. textStyle: {
  127. color: '#fff',
  128. fontSize: 12
  129. },
  130. data: [resources.text_commodity + 'A', resources.text_commodity + 'B', resources.text_commodity + 'C', resources.text_commodity + 'D', resources.text_commodity + 'E', resources.text_commodity + 'F']
  131. },
  132. series: [
  133. {
  134. name: resources.text_commodityClass,
  135. type: 'pie',
  136. selectedMode: 'single',
  137. radius: [0, '30%'],
  138. label: {
  139. normal: {
  140. position: 'inner'
  141. }
  142. },
  143. labelLine: {
  144. normal: {
  145. show: false
  146. }
  147. },
  148. data: categoryDataMap['北京市']
  149. },
  150. {
  151. name: resources.text_commodity,
  152. type: 'pie',
  153. radius: ['40%', '55%'],
  154. data: dataMap['北京市']
  155. }
  156. ]
  157. };
  158. div = document.createElement('div');
  159. chart = echarts.init(div, '', {
  160. width: 650,
  161. height: 400
  162. });
  163. chart.setOption(option);
  164. query();
  165. function query() {
  166. var sqlParam = new SuperMap.QueryBySQLParameters({
  167. queryParams: [{
  168. name: "China_ProCenCity_pt@China",
  169. attributeFilter: "NAME = '广州市' or NAME = '上海市'"
  170. }, {
  171. name: "China_Capital_pt@China",
  172. attributeFilter: "NAME = '北京市'"
  173. }]
  174. });
  175. queryService = new mapboxgl.supermap.QueryService(url).queryBySQL(sqlParam, function (serviceResult) {
  176. var recordsets = serviceResult && serviceResult.result && serviceResult.result.recordsets;
  177. features = recordsets && recordsets[0] && recordsets[0].features;
  178. var featureCollection = features.features;
  179. var feature = recordsets[1].features.features;
  180. featureCollection.push(feature[0]);
  181. var fs = {
  182. features: featureCollection,
  183. type: "FeatureCollection"
  184. };
  185. map.addLayer({
  186. "id": "points",
  187. "type": "symbol",
  188. "layout": {
  189. "icon-image": "positionPoint",
  190. "icon-size": 0.8,
  191. "icon-offset": [0, -15] //设置偏移量
  192. },
  193. "source": {
  194. "type": "geojson",
  195. "data": fs
  196. }
  197. });
  198. map.on('click', 'points', function (e) {
  199. popup = new mapboxgl.Popup({maxWidth: 'none'});
  200. popup.setLngLat(e.lngLat.toArray())
  201. .setDOMContent(div) // sets a popup on this marker
  202. .addTo(map);
  203. var city = e.features[0].properties.NAME;
  204. chart.setOption({
  205. title: {
  206. text: city + resources.text_commoditySales
  207. },
  208. series: [
  209. {
  210. name: resources.text_commodityClass,
  211. data: categoryDataMap[city]
  212. },
  213. {
  214. name: resources.text_commodity,
  215. data: dataMap[city]
  216. }
  217. ]
  218. });
  219. });
  220. });
  221. }
  222. </script>
  223. </body>
  224. </html>