Either download the repository zip / tgz
Or, clone the repository
git://git.cbaines.net/leaflet-workshop.git
“An Open-Source JavaScript Library for Mobile-Friendly Interactive Maps”LeafletJS.com
Contribute on GitHub
var map = L.map('map', {
center: [50.9087036, -1.4045204], // The Art House Cafe
zoom: 13
});
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors'
}).addTo(map);
// Add a marker over the Art House Cafe
var marker = L.marker([50.9087036, -1.4045204])
marker.addTo(map);
// Add a popup to the marker
marker.bindPopup("The Art House Cafe");
// Add a circle to the map
var circle = L.circle(artHouseCafe, 50, {
color: 'red',
fillColor: '#f03',
fillOpacity: 0
}).addTo(map);
// Load some GeoJSON exported from OpenStreetMap using the OverpassAPI
// (http://overpass-turbo.eu/s/7yI)
getJSON("cafes.json", function(cafes) {
L.geoJson(cafes).addTo(map);
});
// plus a utility function: getJSON
// Load some GeoJSON exported from OpenStreetMap using the OverpassAPI
// (http://overpass-turbo.eu/s/7yI)
var coffeeIcon = L.icon({
iconUrl: 'coffee.png',
iconSize: [32, 37], // size of the icon
iconAnchor: [16, 37], // point of the icon which will
popupAnchor: [16, 0] // point from which the
});
getJSON("cafes.json", function(cafes) {
// Coffee icon from
// http://mapicons.nicolasmollet.com/markers/restaurants-bars/bars/coffee/
L.geoJson(cafes, {
pointToLayer: function(feature, latLng) {
console.log(feature.properties);
if (feature.properties.cuisine == "coffee_shop") {
var marker = L.marker(latLng, {
icon: coffeeIcon
});
return marker;
} else {
return L.marker(latLng);
}
},
onEachFeature: function(feature, layer) {
}
}).addTo(map);
});
A short selection
OpenLayers 3 is a
“A high-performance, feature-packed library for all your mapping needs”
In comparison to Leaflet, this library is more powerful, at the expense of being larger and more complicated.
OpenLayers 3 Examples