MapTools.org

[maplab-users] queryByAttributes - search in tileindexed layer

Martin Kiuru Martin.Kiuru@Elion.ee
Wed, 18 Feb 2004 10:58:15 +0200
Hi !
I am trying to add a search feature into the application generated by
maplab. What I need is to find polygon in tileindexed layer and zoom it.
My problem is that search works fine only once. When I'am trying to find
another polygon, located in other place of the layer queryByAttributes
returns error - It seems that after zooming there is only zoomed area in
layer... I tried to fix it by such expression :
//$oMapSession->oMap->setExtent( MAX_EXT_MINX, MAX_EXT_MAXX,
MAX_EXT_MINY, MAX_EXT_MAXY ); each time then search activated, but it
not works properly - application shows some point on the map, located (
It seems for me) on the border of shapefile, but not the position of the
polygon. Here is the code, based on example from maillist. Please, give
me some good idea, how can I put my code to work ? Also, how can I
highlight the founded polygon to display it in different color ?
Thanks !
Martin.

if ( $http_form_vars["parcel-number"] )
{
// the parcel number to query for
$szParcelNumber = $http_form_vars["parcel-number"];
// the current extents will be the default if we fail.
//$oMapSession->oMap->setExtent( MAX_EXT_MINX, MAX_EXT_MAXX,
MAX_EXT_MINY, MAX_EXT_MAXY );
$oExtents = $oMapSession->oMap->extent;
$oldExtents = $oExtents; 
//first we need a handle on the layer, let's assume that we have
//it's name
$oParcelLayer = $oMapSession->oMap->getLayerByName( "TUNNUSED" );
// set up the layer for a query in ms 3.6 - in 3.7 we don't need
// to do this, we can just use querybyattribute. Here we assume
// that the data file associated with the layer has an attribute
// called parcel_number that we are querying.
$oParcelLayer->set( "filteritem", "TUNNUS" );
$oParcelLayer->setFilter( "\"$szParcelNumber\"" );
// use querybyattribute to generate the result, assume a single
// one for simplicity but this can be extended to multiple
// results easily
$oParcelLayer->queryByAttributes('TUNNUS','/'.$szParcelNumber.'/',MS_SIN
GLE);
//now check to see if there are any results?
If ($oParcelLayer->getNumResults() > 0 )
{ 
//at least one result, assume only one for this example
$oResult = $oParcelLayer->getResult( 0 );
//oResult is a resultCacheMemberObj
$oParcelLayer->open(); //new code
$oShape = $oParcelLayer->getShape(
$oResult->tileindex,$oResult->shapeindex );
$oExtents = $oShape->bounds;
$oShape->free();
$oParcelLayer->close();
}
$sessWidth=$oMapSession->oMap->width;
$sessHeight=$oMapSession->oMap->height;
$px1=$sessWidth/($oldExtents->maxx-$oldExtents->minx)*($oExtents->minx-$
oldExtents->minx);
$px2=$sessWidth/($oldExtents->maxx-$oldExtents->minx)*($oExtents->maxx-$
oldExtents->minx);
$py1=$sessHeight/($oldExtents->maxy-$oldExtents->miny)*($oldExtents->max
y-$oExtents->maxy);
$py2=$sessHeight/($oldExtents->maxy-$oldExtents->miny)*($oldExtents->max
y-$oExtents->miny);
$pxX=($px1 + $px2)/2 ;
$pyY=($py1 + $py2)/2 ;
if ($oExtents != $oldExtents ) 
{
$oMapNavigator->zoomScale(8000, $pxX, $pyY);
}
}



This archive was generated by Pipermail.