04_routeLocatorService_point.html 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <!--********************************************************************
  2. * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
  3. *********************************************************************-->
  4. <!DOCTYPE html>
  5. <html lang="en">
  6. <head>
  7. <meta charset="UTF-8">
  8. <title data-i18n="resources.title_routeLocatorPoint"></title>
  9. <script type="text/javascript" src="../js/include-web.js"></script>
  10. <script type="text/javascript" src="../../dist/mapboxgl/include-mapboxgl.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="margin:0 auto;width: 100%;height: 100%"></div>
  14. <script type="text/javascript">
  15. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  16. var map,
  17. routeLocatorParameters_point, routeLocatorService,
  18. attribution = "<a href='https://www.mapbox.com/about/maps/' target='_blank'>© Mapbox </a>" +
  19. " with <span>© <a href='https://iclient.supermap.io' target='_blank'>SuperMap iClient</a> | </span>" +
  20. " Map Data <span>© <a href='http://support.supermap.com.cn/product/iServer.aspx' target='_blank'>SuperMap iServer</a></span> ",
  21. mapUrl = host + "/iserver/services/map-jingjin/rest/maps/京津地区地图/zxyTileImage.png?z={z}&x={x}&y={y}",
  22. serviceUrl = host + "/iserver/services/spatialanalyst-sample/restjsr/spatialanalyst";
  23. map = new mapboxgl.Map({
  24. container: 'map',
  25. style: {
  26. "version": 8,
  27. "sources": {
  28. "raster-tiles": {
  29. "attribution": attribution,
  30. "type": "raster",
  31. "tiles": [mapUrl],
  32. "tileSize": 256
  33. }
  34. },
  35. "layers": [{
  36. "id": "simple-tiles",
  37. "type": "raster",
  38. "source": "raster-tiles",
  39. }]
  40. },
  41. center: [116.2740019864, 39.8970124079],
  42. zoom: 12
  43. });
  44. map.addControl(new mapboxgl.NavigationControl(), 'top-left');
  45. map.addControl(new mapboxgl.supermap.LogoControl(), 'bottom-right');
  46. map.on("load", function () {
  47. routeCalculateMeasureProcess();
  48. });
  49. function routeCalculateMeasureProcess() {
  50. var piontLists = [
  51. [116.2143386597, 39.8959419733, 0],
  52. [116.217501999125, 39.896670999665, 282.3879789906],
  53. [116.220156000875, 39.896820999605, 511.787745072744],
  54. [116.228716999, 39.8968419995966, 1253.201708792909],
  55. [116.25000000025, 39.8968619995886, 3103.167523778722],
  56. [116.27412300025, 39.8967689996258, 5201.062444476062],
  57. [116.310443000875, 39.8971139994878, 8360.617856315024],
  58. [116.344168500812, 39.8976724992644, 11294.738396325054]
  59. ];
  60. var LineGeometryData = {
  61. "type": "Feature",
  62. "geometry": {
  63. "type": "LineString",
  64. "coordinates": piontLists
  65. }
  66. };
  67. map.addLayer({
  68. "id": "route",
  69. "type": "line",
  70. "source": {
  71. "type": "geojson",
  72. "data": LineGeometryData
  73. },
  74. "layout": {
  75. "line-join": "round",
  76. "line-cap": "round"
  77. },
  78. "paint": {
  79. "line-color": "#888",
  80. "line-width": 8
  81. }
  82. });
  83. //将形成路由的点提出来,为了构造下面点定里程服务sourceRoute
  84. var routeLine = LineGeometryData;
  85. //点定里程服务
  86. routeLocatorService = new mapboxgl.supermap.SpatialAnalystService(serviceUrl);
  87. routeLocatorParameters_point = new SuperMap.RouteLocatorParameters({
  88. "sourceRoute": routeLine,
  89. "type": "POINT",
  90. "measure": 6753,
  91. "offset": 0,
  92. "isIgnoreGap": true
  93. });
  94. routeLocatorService.routeLocate(routeLocatorParameters_point, function (routeLocateServiceResult) {
  95. var point = routeLocateServiceResult.result.resultGeometry.geometry.coordinates;
  96. map.addLayer({
  97. "id": "Point",
  98. "type": "circle",
  99. "source": {
  100. "type": "geojson",
  101. "data": {
  102. "type": "Feature",
  103. "geometry": {
  104. "type": "Point",
  105. "coordinates": point
  106. }
  107. }
  108. },
  109. "paint": {
  110. "circle-radius": 6,
  111. "circle-color": "red",
  112. },
  113. });
  114. var innerHTML = resources.msg_queryMileagePoint1 + routeLocatorParameters_point.measure + resources.msg_queryMileagePoint2;
  115. new mapboxgl.Popup().setLngLat(point).setHTML(innerHTML).addTo(map);
  116. });
  117. }
  118. </script>
  119. </body>
  120. </html>