If you aren't rotating the map, you can get the bounding box of the map from the maps camera.
var bounds = map.getCamera().bounds;
This will be an array of numbers in the format [west, south, east, north]. You can then get the coordinates of the map by pairing up these values like [west, north] for top left corner. If the map is rotated, I believe this will capture some additional area that isn't in view as it would get the max north/south/east/west coordinates of the view.
If you want to handle rotation of the map and get the coordinates, what you can do is get the width and height of the map, and then calculate the screen coordinates of the corners of the map relative to the top left corner such that:
- top left = [0,0]
- top right = [width, 0]
- bottom left = [0, height]
- bottom right = [width, height]
Then take these and pass them into the maps pixelsToPositions function
Here is a code sample:
var mapRect = map.getCanvas().getBoundingClientRect();
var width = mapRect.width;
var height = mapRect.height;
var mapCornersPixels = [[0,0], [width, 0], [0, height], [width, height]]
var mapCornersPositions = map.pixelsToPositions(mapCornersPixels);
In the code above mapCornersPositions
will be an array of positions; top left, top right, bottom left, bottom right of the map.