[GIS] Map projection in OpenLayers

coordinate systemgoogle mapsopenlayers-2wgs84

I want to overlay some data whose projection is WGS-84 on Google map layer in OpenLayers. But I just can't make them in the right place. I did as follows:

map = new OpenLayers.Map('map', {           
        numZoomLevels: 20,
        projection: new OpenLayers.Projection("EPSG:900913"),
        displayProjection: new OpenLayers.Projection("EPSG: 4326")
        });
googlelayer = new OpenLayers.Layer.Google("Google street", {sphericalMercator: true});
map.addLayer(googlelayer);
veclayer = new OpenLayers.Layer.Vector("vector", {
                                    projection: map.displayProjection
                                    };
var geojson_format = new OpenLayers.Format.GeoJSON();
veclayer.addFeatures(geojson_format.read(jsonData));

Though I have assigned veclayer in 4326 projection, but it is still interpreted as 900913, and the display coordination system is also 900913, though I set displayProjection to 4326. What mistake do I make?

Best Answer

I'm a big fan of "preFeatureInsert"....

var veclayer = new OpenLayers.Layer.Vector("vector", {
           projection: map.displayProjection,
           preFeatureInsert: function(feature) {
           feature.geometry.transform(projWGS84,proj900913);
           }
        });