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");
include_once(dirname(__FILE__)."/../geomath.php");
/**
* KeyMapDHTMLWidget provides a DHTML enabled mapping interface and the javascript
* functions for doing javascript-based navigation.
*/
class KeyMapDHTML extends NavTool
{
var $msAnchorName = "keymapanchor";
var $msMapImageName = "keymapimage";
var $mszMarqueeColor = "RED";
var $mnMarqueeWidth = 1;
var $mszMarqueeImageHorizontal = "images/a_pixel.gif";
var $mszMarqueeImageVertical = "images/a_pixel.gif";
var $mszURL = "";
var $mbAllowResize = true;
var $mfMinScale = 1;
var $mfMaxScale = -1;
var $mnWidth = 100;
var $mnHeight = 100;
var $mszImage = "";
var $mdMinx = 0;
var $mdMiny = 0;
var $mdMaxx = 0;
var $mdMaxy = 0;
var $mszSRS = '';
var $mszAnchorName = "keyMapAnchor";
var $mszKeyMapImageName = "KeyMapImage";
var $mszKeyMapName = "";
var $mdfZoomMin = 4;
var $mszMode = "ZOOM";
function KeyMapDHTML()
{
// invoke constructor of parent
parent::NavTool();
$this->SetNavCommand("KEY_MAP_DHTML");
$this->SetUniqueId(md5(uniqid(rand())));
$this->moButton->mszAnchorName = $this->mszAnchorName;
$this->maAttributes["WIDTH"] = new IntegerAttribute( "WIDTH", false, 0 );
$this->maAttributes["HEIGHT"] = new IntegerAttribute( "HEIGHT", false, 0 );
$this->maAttributes["IMAGE"] = new StringAttribute( "IMAGE", false );
$this->maAttributes["COLOR"] = new RGBColorAttribute( "COLOR", false );
$this->maAttributes["OUTLINECOLOR"] = new RGBColorAttribute( "OUTLINECOLOR", false );
$this->maAttributes["MINX"] = new FloatAttribute( "MINX", false );
$this->maAttributes["MINY"] = new FloatAttribute( "MINY", false );
$this->maAttributes["MAXX"] = new FloatAttribute( "MAXX", false );
$this->maAttributes["MAXY"] = new FloatAttribute( "MAXY", false );
$this->maAttributes["SRS"] = new StringAttribute( "SRS", false );
$this->mszMarqueeImageHorizontal = $_SESSION['gszCoreWebPath']."/skins/default/images/a_pixel.gif";
$this->mszMarqueeImageVertical = $_SESSION['gszCoreWebPath']."/skins/default/images/a_pixel.gif";
$this->mnMaturityLevel = MATURITY_BETA;
}
function InitDefaults()
{
parent::InitDefaults();
if (!isset($_SESSION['KEYMAPDHTML_INIT']) || $_SESSION['KEYMAPDHTML_INIT'] != "1")
{
$oApp = GetChameleonApplication();
// set width
if (isset($this->maParams['WIDTH']))
{
$this->moMapObject->oMap->reference->set( "width", $this->maParams['WIDTH'] );
}
// set height
if (isset($this->maParams['HEIGHT']))
{
$this->moMapObject->oMap->reference->set( "height", $this->maParams['HEIGHT'] );
}
// set image
if (isset($this->maParams['IMAGE']))
{
$szImage = $oApp->getRemoteFile( $this->maParams['IMAGE'] );
$szImage = $oApp->findFile( $szImage );
$this->moMapObject->oMap->reference->set( "image", $szImage );
}
else
{
$szMapPath = realpath( $_SESSION['gszMapPath'] )."/";
$szImage = $this->moMapObject->oMap->reference->image;
$szImage = realpath($oApp->resolvePath2( $szImage, $szMapPath ));
$this->moMapObject->oMap->reference->set( "image", $szImage );
}
// set extent
if (isset($this->maParams['MINX']) && isset($this->maParams['MINY']) &&
isset($this->maParams['MAXX']) && isset($this->maParams['MAXY']))
{
$this->moMapObject->oMap->reference->extent->setextent( $this->maParams['MINX'],
$this->maParams['MINY'],
$this->maParams['MAXX'],
$this->maParams['MAXY'] );
}
}
// intialize member variables
$this->mnWidth = $this->moMapObject->oMap->reference->width;
$this->mnHeight = $this->moMapObject->oMap->reference->height;
$this->mszImage = $this->moMapObject->oMap->reference->image;
$this->mdMinx = $this->moMapObject->oMap->reference->extent->minx;
$this->mdMiny = $this->moMapObject->oMap->reference->extent->miny;
$this->mdMaxx = $this->moMapObject->oMap->reference->extent->maxx;
$this->mdMaxy = $this->moMapObject->oMap->reference->extent->maxy;
if ($this->isVarSet( "MAP_ORIGINAL_PROJ" ))
$this->mszSRS = $this->getVar( "MAP_ORIGINAL_PROJ" );
elseif ($this->moMapObject->oMap->getmetadata( "original_projection" ) != "")
$this->mszSRS = $this->moMapObject->oMap->getmetadata( "original_projection" );
else
$this->mszSRS = $this->moMapObject->oMap->getprojection();
//echo "keymapdhtml srs is ".$this->mszSRS." \n";
// Accept different format for SRS.
// only a number, we will add init=epsg:
// EPSG:XXXX will result in init=epsg:XXXX
// Or else a valid projection string.
if(isset($this->maParams['SRS']) && $this->maParams['SRS'] != "")
{
$szSRS = "";
$szSRS .= intval($this->maParams['SRS']);
if($szSRS == $this->maParams['SRS'])
{
$this->mszSRS = "init=epsg:".$this->maParams['SRS'];
}
else if(strtoupper(substr($this->maParams['SRS'], 0, 5)) ==
"EPSG:")
{
$this->maParams['SRS'] = "init=epsg:".
substr($this->maParams['SRS'], 5);
}
else
{
$this->mszSRS = $this->maParams['SRS'];
}
}
$_SESSION['KEYMAPDHTML_INIT'] = "1";
}
/**
* handle changes coming from the URL. In this case, we only want
* to verify that the map size is valid
*/
function ParseURL()
{
parent::ParseURL();
$oMap = $this->moMapObject->oMap;
$szCmd = "";
if ($this->isVarSet("NAV_CMD"))
$szCmd = trim($this->getVar("NAV_CMD"));
if ($this->isVarSet('KEYMAP_DHTML_MODE'))
$this->mszMode = $this->getVar('KEYMAP_DHTML_MODE');
if ($szCmd != "" && $this->isVarSet("NAV_INPUT_COORDINATES") &&
$this->isVarSet("NAV_INPUT_TYPE") &&
$szCmd == "KEYMAP_DHTML")
{
$szMapProj = $oMap->getProjection();
//adjust extents/projection first ...
$szInputCoords = $this->getVar("NAV_INPUT_COORDINATES");
$szInputType = $this->getVar("NAV_INPUT_TYPE");
$aPixMin = false;
$aPixMax = false;
if ($szInputType == "RECTANGLE")
{
$aPixPos = explode(";", $szInputCoords);
$aPixMin = explode(",", $aPixPos[0]);
$aPixMax = explode(",", $aPixPos[1]);
// adjust ratio of height & width to match main map
if ($this->mszMode == "ZOOM")
{
$this->adjustBBox( $aPixMin[0], $aPixMin[1], $aPixMax[0], $aPixMax[1],
$oMap->width, $oMap->height );
//check if the rectangle is bigger than the minmum size allowed. */
if (abs($aPixMax[0] - $aPixMin[0]) < $this->mdfZoomMin &&
abs($aPixMax[1] - $aPixMin[1]) < $this->mdfZoomMin)
{
$aPixMax = false;
$szInputType = 'POINT';
}
}
}
else
{
$aPixMin = explode(",", $szInputCoords);
}
//calc geo positions and reproject points
if ($aPixMin != false)
{
$nGeoMinx = Pix2Geo($aPixMin[0], 0, $this->mnWidth, $this->mdMinx, $this->mdMaxx);
$nGeoMiny = Pix2Geo($aPixMin[1], 0, $this->mnHeight, $this->mdMiny, $this->mdMaxy, 1);
reprojectPoint( $nGeoMinx, $nGeoMiny, $this->mszSRS, $this->moMapObject->oMap->getProjection() );
}
if ($aPixMax != false)
{
$nGeoMaxx = Pix2Geo($aPixMax[0], 0, $this->mnWidth, $this->mdMinx, $this->mdMaxx);
$nGeoMaxy = Pix2Geo($aPixMax[1], 0, $this->mnHeight, $this->mdMiny, $this->mdMaxy, 1);
reprojectPoint( $nGeoMaxx, $nGeoMaxy, $this->mszSRS, $this->moMapObject->oMap->getProjection() );
}
if ($this->mszMode == "ZOOM")
{
if ($szInputType == "RECTANGLE")
{
if ($nGeoMinx > $nGeoMaxx)
{
$tmp = $nGeoMinx;
$nGeoMinx = $nGeoMaxx;
$nGeoMaxx = $tmp;
}
if ($nGeoMiny > $nGeoMaxy)
{
$tmp = $nGeoMiny;
$nGeoMiny = $nGeoMaxy;
$nGeoMaxy = $tmp;
}
// set the map extent
$oMap->setExtent($nGeoMinx, $nGeoMiny, $nGeoMaxx, $nGeoMaxy);
}
elseif ($szInputType == "POINT")
{
// convert to map pixels
$aPix[0] = Geo2Pix($nGeoMinx, 0, $oMap->width, $oMap->extent->minx, $oMap->extent->maxx);
$aPix[1] = Geo2Pix($nGeoMiny, 0, $oMap->height, $oMap->extent->miny, $oMap->extent->maxy, true);
// perform zoom
$this->moMapNavigator->zoomPoint(1, $aPix[0], $aPix[1]);
}
else
{
$_SESSION['gErrorManager']->setError(ERR_WARNING,
trim($this->moMLT->get("1", "ERROR: Invalid input type specified in "))." (".$szInputType.") KeyMapDHTML.widget.php.");
return;
}
//cause extents to be recalculated based on size ....
if ($oMap->getprojection() != "")
{
$oMap->setProjection($oMap->getProjection(), true);
}
/* -------------------------------------------------------------------- */
/* Call the reporjectauto function in case the map projection */
/* is set to AUTO:XXX. If it is not, the function will do */
/* nothing. */
/* -------------------------------------------------------------------- */
$this->ReprojectAuto();
}
elseif ($this->mszMode == "RECENTER")
{
if ($szInputType == "POINT")
{
// convert to map pixels
$aPix[0] = Geo2Pix($nGeoMinx, 0, $oMap->width, $oMap->extent->minx, $oMap->extent->maxx);
$aPix[1] = Geo2Pix($nGeoMiny, 0, $oMap->height, $oMap->extent->miny, $oMap->extent->maxy, true);
// perform zoom of factor 1 to recenter
$this->moMapNavigator->zoomPoint(1, $aPix[0], $aPix[1]);
}
elseif ($szInputType == "RECTANGLE")
{
// calculate offset
$nDeltaXGeo = $nGeoMaxx - $nGeoMinx;
$nDeltaYGeo = $nGeoMaxy - $nGeoMiny;
// offset current extent
$oMap->setExtent( $oMap->extent->minx + $nDeltaXGeo,
$oMap->extent->miny + $nDeltaYGeo,
$oMap->extent->maxx + $nDeltaXGeo,
$oMap->extent->maxy + $nDeltaYGeo );
}
else
{
$_SESSION['gErrorManager']->setError(ERR_WARNING,
trim($this->moMLT->get("1", "ERROR: Invalid input type specified in"))." Recenter.php.");
return true;
}
/* -------------------------------------------------------------------- */
/* Call the reporjectauto function in case the map projection */
/* is set to AUTO:XXX. If it is not, the function will do */
/* nothing. */
/* -------------------------------------------------------------------- */
$this->ReprojectAuto();
}
}
// return success
return true;
}
/**
* draw the map DHTML widget interface
*/
function DrawPublish()
{
if (!$this->mbVisible)
return "";
$url = $_SESSION['gszCoreWebPath']."/skins/default/images/a_pixel.gif";
$nWidth = $this->mnWidth;
$nHeight = $this->mnHeight;
$szReturn = <<