I've downloaded .mbtiles file from https://openmaptiles.com/downloads and want to show the map in localhost. I've used following code but it did not show anything.
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>Local Map</title>
<link rel="stylesheet" href="css/ol.css" type="text/css">
<script src="build/ol.js"></script>
</head>
<body onload="init();">
<a href="#mapDiv">Go to map</a>
<div id="mapDiv" class="map" tabindex="0"></div>
<script>
var map;
function init() {
map = new ol.Map ({
target: 'mapDiv' });
var newLayer = new ol.layer.Tile({
source: new ol.source.OSM({
url: 'http://localhost/map/${z}/${x}/${y}.png'
})
});
map.addLayer(newLayer);
}
</script>
</body>
</html>
Following scenarios were tested and non of them were successful
putting .mbtiles file and referring to it as
url: 'pathtofolder/file.mbtiles'
putting .mbtiles file and referring to its parent folder as
url: 'pathtoparentfolder'
extracting .mbtiles with mbutil and obtaining many many numbered folders with metadata.json file and referring to it as
url: 'pathtoparentfolder'
extracting .mbtiles with mbutil and obtaining many many numbered folders with metadata.json file and referring to it as
url: 'pathtoparentfolder/{z}/{x}/{y}.png'
What is the problem and how can I debug OpenLayers? In fact I hesitate between using ol.source.OSM
and ol.source.XYZ
.
It's noteworthy to mention I have many .png files extracted in that folders but they can not be displayed.
http://localhost
too? Any errors in your Javascript console, "file not found" or similar?