markerCluster_4326.html 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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_markerClusterWGS84"></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-world/rest/maps/World/tileFeature/sdffonts/{fontstack}/{range}.pbf",
  73. "sources": {
  74. "raster-tiles": {
  75. "type": "raster",
  76. "tiles": [host + '/iserver/services/map-world/rest/maps/World'],
  77. "rasterSource":"iserver",
  78. "tileSize": 256
  79. }
  80. },
  81. "layers": [{
  82. "id": "simple-tiles",
  83. "type": "raster",
  84. "source": "raster-tiles",
  85. "minzoom": 0,
  86. "maxzoom": 22
  87. }]
  88. },
  89. crs: 'EPSG:4326',
  90. center: [112, 37.94],
  91. zoom: 3
  92. });
  93. map.on('load', function () {
  94. map.addSource("earthquakes", {
  95. type: "geojson",
  96. data: geojson,
  97. cluster: true,
  98. clusterMaxZoom: 14,
  99. clusterRadius: 100
  100. });
  101. map.addLayer({
  102. id: "clusters",
  103. type: "circle",
  104. source: "earthquakes",
  105. filter: ["has", "point_count"],
  106. paint: {
  107. "circle-color": [
  108. "step",
  109. ["get", "point_count"],
  110. "#51bbd6",
  111. 100,
  112. "#f1f075",
  113. 750,
  114. "#f28cb1"
  115. ],
  116. "circle-radius": [
  117. "step",
  118. ["get", "point_count"],
  119. 20,
  120. 100,
  121. 30,
  122. 750,
  123. 40
  124. ]
  125. }
  126. });
  127. map.addLayer({
  128. id: "cluster-count",
  129. type: "symbol",
  130. source: "earthquakes",
  131. filter: ["has", "point_count"],
  132. layout: {
  133. "text-field": "{point_count_abbreviated}",
  134. "text-font": ["DIN Offc Pro Medium", "Arial Unicode MS Bold"],
  135. "text-size": 12
  136. }
  137. });
  138. map.addLayer({
  139. id: "unclustered-point",
  140. type: "circle",
  141. source: "earthquakes",
  142. filter: ["!", ["has", "point_count"]],
  143. paint: {
  144. "circle-color": "#11b4da",
  145. "circle-radius": 4,
  146. "circle-stroke-width": 1,
  147. "circle-stroke-color": "#fff"
  148. }
  149. });
  150. map.on('click', 'clusters', function (e) {
  151. var features = map.queryRenderedFeatures(e.point, {
  152. layers: ['clusters']
  153. });
  154. var clusterId = features[0].properties.cluster_id;
  155. map.getSource('earthquakes').getClusterExpansionZoom(clusterId, function (
  156. err, zoom) {
  157. if (err)
  158. return;
  159. map.easeTo({
  160. center: features[0].geometry.coordinates,
  161. zoom: zoom
  162. });
  163. });
  164. });
  165. map.on('mouseenter', 'clusters', function () {
  166. map.getCanvas().style.cursor = 'pointer';
  167. });
  168. map.on('mouseleave', 'clusters', function () {
  169. map.getCanvas().style.cursor = '';
  170. });
  171. });
  172. })
  173. </script>
  174. </body>
  175. </html>