本文介绍了Openlayers中的投影和OpenLayers.Geometry.Point的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试显示具有三层(谷歌地图层,wms层和点层)的地图,这是我的代码:

I'm trying to show a map with three layers (google maps layers, wms layer and points layer) this is my code:

     var map = new OpenLayers.Map({
         div: "map",
         maxExtent: new OpenLayers.Bounds(-20037508, -20037508, 20037508, 20037508.34)
     });


     var capaGoogle = new OpenLayers.Layer.Google(
                "Google Satellite",
                { type: G_SATELLITE_MAP, sphericalMercator: true, transparent: true }
            );

     var wmsOverlay = new OpenLayers.Layer.WMS("OpenLayers WMS",
         "http://localhost:1979/geoserver/wms",
         { layers: 'world:PYCIUDADES', transparent: true }, { isBaseLayer: false });


     var vectorLayer = new OpenLayers.Layer.Vector("vector");

     vectorLayer.addFeatures([
        new OpenLayers.Feature.Vector(
            new OpenLayers.Geometry.Point(-57.635021, -25.276987)

        ),
        new OpenLayers.Feature.Vector(
            new OpenLayers.Geometry.Point(-56.759034, -22.71539)
        )

        ]

    );

     map.addLayers([wmsOverlay, vectorLayer, capaGoogle]);

     map.addControl(new OpenLayers.Control.LayerSwitcher());
     var center = new OpenLayers.LonLat(-57.58, -25.27).transform(
     new OpenLayers.Projection("EPSG:4326"),
     map.getProjectionObject()
     )
     map.setCenter(center, 6);

"vectorLayer"图层必须在地图上方,但是我知道了(我的wms图层在南美洲,我的点也必须在南美洲,但是它们在非洲附近):

the "vectorLayer" layer must be above of my map, but I get this (my wms layer is in south america, my points have to be also in south america, but they're near africa):

http://i45.tinypic.com/34y40zk.png

我该怎么办?

预先感谢

推荐答案

您应该变换点的坐标:

var epsg4326 = new OpenLayers.Projection('EPSG:4326');
var epsg900913 = new OpenLayers.Projection('EPSG:900913');

vectorLayer.addFeatures([
    new OpenLayers.Feature.Vector(
        new OpenLayers.Geometry.Point(-57.635021, -25.276987).transform(epsg4326, epsg900913)
    ),
    new OpenLayers.Feature.Vector(
        new OpenLayers.Geometry.Point(-56.759034, -22.71539).transform(epsg4326, epsg900913)
    )
]);

这篇关于Openlayers中的投影和OpenLayers.Geometry.Point的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 19:51