mapvLinanJiaData.html 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <!--********************************************************************
  2. * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
  3. *********************************************************************-->
  4. <!DOCTYPE html>
  5. <html lang="en-US">
  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. <title data-i18n="resources.title_lianjia"></title>
  11. <script type="text/javascript" include="mapv,proj4" src="../../dist/mapboxgl/include-mapboxgl.js"></script>
  12. <style>
  13. body {
  14. margin: 0;
  15. padding: 0;
  16. background: #fff;
  17. width: 100%;
  18. height: 100%;
  19. position: absolute;
  20. }
  21. #titleContainer {
  22. width: 100%;
  23. position: absolute;
  24. top: 15px;
  25. color: white;
  26. z-index: 999;
  27. font-size: 20px;
  28. font-weight: bold;
  29. text-align: center;
  30. }
  31. #titleContainer > #title {
  32. letter-spacing: 0.1em;
  33. }
  34. #map {
  35. position: absolute;
  36. top: 0;
  37. bottom: 0;
  38. width: 100%;
  39. }
  40. </style>
  41. </head>
  42. <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%">
  43. <div id="titleContainer">
  44. <h2 id="title" data-i18n="resources.title_lianjia"></h2>
  45. </div>
  46. <div id="map"></div>
  47. <script type="text/javascript" include="jquery" src="../js/include-web.js"></script>
  48. <script type="text/javascript">
  49. var attribution = "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox </a>" +
  50. " with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
  51. " Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a> | </span>" +
  52. "<a href='https://mapv.baidu.com' target='_blank'>© 2018 百度 MapV</a>";
  53. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  54. var tileURL = host + "/iserver/services/map-china400/rest/maps/ChinaDark/zxyTileImage.png?z={z}&x={x}&y={y}";
  55. var dataUrl = "https://www.supermapol.com/iserver/services/map_201802beijingfangjia/rest/maps/2018年2月北京房价_链家小区参考价_蜂巢";
  56. var map = new mapboxgl.Map({
  57. container: 'map',
  58. style: {
  59. "version": 8,
  60. "sources": {
  61. "raster-tiles": {
  62. "attribution": attribution,
  63. "type": "raster",
  64. "tiles": [tileURL],
  65. "tileSize": 256,
  66. },
  67. },
  68. "layers": [{
  69. "id": "simple-tiles",
  70. "type": "raster",
  71. "source": "raster-tiles",
  72. "minzoom": 0,
  73. "maxzoom": 22
  74. }]
  75. },
  76. center: [116.36, 39.954],
  77. zoom: 11
  78. });
  79. map.addControl(new mapboxgl.NavigationControl(), 'top-left');
  80. map.addControl(new mapboxgl.supermap.LogoControl(), 'bottom-right');
  81. query();
  82. function query() {
  83. var param = new SuperMap.QueryBySQLParameters({
  84. queryParams: {
  85. name: "lj_xq_500fc@BJ_201802LJ",
  86. attributeFilter: "SMID > 0"
  87. },
  88. fromIndex: 0,
  89. toIndex: 10000,
  90. maxFeatures: 10000,
  91. });
  92. new mapboxgl.supermap.QueryService(dataUrl).queryBySQL(param, function (serviceResult) {
  93. var features = serviceResult.result.recordsets[0].features.features;
  94. //构造mapv数据
  95. var data = [];
  96. for (var i = 0; i < features.length; i++) {
  97. var feature = features[i];
  98. var average_price = feature.properties.average_price_1;
  99. var coordinates = feature.geometry.coordinates[0];
  100. for (var k = 0; k < coordinates.length; k++) {
  101. for (var j = 0; j < coordinates[k].length; j++) {
  102. coordinates[k][j] = proj4('EPSG:3857', 'EPSG:4326', coordinates[k][j]);
  103. }
  104. }
  105. data.push({
  106. geometry: {
  107. type: 'Polygon',
  108. coordinates: coordinates
  109. },
  110. count: Math.floor(average_price / 10000),
  111. price: parseFloat(average_price).toFixed(2),
  112. });
  113. }
  114. var dataSet = new mapv.DataSet(data.concat());
  115. var mapvOptions = {
  116. max: 27,
  117. globalAlpha: 0.7,
  118. gradient: { // 显示的颜色渐变范围
  119. '0': '#5d5dff',
  120. '0.2': '#74add1',
  121. '0.4': '#ffffbf',
  122. '0.6': '#d73027',
  123. '0.8': '#FF0000'
  124. },
  125. draw: 'intensity',
  126. methods: {
  127. click: function (item) {
  128. if (item != null) {
  129. map.getCanvas().style.cursor = 'pointer';
  130. popup.setLngLat(new mapboxgl.LngLat(item.geometry.coordinates[0][0][0], item.geometry.coordinates[0][0][1])).setHTML("¥" + item.price).addTo(map);
  131. popup.setPosition;
  132. } else {
  133. popup.remove();
  134. }
  135. }
  136. }
  137. };
  138. var popup = new mapboxgl.Popup({closeOnClick: false});
  139. //mapboxgl.supermap.MapvLayer 构造函数的第一个 map 参数将在下个版本遗弃
  140. var mapVLayer = new mapboxgl.supermap.MapvLayer("", dataSet, mapvOptions);
  141. map.addLayer(mapVLayer);
  142. });
  143. }
  144. </script>
  145. </body>
  146. </html>