0

I have a database with cities and values for: bb_left, bb_top, bb_right, bb_bottom, locate_x, and locate_y.

Here's an example:

city    -   bb_left -   bb_top  -   bb_right    -   bb_bottom   -   locate_x    -   locate_y
geneve  -   493485  -   124865  -   506522      -   110870      -   499910      -   117983

The data was used for an older application using OpenLayers 2 which supports a bounding box containing just 4 values, however in OpenLayers 3 - I must create an extent with co-ordinate points but I am unsure how to create the co-ords based on the bounding box data.

Is this even possible to convert ?

1

ol.Extent is simply an array of 4 numbers. But you can translate this extent to a polygon with the function ol.geom.Polygon.fromExtent. And this polygon can be used to create a feature, so that you can display the bounding-box.

var extent = [bb_left, bb_bottom, bb_right, bb_top];
var polygon = ol.geom.Polygon.fromExtent(extent);
var feature = new ol.Feature({
  geometry: polygon
});

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.