Created
January 4, 2015 11:23
-
-
Save vallettea/f8f84182b091b210d76d to your computer and use it in GitHub Desktop.
Trying to figure out how to animate the data ploted on mapbox gl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset='utf-8' /> | |
| <title></title> | |
| <meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' /> | |
| <script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.5.1/mapbox-gl.js'></script> | |
| <link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.5.1/mapbox-gl.css' rel='stylesheet' /> | |
| <style> | |
| body { margin:0; padding:0; } | |
| #map { position:absolute; top:0; bottom:0; width:100%; } | |
| </style> | |
| </head> | |
| <body> | |
| <div id='map'></div> | |
| <script> | |
| mapboxgl.accessToken = 'pk.eyJ1IjoidmFsbGV0dGVhIiwiYSI6IjBsbFBuRDAifQ.zOrauVItBwIKf0my5GMIBw'; | |
| mapboxgl.util.getJSON('https://www.mapbox.com/mapbox-gl-styles/styles/outdoors-v6.json', function (err, style) { | |
| if (err) throw err; | |
| style.layers.push({ | |
| "id": "red", | |
| "type": "line", | |
| "source": "red", | |
| "layout": { | |
| "line-join": "round", | |
| "line-cap": "round" | |
| }, | |
| "paint": { | |
| "line-color": "red", | |
| "line-width": 8 | |
| } | |
| }); | |
| style.layers.push({ | |
| "id": "blue", | |
| "type": "line", | |
| "source": "blue", | |
| "layout": { | |
| "line-join": "round", | |
| "line-cap": "round" | |
| }, | |
| "paint": { | |
| "line-color": "blue", | |
| "line-width": 8 | |
| } | |
| }); | |
| var map = new mapboxgl.Map({ | |
| container: 'map', | |
| style: style, | |
| center: [37.830348, -122.486052], | |
| zoom: 15 | |
| }); | |
| var features1 = [{ | |
| "type": "Feature", | |
| "properties": { | |
| "color": "red" | |
| }, | |
| "geometry": { | |
| "type": "LineString", | |
| "coordinates": [ | |
| [-122.48369693756104, 37.83381888486939], | |
| [-122.48348236083984, 37.83317489144141], | |
| [-122.48339653015138, 37.83270036637107], | |
| [-122.48356819152832, 37.832056363179625], | |
| [-122.48404026031496, 37.83114119107971], | |
| [-122.48404026031496, 37.83049717427869], | |
| [-122.48348236083984, 37.829920943955045], | |
| [-122.48356819152832, 37.82954808664175], | |
| [-122.48507022857666, 37.82944639795659] | |
| ] | |
| } | |
| }]; | |
| var features2 = [ | |
| { | |
| "type": "Feature", | |
| "properties": { | |
| "color": "blue" | |
| }, | |
| "geometry": { | |
| "type": "LineString", | |
| "coordinates": [ | |
| [-122.48610019683838, 37.82880236636284], | |
| [-122.48695850372314, 37.82931081282506], | |
| [-122.48700141906738, 37.83080223556934], | |
| [-122.48751640319824, 37.83168351665737], | |
| [-122.48803138732912, 37.832158048267786], | |
| [-122.48888969421387, 37.83297152392784], | |
| [-122.48987674713133, 37.83263257682617], | |
| [-122.49043464660643, 37.832937629287755], | |
| [-122.49125003814696, 37.832429207817725], | |
| [-122.49163627624512, 37.832564787218985], | |
| [-122.49223709106445, 37.83337825839438], | |
| [-122.49378204345702, 37.83368330777276] | |
| ] | |
| } | |
| }]; | |
| var geoJSON1 = { | |
| "type": "FeatureCollection", | |
| "features": features1 | |
| }; | |
| var geoJSON2 = { | |
| "type": "FeatureCollection", | |
| "features": features2 | |
| }; | |
| var route1 = new mapboxgl.GeoJSONSource({ data: geoJSON1 }); | |
| map.addSource('red', route1); | |
| var route2 = new mapboxgl.GeoJSONSource({ data: geoJSON2 }); | |
| map.addSource('blue', route2); | |
| // document.addEventListener("click", function(){ | |
| // console.log("clicked"); | |
| // route2.setData(geoJSON1); | |
| // }); | |
| document.addEventListener("click", function(){ | |
| console.log("clicked"); | |
| map.removeSource('blue'); | |
| }); | |
| }); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment