gwttransformopenlayersprojectiongwt-openlayers

How to transform a GWT OpenLayers VectorFeature?


I am using OpenLayers GWT. I want to put an GeoJSON shape on top of a Google Maps layer. I have done as follows:

String gson = "{here I put a valid GeoJSON string}";
GeoJSON geoJSON = new GeoJSON();
VectorFeature[] vf = geoJSON.read(gson);
myShapeLayer.addFeature(vf[0]);

The shape is showing on the map, but not a the right position. I think I have to transform the Vector to EPSG:900913 but I don't know how to do that with the VectorFeature. There is no transform function to use. How can I apply the transformation to a GWT VectorFeature?

This question is not getting responses. I would like to explain better what I want to know:

In javascript Openlayers you can do:

var projWGS84 = new OpenLayers.Projection("EPSG:4326");
var proj900913 = new OpenLayers.Projection("EPSG:900913");

feature.geometry.transform(projWGS84, proj900913);

How can I do the same in the GWT version of OpenLayers?

Thanks in advance.


Solution

  • OpenLayers-GWT is missing the GeoJSON constructor that will take an options parameter, this has to be added in the OpenLayers-GWT source. In the mean time this has been added to the KML Vector class. So now you can do like this:

    String kmlString = "{<string with KML>}";
    FormatOptions formatOptions = new FormatOptions();
    formatOptions.setInternalProjection(new Projection("EPSG:900913"));
    formatOptions.setExternalProjection(new Projection("EPSG:4326"));
    KML kml = new KML(formatOptions);
    
    VectorFeature[] vf = KML.read(kmlString);
    myShapeLayer.addFeature(vf[0]);
    

    In the same way it should be added to the GeoJSON class to make the tranformation work.