Add ability to switch maptile style

pull/1/head
Daniel Asher Resnick 4 years ago
parent f2d7d0a5ea
commit f7831de10d
  1. 21
      index.html

@ -24,6 +24,8 @@
attribution: "\u003ca href=\"https://www.maptiler.com/copyright/\" target=\"_blank\"\u003e\u0026copy; MapTiler\u003c/a\u003e \u003ca href=\"https://www.openstreetmap.org/copyright\" target=\"_blank\"\u003e\u0026copy; OpenStreetMap contributors\u003c/a\u003e", attribution: "\u003ca href=\"https://www.maptiler.com/copyright/\" target=\"_blank\"\u003e\u0026copy; MapTiler\u003c/a\u003e \u003ca href=\"https://www.openstreetmap.org/copyright\" target=\"_blank\"\u003e\u0026copy; OpenStreetMap contributors\u003c/a\u003e",
style: 'https://api.maptiler.com/maps/hybrid/style.json?key=PVp0f0cBGCyXeWLnAp9e' style: 'https://api.maptiler.com/maps/hybrid/style.json?key=PVp0f0cBGCyXeWLnAp9e'
}).addTo(map); }).addTo(map);
fetch('shadowrun.kml') fetch('shadowrun.kml')
.then(res => res.text()) .then(res => res.text())
.then(kmltext => { .then(kmltext => {
@ -83,6 +85,19 @@
oursswitcher.addTo(map); oursswitcher.addTo(map);
document.getElementById ("oursswitcher").addEventListener ("click", toggleOurs, false); document.getElementById ("oursswitcher").addEventListener ("click", toggleOurs, false);
var styleSwitcher = L.control({position: 'topleft'});
styleSwitcher.onAdd = function (map) {
var div = L.DomUtil.create('div', 'stylediv');
div.innerHTML = '<form> \
<input id="hybrid-style" type="radio" name="style-selector" value="hybrid" checked />Hybrid <br/>\
<input id="streets-style" type="radio" name="style-selector" value="streets" />Streets <br/>\
</form>';
return div;
};
styleSwitcher.addTo(map);
document.getElementById ("hybrid-style").addEventListener ("click", setMapStyle, false);
document.getElementById ("streets-style").addEventListener ("click", setMapStyle, false);
function toggleChinaGreen() { function toggleChinaGreen() {
if(this.checked){ if(this.checked){
map.addLayer(chinagreen); map.addLayer(chinagreen);
@ -104,6 +119,12 @@
map.removeLayer(ours); map.removeLayer(ours);
} }
} }
function setMapStyle() {
if(this.checked){
gl._glMap.setStyle('https://api.maptiler.com/maps/' + this.value + '/style.json?key=PVp0f0cBGCyXeWLnAp9e');
}
}
</script> </script>
</body> </body>
</html> </html>

Loading…
Cancel
Save