Skip to content

Instantly share code, notes, and snippets.

@lxbarth
Last active January 9, 2019 19:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save lxbarth/9490377 to your computer and use it in GitHub Desktop.
Save lxbarth/9490377 to your computer and use it in GitHub Desktop.
Attribution on a branded Mapbox map
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link href='http://api.tiles.mapbox.com/mapbox.js/v1.6.2/mapbox.css' rel='stylesheet' />
<script src='http://api.tiles.mapbox.com/mapbox.js/v1.6.2/mapbox.js'></script>
<style>
body {padding: 0; margin: 0;}
#map { position:absolute; top:0; bottom:0; width:100%; }
.mapbox-maplogo {
position:absolute;
display:block;
height: 20px;
width: 65px;
left:10px;
bottom:10px;
text-indent: -9999px;
z-index:99999;
overflow:hidden;
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIIAAAAoCAMAAAAFWtJHAAAAwFBMVEUAAAAAAAAAAABtbW0AAAAAAAAAAAAAAAAAAAAAAAClpaUAAADp6ekAAAD5+fna2toAAAAMDAzv7+/Nzc0AAAA2Njb8/Pz9/f3T09MAAAAAAAD7+/sAAAArKyuxsbH39/fs7OwbGxuIiIjz8/N8fHyenp7u7u74+PgAAAC8vLxWVlbx8fF1dXXl5eVcXFyUlJTQ0NDFxcVCQkLAwMC4uLj19fXo6OjW1tarq6ve3t77+/vi4uL6+vrKysrNzc3///8w7gSSAAAAP3RSTlMAOQNdPSYBPywKexLLGPCxNEHXnzFL+v2nGwf1IEiE6dBFad9jd9PuLo1V2mDDV3Cjl06SiuXIq4C3973ym6BQMVUPAAAEXElEQVR4Ae2WCVP6OBiH05L0l1IqrVbkKHJ54I0oHn+PfP9vtUle0z/YdhbH2XVnd58ZnRJIeHiPJOx//mH4vQSAN+8FjAhFxgHIaPvJeZ99hxwEElon5iAQbj85Y98g8ODwjEOMAvGFyeE3FEKgodTBqj0BJGN9DhyNd5Ta3ean9QEopfaA+LsKhnEKRExqg4FSP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xcfd14h21KhuLKUFU4f3osrC7F6uV3WXFnadL7wyAPeKDXw2RoJCO5GY4DouYvb/gepVXheLoewzPseQG9N/vzilrMIjoStE3++zvle4eSurw7XEe76ynI4aq+v7lEyt1x5awiFlFLQbHKIpabnM3eJLym4Szzzc/du7SU+zOXv9UNpECH7IoH/gecURPlN9vdQpeD47yhIFNX0U0QgvID9nENm+yxk/xb+AGAjNfRZuk9qAAAAAElFTkSuQmCC);
background-repeat:no-repeat;
background-position: 0 0 ;
background-size: 65px 20px;
}
</style>
</head>
<body>
<div id='map'>
<!-- Add mapbox watermark -->
<a href="http://mapbox.com/about/maps" class='mapbox-maplogo' target="_blank">MapBox</a>
</div>
<script>
// Configure map hiding info control and attribution control (we'll customize those).
var map = L.mapbox.map('map', 'lxbarth.i6fgdd0o',
{infoControl: false, attributionControl: false})
.setView([40, -74.50], 9);
// Add customized attribution, not repeating "Mapbox" (we already have a logo on there).
var attribution = L.control.attribution();
attribution.setPrefix('');
attribution.addAttribution('<a href="http://openstreetmap.org/copyright">Map data: © OpenStreetMap</a> | <a href="http://mapbox.com/map-feedback/" class="mapbox-improve-map">Improve this map</a>');
attribution.addTo(map);
// Extra points: make sure user lands on proper map and location when clicking 'Improve this map'
// (don't forget to add same map id as in the map creation here).
var editLink = function() {
if (!document.getElementsByClassName) {
return;
}
var link = document.getElementsByClassName('mapbox-improve-map');
if (link.length && map._loaded) {
var center = map.getCenter();
for (var i = 0; i < link.length; i++) {
link[i].href = link[i].href.split('#')[0] + '#lxbarth.mi6fgdd0o'+ center.lng + '/' + center.lat + '/' + map.getZoom();
}
}
};
editLink();
map.on('moveend', editLink);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment