![]() |
||||
|
|
||||
[maplab-users] maplab/mapserver/PHP-mapscript function to search a objectPaul Spencer pgs@magma.caMon, 07 Oct 2002 21:58:32 -0400
|
||||
Andreas,
cool app :) I think I can help point you in the right direction. My
appologies if there is too much detail here and you have already figured
some/all of this out. I am hoping to also help others who may not have
tried to customize their gmapfactory application.
Let's assume that your application is called MyApp and is in a directory
called MyApp under maplab-2.0rc3/projects/gmf_apps/MyApp/.
The main user interface file is called MyApp_contents.php. You will add
your new input box to this file in the appropriate location. It should
be easy to determine where to put it, there are comments ;)
The next file of interest is called MyApp.php. This is the main file
that does all the work for navigation among other things. In here are a
series of if() statements that check for various modes of navigation
that the user could have performed. You will add an if() here something
like:
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.
$oExtents = $oMapSession->oMap->extents;
//first we need a handle on the layer, let's assume that we have
//it's name
$oParcelLayer = $oMapSession->oMap->getLayerByName( "Parcels" );
// 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", "parcel_number" );
$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->queryByAttribute( MS_SINGLE );
//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
$oShape = $oParcelLayer->getShape( $oResult->tileindex,
$oResult->shapeid );
$oExtents = $oShape->bounds;
$oShape->free();
//at this point we might add a buffer to the extents
$nXBuffer = ( $oExtents->maxx - $oExtents->minx )*0.05;
$nYBuffer = ( $oExtents->maxy - $oExtents->miny )*0.05;
$nMinX = $oExtents->minx - $nXBuffer;
$nMaxX = $oExtents->maxx + $nXBuffer;
$nMinY = $oExtents->miny - $nYBuffer;
$nMaxY = $oExtents->maxy + $nYBuffer;
$oExtents->setExtents( $nMinX, $nMinY, $nMaxX, $nMaxY );
}
// now use $oMapNavigator to navigate to the parcel
// location. There are two useful options now. We
// can zoom to a rectangle which we have calculated or
// to a point and scale. Let's assume we have calculated
// a rectangle and put a buffer around it if necessary.
$oMapNavigator->zoomRectangle($oExtents->minx, $oExtents->miny,
$oExtents->maxx, $oExtents->maxy);
// alternately if it's a point and a scale ...
// $oMapNavigator->zoomScale( $nScale, $nX, $nY );
}
The $oMapSession and $oMapNavigator are MapScript wrapper objects that
we created to make working with a map object simpler for us, they can be
found in the wrapper directory of your app. The documentation for
MapScript itself can be found at:
http://www2.dmsolutions.ca/mapserver/php_mapscript/php_mapscript_docs36.html.
Daniel has also mentioned that you should get the old GMap demo and look
for GMapDumpQueryResults() for some related ideas to working with
queries. You should find it at
http://www2.dmsolutions.ca/mapserver/dl/gmap-ms36.zip
For questions like this, you may get faster response by posting to the
mapserver-users mailing list, its very active and responsive ;)
Cheers,
Paul
Andreas Berweger BHA AG wrote:
> Hello together
>
> For first excuse my english. i'm from switzerland and im speaking a bad
> english but well german.
> im working on a project for little communes and there internet-maping.
>
> - i'm using maplab v2.0-rc3, mapserver 3.6.2 with OGR support and PHP 4.2.2
> on windows
> - my data commes from mapinfo Ver 6.0 and im using the tab files with OGR
>
> first i have to say that maplab and mapserver are working very fine on my
> system. maplab is easy to use and understand. The application i've made is
> temporaly browsable at
>
> http://193.246.110.38/mappub/GIS/BHA_apps/GIS_warth-weiningen/GIS_warth-wein
> ingen.phtml
>
> now my question:
>
> I have to made a textbox at the bottom of the legend. The user could input a
> parcell-number and klick on search. now (i hope it would be possible)
> mapserver/maplab had to search for this parcell in the Layer
> "Liegenschaften"(=parcells in german) and zoom on it. Thats all :)
> "liegenschaften" is a polygon layer with the attributes parcell-number and
> area from mapinfo/OGR. You see im not so familar with PHP and mapscript.
>
> I hope you could help me an give me some hints. when i have forgotten
> something or you need data to help me i could give you ...
>
> Thanks a lot and good night
>
>
>
>
> _______________________________________________
> Maplab-users mailing list
> Maplab-users@dmsolutions.ca
> http://lists.dmsolutions.ca/mailman/listinfo/maplab-users
>
--
Paul Spencer
Applications and Software Development
DM Solutions Group
This archive was generated by Pipermail. |
MapTools.org -- Hosted by DM Solutions Group |