analysis_dynamicSegmentation.html 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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_dynamicSegmentation"></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_dynamicSegmentation"></h5></div>
  36. <div class='panel-body content'>
  37. <input type="button" class="btn btn-default" data-i18n="[value]resources.text_input_value_dynamicSegmentation" onclick="GenerateSpatialData()"/>&nbsp;
  38. <input type="button" class="btn btn-default" data-i18n="[value]resources.text_input_value_clear" onclick="clearThemeLayer()"/>
  39. </div>
  40. </div>
  41. <div id="map"></div>
  42. <script type="text/javascript" include="bootstrap,widgets.alert" src="../js/include-web.js"></script>
  43. <script type="text/javascript" exclude="iclient-classic" src="../../dist/classic/include-classic.js"></script>
  44. <script>
  45. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  46. var map, layer, themeLayer,
  47. url = host + "/iserver/services/map-changchun/rest/maps/长春市区图",
  48. url2 = host + "/iserver/services/spatialanalyst-changchun/restjsr/spatialanalyst";
  49. init();
  50. function init() {
  51. layer = new SuperMap.Layer.TiledDynamicRESTLayer("changchun", url, {
  52. transparent: true,
  53. cacheEnabled: true
  54. }, {maxResolution: "auto"});
  55. layer.events.on({"layerInitialized": addLayer});
  56. map = new SuperMap.Map("map", {
  57. allOverlays: true, controls: [
  58. new SuperMap.Control.ScaleLine(),
  59. new SuperMap.Control.Zoom(),
  60. new SuperMap.Control.Navigation({
  61. dragPanOptions: {
  62. enableKinetic: true
  63. }
  64. })]
  65. });
  66. map.addControl(new SuperMap.Control.LayerSwitcher(), new SuperMap.Pixel(42, 80));
  67. }
  68. function addLayer() {
  69. map.addLayers([layer]);
  70. map.setCenter(new SuperMap.LonLat(4503.6240321526, -3861.911472192499), 1);
  71. }
  72. //生成动态分段
  73. function GenerateSpatialData() {
  74. widgets.alert.clearAlert();
  75. clearThemeLayer();
  76. //配置数据返回Option
  77. var option = new SuperMap.REST.DataReturnOption({
  78. expectCount: 1000,
  79. dataset: "generateSpatialData@Changchun",
  80. deleteExistResultDataset: true,
  81. dataReturnMode: SuperMap.REST.DataReturnMode.DATASET_ONLY
  82. }),
  83. //配置动态分段Parameters
  84. parameters = new SuperMap.REST.GenerateSpatialDataParameters({
  85. routeTable: "RouteDT_road@Changchun",
  86. routeIDField: "RouteID",
  87. eventTable: "LinearEventTabDT@Changchun",
  88. eventRouteIDField: "RouteID",
  89. measureField: "",
  90. measureStartField: "LineMeasureFrom",
  91. measureEndField: "LineMeasureTo",
  92. measureOffsetField: "",
  93. errorInfoField: "",
  94. dataReturnOption: option
  95. }),
  96. //配置动态分段iService
  97. iService = new SuperMap.REST.GenerateSpatialDataService(url2, {
  98. eventListeners: {
  99. processCompleted: generateCompleted,
  100. processFailed: generateFailded
  101. }
  102. });
  103. //execute
  104. iService.processAsync(parameters);
  105. //completed
  106. function generateCompleted(generateSpatialDataEventArgs) {
  107. //配置专题样式
  108. var style1, style2, style3;
  109. style1 = new SuperMap.REST.ServerStyle({
  110. fillForeColor: new SuperMap.REST.ServerColor(242, 48, 48),
  111. lineColor: new SuperMap.REST.ServerColor(242, 48, 48),
  112. lineWidth: 1
  113. });
  114. style2 = new SuperMap.REST.ServerStyle({
  115. fillForeColor: new SuperMap.REST.ServerColor(255, 159, 25),
  116. lineColor: new SuperMap.REST.ServerColor(255, 159, 25),
  117. lineWidth: 1
  118. });
  119. style3 = new SuperMap.REST.ServerStyle({
  120. fillForeColor: new SuperMap.REST.ServerColor(91, 195, 69),
  121. lineColor: new SuperMap.REST.ServerColor(91, 195, 69),
  122. lineWidth: 1
  123. });
  124. //配置专题项
  125. var themeUniqueIteme1, themeUniqueIteme2, themeUniqueIteme3;
  126. themeUniqueIteme1 = new SuperMap.REST.ThemeUniqueItem({
  127. unique: "拥挤",
  128. style: style1
  129. });
  130. themeUniqueIteme2 = new SuperMap.REST.ThemeUniqueItem({
  131. unique: "缓行",
  132. style: style2
  133. });
  134. themeUniqueIteme3 = new SuperMap.REST.ThemeUniqueItem({
  135. unique: "畅通",
  136. style: style3
  137. });
  138. var themeUniqueItemes = [themeUniqueIteme1, themeUniqueIteme2, themeUniqueIteme3];
  139. var themeUnique = new SuperMap.REST.ThemeUnique({
  140. uniqueExpression: "TrafficStatus",
  141. items: themeUniqueItemes,
  142. defaultStyle: new SuperMap.REST.ServerStyle({
  143. fillForeColor: new SuperMap.REST.ServerColor(48, 89, 14),
  144. lineColor: new SuperMap.REST.ServerColor(48, 89, 14)
  145. })
  146. });
  147. var themeParameters = new SuperMap.REST.ThemeParameters({
  148. themes: [themeUnique],
  149. datasetNames: ["generateSpatialData"],
  150. dataSourceNames: ["Changchun"],
  151. types: ['REGION']
  152. });
  153. var themeService = new SuperMap.REST.ThemeService(url, {
  154. eventListeners: {
  155. processCompleted: themeCompleted,
  156. processFailed: themeFailed
  157. }
  158. });
  159. themeService.processAsync(themeParameters);
  160. function themeCompleted(themeEventArgs) {
  161. if (themeEventArgs.result.resourceInfo.id) {
  162. themeLayer = new SuperMap.Layer.TiledDynamicRESTLayer("道路交通状况_专题图", url, {
  163. cacheEnabled: false,
  164. transparent: true,
  165. layersID: themeEventArgs.result.resourceInfo.id
  166. }, {"maxResolution": "auto"});
  167. themeLayer.events.on({"layerInitialized": addThemeLayer});
  168. }
  169. }
  170. function addThemeLayer() {
  171. map.addLayer(themeLayer);
  172. }
  173. function themeFailed(e) {
  174. widgets.alert.showAlert(e.error.errorMsg,false);
  175. }
  176. }
  177. //failed
  178. function generateFailded(e) {
  179. widgets.alert.showAlert(e.error.errorMsg,false);
  180. }
  181. }
  182. //移除专题图层
  183. function clearThemeLayer() {
  184. widgets.alert.clearAlert();
  185. if (themeLayer) {
  186. map.removeLayer(themeLayer, true);
  187. themeLayer = null;
  188. }
  189. }
  190. </script>
  191. </body>
  192. </html>