Skip to content

Instantly share code, notes, and snippets.

@zross
Created September 23, 2014 13:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save zross/81674207bf67244fedc0 to your computer and use it in GitHub Desktop.
Save zross/81674207bf67244fedc0 to your computer and use it in GitHub Desktop.
GeoJSON data on Leaflet Map with MapBox tiles
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.7/leaflet.js"></script>
<script src='https://api.tiles.mapbox.com/mapbox.js/v1.6.4/mapbox.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox.js/v1.6.4/mapbox.css' rel='stylesheet' />
<style>
html,
body {
height: 100%;
width: 100%;
}
body {
margin: 0;
}
#map {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<script type="text/javascript">
var mapboxTiles = L.tileLayer('https://{s}.tiles.mapbox.com/v3/examples.map-zr0njcqy/{z}/{x}/{y}.png', {
attribution: '<a href="http://www.mapbox.com/about/maps/" target="_blank">Terms &amp; Feedback</a>'
});
var map = L.map('map')
.addLayer(mapboxTiles)
.setView([40.724936, -73.991455], 16);
var line = L.mapbox.featureLayer()
.loadURL('line.geojson')
.addTo(map);
var points = L.mapbox.featureLayer()
.loadURL('points.geojson')
.addTo(map);
</script>
</body>
</html>
Display the source blob
Display the rendered blob
Raw
{
"type": "FeatureCollection",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{ "type": "Feature", "properties": { "latitude": 40.727250, "longitude": -73.984550, "time": 18, "id": "route1" }, "geometry": { "type": "LineString", "coordinates": [ [ -73.99517, 40.72239 ], [ -73.99548, 40.72158 ], [ -73.99472, 40.72128 ], [ -73.99376, 40.72089 ], [ -73.99348, 40.72158 ], [ -73.99322, 40.72231 ], [ -73.99316, 40.72247 ], [ -73.99274, 40.72358 ], [ -73.99215, 40.72519 ], [ -73.99202, 40.72559 ], [ -73.99151, 40.72539 ], [ -73.98865, 40.72418 ], [ -73.98798, 40.7239 ], [ -73.98751, 40.72455 ], [ -73.98618, 40.72637 ], [ -73.98575, 40.72696 ], [ -73.98531, 40.72757 ], [ -73.98455, 40.72725 ] ] } }
]
}
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@omejiasq
Copy link

Excellent demo Zross. I download the source code but i get some issues. I include this example in my Xampp server and i get the follow errors:
24638.png:1 GET https://c.tiles.mapbox.com/v3/examples.map-zr0njcqy/16/19299/24638.png? 410 (Gone)

  Image (async)    
  _loadTile @ mapbox.js:2
  _addTile @ mapbox.js:2
  _addTilesFromCenterOut @ mapbox.js:2
  _update @ mapbox.js:2
  onAdd @ mapbox.js:2
  _layerAdd @ mapbox.js:2
  eachLayer @ mapbox.js:1
  _resetView @ mapbox.js:1
  setView @ mapbox.js:4
  (anonymous) @ (index):45
  1. How i can to fix this?
  2. Why i can't to see the Mapbox token in your example? Do i need to add the token?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment