Hey everyone, I'm looking to create a polyline or path on Mapbox using my own data. I came across an example on mapbox.com that shows how to draw a sine wave on the map. How can I customize this example to use my own data?
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Drawing and animating a line on a map</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.mapbox.com/mapbox.js/v2.2.3/mapbox.js'></script>
<link href='https://api.mapbox.com/mapbox.js/v2.2.3/mapbox.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>
L.mapbox.accessToken = 'pk.eyJ1IjoiYmFhZ2lpIiwiYSI6ImNpZ295aTltdTAwZjl1c20xaTk0NjMxMHoifQ.qWMU19n430KrdzVcyky5bA';
var map = L.mapbox.map('map', 'mapbox.streets')
.setView([0, 0], 3);
// Adding a new line to the map with no points.
var polyline = L.polyline([]).addTo(map);
// Keeping track of points added to the map.
var pointsAdded = 0;
// Starting to draw the polyline.
add();
function add() {
// `addLatLng` method adds a new latLng coordinate at the end of the
// line. You can use your data or generate coordinates. Here
// we are creating a sine wave using math.
polyline.addLatLng(
L.latLng(
Math.cos(pointsAdded / 20) * 30,
pointsAdded));
// Moving the map along with the line being added.
map.setView([0, pointsAdded], 3);
// Calling `add()` function to continue drawing and panning the map
// until all points have been added (360 in this case).
if (++pointsAdded < 360) window.setTimeout(add, 100);
}
</script>
</body>
</html>