Copyright (c) 2002, DM Solutions Group Inc. * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ include_once(dirname(__FILE__)."/../NavTool.php"); /** * ZoomSelectedLayersWidget * * @desc ZoomSelectedLayers widget. */ class ZoomSelectedLayers extends NavTool { var $mnBuffer = 0.01; /** * ZoomSelectedLayersWidget * * Constructor. Set the default values. */ function ZoomSelectedLayers() { // invoke constructor of parent parent::NavTool(); $this->SetNavCommand( "ZOOM_SELECTED" ); $this->mbSubmitOnClick = true; // set the description for this widget $this->szWidgetDescription = "Zoom to the extents of the selected layers plus a small (1%) buffer"; $this->maAttributes['BUFFER'] = new IntegerAttribute( 'BUFFER', false, 0, 100 ); $this->mnMaturityLevel = MATURITY_BETA; } function InitDefaults() { parent::InitDefaults(); if (isset($this->maParams['BUFFER'])) { $this->mnBuffer = $this->maParams['BUFFER'] / 100; } } /** * ParseURL * * Look for the ZOOM_IN command and if founddo the zooming * according to the other NAV paramaters. */ function ParseURL() { parent::ParseURL(); //sanity test on getextent function if ($this->moMapObject->oMap->numlayers == 0) return true; $oLayer=$this->moMapObject->oMap->getLayer(0); if (!method_exists( $oLayer, "getextent" )) { $_SESSION['gErrorManager']->setError(ERR_WARNING, "The version of mapscript that you are using is not supported by the ZoomSelectedLayers widget. You must use version 4.2.3+ or version 4.4.0+ (beta2 does not work)"); return false; } $szCmd = ""; if ($this->isVarSet( "NAV_CMD" )) $szCmd = trim($this->getVar( "NAV_CMD" )); if ($szCmd == "ZOOM_SELECTED") { //handle ZoomSelectedLayers here. $szOriginalExtents = trim($this->moMapObject->oMap->getMetaData( "original_extents" )); $szOriginalProjection = $this->moMapObject->oMap->getMetaData( "original_projection" ); if (strlen($szOriginalExtents) > 0) { $aszExtents = explode(",", $szOriginalExtents); if (count($aszExtents) == 4) { if ($szOriginalProjection != "" && $szOriginalProjection != $this->moMapObject->oMap->getprojection()) { $aszExtents = $this->moMapNavigator->reprojectExtentFromCenter($aszExtents, $this->moMapObject->oMap->width, $this->moMapObject->oMap->height, $szOriginalProjection,$this->moMapObject->oMap->getProjection()); } } } $szMapProj = $this->moMapObject->oMap->getProjection(); $oMapProj = ms_newProjectionObj( $szMapProj ); $oQueryExtent = ms_newRectObj(); $oQueryExtent->setextent( $aszExtents[0],$aszExtents[1],$aszExtents[2],$aszExtents[3] ); for($i=0; $i<$this->moMapObject->oMap->numlayers;$i++) { $oLayer = $this->moMapObject->oMap->getLayer($i); if ($oLayer->getMetaData( "selected" ) == "1" ) { @$oLayer->queryByRect( $oQueryExtent ); if ($oLayer->getNumResults() > 0) { $nResults = $oLayer->getNumResults(); $oBBox = $oLayer->getExtent(); $szLayerProj = $oLayer->getProjection(); if ($szLayerProj != $szMapProj) { $oLayerProj = ms_newProjectionObj( $szLayerProj ); $oBBox->project( $oLayerProj, $oMapProj ); } } } } if (isset($oBBox)) { $width = ($oBBox->maxx - $oBBox->minx) * $this->mnBuffer; $height = ($oBBox->maxy - $oBBox->miny) * $this->mnBuffer; if( $width == 0 || $height == 0 ) { /* * if projection is not lat/lon * change point to lat/lon * calculate 1 degree buffer as rect object * reproject rect obj back into orig proj * calculate new width/height */ if( $szMapProj != "init=epsg:4326" ) { $oLLProj = ms_newprojectionobj( "init=epsg:4326" ); $oBBox->project( $oMapProj, $oLLProj ); } $oBBox->setextent( $oBBox->minx - 0.5, $oBBox->miny - 0.5, $oBBox->maxx + 0.5, $oBBox->maxy + 0.5 ); if( $szMapProj != "init=epsg:4326" ) { $oBBox->project( $oLLProj, $oMapProj ); } $width = ($oBBox->maxx - $oBBox->minx); $height = ($oBBox->maxy - $oBBox->miny); } //echo 'minx: ' . ($oBBox->minx - $width ). ', miny: ' . ($oBBox->miny - $height ). ', maxx: ' . ($oBBox->maxx+$width ). ', maxy: ' .( $oBBox->maxy + $height ). '

'; $this->moMapObject->oMap->setextent( $oBBox->minx - $width, $oBBox->miny - $height, $oBBox->maxx+$width, $oBBox->maxy + $height ); } } // return success return true; } } ?>