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
|
const mapInfo = { map: null, extent: null, projection: null, setProjection: function (w, h) { this.extent = [0, 0, w, h]; this.projection = new ol.proj.Projection({ code: 'pixel', units: 'pixels', extent: this.extent, }); }, init: function (imageName) { const view = new ol.View({ projection: this.projection, center: ol.extent.getCenter(this.extent), zoom: 2, maxZoom: 8, });
const imageLayer = new ol.layer.Image({ source: new ol.source.ImageStatic({ url: 'images/' + imageName, imageSize: [this.extent[2], this.extent[3]], projection: this.projection, imageExtent: this.extent, }), });
this.map = new ol.Map({ target: 'map', layers: [imageLayer], view: view, });
this.zoomFit(); }, zoomFit: function () { this.map.getView().fit(this.extent, { duration: 200 }); }, };
document.addEventListener('DOMContentLoaded', function () { const width = 500; const height = 500; const imageName = 'image.png';
mapInfo.setProjection(width, height); mapInfo.init(imageName); });
|