echartsGridMapLayer.html 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <!--********************************************************************
  2. * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
  3. *********************************************************************-->
  4. <!DOCTYPE html>
  5. <html lang="en">
  6. <head>
  7. <meta charset="UTF-8">
  8. <title data-i18n="resources.title_lianjia"></title>
  9. <script type="text/javascript" src="../js/include-web.js"></script>
  10. <style>
  11. body {
  12. margin: 0;
  13. overflow: hidden;
  14. background: #fff;
  15. width: 100%;
  16. height: 100%;
  17. position: absolute;
  18. top: 0;
  19. }
  20. #map {
  21. margin: 0 auto;
  22. width: 100%;
  23. height: 100%
  24. }
  25. #titleContainer {
  26. width: 100%;
  27. position: absolute;
  28. top: 30px;
  29. color: white;
  30. z-index: 999;
  31. font-size: 20px;
  32. font-weight: bold;
  33. text-align: center;
  34. }
  35. #titleContainer > #title {
  36. letter-spacing: 0.1em;
  37. }
  38. </style>
  39. </head>
  40. <body>
  41. <div id="map"></div>
  42. <div id="titleContainer">
  43. <h2 id="title" data-i18n="resources.title_lianjia"></h2>
  44. </div>
  45. <script type="text/javascript" include="echarts" src="../../dist/leaflet/include-leaflet.js"></script>
  46. <script>
  47. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  48. var baseurl = host + "/iserver/services/map-china400/rest/maps/ChinaDark";
  49. var dataUrl = "https://www.supermapol.com/iserver/services/map_201802beijingfangjia/rest/maps/2018年2月北京房价_链家小区参考价_格网";
  50. var map = L.map('map', {
  51. center: [39.88076184888246, 116.42898559570312],
  52. zoom: 11,
  53. maxZoom: 18,
  54. minZoom: 6
  55. });
  56. L.supermap.tiledMapLayer(baseurl).addTo(map);
  57. query();
  58. function query() {
  59. var param = new SuperMap.QueryBySQLParameters({
  60. queryParams: {
  61. name: "lj_xq_500gw@BJ_201802LJ",
  62. attributeFilter: "SMID > 0"
  63. },
  64. fromIndex: 0,
  65. toIndex: 10000,
  66. maxFeatures: 10000
  67. });
  68. L.supermap.queryService(dataUrl).queryBySQL(param, function (serviceResult) {
  69. var result = serviceResult.result;
  70. var features = result.recordsets[0].features.features;
  71. //构造数据
  72. var data = [];
  73. for (var i = 0; i < features.length; i++) {
  74. var pointLeftTop = coordsTo4326(features[i].geometry.coordinates[0][0][0]);
  75. var pointRightBottom = coordsTo4326(features[i].geometry.coordinates[0][0][2]);
  76. var value = parseFloat((features[i].properties.average_price_1 / 10000).toFixed(2));
  77. data.push(pointLeftTop.concat(value).concat(pointRightBottom));
  78. }
  79. var COLORS = ['#e0dffb', '#8c88ef', '#5954e8', '#221cd2', '#17138d', '#0c0a48', '#030314', 'red'];
  80. var option = {
  81. tooltip: {},
  82. visualMap: {
  83. type: 'piecewise',
  84. inverse: true,
  85. top: 110,
  86. left: 10,
  87. pieces: [{
  88. gt: 0, lte: 2, color: COLORS[0]
  89. }, {
  90. gt: 2, lte: 4, color: COLORS[1]
  91. }, {
  92. gt: 4, lte: 6, color: COLORS[2]
  93. }, {
  94. gt: 6, lte: 8, color: COLORS[3]
  95. }, {
  96. gt: 8, lte: 10, color: COLORS[4]
  97. }, {
  98. gt: 10, lte: 15, color: COLORS[5]
  99. }, {
  100. gt: 15, lte: 20, color: COLORS[8]
  101. }, {
  102. gt: 20, lte: 28, color: COLORS[9]
  103. }],
  104. borderColor: '#ccc',
  105. borderWidth: 2,
  106. backgroundColor: '#eee',
  107. dimension: 2,
  108. inRange: {
  109. color: COLORS,
  110. opacity: 0.7
  111. }
  112. },
  113. series: [{
  114. type: 'custom',
  115. coordinateSystem: "leaflet",
  116. data: data,
  117. renderItem: renderItem,
  118. animation: false,
  119. itemStyle: {
  120. emphasis: {
  121. color: 'pink'
  122. }
  123. },
  124. encode: {
  125. tooltip: 2
  126. }
  127. }]
  128. };
  129. // 自定义渲染
  130. function renderItem(params, api) {
  131. pointLeftTop =map.latLngToContainerPoint(new L.LatLng(api.value(1),api.value(0)));
  132. pointRightBottom = map.latLngToContainerPoint(new L.LatLng(api.value(4),api.value(3)));
  133. return {
  134. type: 'rect',
  135. shape: {
  136. x: pointLeftTop.x,
  137. y: pointLeftTop.y,
  138. width: pointLeftTop.x - pointRightBottom.x,
  139. height: pointLeftTop.y - pointRightBottom.y
  140. },
  141. style: api.style({
  142. stroke: 'rgba(0,0,0,0.1)'
  143. }),
  144. styleEmphasis: api.styleEmphasis()
  145. };
  146. }
  147. function coordsTo4326(coords) {
  148. var lngLat = L.CRS.EPSG3857.unproject(L.point(coords));
  149. return [lngLat.lng, lngLat.lat];
  150. }
  151. L.supermap.echartsLayer(option).addTo(map);
  152. });
  153. }
  154. </script>
  155. </body>
  156. </html>