12_markerCluster.html 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. <script type="text/javascript" src="../js/include-web.js"></script>
  10. </head>
  11. <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
  12. <div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
  13. <script type="text/javascript" include="leaflet.markercluster" src="../../dist/leaflet/include-leaflet.js"></script>
  14. <script type="text/javascript">
  15. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  16. var map, resultLayer, getFeatureBySQLParams,
  17. dataUrl = host + "/iserver/services/data-DynamicData/rest/data",
  18. url = host + "/iserver/services/map-china400/rest/maps/China";
  19. map = L.map('map', {
  20. preferCanvas: true,
  21. center: [32, 104],
  22. maxZoom: 18,
  23. zoom: 4
  24. });
  25. L.supermap.tiledMapLayer(url).addTo(map);
  26. resultLayer = L.markerClusterGroup({
  27. spiderfyOnMaxZoom: false,
  28. showCoverageOnHover: false,
  29. zoomToBoundsOnClick: false
  30. });
  31. getFeatureBySQLParams = new SuperMap.GetFeaturesBySQLParameters({
  32. queryParameter: new SuperMap.FilterParameter({
  33. name: "Train@DynamicData",
  34. attributeFilter: "SmID>100 and SmID < 800"
  35. }),
  36. toIndex: -1,
  37. datasetNames: ["DynamicData:Train"]
  38. });
  39. loadMarkerCluster();
  40. function loadMarkerCluster() {
  41. L.supermap
  42. .featureService(dataUrl)
  43. .getFeaturesBySQL(getFeatureBySQLParams, function (serviceResult) {
  44. createLayers(serviceResult.result.features);
  45. });
  46. }
  47. function createLayers(result) {
  48. if (!result || !result.features || result.features.length < 1) {
  49. return;
  50. }
  51. result.features.map(function (feature) {
  52. var latLng = L.CRS.EPSG3857.unproject(L.point(feature.geometry.coordinates));
  53. resultLayer.addLayer(L.marker(latLng));
  54. });
  55. resultLayer.addTo(map);
  56. }
  57. </script>
  58. </body>
  59. </html>