Hexagon Geospatial
MENU

Developer Discussions

Discuss topics with other Hexagon Geospatial Power Portfolio developers and experts to get the most out of our products.
Showing results for 
Search instead for 
Do you mean 
Reply
Highlighted
Staff
Posts: 98
Registered: ‎02-10-2017

Zoom to BBox

Hi guys.

 

I'm facing a problem when trying to zoom to a given BBox.

You could reproduce this problem using the SDK examples - "How to make map zoom operation - zoom to bbox" - with a little modification.

The example show you this code:

 

//sample points in EPSG:4326
var bottomLeftCorner = { x: -11, y: 36 },
    topRightCorner = { x: 4, y: 44 };

// transform sample points to current CRS
$GP.crs.transform({
    points: [bottomLeftCorner, topRightCorner],
    sourceCrsId: "EPSG:4326",
    targetCrsId: "EPSG:3857"
}, function (transformationResult) {
    // get BBOX in form minx, miny, maxx, maxy
    var points = transformationResult.points,
        bbox = [points[0].x, points[0].y, points[1].x, points[1].y];
    $GP.map.zoom({
        bbox: bbox
    }, function () {
        // display information
        $GP.ui.info($GP.utils.serialize($GP.map.info()));
    });
});

You have to modify it to :

//sample points in EPSG:4326
var bottomLeftCorner = { x: -11, y: 36 },
    topRightCorner = { x: 4, y: 44 };

// transform sample points to current CRS
$GP.crs.setCurrent("EPSG:3857", $GP.crs.transform({
    points: [bottomLeftCorner, topRightCorner],
    sourceCrsId: "EPSG:4326",
    targetCrsId: "EPSG:3857"
}, function (transformationResult) {
    // get BBOX in form minx, miny, maxx, maxy
    var points = transformationResult.points,
        bbox = [points[0].x, points[0].y, points[1].x, points[1].y];
    $GP.map.zoom({
        bbox: bbox
    }, function () {
        // display information
        $GP.ui.info($GP.utils.serialize($GP.map.info()));
    });
}), this);

 And you also have to change, it could be in the settings panel, the current crs to 4326 (or any other that you want).

 

The problem: when we have the map in our desired CRS and we do a map zoom to a specified bbox, it all works well but if we need to change the crs before doing the map zoom it set a extend that isn't correct.

 

I already tried to notify the crsChanged event before doing the map zoom but the behavior is the same.

It seems that it needs to finish all the processing of the crs.setcurrent before doing anything else in the map because putting our map zoom code in the callback of setcurrent gives the erratic behavior that I mentioned.

 

Anyone has experienced this? Does anyone have a workaround for it?

 

TIA

Do you need immediate support?
Please submit a Ticket through our
Development Ticket Portal.