echartsLianjia.html 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <!--********************************************************************
  2. * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
  3. *********************************************************************-->
  4. <!DOCTYPE html>
  5. <html>
  6. <head>
  7. <meta charset="UTF-8">
  8. <meta http-equiv="X-UA-Compatible" content="IE=Edge">
  9. <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
  10. <script type="text/javascript" include="echarts,ol3-echarts" src="../../dist/ol/include-ol.js"></script>
  11. <title data-i18n="resources.title_lianjia"></title>
  12. <style>
  13. body {
  14. margin: 0;
  15. overflow: hidden;
  16. background: #fff;
  17. width: 100%;
  18. height: 100%
  19. }
  20. #map {
  21. position: absolute;
  22. width: 100%;
  23. height: 100%;
  24. }
  25. #titleContainer {
  26. position: absolute;
  27. color: white;
  28. left: 0;
  29. top: 30px;
  30. text-align: center;
  31. width: 100%;
  32. }
  33. #titleContainer>#title {
  34. letter-spacing: 0.1em;
  35. }
  36. .ol-overlaycontainer-stopevent{
  37. height: 0% !important;
  38. }
  39. </style>
  40. </head>
  41. <body>
  42. <div id="map"></div>
  43. <div id="titleContainer">
  44. <h2 id="title" data-i18n="resources.title_lianjia"></h2>
  45. </div>
  46. <script type="text/javascript" include="jquery" src="../js/include-web.js"></script>
  47. <script>
  48. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  49. var url = host + "/iserver/services/map-china400/rest/maps/ChinaDark";
  50. var queryUrl = "https://www.supermapol.com/iserver/services/map_201802beijingfangjia/rest/maps/2018年2月北京房价_链家小区参考价_格网";
  51. var map = new ol.Map({
  52. target: 'map',
  53. controls: ol.control.defaults({ attributionOptions: { collapsed: true } })
  54. .extend([new ol.supermap.control.Logo()]),
  55. view: new ol.View({
  56. center: [12954583.524137927, 4860747.532344677],
  57. zoom: 10,
  58. projection: 'EPSG:3857',
  59. multiWorld: true
  60. }),
  61. layers: [new ol.layer.Tile({
  62. source: new ol.source.TileSuperMapRest({
  63. url: url
  64. })
  65. })]
  66. });
  67. var echartslayer = new ol3Echarts(null, {
  68. hideOnMoving: true,
  69. hideOnZooming: true
  70. });
  71. echartslayer.appendTo(map);
  72. echartslayer.showLoading();
  73. var sqlParam = new SuperMap.QueryBySQLParameters({
  74. queryParams: {
  75. name: "lj_xq_500gw@BJ_201802LJ",
  76. attributeFilter: "SMID>0",
  77. },
  78. fromIndex: 0,
  79. toIndex: 10000,
  80. maxFeatures: 10000,
  81. });
  82. new ol.supermap.QueryService(queryUrl).queryBySQL(sqlParam, function (data) {
  83. echartslayer.hideLoading();
  84. var features = data.result.recordsets[0].features.features;
  85. var data = [];//由矩形左上角点&权重值&矩形右下角点组成
  86. for (var i = 0; i < features.length; i++) {
  87. var pointLeftTop = features[i].geometry.coordinates[0][0][0];
  88. var pointRightBottom = features[i].geometry.coordinates[0][0][2];
  89. var value = parseFloat((features[i].properties.average_price_1 / 10000).toFixed(2))
  90. data.push(pointLeftTop.concat(value).concat(pointRightBottom));
  91. }
  92. var COLORS = ['#e0dffb', '#8c88ef', '#5954e8', '#221cd2', '#17138d', '#0c0a48', '#030314', 'red'];
  93. var option = {
  94. tooltip: {},
  95. visualMap: {
  96. type: 'piecewise',
  97. inverse: true,
  98. top: 110,
  99. left: 10,
  100. pieces: [{
  101. gt: 0, lte: 2, color: COLORS[0]
  102. }, {
  103. gt: 2, lte: 4, color: COLORS[1]
  104. }, {
  105. gt: 4, lte: 6, color: COLORS[2]
  106. }, {
  107. gt: 6, lte: 8, color: COLORS[3]
  108. }, {
  109. gt: 8, lte: 10, color: COLORS[4]
  110. }, {
  111. gt: 10, lte: 15, color: COLORS[5]
  112. }, {
  113. gt: 15, lte: 20, color: COLORS[8]
  114. }, {
  115. gt: 20, lte: 28, color: COLORS[9]
  116. }],
  117. borderColor: '#ccc',
  118. borderWidth: 2,
  119. backgroundColor: '#eee',
  120. dimension: 2,
  121. inRange: {
  122. color: COLORS,
  123. opacity: 0.7
  124. }
  125. },
  126. series: [{
  127. type: 'custom',
  128. coordinateSystem: "openlayers",
  129. data: data,
  130. renderItem: renderItem,
  131. animation: false,
  132. itemStyle: {
  133. emphasis: {
  134. color: 'pink'
  135. }
  136. },
  137. encode: {
  138. tooltip: 2
  139. }
  140. }]
  141. };
  142. echartslayer.setChartOptions(option);
  143. // 自定义渲染
  144. function renderItem(params, api) {
  145. var pointLeftTop = [api.value(0), api.value(1)];
  146. pointLeftTop = map.getPixelFromCoordinate(pointLeftTop);
  147. var pointRightBottom = [api.value(3), api.value(4)];
  148. pointRightBottom = map.getPixelFromCoordinate(pointRightBottom);
  149. return {
  150. type: 'rect',
  151. shape: {
  152. x: pointLeftTop[0],
  153. y: pointLeftTop[1],
  154. width: pointLeftTop[0] - pointRightBottom[0],
  155. height: pointLeftTop[1] - pointRightBottom[1]
  156. },
  157. style: api.style({
  158. stroke: 'rgba(0,0,0,0.1)'
  159. }),
  160. styleEmphasis: api.styleEmphasis()
  161. };
  162. }
  163. });
  164. </script>
  165. </body>
  166. </html>