Skip to content

Instantly share code, notes, and snippets.

@tmcw
Created July 16, 2014 20:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tmcw/abb512b93c50b1f7c203 to your computer and use it in GitHub Desktop.
Save tmcw/abb512b93c50b1f7c203 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>A simple map</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<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>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<section style="height:500px;">
<div id='map'></div>
<script>
var map = L.mapbox.map('map', 'tsch9.iodm9j8h')
.setView([-37.774960, 144.990514], 15);
var myLayer = L.mapbox.featureLayer().addTo(map);
var geoJson = [{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [144.990514, -37.774960]
},
"properties": {
"title": "Big astronaut",
"icon": {
"iconUrl": "https://www.mapbox.com/mapbox.js/assets/images/astronaut1.png",
"iconSize": [100, 100],
"iconAnchor": [50, 50],
"popupAnchor": [0, -55],
"className": "dot"
}
}
}];
// Set a custom icon on each marker based on feature properties.
myLayer.on('layeradd', function(e) {
var marker = e.layer,
feature = marker.feature;
marker.setIcon(L.icon(feature.properties.icon));
});
// Add features to the map.
myLayer.setGeoJSON(geoJson);
</script></section>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment