Last active
August 29, 2015 14:22
-
-
Save turban/8ed8b2985779b8a6d76b to your computer and use it in GitHub Desktop.
Mapbox GL JS
This file contains 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' /> | |
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.7.0/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 src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.7.0/mapbox-gl.js'></script> | |
<script> | |
mapboxgl.accessToken = 'pk.eyJ1IjoidHVyYmFuIiwiYSI6ImZQaVhCQU0ifQ.X3SS6YechVVo-1G3EXfnCA'; | |
var options = { | |
container: 'map', | |
style: 'https://www.mapbox.com/mapbox-gl-styles/styles/emerald-v7.json', | |
center: [60.604, 7.502], | |
zoom: 7 | |
}; | |
var map = new mapboxgl.Map(options); | |
map.addControl(new mapboxgl.Navigation({position: 'topright'})); | |
map.on('style.load', function() { | |
mapboxgl.util.getJSON("http://turban.cartodb.com/api/v2/sql?q=SELECT the_geom, placename AS name, datetime FROM SPOT WHERE timestamp BETWEEN 1427283000 AND 1429367400 AND message_type = 'OK' ORDER BY timestamp&format=geojson", function (err, geojson) { | |
if (err) throw err; | |
map.addSource('markers', { | |
type: 'geojson', | |
data: geojson | |
}); | |
map.addLayer({ | |
"id": "markers", | |
"type": "symbol", | |
"source": "markers", | |
"layout": { | |
"icon-image": "lodging-12", | |
"text-field": "{name}", | |
"text-font": "Open Sans Semibold, Arial Unicode MS Bold", | |
"text-offset": [1, 0], | |
"text-anchor": "left" | |
}, | |
"paint": { | |
"text-size": 12 | |
} | |
}); | |
}); | |
mapboxgl.util.getJSON('http://turban.cartodb.com/api/v2/sql?q=SELECT ST_MakeLine(the_geom ORDER BY timestamp) AS the_geom FROM spot WHERE timestamp BETWEEN 1427283000 AND 1429367400&format=geojson', function (err, geojson) { | |
if (err) throw err; | |
map.addSource('route', { | |
type: 'geojson', | |
data: geojson | |
}); | |
map.addLayer({ | |
id: 'route', | |
type: 'line', | |
source: 'route', | |
layout: { | |
'line-join': 'round', | |
'line-cap': 'round' | |
}, | |
paint: { | |
'line-color': '#333', | |
'line-width': 4 | |
} | |
}); | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment