openlayers4xy坐标转为经纬度坐标

1、引入坐标转换js库文件proj4.js,地址:http://www.bootcdn.cn/proj4js/;

2、加入需要的坐标参考的定义,两种方式:

    1)单个:

proj4.defs('WGS84', "+title=WGS 84 (long/lat) +proj=longlat +ellps=WGS84 +datum=WGS84 +units=degrees");

    2)多个(分两种):

proj4.defs([
  [
    'EPSG:4326',
    '+title=WGS 84 (long/lat) +proj=longlat +ellps=WGS84 +datum=WGS84 +units=degrees'],
  [
    'EPSG:4269',
    '+title=NAD83 (long/lat) +proj=longlat +a=6378137.0 +b=6356752.31414036 +ellps=GRS80 +datum=NAD83 +units=degrees'
  ]
]);
proj4.defs("EPSG:4610","+proj=longlat +a=6378140 +b=6356755.288157528 +units=dd +no_defs");

proj4.defs("EPSG:2360","+proj=tmerc +lat_0=0 +lon_0=108 +k=1 +x_0=36500000 +y_0=0 +a=6378140 +b=6356755.288157528 +units=m +no_defs");

3、使用ol的方法将xy坐标转换为经纬度坐标:

var c = '36548279.19';
var d = '2557986.78';
var xyCd = [c, d];
// 假如从4490的转到3度带的36度带位置,查询36度带处的参考为2360
 xyCd = ol.proj.transform(xyCd, new ol.proj.Projection({code:'EPSG:2360'}),
                    new ol.proj.Projection({code:'EPSG:4490'}));
好了,现在得到的坐标是经纬度的十进制坐标,xyCd的值为:[ 108.47132924412054, 23.12072825747068]。

你可能感兴趣的:(JavaScript,Openlayers)