Guest User

Untitled

a guest
Oct 23rd, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. // add your points
  2. var points = [
  3. {
  4. "type": "Feature",
  5. "geometry": {
  6. "type": "Point",
  7. "coordinates": [0, 0]
  8. },
  9. "properties": {}
  10. },
  11. {
  12. "type": "Feature",
  13. "geometry": {
  14. "type": "Point",
  15. "coordinates": [10, -10]
  16. },
  17. "properties": {}
  18. },
  19. {
  20. "type": "Feature",
  21. "geometry": {
  22. "type": "Point",
  23. "coordinates": [50, 50]
  24. },
  25. "properties": {}
  26. }
  27. ]
  28.  
  29. // add a variable for keeping track of points
  30. var y = 0;
  31.  
  32. // Start drawing the polyline.
  33. add();
  34.  
  35. function add() {
  36.  
  37. // add a point on the line for the new marker
  38. polyline.addLatLng(
  39. L.latLng(points[y].geometry.coordinates[1],
  40. points[y].geometry.coordinates[0])
  41. );
  42.  
  43.  
  44. // Pan the map along with where the line is being added.
  45. map.setView(points[y].geometry.coordinates, 3);
  46.  
  47. // Continue to draw and pan the map by calling `add()`
  48. // until `y` reaches the number of points
  49. if (++y < points.length) window.setTimeout(add, 1000);
  50. }
  51.  
  52. <!DOCTYPE html>
  53. <html>
  54. <head>
  55. <meta charset='utf-8' />
  56. <title>Animate a line</title>
  57. <meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
  58. <script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.50.0/mapbox-gl.js'></script>
  59. <link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.50.0/mapbox-gl.css' rel='stylesheet' />
  60. <style>
  61. body { margin:0; padding:0; }
  62. #map { position:absolute; top:0; bottom:0; width:100%; }
  63. #route {
  64. stroke-dasharray: 1000;
  65. stroke-dashoffset: 1000;
  66. animation: dash 1s linear alternate infinite;
  67. }
  68.  
  69. @keyframes dash {
  70. from {
  71. stroke-dashoffset: 1000;
  72. }
  73. to {
  74. stroke-dashoffset: 0;
  75. }
  76. }
  77. </style>
  78. </head>
  79. <body>
  80.  
  81. <div id='map'></div>
  82. <script>
  83. mapboxgl.accessToken =
  84. "pk.eyJ1IjoiaHllb25namlua2ltIiwiYSI6ImNpZXh4dXp5eDA2YjFzaGtyOGR2dnBza2oifQ.a5K673tSr0cOcYoX1rpPhg";
  85.  
  86. var map = new mapboxgl.Map({
  87. container: 'map',
  88. style: 'mapbox://styles/mapbox/streets-v9',
  89. center: [-122.486052, 37.830348],
  90. zoom: 5
  91. });
  92.  
  93. map.on('load', function () {
  94.  
  95. map.addLayer({
  96. "id": "route",
  97. "type": "line",
  98.  
  99. "source": {
  100. "type": "geojson",
  101. "data": {
  102. "type": "Feature",
  103. "properties": {},
  104. "geometry": {
  105. "type": "LineString",
  106. "coordinates": [
  107. [-122.414, 37.776],
  108. [-77.032, 38.913]
  109. ]
  110. }
  111. }
  112. }
  113. });
  114.  
  115. });
  116. </script>
  117.  
  118. </body>
  119. </html>
Add Comment
Please, Sign In to add comment