analysis_findLocation.html 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. <style type="text/css">
  10. body {
  11. margin: 0;
  12. overflow: hidden;
  13. background: #fff;
  14. width: 100%;
  15. height: 100%
  16. }
  17. #map {
  18. position: absolute;
  19. width: 100%;
  20. height: 100%;
  21. }
  22. #toolbar {
  23. position: absolute;
  24. top: 50px;
  25. right: 10px;
  26. text-align: center;
  27. z-index: 100;
  28. border-radius: 4px;
  29. }
  30. </style>
  31. </head>
  32. <body>
  33. <div id="toolbar" class="panel panel-primary">
  34. <div class='panel-heading'>
  35. <h5 class='panel-title text-center' data-i18n="resources.text_findLocation"></h5></div>
  36. <div class='panel-body content'>
  37. <input type="button" class="btn btn-default" data-i18n="[value]resources.text_analyst"
  38. onclick="findLocaltion()"/>&nbsp;
  39. <input type="button" class="btn btn-default" data-i18n="[value]resources.text_input_value_clear"
  40. onclick="clearElements()"/>
  41. </div>
  42. </div>
  43. <div id="map"></div>
  44. <script type="text/javascript" include="bootstrap" src="../js/include-web.js"></script>
  45. <script type="text/javascript" exclude="iclient-classic" src="../../dist/classic/include-classic.js"></script>
  46. <script>
  47. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  48. var local, map, layer, vectorLayer, markerLayer1,
  49. markerLayer2,
  50. style = {
  51. strokeColor: "#304DBE",
  52. strokeWidth: 2,
  53. pointRadius: 2,
  54. pointerEvents: "visiblePainted",
  55. fill: true,
  56. fillColor: "#304DBE"
  57. },
  58. url1 = host + "/iserver/services/map-changchun/rest/maps/长春市区图",
  59. url2 = host + "/iserver/services/transportationanalyst-sample/rest/networkanalyst/RoadNet@Changchun";
  60. init();
  61. function init() {
  62. map = new SuperMap.Map("map", {
  63. controls: [
  64. new SuperMap.Control.ScaleLine(),
  65. new SuperMap.Control.Zoom(),
  66. new SuperMap.Control.Navigation({
  67. dragPanOptions: {
  68. enableKinetic: true
  69. }
  70. })], units: "m"
  71. });
  72. map.addControl(new SuperMap.Control.LayerSwitcher(), new SuperMap.Pixel(42, 80));
  73. layer = new SuperMap.Layer.TiledDynamicRESTLayer("Changchun", url1, {
  74. transparent: true,
  75. cacheEnabled: true
  76. }, {maxResolution: "auto"});
  77. layer.events.on({"layerInitialized": addLayer});
  78. vectorLayer = new SuperMap.Layer.Vector("Vector Layer");
  79. markerLayer1 = new SuperMap.Layer.Markers("Markers");
  80. markerLayer2 = new SuperMap.Layer.Markers("Markers");
  81. var size = new SuperMap.Size(44, 40),
  82. offset = new SuperMap.Pixel(-(size.w / 2), -size.h);
  83. markerLayer1.addMarker(new SuperMap.Marker(new SuperMap.LonLat(1675.9256791377206, -593.56822512495194), new SuperMap.Icon("./images/marker-gold.png", size, offset)));
  84. markerLayer1.addMarker(new SuperMap.Marker(new SuperMap.LonLat(2820.35101097629, -2358.0414663985171), new SuperMap.Icon("./images/marker-gold.png", size, offset)));
  85. markerLayer1.addMarker(new SuperMap.Marker(new SuperMap.LonLat(2909.4396668115278, -3647.0074300836109), new SuperMap.Icon("./images/marker-gold.png", size, offset)));
  86. markerLayer1.addMarker(new SuperMap.Marker(new SuperMap.LonLat(1544.5037476378677, -5616.5950974905827), new SuperMap.Icon("./images/marker-gold.png", size, offset)));
  87. markerLayer1.addMarker(new SuperMap.Marker(new SuperMap.LonLat(6623.5972101719526, -2130.4887600981415), new SuperMap.Icon("./images/marker-gold.png", size, offset)));
  88. markerLayer1.addMarker(new SuperMap.Marker(new SuperMap.LonLat(5482.4979617984973, -4504.2328567816048), new SuperMap.Icon("./images/marker-gold.png", size, offset)));
  89. markerLayer1.addMarker(new SuperMap.Marker(new SuperMap.LonLat(6940.6579024271468, -1627.6012900626256), new SuperMap.Icon("./images/marker-gold.png", size, offset)));
  90. markerLayer1.addMarker(new SuperMap.Marker(new SuperMap.LonLat(8215.9188781715948, -5747.5063918659716), new SuperMap.Icon("./images/marker-gold.png", size, offset)));
  91. }
  92. function addLayer() {
  93. map.addLayers([layer, vectorLayer, markerLayer1, markerLayer2]);
  94. map.setCenter(new SuperMap.LonLat(4503.6240321526, -3861.911472192499), 0);
  95. }
  96. function findLocaltion() {
  97. vectorLayer.removeAllFeatures();
  98. markerLayer2.clearMarkers();
  99. var findLocaltionService, parameter, analystParameter, resultSetting,
  100. supplyCenterType_FIXEDCENTER = SuperMap.REST.SupplyCenterType.FIXEDCENTER,
  101. supplyCenterType_NULL = SuperMap.REST.SupplyCenterType.NULL;
  102. supplyCenterType_OPTIONALCENTER = SuperMap.REST.SupplyCenterType.OPTIONALCENTER,
  103. supplyCenters = [new SuperMap.REST.SupplyCenter({
  104. maxWeight: 500,
  105. nodeID: 139,
  106. resourceValue: 100,
  107. type: supplyCenterType_OPTIONALCENTER
  108. }),
  109. new SuperMap.REST.SupplyCenter({
  110. maxWeight: 500,
  111. nodeID: 1358,
  112. resourceValue: 100,
  113. type: supplyCenterType_OPTIONALCENTER
  114. }),
  115. new SuperMap.REST.SupplyCenter({
  116. maxWeight: 500,
  117. nodeID: 2972,
  118. resourceValue: 100,
  119. type: supplyCenterType_OPTIONALCENTER
  120. }),
  121. new SuperMap.REST.SupplyCenter({
  122. maxWeight: 500,
  123. nodeID: 5523,
  124. resourceValue: 100,
  125. type: supplyCenterType_OPTIONALCENTER
  126. }),
  127. new SuperMap.REST.SupplyCenter({
  128. maxWeight: 500,
  129. nodeID: 1161,
  130. resourceValue: 100,
  131. type: supplyCenterType_OPTIONALCENTER
  132. }),
  133. new SuperMap.REST.SupplyCenter({
  134. maxWeight: 500,
  135. nodeID: 4337,
  136. resourceValue: 100,
  137. type: supplyCenterType_OPTIONALCENTER
  138. }),
  139. new SuperMap.REST.SupplyCenter({
  140. maxWeight: 500,
  141. nodeID: 5732,
  142. resourceValue: 100,
  143. type: supplyCenterType_NULL
  144. }),
  145. new SuperMap.REST.SupplyCenter({
  146. maxWeight: 500,
  147. nodeID: 663,
  148. resourceValue: 100,
  149. type: supplyCenterType_FIXEDCENTER
  150. })
  151. ];
  152. parameter = new SuperMap.REST.FindLocationParameters({
  153. expectedSupplyCenterCount: 3,
  154. isFromCenter: false,
  155. nodeDemandField: "Demand",
  156. turnWeightField: "TurnCost",
  157. weightName: "length",
  158. supplyCenters: supplyCenters
  159. });
  160. findLocaltionService = new SuperMap.REST.FindLocationService(url2, {
  161. eventListeners: {"processCompleted": processCompleted}
  162. });
  163. findLocaltionService.processAsync(parameter);
  164. }
  165. function processCompleted(findLocationEventArgs) {
  166. var result = findLocationEventArgs.result,
  167. features = [];
  168. if (result.demandResults) {
  169. for (var i = 0, demandResults = result.demandResults, len = demandResults.length; i < len; i++) {
  170. var feature = new SuperMap.Feature.Vector();
  171. feature.geometry = demandResults[i].geometry;
  172. feature.style = style;
  173. features.push(feature);
  174. }
  175. }
  176. vectorLayer.addFeatures(features);
  177. }
  178. function clearElements() {
  179. vectorLayer.removeAllFeatures();
  180. markerLayer2.clearMarkers();
  181. }
  182. </script>
  183. </body>
  184. </html>