05_findLocationService.html 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. <script type="text/javascript" src="../../dist/ol/include-ol.js"></script>
  11. </head>
  12. <body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%; position: absolute;top: 0;">
  13. <div id="map" style="width: 100%;height:100%"></div>
  14. <script type="text/javascript">
  15. var map, options,
  16. baseUrl = (window.isLocal ? window.server : "https://iserver.supermap.io")+"/iserver/services/map-changchun/rest/maps/长春市区图",
  17. serviceUrl = (window.isLocal ? window.server : "https://iserver.supermap.io")+"/iserver/services/transportationanalyst-sample/rest/networkanalyst/RoadNet@Changchun";
  18. var extent = [48.4, -7668.25, 8958.85, -55.58];
  19. var projection = new ol.proj.Projection({
  20. code:'',
  21. extent: extent,
  22. units: 'm'
  23. });
  24. new ol.supermap.MapService(baseUrl).getMapInfo(function (serviceResult) {
  25. var mapJSONObj = serviceResult.result;
  26. map = new ol.Map({
  27. target: 'map',
  28. controls: ol.control.defaults({attributionOptions: {collapsed: false}})
  29. .extend([new ol.supermap.control.Logo()]),
  30. view: new ol.View({
  31. center: [4800, -3700],
  32. zoom: 2,
  33. projection: projection,
  34. multiWorld: true
  35. }),
  36. });
  37. options = ol.source.TileSuperMapRest.optionsFromMapJSON(baseUrl, mapJSONObj);
  38. var layer = new ol.layer.Tile({
  39. source: new ol.source.TileSuperMapRest(options)
  40. });
  41. map.addLayer(layer);
  42. findLocationProcess();
  43. });
  44. function findLocationProcess() {
  45. //添加设施点
  46. var facilityPoint1 = new ol.geom.Point([1675.9256791377206, -593.56822512495194]);
  47. var facilityPoint2 = new ol.geom.Point([2820.35101097629, -2358.0414663985171]);
  48. var facilityPoint3 = new ol.geom.Point([2909.4396668115278, -3647.0074300836109]);
  49. var facilityPoint4 = new ol.geom.Point([1544.5037476378677, -5616.5950974905827]);
  50. var facilityPoint5 = new ol.geom.Point([6623.5972101719526, -2130.4887600981415]);
  51. var facilityPoint6 = new ol.geom.Point([5482.4979617984973, -4504.2328567816048]);
  52. var facilityPoint7 = new ol.geom.Point([6940.6579024271468, -1627.6012900626256]);
  53. var facilityPoint8 = new ol.geom.Point([8215.9188781715948, -5747.5063918659716]);
  54. var facilityFeature1 = new ol.Feature(facilityPoint1);
  55. var facilityFeature2 = new ol.Feature(facilityPoint2);
  56. var facilityFeature3 = new ol.Feature(facilityPoint3);
  57. var facilityFeature4 = new ol.Feature(facilityPoint4);
  58. var facilityFeature5 = new ol.Feature(facilityPoint5);
  59. var facilityFeature6 = new ol.Feature(facilityPoint6);
  60. var facilityFeature7 = new ol.Feature(facilityPoint7);
  61. var facilityFeature8 = new ol.Feature(facilityPoint8);
  62. var iconStyle_facility = new ol.style.Style({
  63. image: new ol.style.Icon(({
  64. src: '../img/marker.png',
  65. anchor: [0.5, 1]
  66. }))
  67. });
  68. facilityFeature1.setStyle(iconStyle_facility);
  69. facilityFeature2.setStyle(iconStyle_facility);
  70. facilityFeature3.setStyle(iconStyle_facility);
  71. facilityFeature4.setStyle(iconStyle_facility);
  72. facilityFeature5.setStyle(iconStyle_facility);
  73. facilityFeature6.setStyle(iconStyle_facility);
  74. facilityFeature7.setStyle(iconStyle_facility);
  75. facilityFeature8.setStyle(iconStyle_facility);
  76. var facilitySource = new ol.source.Vector({
  77. features: [
  78. facilityFeature1, facilityFeature2,
  79. facilityFeature3, facilityFeature4,
  80. facilityFeature5, facilityFeature6,
  81. facilityFeature7, facilityFeature8
  82. ]
  83. });
  84. var facilityLayer = new ol.layer.Vector({
  85. source: facilitySource
  86. });
  87. // 设置设施点的资源供给中心
  88. var supplyCenterType_FIXEDCENTER = SuperMap.SupplyCenterType.FIXEDCENTER,
  89. supplyCenterType_NULL = SuperMap.SupplyCenterType.NULL;
  90. var supplyCenterType_OPTIONALCENTER = SuperMap.SupplyCenterType.OPTIONALCENTER,
  91. supplyCenters = [new SuperMap.SupplyCenter({
  92. maxWeight: 500, // 资源供给中心的最大耗费值,必设参数
  93. nodeID: 139, // 资源供给中心点的结点 ID 号,必设参数
  94. resourceValue: 100, // 资源供给中心能提供的最大服务量或商品数量,必设参数
  95. type: supplyCenterType_OPTIONALCENTER //选址分区中资源中心的类型包括固定中心和可选中心两种
  96. }),
  97. new SuperMap.SupplyCenter({
  98. maxWeight: 500,
  99. nodeID: 1358,
  100. resourceValue: 100,
  101. type: supplyCenterType_OPTIONALCENTER
  102. }),
  103. new SuperMap.SupplyCenter({
  104. maxWeight: 500,
  105. nodeID: 2972,
  106. resourceValue: 100,
  107. type: supplyCenterType_OPTIONALCENTER
  108. }),
  109. new SuperMap.SupplyCenter({
  110. maxWeight: 500,
  111. nodeID: 5523,
  112. resourceValue: 100,
  113. type: supplyCenterType_OPTIONALCENTER
  114. }),
  115. new SuperMap.SupplyCenter({
  116. maxWeight: 500,
  117. nodeID: 1161,
  118. resourceValue: 100,
  119. type: supplyCenterType_OPTIONALCENTER
  120. }),
  121. new SuperMap.SupplyCenter({
  122. maxWeight: 500,
  123. nodeID: 4337,
  124. resourceValue: 100,
  125. type: supplyCenterType_OPTIONALCENTER
  126. }),
  127. new SuperMap.SupplyCenter({
  128. maxWeight: 500,
  129. nodeID: 5732,
  130. resourceValue: 100,
  131. type: supplyCenterType_NULL
  132. }),
  133. new SuperMap.SupplyCenter({
  134. maxWeight: 500,
  135. nodeID: 663,
  136. resourceValue: 100,
  137. type: supplyCenterType_FIXEDCENTER
  138. })
  139. ];
  140. //创建选址分区分析参数实例
  141. var findLocationParameter = new SuperMap.FindLocationParameters({
  142. // 期望用于最终设施选址的资源供给中心数量,必设字段
  143. expectedSupplyCenterCount: 8,
  144. // 是否从中心点开始分配资源。默认为 false
  145. isFromCenter: false,
  146. nodeDemandField: "Demand",
  147. // 转向权值字段的名称
  148. turnWeightField: "TurnCost",
  149. // 阻力字段的名称, 必设
  150. weightName: "length",
  151. // 资源供给中心集合,必设字段
  152. supplyCenters: supplyCenters
  153. });
  154. //进行查找
  155. new ol.supermap.NetworkAnalystService(serviceUrl).findLocation(findLocationParameter, function (serviceResult) {
  156. var vectorSource = new ol.source.Vector({
  157. features: (new ol.format.GeoJSON()).readFeatures(serviceResult.result.demandResults)
  158. });
  159. var polygonLayer = new ol.layer.Vector({
  160. source: vectorSource,
  161. style: new ol.style.Style({
  162. image: new ol.style.Circle({
  163. radius: 2.5,
  164. fill: new ol.style.Fill({
  165. color: 'dodgerblue'
  166. })
  167. })
  168. })
  169. });
  170. map.addLayer(polygonLayer);
  171. map.addLayer(facilityLayer);
  172. });
  173. }
  174. </script>
  175. </body>
  176. </html>