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:


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

and the function:

get_poi_url: function(bounds) {
    var bounds = tbMap.map.getExtent();
    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.

2 Answers 2


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;

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

If you catch the map pan/zoom events then you could update the request parameters for the layer as the user moves round the map. You would have to check that these events get fired before the request is sent though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.