Skip to content

IGN WMTS ​

IGN WMTS示例。 french IGN geoportail WMTS 网格

本示例展示了 IGN WMTS 图层的显示。有关 IGN WMTS 服务的更多信息,请参阅 IGN Géoportail API web page 和 Documentation de l’offre de données et services de l’IGN(法语)。

main.js
js
import Map from 'ol/Map.js';
import View from 'ol/View.js';
import {getWidth} from 'ol/extent.js';
import TileLayer from 'ol/layer/Tile.js';
import {fromLonLat, get as getProjection} from 'ol/proj.js';
import WMTS from 'ol/source/WMTS.js';
import WMTSTileGrid from 'ol/tilegrid/WMTS.js';

const map = new Map({
  target: 'map',
  view: new View({
    zoom: 5,
    center: fromLonLat([5, 45]),
  }),
});

const resolutions = [];
const matrixIds = [];
const proj3857 = getProjection('EPSG:3857');
const maxResolution = getWidth(proj3857.getExtent()) / 256;

for (let i = 0; i < 20; i++) {
  matrixIds[i] = i.toString();
  resolutions[i] = maxResolution / Math.pow(2, i);
}

const tileGrid = new WMTSTileGrid({
  origin: [-20037508, 20037508],
  resolutions: resolutions,
  matrixIds: matrixIds,
});

const ign_source = new WMTS({
  url: 'https://data.geopf.fr/wmts',
  layer: 'GEOGRAPHICALGRIDSYSTEMS.PLANIGNV2',
  matrixSet: 'PM',
  format: 'image/png',
  projection: 'EPSG:3857',
  tileGrid: tileGrid,
  style: 'normal',
  attributions:
    '<a href="https://www.ign.fr/" target="_blank">' +
    '<img src="https://data.geopf.fr/annexes/ressources/logos/ign.gif" title="Institut national de l\'' +
    'information géographique et forestière" alt="IGN"></a>',
});

const ign = new TileLayer({
  source: ign_source,
});

map.addLayer(ign);
index.html
html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>IGN WMTS</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": "wmts-ign",
  "dependencies": {
    "ol": "10.11.0"
  },
  "devDependencies": {
    "vite": "^8.1.5"
  },
  "scripts": {
    "start": "vite",
    "build": "vite build"
  }
}