mapvLianjia.html 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <!--********************************************************************
  2. * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
  3. *********************************************************************-->
  4. <!DOCTYPE html>
  5. <html>
  6. <head>
  7. <meta http-equiv="X-UA-Compatible" content="IE=Edge">
  8. <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
  9. <script type="text/javascript" include="mapv" src="../../dist/ol/include-ol.js"></script>
  10. <title data-i18n="resources.title_lianjia"></title>
  11. <style>
  12. body {
  13. margin: 0;
  14. overflow: hidden;
  15. background: #fff;
  16. width: 100%;
  17. height: 100%;
  18. position: absolute;
  19. top: 0;
  20. }
  21. #map {
  22. width: 100%;
  23. height: 100%;
  24. }
  25. #popupContainer {
  26. background: rgba(9, 1, 54, 0.589);
  27. color: red;
  28. display: none;
  29. padding: 15px;
  30. color: white;
  31. font-size: 15px;
  32. font-weight: bolder;
  33. border-radius: 5px;
  34. box-shadow: 0px -1px 46px 0px rgba(0, 0, 0, 0.75);
  35. }
  36. #price {
  37. font-weight: lighter;
  38. padding-right: 5px;
  39. }
  40. #titleContainer {
  41. position: absolute;
  42. color: white;
  43. left: 0;
  44. top: 30px;
  45. text-align: center;
  46. width: 100%;
  47. }
  48. #titleContainer>#title {
  49. letter-spacing: 0.1em;
  50. }
  51. </style>
  52. </head>
  53. <body>
  54. <div id="map"></div>
  55. <div id="titleContainer">
  56. <h2 id="title" data-i18n="resources.title_lianjia"></h2>
  57. </div>
  58. <div id="popupContainer">
  59. <table>
  60. <tr>
  61. <td data-i18n="resources.text_mapvLianjia_tooltip"></td>
  62. <td id="price"></td>
  63. </tr>
  64. </table>
  65. </div>
  66. <script type="text/javascript" include="jquery" src="../js/include-web.js"></script>
  67. <script type="text/javascript">
  68. // map
  69. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  70. var url = host + "/iserver/services/map-china400/rest/maps/ChinaDark";
  71. var queryUrl = "https://www.supermapol.com/iserver/services/map_201802beijingfangjia/rest/maps/2018年2月北京房价_链家小区参考价_蜂巢";
  72. var map = new ol.Map({
  73. target: 'map',
  74. controls: ol.control.defaults({ attributionOptions: { collapsed: true } })
  75. .extend([new ol.supermap.control.Logo()]),
  76. view: new ol.View({
  77. center: [12956083.664865, 4872418.298275658],
  78. zoom: 10,
  79. projection: 'EPSG:3857',
  80. multiWorld: true
  81. }),
  82. layers: [new ol.layer.Tile({
  83. source: new ol.source.TileSuperMapRest({
  84. url: url
  85. })
  86. })]
  87. });
  88. // popup
  89. var popupContainer = document.getElementById('popupContainer');
  90. var popup = new ol.Overlay({
  91. element: document.getElementById('popupContainer'),
  92. offset: [15, -50]
  93. });
  94. map.addOverlay(popup);
  95. var sqlParam = new SuperMap.QueryBySQLParameters({
  96. queryParams: {
  97. name: "lj_xq_500fc@BJ_201802LJ",
  98. attributeFilter: "SMID>0",
  99. },
  100. fromIndex: 0,
  101. toIndex: 10000,
  102. maxFeatures: 10000,
  103. });
  104. new ol.supermap.QueryService(queryUrl).queryBySQL(sqlParam, function (data) {
  105. var features = data.result.recordsets[0].features.features;
  106. //构造mapv数据
  107. var data = [], arr = [];
  108. for (var i = 0; i < features.length; i++) {
  109. var feature = features[i];
  110. var average_price = feature.properties.average_price_1;
  111. data.push({
  112. geometry: {
  113. type: 'Polygon',
  114. coordinates: feature.geometry.coordinates[0]
  115. },
  116. count: Math.floor(average_price / 10000),
  117. price: parseFloat(average_price).toFixed(2),
  118. });
  119. };
  120. var dataSet = new mapv.DataSet(data.concat());
  121. var mapvOptions = {
  122. max: 27,
  123. gradient: { // 显示的颜色渐变范围
  124. '0': 'rgba(0,0,255,0.7)',
  125. '0.6': 'rgba(255,0,0,0.7)'
  126. },
  127. draw: 'intensity',
  128. methods: {
  129. click: function (item) {
  130. if (item != null) {
  131. $("#price").text("¥" + item.price);
  132. popupContainer.style.display = "block";
  133. popup.setPosition(item.geometry.coordinates[0][0]);
  134. } else {
  135. popup.setPosition();
  136. };
  137. }
  138. }
  139. };
  140. var options = {
  141. map: map, dataSet: dataSet, mapvOptions: mapvOptions
  142. };
  143. map.addLayer(new ol.layer.Image({
  144. source: new ol.source.Mapv(options)
  145. }));
  146. });
  147. </script>
  148. </body>
  149. </html>