openLayers mousePosition 返回光标位置的坐标 x,y。
var mousePosition = new ol.control.MousePosition({
undefinedHTML: ' ',
projection: 'EPSG:4326',
coordinateFormat: function(coordinate) {
return ol.coordinate.format(coordinate, '{x}, {y}', 6);
},
className: 'ol-mouse-position',
target: document.getElementById('myposition'),
});
提取经度和纬度并使用这两个值在表单中显示的最简单方法是什么?坐标格式的结构是什么?
最佳答案
坐标值是一个普通的 JavaScript 数组。您可以像这样访问值:
var x = coordinate[0];
var y = coordinate[1];
请参阅API docs on Coordinate了解更多详情。
关于javascript - 如何从 OpenLayers 坐标中分离经度和纬度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60148228/