05_findClosestFacilitiesService.html 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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_closestFacilitiesService"></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" 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, findClosetFacilitiesService, findClosetFacilitiesParameter, resultLayer,
  17. baseUrl = host + "/iserver/services/map-changchun/rest/maps/长春市区图",
  18. serviceUrl = host + "/iserver/services/transportationanalyst-sample/rest/networkanalyst/RoadNet@Changchun";
  19. map = L.map('map', {
  20. crs: L.CRS.NonEarthCRS({
  21. bounds: L.bounds([48.4, -7668.25], [8958.85, -55.58]),
  22. origin: L.point(48.4, -55.58)
  23. }),
  24. center: [-3600, 4700],
  25. maxZoom: 18,
  26. zoom: 2
  27. });
  28. L.supermap.tiledMapLayer(baseUrl, {noWrap: true})
  29. .addTo(map)
  30. .on('load', function () {
  31. findClosetFacilitiesProcess();
  32. });
  33. function findClosetFacilitiesProcess() {
  34. //添加设施点
  35. var marker1 = L.marker([-3500, 2500]).addTo(map);
  36. marker1.bindPopup(resources.text_facilityPoint1);
  37. var marker2 = L.marker([-2500, 5500]).addTo(map);
  38. marker2.bindPopup(resources.text_facilityPoint2);
  39. var marker3 = L.marker([-4000, 7000]).addTo(map);
  40. marker3.bindPopup(resources.text_facilityPoint3);
  41. //添加事件点
  42. var myIcon = L.icon({
  43. iconUrl: '../img/marker.png',
  44. iconSize: [44, 30]
  45. });
  46. var marker4 = L.marker([-3700, 5000], {icon: myIcon}).addTo(map);
  47. marker4.bindPopup(resources.text_input_value_eventPoint);
  48. //创建最近设施分析服务实例
  49. findClosetFacilitiesService = L.supermap.networkAnalystService(serviceUrl);
  50. //创建最近设施分析参数实例
  51. var resultSetting = new SuperMap.TransportationAnalystResultSetting({
  52. returnEdgeFeatures: true,
  53. returnEdgeGeometry: true,
  54. returnEdgeIDs: true,
  55. returnNodeFeatures: true,
  56. returnNodeGeometry: true,
  57. returnNodeIDs: true,
  58. returnPathGuides: true,
  59. returnRoutes: true
  60. });
  61. var analystParameter = new SuperMap.TransportationAnalystParameter({
  62. resultSetting: resultSetting,
  63. turnWeightField: "TurnCost",
  64. weightFieldName: "length" //length,time
  65. });
  66. findClosetFacilitiesParameter = new SuperMap.FindClosestFacilitiesParameters({
  67. //事件点,必设参数
  68. event: L.latLng(-3700, 5000),
  69. //要查找的设施点数量。默认值为1
  70. expectFacilityCount: 1,
  71. //设施点集合,必设
  72. facilities: [L.latLng(-3500, 2500), L.latLng(-2500, 5500), L.latLng(-4000, 7000)],
  73. isAnalyzeById: false,
  74. parameter: analystParameter
  75. });
  76. //进行查找
  77. findClosetFacilitiesService.findClosestFacilities(findClosetFacilitiesParameter, function (serviceResult) {
  78. var rersult = serviceResult.result;
  79. rersult.facilityPathList.map(function (result) {
  80. resultLayer = L.geoJSON(result.route).addTo(map);
  81. });
  82. });
  83. }
  84. </script>
  85. </body>
  86. </html>