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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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