/**
 * External JS dependencies:
 * AjaxMap
 *
 * External var dependencies:
 * none!
 */

/**
 * Ajax callback-method for the calls that return a new map image URL that shall be updated.
 */
function zoominCallback(newMapData) {
    setMapData(newMapData);
}

/**
 * Enabeles the rectangle tool, and sets up events for zooming in when rectangle is drawn in map
 */
function zoominOnButtonClick(e) {
    getFrame('mapframe').enableRectangleTool(zoominOnRectangleDrawn);
}

/**
 * Zooms in on the spesified extent (in pixel coordinates)
 */
function zoominOnRectangleDrawn(x1, y1, x2, y2) {
    //alert('zoom: ' + Math.abs(x1-x2) + ', ' + Math.abs(y1-y2));
    if ((Math.abs(x1-x2) > 5) || (Math.abs(y1-y2) > 5)) { // If box is biger than minimum:
        var ext = {
            minX:Math.min(x1,x2),
            maxX:Math.max(x1,x2),
            minY:Math.min(y1,y2),
            maxY:Math.max(y1,y2)
        };
        AjaxMap.zoomIn(ext, getMapWidthInPixels(), getMapHeightInPixels(), zoominCallback);
    }
}
