Skip to content

Stadia Maps (Retina 瓦片) ​

Stadia Maps (Retina 瓦片)示例。 stadia-maps retina dark hidpi

示例展示来自 Stadia Maps 的 Alidade Smooth Dark 主题,使用 retina(HiDPI)瓦片。

main.js
js
import Map from 'ol/Map.js';
import View from 'ol/View.js';
import TileLayer from 'ol/layer/Tile.js';
import {fromLonLat} from 'ol/proj.js';
import StadiaMaps from 'ol/source/StadiaMaps.js';

const map = new Map({
  layers: [
    // 注意:来自 Stadia Maps 的图层在本地开发或大多数生产
    // 网页部署中不需要 API 密钥。详情请参阅 https://docs.stadiamaps.com/authentication/。
    new TileLayer({
      source: new StadiaMaps({
        layer: 'alidade_smooth_dark',
        retina: true,
        // apiKey: 'OPTIONAL'
      }),
    }),
  ],
  target: 'map',
  view: new View({
    center: fromLonLat([24.750645, 59.444351]),
    zoom: 14,
  }),
});
index.html
html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>Stadia Maps(Retina 瓦片)</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": "stadia-maps",
  "dependencies": {
    "ol": "10.11.0"
  },
  "devDependencies": {
    "vite": "^8.1.5"
  },
  "scripts": {
    "start": "vite",
    "build": "vite build"
  }
}