OpenLayers 4获得西南坐标

问题描述 投票:-1回答:1

我正在将地图从谷歌地图迁移到openlayers,但我遇到了一些功能问题。

应用程序应创建一些应放置图像的叠加层。此图像必须位于特定位置。实施Google Maps api时,他们使用“getBounds”方法,然后在那里,您可以访问“getSouthWest”和“getNorthEast”方法。

从技术上讲,我需要对openlayer做同样的事情,但我不知道如何在那里访问类似的功能。这个文档很复杂,因为谷歌显示旧版本的功能。

在这一刻,我有这个

var extent = map.getView().calculateExtent(map.getSize());

最后一行只返回一个包含整个边界的数组。我需要知道如何从那里获得“西南”和“东北”的界限。

javascript google-maps openlayers
1个回答
2
投票

您需要转换范围的坐标

var extentEPSG4326 = ol.proj.transformExtent(map.getView().calculateExtent(), 'EPSG:3857', 'EPSG:4326');

console.log('Extent is an array of numbers with the following order: [minx, miny, maxx, maxy]', extentEPSG4326);

所以要获得西南坐标,

console.log('SouthWest', [extentEPSG4326[1], extentEPSG4326[0]])

所以要获得东北坐标,

console.log('NorthEast', [extentEPSG4326[3], extentEPSG4326[2]])
© www.soinside.com 2019 - 2024. All rights reserved.