04_routeLocatorService_line.html 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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_routeLocatorLine"></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, queryBySQLParams, queryBySQLService, resultLayer,
  16. routeLocatorParameters_line, routeLocatorService,
  17. baseUrl = (window.isLocal ? window.server : "https://iserver.supermap.io")+"/iserver/services/map-changchun/rest/maps/长春市区图",
  18. serviceUrl = (window.isLocal ? window.server : "https://iserver.supermap.io")+"/iserver/services/spatialanalyst-changchun/restjsr/spatialanalyst";
  19. var extent = [48.4, -7668.25, 8958.85, -55.58];
  20. var projection = new ol.proj.Projection({
  21. code:'',
  22. extent: extent,
  23. units: 'm'
  24. });
  25. var mapService = new ol.supermap.MapService(baseUrl);
  26. mapService.getMapInfo(function (serviceResult) {
  27. var mapJSONObj = serviceResult.result;
  28. map = new ol.Map({
  29. target: 'map',
  30. controls: ol.control.defaults({attributionOptions: {collapsed: false}})
  31. .extend([new ol.supermap.control.Logo()]),
  32. view: new ol.View({
  33. center: [4503.62, -3861.91],
  34. zoom: 2,
  35. projection: projection,
  36. multiWorld: true
  37. })
  38. });
  39. options = ol.source.TileSuperMapRest.optionsFromMapJSON(baseUrl, mapJSONObj);
  40. var layer = new ol.layer.Tile({
  41. source: new ol.source.TileSuperMapRest(options)
  42. });
  43. map.addLayer(layer);
  44. routeLocatorProcess_line();
  45. });
  46. function routeLocatorProcess_line() {
  47. //通过SQL查询的方法建立路由,并添加到地图上
  48. queryBySQLService = new ol.supermap.QueryService(baseUrl);
  49. queryBySQLParams = new SuperMap.QueryBySQLParameters({
  50. queryParams: [
  51. new SuperMap.FilterParameter({
  52. name: "RouteDT_road@Changchun",
  53. attributeFilter: "RouteID=1690"
  54. })
  55. ]
  56. });
  57. queryBySQLService.queryBySQL(queryBySQLParams, function (SQLQueryServiceResult) {
  58. var queryBySQLResult = SQLQueryServiceResult.result.recordsets[0].features;
  59. var pathSource = new ol.source.Vector({
  60. features: (new ol.format.GeoJSON()).readFeatures(queryBySQLResult)
  61. });
  62. pathLayer = new ol.layer.Vector({
  63. source: pathSource,
  64. style: new ol.style.Style({
  65. stroke: new ol.style.Stroke({
  66. color: 'rgba(100, 100, 225, 10)',
  67. width: 3
  68. })
  69. })
  70. });
  71. map.addLayer(pathLayer);
  72. //将形成路由的点提出来,为了构造下面点定里程服务sourceRoute
  73. var pointsList = [];
  74. var routeObj = queryBySQLResult.features[0].geometry.coordinates[0];
  75. for (var i = 0; i < routeObj.length; i++) {
  76. pointsList.push([routeObj[i][0], routeObj[i][1], routeObj[i][2]])
  77. }
  78. var routeLine = new ol.geom.LineString([pointsList]);
  79. //里程定线服务
  80. routeLocatorService = new ol.supermap.SpatialAnalystService(serviceUrl);
  81. routeLocatorParameters_line = new SuperMap.RouteLocatorParameters({
  82. "sourceRoute": routeLine,
  83. "type": "LINE",
  84. "startMeasure": 200,
  85. "endMeasure": 1000,
  86. "isIgnoreGap": true
  87. });
  88. routeLocatorService.routeLocate(routeLocatorParameters_line, function (routeLocateServiceResult) {
  89. var vectorSource = new ol.source.Vector({
  90. features: [(new ol.format.GeoJSON()).readFeature(routeLocateServiceResult.result.resultGeometry)],
  91. wrapX: false
  92. });
  93. resultLayer = new ol.layer.Vector({
  94. source: vectorSource,
  95. style: new ol.style.Style({
  96. stroke: new ol.style.Stroke({
  97. color: 'red',
  98. width: 3
  99. }),
  100. fill: new ol.style.Fill({
  101. color: 'rgba(0, 0, 255, 0.1)'
  102. })
  103. })
  104. });
  105. map.addLayer(resultLayer);
  106. });
  107. });
  108. }
  109. </script>
  110. </body>
  111. </html>