Add ol.control.MousePosition.setProjection

This commit is contained in:
Frederic Junod
2013-05-06 11:46:48 +02:00
parent 153fea538a
commit 916dde0045
4 changed files with 36 additions and 23 deletions
+5 -1
View File
@@ -30,7 +30,11 @@
<div class="row-fluid">
<div class="span12">
<div id="map" class="map"></div>
<small id="mouse-position"></small>
<select id="projection">
<option value="EPSG:4326">EPSG:4326</option>
<option value="EPSG:3857">EPSG:3857</option>
</select>
<div style="display: inline-block;" id="mouse-position"></div>
</div>
</div>
+14 -11
View File
@@ -7,19 +7,18 @@ goog.require('ol.coordinate');
goog.require('ol.layer.TileLayer');
goog.require('ol.source.OSM');
var control = 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: '&nbsp;'
});
var map = new ol.Map({
controls: ol.control.defaults({}, [
new ol.control.MousePosition({
coordinateFormat: ol.coordinate.toStringHDMS,
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: '&nbsp;'
})
]),
controls: ol.control.defaults({}, [control]),
layers: [
new ol.layer.TileLayer({
source: new ol.source.OSM()
@@ -32,3 +31,7 @@ var map = new ol.Map({
zoom: 2
})
});
document.getElementById('projection').addEventListener('change', function() {
control.setProjection(this.value);
}, false);