多边形转换
遍历点,转换后重新new一个Polygon对象
var s = [[547225.076059,3375153.970705],[547268.959189,3374903.376212],[547381.875693,3374854.140213],[547555.065457,3375144.238708],[547225.076059,3375153.970705]];
var ss = s.map((it, index) => {
// mark(it[0], it[1], 80, `${index+1}`);
return ol.proj.transform(it, SRS, 'EPSG:4326')
});
new Polygon([ss]);
如果发现 extent_
是四个无穷大的值,只需要调用一下 polygon.getExtent();
就可以计算出来并自动赋值。只要 flatCoordinates
是一维的number数组,并且 layout
正确识别为 "XY" 或者 "XYZ" 就可以了。
还可以使用 Polygon#transform
https://openlayers.org/en/latest/apidoc/module-ol_geom_Polygon-Polygon.html#transform
see
坐标系
// 3857 google
// 4326 WGS-84:是国际标准,GPS坐标(Google Earth使用、或者GPS模块)
// 2437 GCJ-02:中国坐标偏移标准,Google Map、高德、腾讯使用
// BD-09:百度坐标偏移标准,Baidu Map使用
坐标系转换
‘EPSG:4326’-经纬度坐标-WGS84
‘EPSG:3857’- xy坐标-web墨卡托
》》》:
1.var m_center=[116.35,39.9];//地图中心点-经纬度坐标
//经纬度转至xy
m_center = ol.proj.transform(m_center,‘EPSG:4326’, ‘EPSG:3857’ );
//反过来
2. var m_center=[12914838.35,4814529.9];//地图中心点-xy坐标
//经纬度转至经纬度
m_center = ol.proj.transform(m_center, ‘EPSG:3857’ ,‘EPSG:4326’);
ol3默认的坐标系为3857,即在创建ol.map的时候,若不指定projection,则默认为EPSG:3857
————————————————
版权声明:本文为CSDN博主「听风许诺」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_41591572/article/details/85263826
node端(webpack + ts)
import * as proj from '!ol/proj';
import { register } from '!ol/proj/proj4';
import proj4 from 'proj4';
import epsg from 'epsg';
function add_epsg(srsName) {
proj4.defs(srsName, epsg[srsName]);
register(proj4);
}
function transform(cood, from, to) {
add_epsg(from);
add_epsg(to);
return proj.transform(cood, from, to);
}
var result = transform([517036.801995, 3689221.295122], 'EPSG:4549', 'EPSG:4326');
console.log(result);
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】博客园2025新款「AI繁忙」系列T恤上架,前往周边小店选购
【推荐】凌霞软件回馈社区,携手博客园推出1Panel与Halo联合会员
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步