I finally managed to do my JSON call once and then fill all my necessary layers. Here are the basic aspects in code:
var wgs84 = new OpenLayers.Projection("EPSG:4326");
var mercator = new OpenLayers.Projection("EPSG:900913");
function init() {
function Incorporate_Data(r) { /* Function inside init() */
var x=r.priv.responseText;
var arr=[ stations, temperatures, visibility, clouds ]; /* ARRAY OF MAP LAYERS TO BE FILLED */
var j=new OpenLayers.Format.GeoJSON({'internalProjection':mercator,'externalProjection':wgs84});
for(i in arr) {
arr[i].destroyFeatures();
arr[i].addFeatures(j.read(x));
}
}
/* define mapoptions here */
var map=new OpenLayers.Map(mapoptions);
/* define some base layer here */
var mainstyle=new OpenLayers.Style();
/* define mainstyle and more styles here */
var myStyles=new OpenLayers.Stylemap({"default":mainstyle});
/* define more stylemaps here */
var temperatures=new OpenLayers.Layer.Vector("TEMPERATURES", styleMap: tempStyles, renderers: ["Canvas"]});
/* define more of the layers here (such as visibility and clouds) */
var stations=new OpenLayers.Layer.Vector("STATIONS", {
strategies: [
new OpenLayers.Strategy.Refresh({interval:30000}),
new OpenLayers.Strategy.BBOX(),
new OpenLayers.Strategy.Fixed()], stylemap:myStyles,
protocol: new OpenLayers.Protocol.HTTP({
url: "http://localhost:8080/wxproj/wx-json.php",
format: new OpenLayers.Format.GeoJSON({'internalProjection':mercator,'externalProjection':wgs84}),
async:true,
handleResponse: Incorporate_Data}),
renderers: ["Canvas"]});
map.addLayers([baselayer, stations, temperature, visibility, clouds]);
map.setCenter(center,zoom);
}//init()
Although I think that there can be more efficient code, I hope that this works fine.
I want to answer if it possible to keep the Incorporate_Data() function out of the init() function, and if the strategies for stations can be reduced.
Any comments welcome.
It really depends on how you want to use the data once you have it in MongoDB. From the sounds of it, you will likely want to have a single MongoDB collection with a document for each feature.
This will allow you to use indexes and queries utilizing those indexes, most notably the 2dsphere index on the GeoJSON itself. There may be ways of doing that with a single document, but I don't think that makes much sense in this case.
Another thing to point out is that MongoDB is really only concerned with the geometry portion of the GeoJSON (for 2dsphere indexes). As you pointed out the FeatureCollection in the GeoJSON is mostly analogous to a collection in MongoDB. You could use the full hierarchy, but it's not required and may not make sense in some cases.
Best Answer
GeoTools is a Java library which can read and write GeoJSON and provides access to features like area via the JTS library. It will also help you to reproject the geometries from the lat/lon of GeoJSON to a suitable projection for calculating areas in m^2.