UNPKG

1.32 kBJavaScriptView Raw
1goog.require('ol.Map');
2goog.require('ol.View');
3goog.require('ol.control');
4goog.require('ol.control.MousePosition');
5goog.require('ol.coordinate');
6goog.require('ol.layer.Tile');
7goog.require('ol.source.OSM');
8
9var mousePositionControl = new ol.control.MousePosition({
10 coordinateFormat: ol.coordinate.createStringXY(4),
11 projection: 'EPSG:4326',
12 // comment the following two lines to have the mouse position
13 // be placed within the map.
14 className: 'custom-mouse-position',
15 target: document.getElementById('mouse-position'),
16 undefinedHTML: ' '
17});
18
19var map = new ol.Map({
20 controls: ol.control.defaults({
21 attributionOptions: {
22 collapsible: false
23 }
24 }).extend([mousePositionControl]),
25 layers: [
26 new ol.layer.Tile({
27 source: new ol.source.OSM()
28 })
29 ],
30 target: 'map',
31 view: new ol.View({
32 center: [0, 0],
33 zoom: 2
34 })
35});
36
37var projectionSelect = document.getElementById('projection');
38projectionSelect.addEventListener('change', function(event) {
39 mousePositionControl.setProjection(event.target.value);
40});
41
42var precisionInput = document.getElementById('precision');
43precisionInput.addEventListener('change', function(event) {
44 var format = ol.coordinate.createStringXY(event.target.valueAsNumber);
45 mousePositionControl.setCoordinateFormat(format);
46});