Javascript 如何使用openlayers3在文本框上显示映射鼠标悬停值?
我正在处理ol3,我有下面的鼠标悬停代码,它获取纬度和经度,然后将它们扔到id为“鼠标位置”的DIV上:Javascript 如何使用openlayers3在文本框上显示映射鼠标悬停值?,javascript,openlayers-3,Javascript,Openlayers 3,我正在处理ol3,我有下面的鼠标悬停代码,它获取纬度和经度,然后将它们扔到id为“鼠标位置”的DIV上: var mousePositionControl = new ol.control.MousePosition({ coordinateFormat: ol.coordinate.createStringXY(4), projection: 'EPSG:4326', // comment the following two lines to have the mouse posi
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: ' '
});
相应的html div是:
<div class="span6" id="mouse-position"> </div>
问题:我想在文本框上显示这些纬度/经度值,而不是简单地在div上显示它们
我简单地将目标字段中的div id更改为textbox的id,但它不起作用!我还使用了value属性,但找不到解决方案。我期待您的建议,非常感谢您抽出时间
注意:上述代码片段的完整代码可在以下链接中找到:
如果textbox指的是textarea,那么这将不起作用。Textarea需要一个值,而不是像innerHTML那样的值。尝试以下方法获取坐标:
var corde = document.getElementsByClassName("custom-mouse-position");
var resultElement=corde[0].innerHTML
然后将此值设置为文本框