05_findMTSPPathsService.html 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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_findMTSPPathsServiceLogistics"></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, findMTSPPathsService, resultSetting, analystParameter, findMTSPPathsParameter,
  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. .once("load", function () {
  31. findMTSPPathsProcess();
  32. });
  33. function findMTSPPathsProcess() {
  34. //添加配送点
  35. var marker1 = L.marker([-5500, 6000]).addTo(map);
  36. var marker2 = L.marker([-2500, 5500]).addTo(map);
  37. var marker3 = L.marker([-3500, 2500]).addTo(map);
  38. //为配送点添加弹窗
  39. marker1.bindPopup(resources.text_distributionCentre1);
  40. marker2.bindPopup(resources.text_distributionCentre2);
  41. marker3.bindPopup(resources.text_distributionCentre3);
  42. //添加配送目的地
  43. var myIcon = L.icon({
  44. iconUrl: '../img/marker.png',
  45. iconSize: [44, 30]
  46. });
  47. var marker4 = L.marker([-5000, 5000], {icon: myIcon}).addTo(map);
  48. var marker5 = L.marker([-2800, 8000], {icon: myIcon}).addTo(map);
  49. //为配送点添加弹窗
  50. marker4.bindPopup(resources.text_destination1);
  51. marker5.bindPopup(resources.text_destination2);
  52. //创建多旅行商分析服务实例
  53. findMTSPPathsService = L.supermap.networkAnalystService(serviceUrl);
  54. //创建多旅行商分析参数实例
  55. resultSetting = new SuperMap.TransportationAnalystResultSetting({
  56. returnEdgeFeatures: true,
  57. returnEdgeGeometry: true,
  58. returnEdgeIDs: true,
  59. returnNodeFeatures: true,
  60. returnNodeGeometry: true,
  61. returnNodeIDs: true,
  62. returnPathGuides: true,
  63. returnRoutes: true
  64. });
  65. analystParameter = new SuperMap.TransportationAnalystParameter({
  66. resultSetting: resultSetting,
  67. weightFieldName: "length"
  68. });
  69. findMTSPPathsParameter = new SuperMap.FindMTSPPathsParameters({
  70. centers: [L.latLng(-5500, 6000), L.latLng(-2500, 5500), L.latLng(-3500, 2500)],
  71. isAnalyzeById: false,
  72. nodes: [L.latLng(-5000, 5000), L.latLng(-2800, 8000)],
  73. hasLeastTotalCost: true,
  74. parameter: analystParameter
  75. });
  76. //进行查找
  77. findMTSPPathsService.findMTSPPaths(findMTSPPathsParameter, function (serviceResult) {
  78. var result = serviceResult.result;
  79. result.pathList.map(function (result) {
  80. L.geoJSON(result.route, {color: "green"}).addTo(map);
  81. });
  82. });
  83. }
  84. </script>
  85. </body>
  86. </html>