Created
December 10, 2012 15:41
-
-
Save yhahn/4251319 to your computer and use it in GitHub Desktop.
Load markers from geojson URL
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> | |
<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 & Feedback</a>'); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment