UNPKG

1.22 kBJavaScriptView Raw
1goog.require('ol.Map');
2goog.require('ol.View');
3goog.require('ol.control');
4goog.require('ol.extent');
5goog.require('ol.layer.Tile');
6goog.require('ol.proj');
7goog.require('ol.source.OSM');
8
9
10var 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: /** @type {olx.control.AttributionOptions} */ ({
19 collapsible: false
20 })
21 }),
22 view: new ol.View({
23 center: [0, 0],
24 zoom: 2
25 })
26});
27
28function display(id, value) {
29 document.getElementById(id).value = value.toFixed(2);
30}
31
32function wrapLon(value) {
33 var worlds = Math.floor((value + 180) / 360);
34 return value - (worlds * 360);
35}
36
37function 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
50map.on('moveend', onMoveEnd);