I would like to change the output text inside the target attribute ol.control.MouseControl (openlayers 3.15.1). Now the code shows only the value of longitude and latitude. I want to add the string "long" and "lat" before a single value: for example lat: 12.543, long: 14.567. How can i do this?
var regStyle = new ol.style.Style ({
fill: new ol.style.Fill({
color: 'rgba(127,129,112,0.1)'
}),
stroke: new ol.style.Stroke({
color: 'green', width: 2})
});
var reg = new ol.layer.Vector({
source: new ol.source.Vector({
url: 'http://localhost:8080/Project_first/assets/geojson/regioni.geojson',
format: new ol.format.GeoJSON(),
projection: 'EPSG:3857'
}),
style: regStyle
});
var prov = new ol.layer.Vector({
source: new ol.source.Vector({
url: 'http://localhost:8080/Project_first/assets/kml/province.kml',
format: new ol.format.KML(),
projection: 'EPSG:3857'
})
});
var base_layer = new ol.layer.Tile({
source: new ol.source.OSM()
});
var italy = ol.proj.fromLonLat([14.334, 40.965])
var view = new ol.View({
center: italy,
zoom: 6,
});
var scale = new ol.control.ScaleLine({
className: 'ol-scale-line',
target: document.getElementById('scale-line')
});
var mousePositionControl = new ol.control.MousePosition({
coordinateFormat: ol.coordinate.createStringXY(2),
projection: 'EPSG:3857',
className: 'custom-mouse-position',
target: document.getElementById('mouse-position'),
undefinedHTML: ' '
});
var scale = new ol.control.ScaleLine();
var map = new ol.Map({
controls: ol.control.defaults({
attributionOptions: ({ collapsible: false })
}).extend([mousePositionControl, scale]),
target: 'map',
layers: [base_layer, prov,reg],
view: view
});
function initMap()
{
GEvent.addListener(map, "click", function(overlay, latLng)
{
document.getElementById("lat").value = latLng.lat();
document.getElementById("lng").value = latLng.lng();
});
}
source
share