noruka-google-vector-tiles
Version:
A vector map tiler for google map
78 lines (72 loc) • 2.88 kB
HTML
<html>
<head>
<title>Layers</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<div class="container-left">
<div id="map"></div>
</div>
<div class="container-right">
<div>
<h2>Layers</h2>
<p>
Show / hide selected layers.
</p>
<p>
<input type="checkbox" id="country" name="census" value="country">
<label for="country">country</label><br>
<input type="checkbox" id="provinces" name="census" value="provinces" checked="checked">
<label for="provinces">provinces</label><br>
<input type="checkbox" id="municipalities" name="census" value="municipalities">
<label for="municipalities">municipalities</label><br>
</p>
</div>
</div>
<script src="../dist/vector-tiles-google-maps.js"></script>
<script type="text/javascript">
var map;
var mvtSource;
var input = document.getElementsByName("census");
function InitGoogleMap() {
map = new google.maps.Map(document.getElementById("map"), {
center: { lat: 37.08, lng: -6.84 },
zoom: 5
});
// if tiles have not been loaded, GetTile will trigger twice.
google.maps.event.addListenerOnce(map, 'tilesloaded', function () {
InitVectorTiles();
});
}
function CheckedLayers() {
var layers = [];
input.forEach(function (elem) {
if (elem.checked) {
layers.push(elem.value);
}
});
return layers;
}
function InitVectorTiles() {
var options = {
url: "https://api.mapbox.com/v4/techjb.bwtby589/{z}/{x}/{y}.vector.pbf?sku=101D1qzcYDQhj&access_token=pk.eyJ1IjoidGVjaGpiIiwiYSI6ImNrbzFuMDV6MzBhYXQycWxwaG4ydGozZTgifQ.hCgIvpwnfw93KFcWaR5WBA",
sourceMaxZoom: 14,
visibleLayers: CheckedLayers()
};
var mvtSource = new MVTSource(map, options);
map.overlayMapTypes.insertAt(0, mvtSource);
input.forEach(function (elem) {
elem.addEventListener("change", function () {
var layers = CheckedLayers();
mvtSource.setVisibleLayers(layers);
});
});
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyA_bDL3sglTy8HGoiAU9JsLtayEkQakE7c&callback=InitGoogleMap&libraries=&v=weekly"
defer></script>
</body>
</html>