05_findLocationService.html 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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_findLocation"></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, findLocationService, findLocationParameter,
  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. findLocationProcess();
  32. });
  33. function findLocationProcess() {
  34. //添加设施点
  35. L.marker([-593.56822512495194, 1675.9256791377206]).addTo(map);
  36. L.marker([-2358.0414663985171, 2820.35101097629]).addTo(map);
  37. L.marker([-3647.0074300836109, 2909.4396668115278]).addTo(map);
  38. L.marker([-5616.5950974905827, 1544.5037476378677]).addTo(map);
  39. L.marker([-2130.4887600981415, 6623.5972101719526]).addTo(map);
  40. L.marker([-4504.2328567816048, 5482.4979617984973]).addTo(map);
  41. L.marker([-1627.6012900626256, 6940.6579024271468]).addTo(map);
  42. L.marker([-5747.5063918659716, 8215.9188781715948]).addTo(map);
  43. // 设置设施点的资源供给中心
  44. var supplyCenterType_FIXEDCENTER = SuperMap.SupplyCenterType.FIXEDCENTER,
  45. supplyCenterType_NULL = SuperMap.SupplyCenterType.NULL;
  46. var supplyCenterType_OPTIONALCENTER = SuperMap.SupplyCenterType.OPTIONALCENTER,
  47. supplyCenters = [new SuperMap.SupplyCenter({
  48. maxWeight: 500, // 资源供给中心的最大耗费值,必设参数
  49. nodeID: 139, // 资源供给中心点的结点 ID 号,必设参数
  50. resourceValue: 100, // 资源供给中心能提供的最大服务量或商品数量,必设参数
  51. type: supplyCenterType_OPTIONALCENTER //选址分区中资源中心的类型包括固定中心和可选中心两种
  52. }),
  53. new SuperMap.SupplyCenter({
  54. maxWeight: 500,
  55. nodeID: 1358,
  56. resourceValue: 100,
  57. type: supplyCenterType_OPTIONALCENTER
  58. }),
  59. new SuperMap.SupplyCenter({
  60. maxWeight: 500,
  61. nodeID: 2972,
  62. resourceValue: 100,
  63. type: supplyCenterType_OPTIONALCENTER
  64. }),
  65. new SuperMap.SupplyCenter({
  66. maxWeight: 500,
  67. nodeID: 5523,
  68. resourceValue: 100,
  69. type: supplyCenterType_OPTIONALCENTER
  70. }),
  71. new SuperMap.SupplyCenter({
  72. maxWeight: 500,
  73. nodeID: 1161,
  74. resourceValue: 100,
  75. type: supplyCenterType_OPTIONALCENTER
  76. }),
  77. new SuperMap.SupplyCenter({
  78. maxWeight: 500,
  79. nodeID: 4337,
  80. resourceValue: 100,
  81. type: supplyCenterType_OPTIONALCENTER
  82. }),
  83. new SuperMap.SupplyCenter({
  84. maxWeight: 500,
  85. nodeID: 5732,
  86. resourceValue: 100,
  87. type: supplyCenterType_NULL
  88. }),
  89. new SuperMap.SupplyCenter({
  90. maxWeight: 500,
  91. nodeID: 663,
  92. resourceValue: 100,
  93. type: supplyCenterType_FIXEDCENTER
  94. })
  95. ];
  96. //创建选址分区分析服务实例
  97. findLocationService = L.supermap.networkAnalystService(serviceUrl);
  98. //创建选址分区分析参数实例
  99. findLocationParameter = new SuperMap.FindLocationParameters({
  100. // 期望用于最终设施选址的资源供给中心数量,必设字段
  101. expectedSupplyCenterCount: 8,
  102. // 是否从中心点开始分配资源。默认为 false
  103. isFromCenter: false,
  104. nodeDemandField: "Demand",
  105. // 转向权值字段的名称
  106. turnWeightField: "TurnCost",
  107. // 阻力字段的名称, 必设
  108. weightName: "length",
  109. // 资源供给中心集合,必设字段
  110. supplyCenters: supplyCenters
  111. });
  112. //进行查找
  113. findLocationService.findLocation(findLocationParameter, function (serviceResult) {
  114. L.geoJSON(serviceResult.result.demandResults, {
  115. pointToLayer: function (geoJsonPoint, latlng) {
  116. return L.circleMarker(latlng, {radius: 1, color: "green"});
  117. }
  118. }).addTo(map);
  119. });
  120. }
  121. </script>
  122. </body>
  123. </html>