What i want to do here is to create a vector layer (using openlayers) from a GeoServer JSON Response. Actually i'm doing this:
var url = "http://"+ip+":"+puerto+"/geoserver/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=tiger:poi&outputFormat=text/javascript&format_options=callback:getJson";
jQuery.ajax({
jsonp: false,
jsonpCallback: 'getJson',
type: 'GET',
url: url,
async: false,
dataType: 'jsonp',
success: function(jsonObject) {
alert(jsonObject);
//handler(jsonObject);
create_GeoJSON(jsonObject);
}
});
With the code above (after a long time of headaches with cross domain issues) we can retrieve data from GeoServer (through WFS) using JSONP.
The function below handles the response, tries to create the vector layer and put that vector over the map, using GeoJSON.
function create_GeoJSON(json){
var in_options = {
'internalProjection': window.map.projection,
'externalProjection': window.map.projection
};
var jsonString = JSON.stringify(json);
var geojson_format = new OpenLayers.Format.GeoJSON(in_options);
var vector_layer = new OpenLayers.Layer.Vector("Consulados");
vector_layer.addFeatures(geojson_format.read(jsonString, "FeatureCollection"));
window.map.addLayer(vector_layer); }
Now, the problem is that the map isn't showing the layer components properly. As you can see i only see a point (or maybe a lot of superposed) drawed over the (0,0). This seems to be an issue related with the coordinates, projections or something like that.
By the way, here is the map init:
var options = {
projection: "EPSG:900913",
displayProjection: "EPSG:4326",
controls: [],
};
window.map = new OpenLayers.Map('map_canvas', options);
What you think about that? I "waste" a lot of time over this right now and still don't have a solution.
Thanks.
PS: Feel free to edit the post, my english is a little poor.