Created
October 8, 2012 08:10
-
-
Save turban/3851326 to your computer and use it in GitHub Desktop.
This file contains 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
// Create map layers | |
var layers = { | |
'Seafloor': L.tileLayer('tiles/nz-seafloor/{z}/{x}/{y}.png', { | |
maxZoom: 9, | |
attribution: '<a href="http://www.niwa.co.nz/our-science/oceans/bathymetry">NIWA</a>' | |
}), | |
'Topographic': L.tileLayer('tiles/nz-topo/{z}/{x}/{y}.png', { | |
attribution: '<a href="http://data.linz.govt.nz/">LINZ</a>, <a href="http://lris.scinfo.org.nz/">LRIS</a>' | |
}), | |
'Tour': L.cartoDB('http://thematicmapping.cartodb.com/api/v2/sql?q=SELECT * FROM new_zealand_tour', { | |
pointToLayer: function(feature, latlng) { | |
return L.marker(latlng, { | |
icon: L.icon({ | |
iconSize: [27, 27], | |
iconAnchor: [13, 27], | |
popupAnchor: [1, -24], | |
iconUrl: 'icons/' + feature.properties.icon + '.png' | |
}) | |
}) | |
}, | |
onEachFeature: function(feature, layer) { | |
layer.bindPopup('<strong>' + feature.properties.name + '</strong><br>' + (feature.properties.description ? feature.properties.description : '')); | |
} | |
}) | |
}; | |
// Get url parameters | |
var params = {}; | |
window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m, key, value) { | |
params[key] = value; | |
}); | |
if (params.layers) { | |
var activeLayers = params.layers.split(',').map(function(item) { // map function not supported in IE < 9 | |
return layers[item]; | |
}); | |
} | |
// Create map | |
var map = new L.Map('map', { | |
center: [params.lat || -41.2728, params.lng || 173.2996], | |
minZoom: 4, | |
maxZoom: 12, | |
zoom: params.zoom || 6, | |
layers: activeLayers || [layers.Seafloor, layers.Topographic] | |
}); | |
map.attributionControl.setPrefix('<a href="http://blog.thematicmapping.org/">thematic mapping blog</a>'); | |
// Add controls | |
L.control.scale().addTo(map); | |
L.control.layers({}, layers).addTo(map); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment