-
-
Save tmcw/3500323 to your computer and use it in GitHub Desktop.
MapBox showOnHover debugging
This file contains hidden or 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.4/mapbox.js'></script> | |
<link href='http://api.tiles.mapbox.com/mapbox.js/v0.6.4/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 type="text/javascript"> | |
mapbox.auto('map', 'http://a.tiles.mapbox.com/v3/inbar.map-6zm8kgdb.jsonp', function(map, tiledata) { | |
map.setZoomRange(1, 4); | |
// tiledata.markers is the markers layer. | |
var markersLayer = tiledata.markers; | |
markersLayer.addCallback('drawn', function() { | |
if (map.zoom() < 2) markersLayer.disable(); | |
else markersLayer.enable(); | |
}); | |
var interaction = mapbox.markers.interaction(markersLayer) | |
.showOnHover(false); | |
// Custom formatter function | |
interaction.formatter(function(feature) { | |
var o = '', props = feature.properties; | |
if (props.title) { | |
o += '<strong class="marker-title">' + props.title + '</strong>'; | |
} | |
if (props.description) { | |
o += '<div class="marker-description">' + props.description + '</div>'; | |
} | |
o += '<div class="allclear"></div>'; | |
if (typeof html_sanitize !== undefined) { | |
o = html_sanitize(o, | |
function(url) { | |
if (/^(https?:\/\/|data:image)/.test(url)) return url; | |
}, | |
function(x) { return x; }); | |
} | |
return o; | |
}); | |
// Replace marker factory function with our version | |
markersLayer.factory(function(m) { | |
// Create a marker using the simplestyle factory | |
var elem = mapbox.markers.simplestyle_factory(m); | |
// Add function that centers marker on click | |
MM.addEvent(elem, 'click', function(e) { | |
map.ease.location({ | |
lat: m.geometry.coordinates[1]+40/map.zoom(), | |
lon: m.geometry.coordinates[0] | |
}).zoom(map.zoom()).optimal(); | |
}); | |
return elem; | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment