【问题标题】:OpenLayers: how to change format of MousePosition coordinates to HDMS?OpenLayers:如何将 MousePosition 坐标的格式更改为 HDMS?
【发布时间】:2021-07-23 18:27:53
【问题描述】:

我正在使用 MousePosition 控件来显示鼠标移动时的坐标,但我显示的输出类似于:'7.85, 47.98' 但我想要这样的输出:'47° 58' 60.0″ N 7° 50' 60.0 " E'。

JS

var mouseposition = new ol.control.MousePosition({
            projection: 'EPSG:4326',
            coordinateFormat: ol.coordinate.createStringXY(2),
            undefinedHTML: '',
            className: 'ol-mouse-position ol-control'
        });
        map.addControl(mouseposition);

我试过用toStringHDMS()但是不是我想要的格式,不知道是不是我用错了

var mouseposition = new ol.control.MousePosition({
            projection: 'EPSG:4326',
            coordinateFormat: ol.coordinate.toStringHDMS(),
            undefinedHTML: '',
            className: 'ol-mouse-position ol-control'
        });
        map.addControl(mouseposition);

在此示例中,输出为:-46.20849609375,-23.595295498937958

【问题讨论】:

    标签: coordinates gis openlayers format-string


    【解决方案1】:

    使用

    coordinateFormat: ol.coordinate.toStringHDMS,
    

    没有()

    createStringXY() 是一个返回 CoordinateFormat 函数的函数

    toStringHDMS 已经是一个 CoordinateFormat 函数

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多