如何从OpenLayers坐标中分离经度和纬度

问题描述 投票:0回答:2

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 position coordinates extract openlayers
2个回答
2
投票

坐标值为纯JavaScript数组。您可以像这样访问值:

var x = coordinate[0];
var y = coordinate[1];

请参阅API docs on Coordinate了解更多详细信息。


0
投票

非常感谢!我当时觉得太复杂了。抱歉。我在这里用map.on('click', function(evt){var lonlat=(ol.proj.transform(evt.coordinate, 'EPSG:3857', 'EPSG:4326')); coordlon=(lonlat['0']).toFixed(6); coordlat=(lonlat['1']).toFixed(6); document.getElementById('lat').innerHTML=coordlat; document.getElementById('lon').innerHTML=coordlon;});再次感谢您的提示!

© www.soinside.com 2019 - 2024. All rights reserved.