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 60 61 62
| import './style.css'; import Map from 'ol/Map.js'; import OSM from 'ol/source/OSM.js'; import TileLayer from 'ol/layer/Tile.js' import TileWMS from 'ol/source/TileWMS.js'; import View from 'ol/View.js'; import XYZ from 'ol/source/XYZ.js';
const map = new Map({ target: 'map', layers: [ new TileLayer({ source: new XYZ({ url:"http://a.tile.osm.org/{z}/{x}/{y}.png" }), }), new TileLayer({ source: new XYZ({ tileLoadFunction: function(tile, src){ console.log(src) const xhr = new XMLHttpRequest(); xhr.responseType = 'blob'; xhr.addEventListener('loadend', function (evt) { const data = this.response; if (data !== undefined) { console.log(data) tile.getImage().src = URL.createObjectURL(data); } else { tile.setState(TileState.ERROR); } }); xhr.addEventListener('error', function () { tile.setState(TileState.ERROR); }); xhr.open('GET', src); xhr.setRequestHeader('authorization','eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3MzU1NzIzMjAsInVzZXJuYW1lIjoiYWRtaW4ifQ.ZjEfILBREJ7PNIK41GXWhH8giIWNbU1m46_suxYCRNg'); xhr.setRequestHeader('x-access-token','eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3MzU1NzIzMjAsInVzZXJuYW1lIjoiYWRtaW4ifQ.ZjEfILBREJ7PNIK41GXWhH8giIWNbU1m46_suxYCRNg'); xhr.send(); }, tileUrlFunction: function (tileCoord) { let z = tileCoord[0]; let x = tileCoord[1]; let y = Math.pow(2, z) - tileCoord[2] - 1; return "https://openmap.tech/dronecloudserver/drone/orthophoto/tiles/8508b43a778e436cb4f786d4706961e9/" + z + "/" + x + "/" + y; } }), }),
], view: new View({ projection: 'EPSG:4326', center: [120.143937453271,30.12599771681532], zoom: 18, }), });
|