如何在openlayers中向MGRS显示纬度和纬度的鼠标位置

How to show mouse position of latituds and logituds to MGRS in Openlayers3?

本文关键字:纬度 鼠标 位置 显示 MGRS openlayers 中向      更新时间:2023-09-26

我在我的项目中集成了openlayers3,它将鼠标位置显示为纬度和经度格式。我想要的是在MGRS格式中显示鼠标位置。如何做到这一点,请帮助。演示

MousePosition控件接受一个可选的coordinateFormat函数,该函数接受坐标作为参数并返回一个格式化字符串。

您可以自己编写或使用内置的。我不确定你所说的"GPS格式"是什么意思,但假设它是由ol.coordinate.toStringHDMS产生的以小时,分钟和秒为单位的经纬度。

var mousePositionControl = new ol.control.MousePosition({
  coordinateFormat: ol.coordinate.toStringHDMS,
  projection: 'EPSG:4326'
});