49 lines
1.2 KiB
JavaScript
49 lines
1.2 KiB
JavaScript
import _ol_Map_ from '../src/ol/Map.js';
|
|
import _ol_View_ from '../src/ol/View.js';
|
|
import _ol_control_ from '../src/ol/control.js';
|
|
import * as _ol_extent_ from '../src/ol/extent.js';
|
|
import _ol_layer_Tile_ from '../src/ol/layer/Tile.js';
|
|
import {toLonLat} from '../src/ol/proj.js';
|
|
import _ol_source_OSM_ from '../src/ol/source/OSM.js';
|
|
|
|
|
|
var map = new _ol_Map_({
|
|
layers: [
|
|
new _ol_layer_Tile_({
|
|
source: new _ol_source_OSM_()
|
|
})
|
|
],
|
|
target: 'map',
|
|
controls: _ol_control_.defaults({
|
|
attributionOptions: {
|
|
collapsible: false
|
|
}
|
|
}),
|
|
view: new _ol_View_({
|
|
center: [0, 0],
|
|
zoom: 2
|
|
})
|
|
});
|
|
|
|
function display(id, value) {
|
|
document.getElementById(id).value = value.toFixed(2);
|
|
}
|
|
|
|
function wrapLon(value) {
|
|
var worlds = Math.floor((value + 180) / 360);
|
|
return value - (worlds * 360);
|
|
}
|
|
|
|
function onMoveEnd(evt) {
|
|
var map = evt.map;
|
|
var extent = map.getView().calculateExtent(map.getSize());
|
|
var bottomLeft = toLonLat(_ol_extent_.getBottomLeft(extent));
|
|
var topRight = toLonLat(_ol_extent_.getTopRight(extent));
|
|
display('left', wrapLon(bottomLeft[0]));
|
|
display('bottom', bottomLeft[1]);
|
|
display('right', wrapLon(topRight[0]));
|
|
display('top', topRight[1]);
|
|
}
|
|
|
|
map.on('moveend', onMoveEnd);
|