Snippets

Piotr Szrajber Smart M.App - zoom to bbox

Created by Piotr Szrajber
function zoomToBBox (bottomLeftCorner, topRightCorner, callback, errback) {
    // transform sample points to current CRS
    gsp.crs.transform({
        points: [bottomLeftCorner, topRightCorner],
        sourceCrsId: "EPSG:4326",
        targetCrsId: gsp.crs.getCurrent()
    }, 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];
        gsp.map.zoom({
            bbox: bbox
        });
    });
}

// example usage
zoomToBBox({x: -179.9999, y: -89.9999 }, { x: 179.9999, y: 89.9999 });

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.