Advertisement
Guest User

Untitled

a guest
Apr 26th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.32 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset='utf-8' />
  5. <title>Bikes of NYC</title>
  6. <meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
  7. <script src=''></script>
  8. <script src='traveling_bike.js'></script>
  9. <script src='lib/moment.min.js'></script>
  10. <link href='' rel='stylesheet' />
  11. <script src='lib/deckgl.min.js'></script>
  12. <script type='text/javascript'>
  13. const {MapboxLayer} = deck;
  14. </script>
  15. <style>
  16. body { margin:0; padding:0; }
  17. #map { position:absolute; top:0; bottom:0; width:100%; }
  18. </style>
  19. </head>
  20. <body>
  21.  
  22. <style>
  23. .overlay {
  24. position: absolute;
  25. top: 10px;
  26. left: 10px;
  27. }
  28.  
  29. .overlay button {
  30. font:600 12px/20px 'Helvetica Neue', Arial, Helvetica, sans-serif;
  31. background-color: #3386c0;
  32. color: #fff;
  33. display: inline-block;
  34. margin: 0;
  35. padding: 10px 20px;
  36. border: none;
  37. cursor: pointer;
  38. border-radius: 3px;
  39. }
  40.  
  41. .overlay button:hover {
  42. background-color:#4ea0da;
  43. }
  44. </style>
  45. <script src='' charset='utf-8'></script>
  46.  
  47. <div id='map'></div>
  48. <div class='overlay'>
  49. <div id='replay' style="background-color: whitesmoke; color: black; ; font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif"></div>
  50. </div>
  51.  
  52. <script>
  53.  
  54. class ArcBrushingLayer extends deck.ArcLayer {
  55. getShaders() {
  56. return Object.assign({}, super.getShaders(), {
  57. inject: {
  58. 'vs:#decl': `
  59. uniform float coef1;
  60. uniform float coef2;
  61. `,
  62. 'vs:#main-end': `
  63. if (coef1 > 0.0) {
  64. vec4 pct = vec4(segmentRatio);
  65. pct.a = step(coef1, segmentRatio);
  66. vec4 colorA = instanceSourceColors;
  67. vec4 colorB = vec4(instanceTargetColors.r, instanceTargetColors.g, instanceTargetColors.b, 0.0);
  68. vec4 color = mix(colorA, colorB, pct) / 255.;
  69. vColor = color;
  70. }
  71. if (coef2 > 0.0) {
  72. vec4 pct = vec4(segmentRatio);
  73. pct.a = step(coef2, segmentRatio);
  74. vec4 colorA = instanceTargetColors;
  75. vec4 colorB = vec4(instanceSourceColors.r, instanceSourceColors.g, instanceSourceColors.b, 0.0);
  76. vec4 color = mix(colorB, colorA, pct) / 255.;
  77. vColor = color;
  78. }
  79. `,
  80. 'fs:#main-start': `
  81. if (vColor.a == 0.0) discard;
  82. `
  83. }
  84. });
  85. }
  86.  
  87. draw(opts) {
  88. const {coef1, coef2} = this.props;
  89. // add uniforms
  90. const uniforms = Object.assign({}, opts.uniforms, { coef1: coef1, coef2: coef2 });
  91. super.draw(Object.assign({}, opts, {uniforms}));
  92. }
  93. }
  94.  
  95. mapboxgl.accessToken = '';
  96. var map = new mapboxgl.Map({
  97. container: 'map',
  98. style: '',
  99. center: [-74.0060, 40.7128],
  100. zoom: 12,
  101. pitch: 60, // pitch in degrees
  102. });
  103.  
  104. map.on('load', function () {
  105. const firstLabelLayerId = map.getStyle().layers.find(layer => layer.type === 'symbol').id;
  106. map.addLayer({
  107. 'id': '3d-buildings',
  108. 'source': 'composite',
  109. 'source-layer': 'building',
  110. 'filter': ['==', 'extrude', 'true'],
  111. 'type': 'fill-extrusion',
  112. 'minzoom': 15,
  113. 'paint': {
  114. 'fill-extrusion-color': '#aaa',
  115. 'fill-extrusion-height': [
  116. "interpolate", ["linear"], ["zoom"],
  117. 15, 0,
  118. 15.05, ["get", "height"]
  119. ],
  120. 'fill-extrusion-base': [
  121. "interpolate", ["linear"], ["zoom"],
  122. 15, 0,
  123. 15.05, ["get", "min_height"]
  124. ],
  125. 'fill-extrusion-opacity': .6
  126. }
  127. }, firstLabelLayerId);
  128.  
  129. travel = travel.sort(function(a, b) {
  130. if (a.start_date == b.start_date) {
  131. if (a.start_time > b.start_time) {
  132. return 1;
  133. } else {
  134. return -1;
  135. }
  136. } else if (a.start_date > b.start_time) {
  137. return 1
  138. } else {
  139. return -1
  140. }
  141. });
  142.  
  143. var arcLayer = null
  144.  
  145. function pickTrip () {
  146.  
  147. if (arcLayer) {
  148. map.removeLayer(arcLayer.id)
  149. }
  150.  
  151. trip = travel.shift()
  152.  
  153. var arcData = [{
  154. source: [trip.start_station_longitude, trip.start_station_latitude],
  155. target: [trip.end_station_longitude, trip.end_station_latitude]
  156. }]
  157.  
  158. arcLayer = new MapboxLayer({
  159. id: 'deckgl-arc',
  160. type: ArcBrushingLayer,
  161. data: arcData,
  162. getSourcePosition: d => d.source,
  163. getTargetPosition: d => d.target,
  164. getSourceColor: [0, 0, 255],
  165. getTargetColor: [50, 255, 255],
  166. getStrokeWidth: 8,
  167. coef1: 0.05,
  168. coef2: 0
  169. })
  170.  
  171. map.addLayer(arcLayer)
  172. document.getElementById('replay').innerHTML = trip.start_station_name + " to " + trip.end_station_name
  173. }
  174.  
  175. function animate () {
  176. if (arcLayer.props.coef1 < 1) {
  177. arcLayer.setProps({coef1: arcLayer.props.coef1 + 0.1})
  178. } else if (arcLayer.props.coef2 < 1) {
  179. arcLayer.setProps({coef2: arcLayer.props.coef2 + 0.1})
  180. } else {
  181. pickTrip()
  182. }
  183. }
  184.  
  185. pickTrip()
  186. setInterval(animate, 50);
  187. });
  188. </script>
  189.  
  190. </body>
  191. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement