bmap.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <?php
  2. echo $this->render("_nav", [
  3. 'boxId' => $boxId,
  4. 'config' => $config,
  5. 'themeJs' => $themeJs,
  6. 'themeConfig' => $themeConfig,
  7. 'columns' => $columns,
  8. ]);
  9. $jsonConfig = \yii\helpers\Json::encode($config);
  10. Yii::$app->view->registerJs(<<<JS
  11. var boxId = "$boxId";
  12. var geoCoordMap;
  13. echartsList[boxId] = echarts.init(document.getElementById(boxId + '-echarts'), '$themeJs');
  14. echartsListConfig[boxId] = jQuery.parseJSON('$jsonConfig');
  15. // 动态加载数据
  16. $('#'+ boxId +' div span').click(function () {
  17. if (!$(this).data('type')) {
  18. return;
  19. }
  20. $(this).parent().find('span').removeClass('orange');
  21. $(this).addClass('orange');
  22. var type = $(this).data('type');
  23. var start = $(this).attr('data-start');
  24. var end = $(this).attr('data-end');
  25. var boxId = $(this).parent().parent().attr('id');
  26. var config = echartsListConfig[boxId];
  27. $.ajax({
  28. type:"get",
  29. url: config.server,
  30. dataType: "json",
  31. data: {type:type, echarts_type: 'bmap', echarts_start: start, echarts_end: end},
  32. success: function(result){
  33. var data = result.data;
  34. if (parseInt(result.code) === 200) {
  35. geoCoordMap = data.geoCoordMapData;
  36. echartsList[boxId].setOption({
  37. title: {
  38. text: '',
  39. subtext: '',
  40. sublink: '',
  41. left: 'center'
  42. },
  43. tooltip : {
  44. trigger: 'item'
  45. },
  46. bmap: {
  47. center: [104.114129, 37.550339],
  48. zoom: 5,
  49. roam: true,
  50. mapStyle: {
  51. styleJson: [{
  52. 'featureType': 'water',
  53. 'elementType': 'all',
  54. 'stylers': {
  55. 'color': '#d1d1d1'
  56. }
  57. }, {
  58. 'featureType': 'land',
  59. 'elementType': 'all',
  60. 'stylers': {
  61. 'color': '#f3f3f3'
  62. }
  63. }, {
  64. 'featureType': 'railway',
  65. 'elementType': 'all',
  66. 'stylers': {
  67. 'visibility': 'off'
  68. }
  69. }, {
  70. 'featureType': 'highway',
  71. 'elementType': 'all',
  72. 'stylers': {
  73. 'color': '#fdfdfd'
  74. }
  75. }, {
  76. 'featureType': 'highway',
  77. 'elementType': 'labels',
  78. 'stylers': {
  79. 'visibility': 'off'
  80. }
  81. }, {
  82. 'featureType': 'arterial',
  83. 'elementType': 'geometry',
  84. 'stylers': {
  85. 'color': '#fefefe'
  86. }
  87. }, {
  88. 'featureType': 'arterial',
  89. 'elementType': 'geometry.fill',
  90. 'stylers': {
  91. 'color': '#fefefe'
  92. }
  93. }, {
  94. 'featureType': 'poi',
  95. 'elementType': 'all',
  96. 'stylers': {
  97. 'visibility': 'off'
  98. }
  99. }, {
  100. 'featureType': 'green',
  101. 'elementType': 'all',
  102. 'stylers': {
  103. 'visibility': 'off'
  104. }
  105. }, {
  106. 'featureType': 'subway',
  107. 'elementType': 'all',
  108. 'stylers': {
  109. 'visibility': 'off'
  110. }
  111. }, {
  112. 'featureType': 'manmade',
  113. 'elementType': 'all',
  114. 'stylers': {
  115. 'color': '#d1d1d1'
  116. }
  117. }, {
  118. 'featureType': 'local',
  119. 'elementType': 'all',
  120. 'stylers': {
  121. 'color': '#d1d1d1'
  122. }
  123. }, {
  124. 'featureType': 'arterial',
  125. 'elementType': 'labels',
  126. 'stylers': {
  127. 'visibility': 'off'
  128. }
  129. }, {
  130. 'featureType': 'boundary',
  131. 'elementType': 'all',
  132. 'stylers': {
  133. 'color': '#fefefe'
  134. }
  135. }, {
  136. 'featureType': 'building',
  137. 'elementType': 'all',
  138. 'stylers': {
  139. 'color': '#d1d1d1'
  140. }
  141. }, {
  142. 'featureType': 'label',
  143. 'elementType': 'labels.text.fill',
  144. 'stylers': {
  145. 'color': '#999999'
  146. }
  147. }]
  148. }
  149. },
  150. series : [
  151. {
  152. name: '',
  153. type: 'scatter',
  154. coordinateSystem: 'bmap',
  155. data: convertData(data.seriesData),
  156. symbolSize: function (val) {
  157. return val[2] / 10;
  158. },
  159. label: {
  160. normal: {
  161. formatter: '{b}',
  162. position: 'right',
  163. show: false
  164. },
  165. emphasis: {
  166. show: true
  167. }
  168. },
  169. itemStyle: {
  170. normal: {
  171. color: 'rgb(89, 196, 230)'
  172. }
  173. }
  174. },
  175. {
  176. name: '',
  177. type: 'effectScatter',
  178. coordinateSystem: 'bmap',
  179. data: convertData(data.seriesData.sort(function (a, b) {
  180. return b.value - a.value;
  181. }).slice(0, 6)),
  182. symbolSize: function (val) {
  183. return val[2] / 10;
  184. },
  185. showEffectOn: 'render',
  186. rippleEffect: {
  187. brushType: 'stroke'
  188. },
  189. hoverAnimation: true,
  190. label: {
  191. normal: {
  192. formatter: '{b}',
  193. position: 'right',
  194. show: true
  195. }
  196. },
  197. itemStyle: {
  198. normal: {
  199. color: 'rgb(89, 196, 230)',
  200. shadowBlur: 10,
  201. shadowColor: 'rgb(150, 222, 232)'
  202. }
  203. },
  204. zlevel: 1
  205. }
  206. ]
  207. }, true);
  208. } else {
  209. rfWarning(result.message);
  210. }
  211. }
  212. });
  213. });
  214. var convertData = function (data) {
  215. var res = [];
  216. for (var i = 0; i < data.length; i++) {
  217. var geoCoord = geoCoordMap[data[i].name];
  218. if (geoCoord) {
  219. res.push({
  220. name: data[i].name,
  221. value: geoCoord.concat(data[i].value)
  222. });
  223. }
  224. }
  225. return res;
  226. };
  227. // 首个触发点击
  228. $('#'+ boxId +' div span:first').trigger('click');
  229. JS
  230. ) ?>
粤ICP备19079148号