Sombriks
Sombriks

Reputation: 3622

how to get the map bounds?

I'm migrating from leaflet and back then if i needed the map bound i used the following code:

var b = map.getBounds();
$scope.filtromapa.lat1 = b.getSouth();
$scope.filtromapa.lat2 = b.getNorth();
$scope.filtromapa.lng1 = b.getWest();
$scope.filtromapa.lng2 = b.getEast();

Those values where valid latitude/longitude positions therefore i could send it to my backend and query any position inside this area.

How can i do that using openlayers?

for now all i have is:

var b = map.getView().calculateExtent(map.getSize());

however the positions aren't valid latitude/longitude positions.

I'm using openlayers 3.19.1

Upvotes: 1

Views: 671

Answers (1)

Gabriele Petrioli
Gabriele Petrioli

Reputation: 196236

Following the answer at https://gis.stackexchange.com/questions/122250/how-to-get-the-feature-location-in-openlayers-v3 (and its assumptions)

var currentExtent = map.getView().calculateExtent(map.getSize()),
    TLpoint = ol.extent.getTopLeft( currentExtent ),
    BRpoint = ol.extent.getBottomRight( currentExtent ),
    TLcoords = ol.proj.transform( TLpoint, 'EPSG:3857', 'EPSG:4326' ),
    BRcoords = ol.proj.transform( BRpoint, 'EPSG:3857', 'EPSG:4326' );

Upvotes: 2

Related Questions