1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| import MVT from 'ol/format/MVT.js'; import Map from 'ol/Map.js'; import VectorTileLayer from 'ol/layer/VectorTile.js'; import VectorTileSource from 'ol/source/VectorTile.js'; import View from 'ol/View.js';
const map = new Map({ target: 'map', view: new View({ center: [0, 0], zoom: 2, }), layers: [ new VectorTileLayer({ source: new VectorTileSource({ format: new MVT(), url: 'https://basemaps.arcgis.com/arcgis/rest/services/World_Basemap_v2/VectorTileServer/tile/{z}/{y}/{x}.pbf', }), }), ], });
map.on('pointermove', showInfo);
const info = document.getElementById('info'); function showInfo(event) { const features = map.getFeaturesAtPixel(event.pixel); if (features.length == 0) { info.innerText = ''; info.style.opacity = 0; return; } const properties = features[0].getProperties(); info.innerText = JSON.stringify(properties, null, 2); info.style.opacity = 1; }
|