Last active
          August 29, 2015 13:55 
        
      - 
      
- 
        Save geografa/8743008 to your computer and use it in GitHub Desktop. 
    custom-marker-from-geojson
  
        
  
    
      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> | |
| <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> | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment