I'm currently coding a simple HTML page with embedded Javascript to visualise a local mbtiles
, including local glyphs
and sprites
.
The html index.html
is :
...
<script src="https://unpkg.com/maplibre-gl@2.1.9/dist/maplibre-gl.js"></script>
<link href="https://unpkg.com/maplibre-gl@2.1.9/dist/maplibre-gl.css" rel="stylesheet" />
...
<body>
<div id="map"></div>
</body>
<script type="module" src="./index.js" async defer></script>
The javascript index.js
is :
var map = new maplibregl.Map({
container: 'map',
style:
'styles/style.json',
center: [174.746344, -36.8899343],
zoom: 11.15
});
and the goal is to load a style.json
file that would define the mbtiles
, sprites
and glyphs
local location.
I'm currently using the OSM Bright style, copied over locally on my machine, within the style.json
file and the goal is to swap any connection to remote files by local files:
glyphs
"glyphs": "./glyphs/{fontstack}/{range}.pbf",
It works well for the glyphs
sprites
"sprite": "./sprites/sprite",
I have the following error : Unable to parse URL "./sprites/sprite"
mbtiles
"sources": {
"openmaptiles": {
"type": "vector",
"url": "./mbtiles/country.mbtiles"
}
},
I got the following error : Error: Unexpected token 'S', "SQLite for"... is not valid JSON
I'm definitely missing some protocols
here, and I can't find any answer to my question so far, knowing :
- I'm not looking to build an IOS/Android app : so this useful website for instance https://medium.com/@ty2/how-to-display-offline-maps-using-maplibre-mapbox-39ad0f3c7543 doesn't apply to my case -> I've tried to add
asset://sprites/sprite
or
mbtiles://country.mbtiles
but that doesn't work (neither for the glyphs
, but it doesn't look like it's necessary any way)
- this Load local .mbtiles with maplibre-gl-js looks like the closest to my need, but again the answer focus on application and not html, plus the question has not yet been fully resolved neither
So any help would be appreciated, especially I would be interested to know if this is even possible with the maplibre-gl.js
library that I'm using as this might just not be possible. If that's the case, I would appreciate a similar answer with mapbox-gl.js
if necessary, but still using local (offline) files.
In other words the main objective is to run a website (not an app) with maplibre (not mapbox - at least if possible) and only including local files.
Thanks for any feedback.