Here is simple serch code for ka-map!<br><br> <br><?<br>include_once( '../include/config.php' );<br><br>if (!extension_loaded('MapScript'))<br>{<br> dl( $szPHPMapScriptModule );<br>}<br><br>$results = array();<br>$oMap = ms_newMapObj($szMapFile);
<br>//$map=$oMap; //jus for test<br>$aLayers = $oMap->getAllLayerNames(); //get all layers in map file<br>$tot = $oMap->numlayers; // total layers-count<br>//------------------------------------------------------------------------------
<br><br> foreach($aLayers AS $layer) {<br><br> $oLayer = $oMap->getLayerByName($layer);<br> <br>/* detect if group should be searchable In yor mapfile sercahable layer will be detected just like "queryable" "true" but her use "searchfield" "field_name"*/
<br> $szSearchfield = $oLayer->getMetaData('searchfield');<br> if ($oLayer->getMetaData( "searchfield" ) != "") {<br> $szSearchfield = $szSearchfield;<br> //----------------------------------------------------
<br>//postgis connect (NOT TESTED IF is possible to test it culd be nice to know works it or not)<br> if($oLayer->connectiontype == MS_POSTGIS){<br> $searchstring = $szSearchfield . ' ~* \'' . $searchstring .'\' ';
<br> } else { // Shapefile<br> $numclasses = $oLayer->numclasses;<br> for($i = 1 ; $i < $numclasses; $i++){<br> }<br> // Second HACK: it work
<br> if($numclasses > 1){<br> $class = $oLayer->getClass(0);<br> // Match all<br> $class->setExpression('/.*/');<br> }<br> }
<br> #----------------------------------------------------------------------------------------------<br> if(@$oLayer->queryByAttributes($szSearchfield, $searchstring, MS_MULTIPLE) == MS_SUCCESS ){ //MS_SUCCESS
<br> $oLayer->open();<br> // Add element to results array for each result row<br> for ($j=0; $j < $oLayer->getNumResults(); $j++)<br> {<br> // get next shape row
<br> $result = $oLayer->getResult($j);<br> $shape = $oLayer->getShape($result->tileindex, $result->shapeindex);<br> //var_dump($shape);<br> // push the row array onto the results array
<br> $aTmp = $shape->values;<br> //Calculate centroid<br> $x_c = ($shape->bounds->minx + $shape->bounds->maxx) / 2; //get x average value<br> $y_c = ($shape->bounds->miny + $shape->bounds->maxy) / 2; //get y average value
<br> //$aTmp = array_merge( $aTmp , array('x' => $x,'y' => $y, 'id' => $result->shapeindex));<br> $xmin = $shape->bounds->minx;<br> $xmax = $shape->bounds->maxx;
<br> $ymin = $shape->bounds->miny;<br> $ymax = $shape->bounds->maxy;<br> $aTmp = array_merge( $aTmp , array('xmin' => $xmin,'xmax' => $xmin,'ymin' => $ymin,'ymax' => $ymax,'x_c'=>$x_c,'y_c'=>$y_c, 'id' => $result->shapeindex));
<br> $results[$layername][] = $aTmp;<br> // end for loop<br> }<br> //echo implode<br> printer($results,$szSearchfield,$layer); //printing<br> }
<br> else{<br> print('No results returned!<br> Searched string:' . "\n" . $searchstring);<br> }<br> $oLayer->close();<br> //----------------------------------------------------
<br> <br> $results=flush($results);<br> }<br> else{<br> $szSearchfield = "Not defined searchfield";<br> }<br> } <br><br>function search($szSearchfield,$searchstring){
<br>//----------------------------------------------------<br> <br>}<br>//-------------------------------------create print -----------------------------<br>function printer($results,$szSearchfield,$layer){<br>
foreach($results as $key_val => $value) {<br> echo "<br>Returned results for layer:<b>".$layer."</b><br>"; // top for each layer<br> foreach($value as $key_val => $v) {
<br> $m = iconv("latin1", "UTF-8", $v[strtoupper($szSearchfield)]);<br> $field=$v[strtoupper($szSearchfield)];<br>//In $m place you can use $v[strtoupper($szSearchfield)] this is used for iconv etc..
<br> print "<a href=# onClick=\"myKaMap.zoomToExtents(".$v["xmin"].",".$v["ymin"].",".$v["xmax"].",".$v["ymax"].")\" onMouseOver=\"
toolTip.moveGeo(".$v["x_c"].",".$v["y_c"]."), toolTip.setText('".$m."')\" onMouseOut=\"toolTip.move()\">".$m."</a><br>\n"; <br>
}<br>}<br>}<br>?><br><br><br>links to working examples:<br><a href="http://85.234.167.38/js/ka-map/htdocs/index_tooltip_search.html">http://85.234.167.38/js/ka-map/htdocs/index_tooltip_search.html</a><br>and <a href="http://85.234.167.38/js/ka-map/htdocs/index_search.html">
http://85.234.167.38/js/ka-map/htdocs/index_search.html</a><br><br><div><span class="gmail_quote">On 4/21/06, <b class="gmail_sendername">Paul Spencer</b> <<a href="mailto:pspencer@dmsolutions.ca">pspencer@dmsolutions.ca
</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Ramesh,<br><br>the bounds of the shape should be a RectObj. This means you can use
<br>the project() function to reproject it.<br><br>see: <a href="http://mapserver.gis.umn.edu/docs/reference/phpmapscript-class/">http://mapserver.gis.umn.edu/docs/reference/phpmapscript-class/</a><br>classes/rectobj<br><br>
You would need to do something like:<br><br>$shp->bounds->project($oLayer->getProjection(),$oMap->getProjection());<br><br>I'm not sure if you can actually do this to a rectObj that is part of<br>a shape. To be safe, you can do this:
<br><br>$rect = ms_newRectObj();<br>$rect->setExtent($shp->bounds->minx,$shp->bounds->miny,$shp->bounds-<br> >maxx,$shp->bounds->maxy);<br><br>$rect->project($oLayer->getProjection(),$oMap->getProjection());
<br><br>Cheers<br><br>Paul<br><br>On 20-Apr-06, at 10:36 PM, ramesh karra wrote:<br><br>> Hi paul,<br>><br>> Hope it is OK to send this mail directly to you. If<br>> not, let me know, I will send this to mapservers list.
<br>><br>> I made some progress in writing in the php script to<br>> retrieve data from the dbf file. The data in the dbf<br>> file is in lat+long projection and I am different<br>> output projection to display the lines/points
<br>> correctly. How do I get the data retrieved from the<br>> dbf file converted to my output projection?<br>><br>> $oMap = ms_newMapObj($szMapFile);<br>><br>><br>> $oLayer = $oMap->getLayerByName("mylayer");
<br>> $oLayer->queryByAttributes("Name", "xxxx",<br>> MS_SINGLE);<br>><br>> if ($oLayer->getNumResults() > 0) {<br>> $r = $oLayer->getResult(0);<br>> $oLayer->open();
<br>> $shp = $oLayer->getShape($r->tileindex,<br>> $r->shapeindex);<br>> $ext = $shp->bounds;<br>> $shp->free();<br>> $oLayer->close();<br>><br>> print $ext->minx;
<br>> }<br>><br>> Basically, the above script works and prints the value<br>> but it is in lat+long projection (like 71.231789), I<br>> need to convert this to my output projection. I am<br>> hoping that there some function to do this because
<br>> mapserver is already doing it while displaying my map.<br>><br>> Thanks<br>> Ramesh<br>><br>><br>> --- Paul Spencer <<a href="mailto:pspencer@dmsolutions.ca">pspencer@dmsolutions.ca</a>> wrote:
<br>><br>>> Ramesh, there are soooo many! I don't even know<br>>> where to start. Try<br>>> googling php ajax and see what you get :)<br>>><br>>> Cheers<br>>><br>>> Paul<br>>>
<br>>> On 13-Apr-06, at 7:00 PM, ramesh karra wrote:<br>>><br>>>> Thanks for the quick reply paul!<br>>>><br>>>> I am relatively new to both PHP and AJAX. To<br>>> achieve<br>>>> what you suggested, could you also suggest some
<br>>> online<br>>>> tutorial/examples or books?<br>>>><br>>>> Thanks again,<br>>>> Ramesh<br>>>><br>>>> --- Paul Spencer <<a href="mailto:pspencer@dmsolutions.ca">
pspencer@dmsolutions.ca</a>> wrote:<br>>>><br>>>>> Ramesh,<br>>>>><br>>>>> I would write a small php script to do the<br>>>>> interaction with the dbf<br>>>>> file and call it from my page using ajax.
<br>>> Actually,<br>>>>> I'd use postgis<br>>>>> but that's another discussion ;)<br>>>>><br>>>>> Cheers<br>>>>><br>>>>> Paul<br>>>>>
<br>>>>> On 13-Apr-06, at 6:47 PM, ramesh karra wrote:<br>>>>><br>>>>>> Hi,<br>>>>>><br>>>>>> I have 100s of points in shapefiles(.shp,.shx<br>>> and
<br>>>>>> .dbf).<br>>>>>> that I use with my maps to show a place and<br>>> label<br>>>>> it.<br>>>>>> Is it possible to access the .dbf file in kaMap?<br>>>>>> I would like to implement a feature to search
<br>>> for<br>>>>> a<br>>>>>> point and when a point of interest is found,<br>>> zoom<br>>>>> to<br>>>>>> that place. Is it possible to do this in kaMap<br>
>>>> without<br>>>>>> having to create an XML file from .dbf file?<br>>>>>><br>>>>>> Thanks<br>>>>>> Ramesh<br>>>>>><br>>>>>>
<br>>> __________________________________________________<br>>>>>> Do You Yahoo!?<br>>>>>> Tired of spam? Yahoo! Mail has the best spam<br>>>>> protection around<br>>>>>>
<a href="http://mail.yahoo.com">http://mail.yahoo.com</a><br>>>>>> _______________________________________________<br>>>>>> ka-Map-users mailing list<br>>>>>> <a href="mailto:ka-Map-users@lists.maptools.org">
ka-Map-users@lists.maptools.org</a><br>>>>>><br>>>>><br>>>><br>>><br>> <a href="http://lists.maptools.org/mailman/listinfo/ka-map-users">http://lists.maptools.org/mailman/listinfo/ka-map-users
</a><br>>>>><br>>>>><br>>>><br>>><br>> +-----------------------------------------------------------------+<br>>>>> |Paul Spencer<br>>>>> <a href="mailto:pspencer@dmsolutions.ca">
pspencer@dmsolutions.ca</a> |<br>>>>><br>>>><br>>><br>> +-----------------------------------------------------------------+<br>>>>> |Applications & Software Development<br>>>>> |
<br>>>>> |DM Solutions Group Inc<br>>>>> <a href="http://www.dmsolutions.ca/|">http://www.dmsolutions.ca/|</a><br>>>>><br>>>><br>>><br>> +-----------------------------------------------------------------+
<br>>>>><br>>>>><br>>>>><br>>>>><br>>>>><br>>>><br>>>><br>>>> __________________________________________________<br>>>> Do You Yahoo!?
<br>>>> Tired of spam? Yahoo! Mail has the best spam<br>>> protection around<br>>>> <a href="http://mail.yahoo.com">http://mail.yahoo.com</a><br>>><br>>><br>> +-----------------------------------------------------------------+
<br>>> |Paul Spencer<br>>> <a href="mailto:pspencer@dmsolutions.ca">pspencer@dmsolutions.ca</a> |<br>>><br>> +-----------------------------------------------------------------+<br>>> |Applications & Software Development
<br>>> |<br>>> |DM Solutions Group Inc<br>>> <a href="http://www.dmsolutions.ca/|">http://www.dmsolutions.ca/|</a><br>>><br>> +-----------------------------------------------------------------+
<br>>><br>>><br>>><br>>><br>>><br>><br>><br>> __________________________________________________<br>> Do You Yahoo!?<br>> Tired of spam? Yahoo! Mail has the best spam protection around
<br>> <a href="http://mail.yahoo.com">http://mail.yahoo.com</a><br><br>+-----------------------------------------------------------------+<br>|Paul Spencer <a href="mailto:pspencer@dmsolutions.ca">
pspencer@dmsolutions.ca</a> |<br>+-----------------------------------------------------------------+<br>|Applications & Software Development |<br>|DM Solutions Group Inc
<a href="http://www.dmsolutions.ca/|">http://www.dmsolutions.ca/|</a><br>+-----------------------------------------------------------------+<br><br><br><br><br>_______________________________________________<br>ka-Map-users mailing list
<br><a href="mailto:ka-Map-users@lists.maptools.org">ka-Map-users@lists.maptools.org</a><br><a href="http://lists.maptools.org/mailman/listinfo/ka-map-users">http://lists.maptools.org/mailman/listinfo/ka-map-users</a><br>
</blockquote></div><br><br clear="all"><br>-- <br>pb