06-07-2016 07:59 AM - edited 06-07-2016 08:01 AM
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
06-07-2016 10:09 AM
This works great! Map redraws in the correct spot after portal loads.