2

I have a dropdown list. On Selection, it will request extent of selected property to database (PostgreSQL). I am using PHP for server-side processing.

At client-side on console log gives extent output result (variable res):

[74.3965356273929, 75.2484319931094, 35.6450698628058, 34.776235256942]

Also I am sure that coordinates are float and not string using parseFloat() function. later I am passing that variable to OpenLayers.Bounds.

    var extent = new OpenLayers.Bounds(res);
    map.zoomToExtent(extent);

OpenLayers.Bounds gives following output:

OpenLayers.Bounds.OpenLayers.Class.initialize {left: 74.396535627393, bottom: 75.248431993109, right: 35.645069862806, top: 34.776235256942, left: null…}

Which is I guess correct. But Openlayers is not zooming to the provided extent and it is zooming to maximum zoom level at current map view only.

3
  • What projection is your map in? is it web Mercator(EPSG:3857)? Nov 18, 2013 at 11:52
  • its just a guess, but can you try to switch the order of the coordinates? like this: 34.776235256942, 74.3965356273929, 35.6450698628058, 75.2484319931094
    – ylka
    Nov 18, 2013 at 11:52
  • and is the left parameter really null? Nov 18, 2013 at 11:56

1 Answer 1

1

The order of attributes when you create an OpenLayers.Bounds object, you have to order the arguments like this: minx, miny, maxx, maxy.

See the following example:

http://jsfiddle.net/KfkwV/2/

1
  • That is the answer. worked like charm...
    – apaleja
    Nov 19, 2013 at 8:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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