Javascript OpenLayers-获取几何体投影
如何在openlayers(2.12)中获得点或几何体的投影 例如: x=30.453789, y=35.637485==>EPSG:4326 及 x=3667550.3453, y=2205578.3453==>EPSG:900913Javascript OpenLayers-获取几何体投影,javascript,openlayers,gis,map-projections,Javascript,Openlayers,Gis,Map Projections,如何在openlayers(2.12)中获得点或几何体的投影 例如: x=30.453789, y=35.637485==>EPSG:4326 及 x=3667550.3453, y=2205578.3453==>EPSG:900913 非常感谢OpenLayers 2中的任何帮助,它是具有关联投影的底图。如果您的基础层是从SphereCalmercator继承的Google地图,则基础层将是EPSG:900913 aka。如果您的底图来自其他服务,则投影可能是WGS84 aka或其他投影 稍后
非常感谢OpenLayers 2中的任何帮助,它是具有关联投影的底图。如果您的基础层是从SphereCalmercator继承的Google地图,则基础层将是EPSG:900913 aka。如果您的底图来自其他服务,则投影可能是WGS84 aka或其他投影 稍后在代码中,您可能需要确定响应事件的点的投影,以便知道是否需要将它们投影到另一个坐标参照系。一种方法是:
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的发展,地图现在在WGS84中,不管它以前是什么
如果您还有其他问题,我建议您在问题中添加一些代码,以显示您正在尝试完成的任务。我无法通过lat-lon值获得点投影,但通过为将添加到图层的每个特征添加投影特性来解决它。我的代码是这样的:
var mapProjection = new OpenLayers.Projection("EPSG:900913");
var dbProjection = new OpenLayers.Projection("EPSG:4326");
layer.preFeatureInsert = function (feature) {
if (!feature.projection)
feature.projection = dbProjection;
if (feature.projection != mapProjection)
feature.geometry.transform(feature.projection, mapProjection);
//do something...
}
map.addLayer(layer);
在第一次使用中,特征投影设置为wgs84,然后转换为球形墨卡托。下次使用时,不要更改任何内容。这些看起来可能已经是EPSG:4326和EPSG:900913了。你是不是想走另一条路?也就是说,对于EPSG:900913,lat=30.453789,lon=35.637485,x=3667550.3453,y=2205578.3453,EPSG:4326?关于第一个:x=30.453789,y=35.637485-其中任何一个都可能是纬度值(别忘了,纬度是“y”方向的。)@jwd630:谢谢你的回答。我知道x和y值可能相似,但我想通过y和x(lat,lon)值得到点投影的类型。感谢您的回复,我用一个与您的代码类似的代码解决了这个问题,但我想通过x,y值确定点投影。我的baseLayer具有球形墨卡托,我在db中的对象具有wgs84投影。我在map.addLayers()函数中使用了layer.preFeatureInsert()函数。当一个特征添加到图层中时,我会手动为其创建投影特性。下次我检查时,如果需要,更改特征投影。。。