[GIS] Howto change OpenLayers BBOX request projection

coordinate systemopenlayers-2

My map uses EPSG:900913 projection on the map.
All coördinates in the database are stored in the 'normal' google format / GPS coordinates (WGS84). For instance, if you save a new location..Before I submit coordinates back to the server they get transformed like

mapPosition = OpenLayers.Projection.transform({
        x: lon,
        y: lat
    }, new OpenLayers.Projection("EPSG:900913"), new OpenLayers.Projection("EPSG:4326"));

The OpenLayers BBOX strategy makes request like:

?bbox=497590.72212427,6707253.6848049,748304.17486475,6814265.5243893,EPSG:900913

How do I change this so the server gets the bounding coordinates in ESPG:4326??
That would be much better then transforming the coordinates serverside.

EDIT
I tried to create a function that appends an extra set of bounds to the request URL:

this.layer = new OpenLayers.Layer.Vector("POI",{
        strategies: [new OpenLayers.Strategy.BBOX({resFactor: 1})],
        protocol: new OpenLayers.Protocol.Script({
            url: 'http://localhost/tests/poi', //this.get_poi_url,
            params: {
                bounds: this.get_poi_url()
            },
            callbackKey: 'jsoncallback',
            srsInBBOX: true
        }),
    });
    tbMap.map.addLayers([this.layer]);

and the function:

get_poi_url: function(bounds) {
    var bounds = tbMap.map.getExtent();
    console.log(bounds);
    bounds = bounds.clone().transform(
        config.projection, config.displayProjection
    );
    console.log(bounds); // OK, it works, I want these coordinates
    var url = ""
        + bounds.top + ','
        + bounds.left + ','
        + bounds.bottom + ','
        + bounds.right;
    return url;
}

The problem is that this set of extra parameters (or if I would build the URL like this) doesn't get an update since it is set with the layer creation. So If you move the map, it would still transmit the original bounds.

Best Answer

I've chosen to override the OL BBOX calculate bounds function.

strategies: [
        new OpenLayers.Strategy.BBOX({
            resFactor: 2,
            active: false,
            autoActivate: false,
            ratio: 1.3,
            noAbort: true
        }), 

and later...

    this.layer.strategies[0].calculateBounds = this.myCalculateBounds;
    this.layer.strategies[0].activate();

and ofcourse the function, it just adds the transformation right on the end.

myCalculateBounds: function(mapBounds) {
    if(!mapBounds) {
        mapBounds = this.getMapBounds();
    }
    var center = mapBounds.getCenterLonLat();
    var dataWidth = mapBounds.getWidth() * this.ratio;
    var dataHeight = mapBounds.getHeight() * this.ratio;
    this.bounds = new OpenLayers.Bounds(
        center.lon - (dataWidth / 2),
        center.lat - (dataHeight / 2),
        center.lon + (dataWidth / 2),
        center.lat + (dataHeight / 2)
    );
    this.bounds = this.bounds.clone().transform(
        config.projection, config.displayProjection
    );
},