TileJSON
TileJSON示例。 tilejson
WARNING
底图用 maps.gnosis.earth 的 OGC Map Tiles 服务,需要授权使用,未授权时报错 GNOSIS Map Server (OGCAPI) - 401 Unauthorized。
TileJSON 图层示例。
main.js
js
import Map from 'ol/Map.js';
import View from 'ol/View.js';
import TileLayer from 'ol/layer/Tile.js';
import TileJSON from 'ol/source/TileJSON.js';
const map = new Map({
layers: [
new TileLayer({
source: new TileJSON({
url: 'https://maps.gnosis.earth/ogcapi/collections/NaturalEarth:raster:HYP_HR_SR_OB_DR/map/tiles/WebMercatorQuad?f=tilejson',
crossOrigin: 'anonymous',
}),
}),
],
target: 'map',
view: new View({
center: [0, 0],
zoom: 2,
}),
});index.html
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>TileJSON 瓦片图层</title>
<link rel="stylesheet" href="node_modules/ol/ol.css">
<style>
.map {
width: 100%;
height: 400px;
}
</style>
</head>
<body>
<div id="map" class="map"></div>
<script type="module" src="main.js"></script>
</body>
</html>package.json
json
{
"name": "tilejson",
"dependencies": {
"ol": "10.11.0"
},
"devDependencies": {
"vite": "^8.1.5"
},
"scripts": {
"start": "vite",
"build": "vite build"
}
}