【发布时间】:2016-04-19 13:09:18
【问题描述】:
对于我的项目,每当我点击地图时,我想用 x 和 y 坐标填充一个文本框。我用这个标准代码在我的屏幕上显示了坐标:
var mousePositionControl = new ol.control.MousePosition({
className: 'custom-mouse-position',
target: document.getElementById('location'),
coordinateFormat: ol.coordinate.createStringXY(5),
undefinedHTML: ' '
});
所以我想:如果我使用 mousePositionControl 作为 x 和 y 坐标的变量,我会在文本框中得到它。所以我尝试了这个:
map.on('click', function() {
document.getElementById("coördinates").value = mousePositionControl;
});
但我在文本框中得到的结果是:[object Object]
有人可以帮我解决这个问题吗?
【问题讨论】:
-
ol.control.MousePosition类型对象的字符串表示形式是“[object Object]”,因此代码完全按照您的要求执行。click处理程序接收event对象,该对象已包含单击像素的坐标,因此无需涉及控件。 -
是元素
location,显示x和y。为什么元素coördinates需要第二次获取x和y? -
附带说明,“coördinates”和“coöperate”在英文中分别写为“coordinates”和“cooperate”。
标签: openlayers-3