如何在openlayers(2.12)中投影点或几何?
例如:
x = 30.453789, y = 35.637485 ==> EPSG:4326
和
x = 3667550.3453, y = 2205578.3453 ==> EPSG:900913
感谢任何帮助
答案 0 :(得分:2)
在OpenLayers 2中,它是具有关联投影的基本地图。如果您的基础图层是继承自SphericalMercator的Google地图,则基础图层将为EPSG:900913 aka EPSG:3857。如果你的基本地图来自其他一些服务,则投影可能是WGS84又名EPSG:4326,或者它可能是其他投影。
稍后在您的代码中,您可能需要确定您为响应事件而获得的点的投影,以便您知道是否需要将它们投影到另一个坐标参考框架。一种方法是:
WGS84 = new OpenLayers.Projection("EPSG:4326"),
...
// Register event handler
map_layers.point.events.on({
beforefeatureadded: recordCoord,
featuremodified: recordCoord,
afterfeaturemodified: recordCoord,
featureselected: recordCoord,
featureunselected: recordCoord,
vertexmodified: recordCoord
});
...
// Handler to capture map additions/modifications/etc.
function recordCoord(event) {
var layer = this,
geometry = event.feature.geometry,
map_loc = new OpenLayers.LonLat(geometry.x, geometry.y);
if (map.getProjection() !== WGS84.getCode()) {
map_loc.transform(map.getProjectionObject(), WGS84);
}
...
当recordCoord
继续进行时,map_loc现在在WGS84中,无论之前是什么。
如果您还有其他问题,我建议您在问题中添加一些代码,以显示您要完成的任务。
答案 1 :(得分:0)
我无法通过lat lon值获得点投影,但是通过为将添加到图层的每个要素添加投影属性来解决它。我的代码是这样的:
byte[]
在首次使用时,将投影设置为wgs84,然后转换为球形墨卡托。对于下次使用,不会改变任何东西。