Skip to content

Instantly share code, notes, and snippets.

@geografa
Last active August 29, 2015 13:55
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 geografa/8743008 to your computer and use it in GitHub Desktop.
Save geografa/8743008 to your computer and use it in GitHub Desktop.
custom-marker-from-geojson
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title></title>
<script src='//api.tiles.mapbox.com/mapbox.js/v1.6.1/mapbox.js'></script>
<link href='//api.tiles.mapbox.com/mapbox.js/v1.6.1/mapbox.css' rel='stylesheet' />
<!--[if lte IE 8]>
<link href='//api.tiles.mapbox.com/mapbox.js/v1.6.1/mapbox.ie.css' rel='stylesheet'>
<![endif]-->
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
.marker {}
</style>
</head>
<body>
<div id='map'></div>
<script type='text/javascript'>
var map = L.mapbox.map('map', 'grafa.h0599p73')
.setView([45.68882429809956, -121.84547066688538], 16);
var featureLayer = L.mapbox.featureLayer()
.loadURL('map.geojson');
// function to run once marker has loaded
featureLayer.on('ready', function(){
// navigate the GeoJSON to get to the coordinates
var geojson = featureLayer.getGeoJSON();
var myIcon = L.icon({
iconUrl: 'https://i.cloudup.com/E44IxhcVLk.thumb.png',
iconSize: [75,75]
});
for (i = geojson.features.length - 1; i >= 0; i--) {
// add the coords in the correct order
var coords = geojson["features"][i]["geometry"]["coordinates"],
lat = coords[1],
lng = coords[0];
L.marker([lat,lng], {icon: myIcon})
.addTo(map);
};
});
</script>
</body>
</html>
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment