Created
May 26, 2015 01:20
-
-
Save BaconSoap/1d452c8b4bc17a6e3fa7 to your computer and use it in GitHub Desktop.
blog-leaflet-mapping: iteration 2
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
(function(){ | |
var map; | |
var catImg = '<img src="http://thecatapi.com/api/images/get?format=src&type=png&size=small">'; | |
function init() { | |
// create a new map with no base layer | |
map = new L.Map("map", { | |
center: new L.LatLng(42.3964631, -71.1205171), | |
zoom: 16 | |
}); | |
// use Stamen's 'terrain' base layer | |
var layer = new L.StamenTileLayer("terrain"); | |
map.addLayer(layer); | |
// add a marker at the center of the map | |
addMarker([42.3964631, -71.1205171]); | |
} | |
/** | |
* add a marker with a popup at the specified coordinates | |
*/ | |
function addMarker(coords) { | |
var marker = L.marker(coords); | |
marker.bindPopup('<h3>I\'m Fluffy</h3>' + catImg); | |
marker.addTo(map); | |
} | |
document.addEventListener('DOMContentLoaded', init); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment