WebGIS Discussions

Need a push in the right direction when configuring WebMap, Portal or SDI services? Looking for hints and tips, or just looking for Ideas and information? The WebGIS discussion board is where you start those discussions, connect and share information.
Showing results for 
Search instead for 
Do you mean 
Reply
Technical Evangelist
Posts: 1,408
Registered: ‎09-11-2015

Re: zoom to bounding box url for SDK

[ Edited ]

You can place it anywhere to a script which is loaded by the Portal, so e.g. HelloWorld.js, or other custom script. Of course do not embed any irrelevant code inside such as creating the Hello World button, I left it there by mistake.

 

This is the fully working code. I have rewritten the parameter getter because this one looks better :-)

 

window.onload = function () {
    zoomToBBox();
};

function getURLParameter(name) {
  return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search) || [null, ''])[1].replace(/\+/g, '%20')) || null;
}

function zoomToBBox() {
    bbox = getURLParameter("bounds");
    if (bbox == null) return;
    bbox = bbox.split(",");

    //sample points in EPSG:4326
    var bottomLeftCorner = { x: bbox[0], y: bbox[1] },
        topRightCorner = { x: bbox[2], y: bbox[3] };

    $GP.ui.info("zoming");
    $GP.crs.transform({
        points: [bottomLeftCorner, topRightCorner],
        sourceCrsId: "EPSG:4326", 
        targetCrsId: $GP.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];
        $GP.map.zoom({
            bbox: bbox
        }, function () {
            // display information
            $GP.ui.info($GP.utils.serialize($GP.map.info()));
        });
    });
}

Sample URL:

http://localhost/PortalSDK/Examples.aspx?gpw=830f37a6-60df-4bcc-adc1-ea7c68150710&bounds=-11,36,4,44

 

 

Jan Neumann
Post Sales Engineer Web Applications
Hexagon Geospatial

Regular Contributor
Posts: 239
Registered: ‎05-01-2016

Re: zoom to bounding box url for SDK

This works great!  Map redraws in the correct spot after portal loads.