1 | goog.require('ol.Map');
|
2 | goog.require('ol.View');
|
3 | goog.require('ol.control');
|
4 | goog.require('ol.extent');
|
5 | goog.require('ol.layer.Tile');
|
6 | goog.require('ol.proj');
|
7 | goog.require('ol.source.OSM');
|
8 |
|
9 |
|
10 | var map = new ol.Map({
|
11 | layers: [
|
12 | new ol.layer.Tile({
|
13 | source: new ol.source.OSM()
|
14 | })
|
15 | ],
|
16 | target: 'map',
|
17 | controls: ol.control.defaults({
|
18 | attributionOptions: ({
|
19 | collapsible: false
|
20 | })
|
21 | }),
|
22 | view: new ol.View({
|
23 | center: [0, 0],
|
24 | zoom: 2
|
25 | })
|
26 | });
|
27 |
|
28 | function display(id, value) {
|
29 | document.getElementById(id).value = value.toFixed(2);
|
30 | }
|
31 |
|
32 | function wrapLon(value) {
|
33 | var worlds = Math.floor((value + 180) / 360);
|
34 | return value - (worlds * 360);
|
35 | }
|
36 |
|
37 | function onMoveEnd(evt) {
|
38 | var map = evt.map;
|
39 | var extent = map.getView().calculateExtent(map.getSize());
|
40 | var bottomLeft = ol.proj.transform(ol.extent.getBottomLeft(extent),
|
41 | 'EPSG:3857', 'EPSG:4326');
|
42 | var topRight = ol.proj.transform(ol.extent.getTopRight(extent),
|
43 | 'EPSG:3857', 'EPSG:4326');
|
44 | display('left', wrapLon(bottomLeft[0]));
|
45 | display('bottom', bottomLeft[1]);
|
46 | display('right', wrapLon(topRight[0]));
|
47 | display('top', topRight[1]);
|
48 | }
|
49 |
|
50 | map.on('moveend', onMoveEnd);
|