如何将范围从 EPSG 3857 转换为 EPSG 26331

How to convert extent from EPSG 3857 to EPSG 26331

我正在尝试通过 ol.proj.transformExtent(map.getView().calculateExtent(map.getSize()),[=12 将 3857 投影中的范围转换为 OpenLayers 中的 26331 投影=],'EPSG:26331')

您首先需要包含 proj4js 库

<script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.6.2/proj4.js"></script>

然后 EPSG:26331 proj4js 定义来自 https://epsg.io/26331

proj4.defs("EPSG:26331","+proj=utm +zone=31 +ellps=clrk80 +towgs84=-92,-93,122,0,0,0,0 +units=m +no_defs");
ol.proj.proj4.register(proj4);  // if you are using OpenLayers 5 or 6

var transformedExtent = ol.proj.transformExtent(map.getView().calculateExtent(map.getSize()),'EPSG:3857','EPSG:26331');