Shared Samples

WebGIS enables powerful geospatial web applications and services that securely share your organization’s rich geospatial data, and provides tools to deeply examine spatial data and create value added products, on demand.
Showing results for 
Search instead for 
Do you mean 

Examples: Zoom To BBox Url

by Technical Evangelist on ‎09-09-2015 04:11 AM (2,923 Views)

Description

By default the product ignores thebbox parameter when thegpw orgpm parameters are used or there is some issue. To force zooming to abbox passed in the URL you can use the following function
function zoomToBBox() {
    var match = location.href.match(/bbox=((?:\d+(?:\.\d+)?)(?:,(?:\d+(?:\.\d+)?)){3})/i),
        bboxString = match[1],
        bbox = !!bboxString ? bboxString.split(",") : undefined;
    if (!bbox || bbox.length != 4) return;
    bbox = bbox.map(function (item) {
        return +item;
    }); // convert to numbers
    var config = {
        minX: bbox[0],
        minY: bbox[1],
        maxX: bbox[2],
        maxY: bbox[3],
        options: {
            exact: true
        }
    };
    $GP.map.transform(config);
}

which you place in $GP.ready block within the script tag:

<script type="text/javascript">
$GP.ready(function(){
    zoomToBBox();
});
</script>
Comments
by
‎05-13-2016 09:27 PM - edited ‎05-13-2016 09:28 PM

Can you give an example of the URL you would supply with the bounding box information?  

Could i append it to this?

http://www.abc.com/PortalSDK2/Examples.aspx?gpw=9387cc32-0b25-40f8-a67d-24e43e18c7a7

Would it be something like

http://www.abc.com/PortalSDK2/Examples.aspx?gpw=9387cc32-0b25-40f8-a67d-24e43e18c7a7&bbox=90,30,93,3...

The code i added to process a supplied bounding box is being executed - i just don't have the bounding box supplied in the required (unknown) format.

by
on ‎05-14-2016 06:47 PM

Got it - format for the URL that will supply bounding box information for the initial zoom.

 

http://www.webgis.net/PortalSDK2/Examples.aspx?gpw=9387cc32-0b25-40f8-a67d-24e43e18c7a7&bbox=333555,...

by
on ‎05-19-2016 08:02 PM

This works fine if i cut and paste it into an example on the examples panel and hardcode the bounding box numbers (since no url will be passed) but if it runs during startup, the zoom is not made to the coordinates of the calculated bounding box (which are calculated correctly (the parsed 4 bbox numbers are converted to EPGS:3857 coordinates)) - instead it appears to zoom to where the map would display without the bounding box zoom but zoomed to to the size of the specified bounding box

by
on ‎06-02-2016 07:25 AM

When the zoomtobbox is done in the HelloWorld.js file, then it is overwritten by zooms made in the API.js file that is executed on startup.  Is there any way around this?  I want to start up with the initial map based on bbox=x1,y1,x2,y2 coordinates that are included in the URL to start up my GeoSpatial portal.  I have a button that does the zoomtobox and it works fine, but that is after the map has already loaded.

Overview