UNPKG

openlayers

Version:

Build tools and sources for developing OpenLayers based mapping applications

47 lines (42 loc) 1.32 kB
goog.require('ol.Map'); goog.require('ol.View'); goog.require('ol.control'); goog.require('ol.control.MousePosition'); goog.require('ol.coordinate'); goog.require('ol.layer.Tile'); goog.require('ol.source.OSM'); var mousePositionControl = new ol.control.MousePosition({ coordinateFormat: ol.coordinate.createStringXY(4), projection: 'EPSG:4326', // comment the following two lines to have the mouse position // be placed within the map. className: 'custom-mouse-position', target: document.getElementById('mouse-position'), undefinedHTML: ' ' }); var map = new ol.Map({ controls: ol.control.defaults({ attributionOptions: { collapsible: false } }).extend([mousePositionControl]), layers: [ new ol.layer.Tile({ source: new ol.source.OSM() }) ], target: 'map', view: new ol.View({ center: [0, 0], zoom: 2 }) }); var projectionSelect = document.getElementById('projection'); projectionSelect.addEventListener('change', function(event) { mousePositionControl.setProjection(event.target.value); }); var precisionInput = document.getElementById('precision'); precisionInput.addEventListener('change', function(event) { var format = ol.coordinate.createStringXY(event.target.valueAsNumber); mousePositionControl.setCoordinateFormat(format); });