markerCluster_3857.html 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. <title data-i18n="resources.title_markerCluster"></title>
  9. <meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
  10. <script type="text/javascript" include="jquery,papaparse" src="../js/include-web.js"></script>
  11. <style>
  12. body {
  13. margin: 0;
  14. padding: 0;
  15. }
  16. #map {
  17. position: absolute;
  18. top: 0;
  19. bottom: 0;
  20. width: 100%;
  21. }
  22. .mapboxgl-marker {
  23. width: 10px;
  24. height: 10px;
  25. background: red;
  26. margin-top: -5px;
  27. margin-left: -5px;
  28. border-radius: 5px;
  29. cursor: pointer;
  30. }
  31. </style>
  32. </head>
  33. <body>
  34. <div id='map'></div>
  35. <script type="text/javascript" include='mapbox-gl-enhance' src="../../dist/mapboxgl/include-mapboxgl.js"></script>
  36. <script type="text/javascript">
  37. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  38. $.get("../data/chinaEarthquake.csv", function (response) {
  39. var dataObj = Papa.parse(response, {
  40. skipEmptyLines: true,
  41. header: true
  42. });
  43. var data = dataObj.data;
  44. var geojson = {
  45. "type": "FeatureCollection",
  46. "features": []
  47. };
  48. for (var i = 0; i < data.length; i++) {
  49. var item = data[i];
  50. var date = new Date(item.date);
  51. var year = date.getFullYear();
  52. //2w+地震数据
  53. if (year > 2000 && year < 2015) {
  54. var feature = {
  55. "type": "feature",
  56. "geometry": {
  57. "type": "Point",
  58. "coordinates": []
  59. },
  60. "properties": {
  61. "value": parseFloat(item.level)
  62. }
  63. };
  64. feature.geometry.coordinates = [parseFloat(item.X), parseFloat(item.Y)];
  65. geojson.features.push(feature);
  66. }
  67. }
  68. map = new mapboxgl.Map({
  69. container: 'map',
  70. style: {
  71. "version": 8,
  72. "glyphs": host + "/iserver/services/map-china400/rest/maps/China/tileFeature/sdffonts/{fontstack}/{range}.pbf",
  73. "sources": {
  74. "raster-tiles": {
  75. "type": "raster",
  76. "tiles": [host + '/iserver/services/map-china400/rest/maps/China/zxyTileImage.png?z={z}&x={x}&y={y}'],
  77. "tileSize": 256
  78. }
  79. },
  80. "layers": [{
  81. "id": "simple-tiles",
  82. "type": "raster",
  83. "source": "raster-tiles",
  84. "minzoom": 0,
  85. "maxzoom": 22
  86. }]
  87. },
  88. center: [112, 37.94],
  89. zoom: 3
  90. });
  91. map.on('load', function () {
  92. map.addSource("earthquakes", {
  93. type: "geojson",
  94. data: geojson,
  95. cluster: true,
  96. clusterMaxZoom: 14,
  97. clusterRadius: 100
  98. });
  99. map.addLayer({
  100. id: "clusters",
  101. type: "circle",
  102. source: "earthquakes",
  103. filter: ["has", "point_count"],
  104. paint: {
  105. "circle-color": [
  106. "step",
  107. ["get", "point_count"],
  108. "#51bbd6",
  109. 100,
  110. "#f1f075",
  111. 750,
  112. "#f28cb1"
  113. ],
  114. "circle-radius": [
  115. "step",
  116. ["get", "point_count"],
  117. 20,
  118. 100,
  119. 30,
  120. 750,
  121. 40
  122. ]
  123. }
  124. });
  125. map.addLayer({
  126. id: "cluster-count",
  127. type: "symbol",
  128. source: "earthquakes",
  129. filter: ["has", "point_count"],
  130. layout: {
  131. "text-field": "{point_count_abbreviated}",
  132. "text-font": ["DIN Offc Pro Medium", "Arial Unicode MS Bold"],
  133. "text-size": 12
  134. }
  135. });
  136. map.addLayer({
  137. id: "unclustered-point",
  138. type: "circle",
  139. source: "earthquakes",
  140. filter: ["!", ["has", "point_count"]],
  141. paint: {
  142. "circle-color": "#11b4da",
  143. "circle-radius": 4,
  144. "circle-stroke-width": 1,
  145. "circle-stroke-color": "#fff"
  146. }
  147. });
  148. map.on('click', 'clusters', function (e) {
  149. var features = map.queryRenderedFeatures(e.point, {
  150. layers: ['clusters']
  151. });
  152. var clusterId = features[0].properties.cluster_id;
  153. map.getSource('earthquakes').getClusterExpansionZoom(clusterId, function (
  154. err, zoom) {
  155. if (err)
  156. return;
  157. map.easeTo({
  158. center: features[0].geometry.coordinates,
  159. zoom: zoom
  160. });
  161. });
  162. });
  163. map.on('mouseenter', 'clusters', function () {
  164. map.getCanvas().style.cursor = 'pointer';
  165. });
  166. map.on('mouseleave', 'clusters', function () {
  167. map.getCanvas().style.cursor = '';
  168. });
  169. });
  170. })
  171. </script>
  172. </body>
  173. </html>