import Map from 'ol/Map'; import View from 'ol/View'; import {getWidth, getTopLeft} from 'ol/extent'; import TileLayer from 'ol/layer/Tile'; import {get as getProjection} from 'ol/proj'; import OSM from 'ol/source/OSM'; import WMTS from 'ol/source/WMTS'; import WMTSTileGrid from 'ol/tilegrid/WMTS'; const projection = getProjection('EPSG:3857'); const projectionExtent = projection.getExtent(); const size = getWidth(projectionExtent) / 256; const resolutions = new Array(14); const matrixIds = new Array(14); for (let z = 0; z < 14; ++z) { // generate resolutions and matrixIds arrays for this WMTS resolutions[z] = size / Math.pow(2, z); matrixIds[z] = z; } const map = new Map({ layers: [ new TileLayer({ source: new OSM(), opacity: 0.7 }), new TileLayer({ opacity: 0.7, source: new WMTS({ attributions: 'Tiles © ArcGIS', url: 'https://services.arcgisonline.com/arcgis/rest/' + 'services/Demographics/USA_Population_Density/MapServer/WMTS/', layer: '0', matrixSet: 'EPSG:3857', format: 'image/png', projection: projection, tileGrid: new WMTSTileGrid({ origin: getTopLeft(projectionExtent), resolutions: resolutions, matrixIds: matrixIds }), style: 'default', wrapX: true }) }) ], target: 'map', view: new View({ center: [-11158582, 4813697], zoom: 4 }) });