On Github luxembourgjs / leaflet-demo
By Thierry Nicola / eevol.lu / @littleiffel
No Kittens where harmed in the creation of these slides
Vladimir Agafonkin works at MapBox.com
Where is the sexy code!
Attention! Live coding
var map = L.map('map', { center: [49, 6], zoom: 13 }); L.tileLayer('http://a.tiles.mapbox.com/v3/eevol.h0194mcj/{z}/{x}/{y}.png', { }).addTo(map); // L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', { // attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors' // }).addTo(map);
var marker = L.marker([49, 5.49]).addTo(map); var polygon = L.polygon([ [51.509, -0.08], [51.503, -0.06], [51.51, -0.047] ]).addTo(map); marker.bindPopup("<b>Hello world!</b><br>I am a popup.").openPopup(); polygon.bindPopup("I am a polygon.");
var mapbox = L.tileLayer('http://a.tiles.mapbox.com/v3/eevol.h0194mcj/{z}/{x}/{y}.png'), osm = L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', { attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors' }); var map = L.map('map', { center: new L.LatLng(49.72, 6.13), zoom: 10, layers: [mapbox, osm] }); var maps = { "MapBox.com": mapbox, "OSM": osm }; var controlLayers = L.control.layers(maps).addTo(map); var amazon = L.marker([49.72, 6.134]).bindPopup('YOU ARE HERE'), skype = L.marker([49.74, 6.137]).bindPopup('The app next door'); var markers = L.layerGroup([amazon, skype]); controlLayers.addOverlay(markers, "Markers"); map.removeLayer(osm);
Execute this code in Console for iframe 'wherewerewe'
map.getCenter(); map.getBounds(); map.getZoom(); map.getPixelBounds();
Execute this code in Console for iframe 'controlthemap'
map.setView(L.latLng(50, 30), 5); var popup = L.popup().setLatLng([51.5, -0.09]).setContent("I am a standalone popup.").openOn(map); L.control.scale().addTo(map);
Click the map to log Event, and Double Click to get Position
function onClickMap(e){ console.log(e); } map.on('click', onClickMap); // Listen to Click on Map //map.off('click', onClickMap); // Remove event Listener var popup = L.popup(); function onMapDblClick(e) { popup .setLatLng(e.latlng) .setContent("You clicked the map at " + e.latlng.toString() ) .openOn(map); } map.on('dblclick', onMapDblClick);
If you made it this far...
var myLines = [{ "type": "LineString", "coordinates": [[-100, 40], [-105, 45], [-110, 55]] }, { "type": "LineString", "coordinates": [[-105, 40], [-110, 45], [-115, 55]] }]; var myStyle = { "color": "#ff7800", "weight": 5, "opacity": 0.65 }; L.geoJson(myLines, { style: myStyle }).addTo(map);
...almost...