原文链接及内容

通过使用fromEPSGCode()
方法,使COG能够在不同投影中的另一个图层上渲染的示例。
main.js
代码如下:
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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| import GeoTIFF from 'ol/source/GeoTIFF.js'; import Map from 'ol/Map.js'; import TileLayer from 'ol/layer/WebGLTile.js'; import XYZ from 'ol/source/XYZ.js'; import proj4 from 'proj4'; import { epsgLookupMapTiler, fromEPSGCode, register, setEPSGLookup, } from 'ol/proj/proj4.js';
const key = 'Get your own API key at https://www.maptiler.com/cloud/'; const attributions = '<a href="https://www.maptiler.com/copyright/" target="_blank">© MapTiler</a> ' + '<a href="https://www.openstreetmap.org/copyright" target="_blank">© OpenStreetMap contributors</a>';
register(proj4); setEPSGLookup(epsgLookupMapTiler(key));
const cogSource = new GeoTIFF({ sources: [ { url: 'https://mikenunn.net/data/MiniScale_(std_with_grid)_R23.tif', nodata: 0, }, ], });
cogSource.setAttributions( 'Contains OS data © Crown Copyright and database right ' + new Date().getFullYear() );
const map = new Map({ target: 'map', layers: [ new TileLayer({ source: new XYZ({ attributions: attributions, url: 'https://api.maptiler.com/tiles/satellite/{z}/{x}/{y}.jpg?key=' + key, maxZoom: 20, crossOrigin: '', }), style: {exposure: 0.2}, }), new TileLayer({ source: cogSource, opacity: 0.7, style: {gamma: 0.7}, }), ], view: cogSource .getView() .then((viewConfig) => fromEPSGCode(viewConfig.projection.getCode()).then(() => viewConfig) ), });
|
界面布局文件index.html
代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>COG with Projection Lookup</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>
|