Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@yhahn
Created December 10, 2012 15:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yhahn/4251319 to your computer and use it in GitHub Desktop.
Save yhahn/4251319 to your computer and use it in GitHub Desktop.
Load markers from geojson URL
<!DOCTYPE html>
<html>
<head>
<script src='http://api.tiles.mapbox.com/mapbox.js/v0.6.6/mapbox.js'></script>
<link href='http://api.tiles.mapbox.com/mapbox.js/v0.6.6/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>
// Create map
var map = mapbox.map('map');
map.addLayer(mapbox.layer().id('examples.map-zr0njcqy'));
// Create and add marker layer
var url = 'http://a.tiles.mapbox.com/v3/examples.map-zr0njcqy/markers.geojsonp';
mapbox.markers.layer().url(url, function(err, features, markerLayer) {
var interaction = mapbox.markers.interaction(markerLayer);
map.addLayer(markerLayer);
// Set a custom formatter for tooltips
// Provide a function that returns html to be used in tooltip
interaction.formatter(function(feature) {
return '<strong>' + feature.properties.title + '</strong>' +
'<p>' + feature.properties.description + '</p>';
});
// Set iniital center and zoom
map.centerzoom({
lat: 38.93,
lon: -77.03
}, 13);
// Attribute map
map.ui.attribution.add()
.content('<a href="http://mapbox.com/about/maps">Terms &amp; Feedback</a>');
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment