I want to change keywords searching from CGI Model to PHP/MapScript Model. But I have some problems<br><br>something changed as follow:<br><br>petrochina_admin.xml:<br> <service title="搜索管线" selectable="false" default="false" locked="true" div="buildingsearch"><br>
<url>php/search.php</url><br> <input type="hidden" name="map" value="/ms4w/apps/GeoMOOSE/petrochina/itemquery.map"/><br> <input type="hidden" name="mode" value="nquery"/><br>
<input type="user" name="id" title="Zoom to building#:"/><br> </service><br><br>petrochina.html:<br clear="all"><div id="CustomForms"><br> <div id="Buildingsearch"><br>
<font color="black"><b>搜索管线:</b></font><br/><br> <input name="id"/><input type="submit" value="查询"/><br>
<input type="hidden" name="map" value="/ms4w/apps/GeoMOOSE/petrochina/itemquery.map"/><br> <input type="hidden" name="mode" value="nquery"/><br>
<br><i>输入管线名称<i/><br> </div><br><br><div id="WaitingMessage"><br><b>请稍候...</b><br></div><br><br>and new search.php:<br><?php<br>#<br># select.php (c) 2007 Dan "Ducky" Little<br>
# Write for the GeoMOOSE project, sponsored by the OpenMNND Organization<br># PHP Translation of the Perl script select.pl<br>#<br><br># Make the PHP Script Shut Up, but still give something useful if there<br># is a legit error or parsing bug.<br>
error_reporting(E_ERROR | E_PARSE);<br><br># Include the GeoMOOSE PHP Library Utilities<br># Get in the information from the request<br>$coordinates = $_REQUEST['coords'];<br>$title = $_REQUEST['title'];<br>
$shapeType = $_REQUEST['shape'];<br>$buffer = $_REQUEST['buffer'];<br>$layer = $_REQUEST['layer'];<br>$output = $_REQUEST['output'];<br>$identifyMap = $_REQUEST['map'];<br>$selectMap = $_REQUEST['select'];<br>
$string = $_REQUEST['qstring'];<br><br><br># Check for some vitals<br>if(!isset($layer)) {<br> appError('Layer value is not set or invalid: '.$layer);<br>}<br>if(!isset($output)) {<br> $output = $DEFAULT_OUTPUT;<br>
}<br><br># Check the CGI for the layer/column Delimiter,<br># If it's not found, then use the default.<br>$delim = $_REQUEST['delim'];<br>if(!isset($delim)) {<br> $delim = $DEFAULT_DELIM;<br>}<br># This splits the input layer sting into the Layer Name and the Column Containing the ID's for the layer<br>
list($layer, $queryColumn) = explode($delim, $layer);<br><br># This checks for the existance of the select mapfile.<br># If it does not exist the application quits with an error message.<br>if(!file_exists($selectMap)) {<br>
appError('Could not find: '.$selectMap);<br>}<br><br># This checks to see what "shape" is being passed to the script to query against.<br>if($shapeType == "point") {<br> $shapeType = MS_SHAPE_POINT;<br>
} elseif($shapeType == 'circle') {<br>} elseif($shapeType == 'line') {<br> $shapeType = MS_SHAPE_LINE;<br> if(empty($buffer)) {<br> $buffer = 1; # Makes the line work if there is no buffer specified or the buffer = 0<br>
}<br>} else {<br> $shapeType = MS_SHAPE_POLYGON;<br>}<br><br><br># Convert the coordinates to a new shape object<br># This takes the coordinates from the CGI and adds them to a Shape for querying.<br>$shape = ms_newShapeObj($shapeType);<br>
$coords = array();<br>$coords = explode(' ', $coordinates);<br>$line = ms_newLineObj();<br>foreach ($coords as $coord) {<br> list($x, $y) = explode(',',$coord);<br> $line->addXY($x,$y);<br>}<br>$shape->add($line); # This adds the line with all the coordinates from the CGI<br>
#$shape->setBounds(); # This initalizes the shape.<br><br># Buffer as desired.<br>if(isset($buffer)) {<br> $shape = $shape->buffer($buffer); # Mapscript using GEOS to bufffer the shape<br> if(!isset($shape)) { # Check to make sure the function returned a valid shape, if not, error.<br>
appError("Buffering Failed. Buffer size: $buffer. Verify mapscript was linked with GEOS and that the buffer is a positive-real number.");<br> }<br>}<br><br># Create a new Coordinate string based on any potential buffering.<br>
# This is needed because after the object has been buffered it will have a new coordinate string.<br># This information is passed back to the GeoMOOSE client so that it can set the "mapshape" parameter<br># which displays the layer highlighting.<br>
$coordString = '';<br>for($line = 0; $line < $shape->{numlines}; $line++) {<br> $lineObj = $shape->line($line);<br> for($point = 0; $point < $lineObj->{numpoints}; $point++) {<br> $pointObj = $lineObj->point($point);<br>
$coordString = $coordString.$pointObj->{x}.' '.$pointObj->{y}.' ';<br> }<br>}<br><br># Set up the query to perform the select, with the buffer and all!<br># If the Map does not open correctly, error out.<br>
$queryMap = ms_newMapObj($selectMap) or appError('Could not open mapfile: '.$selectMap."\n".'Please verify the Map file is valid.');<br><br># This section of code searches for the query layer.<br>
# If a layer is not the query layer, it is turned off so that errorneous/extraneous results are not<br># also returned. This also helps speed queries so that multiple large datasets are not simultaneously queried.<br>$queryLayerFound = false; # Set an error condition in case we do not find the layer<br>
for($l = 0; $l < $queryMap->{numlayers}; $l++) {<br> $queryLayer = $queryMap->getLayer($l);<br> $queryLayer->set('status', MS_OFF); # Turn the layer off<br> if($queryLayer->{name} == $layer) { # If it's the layer we're trying to search...<br>
$queryLayer->set('status',MS_ON); # Turn it on!<br> $queryLayerFound = true; # "Unset" the Error Condition<br> }<br>}<br><br>if(!$queryLayerFound) { # If they layer is not found in the mapfile, error out.<br>
appError("The Query Layer '$layer' could not be found in the mapfile ($selectMap).");<br>}<br># Perform the Query.<br>//$qstring='大';<br># select a Chinese char as example<br>$searchstring=iconv("gbk", "ISO-8859-13", $qstring);<br>
# charset convert<br>$searchstring="/".$searchstring."/";<br>$searchstring="/".$qstring."/";<br><br>$queryMap= $queryMap->getLayerByName($layer); <br>$queryMap->set("status", MS_ON); <br>
<br>$queryResultCheck = $queryMap->queryByAttributes('Name', $searchstring, MS_SINGLE);;<br>if($queryResultCheck == MS_FAILURE) { # If the query fails, error out.<br> # Check to see if the Map has any pointers to an empty file<br>
$empty = $queryMap->web->empty;<br> # If it's set then show that HTML instead. :D<br> if(isset($empty) and $empty != '') {<br> readfile($empty);<br> exit(0); <br> } else {<br>
appError('查询返回结果失败!');<br> }<br>}<br><br># Cycle through the results of the query and build an array containing the results.<br>$resultContents = array();<br>for($l = 0; $l < $queryMap->{numlayers}; $l++) { # Cycle through the layers<br>
$queryLayer = $queryMap->getLayer($l); # Get they layer object from the map.<br> if($queryLayer->{name} == $layer) { # Check to make sure it's our layer of interest.<br># $queryResults = $queryLayer->getResults(); # Get the results from the query.<br>
$queryColumns = array(); # Hash table to hold the column names.<br><br> $queryLayer->open(); # Open the layer for operation.<br><br> # This loop deserves from definition.<br>
# What this look is doing is creating a assosciative array (hash table) containing the shapefile<br> # indexes of the column names<br> # Example: <br> # A layer could contain the following columns: 0 - ID, 1 - OWNER, 2 - CITY<br>
# This loop would create an associative array that has the indexes of {'ID','OWNER','CITY'} and the corresponding values {0,1,2}<br> # Ergo, $queryColumns{'OWNER'} will return 0<br>
for($item = 0; $item < $queryLayer->{numitems}; $item++) {<br> $queryColumns{$queryLayer->getItem($item)} = $item;<br> }<br><br> if($queryLayer->getNumResults() > 0) { # Check to make sure we have SOME results<br>
# for($result = 0; $result < $queryResults->{numresults}; $result++) { # Loop through the results<br> for($result = 0; $result < $queryLayer->getNumResults(); $result++) {<br>
# Get the member of the result set<br> $queryResult = $queryLayer->getResult($result);<br> # Get the feature from that result.<br> # I left getFeature in here, as getShape will be deprecated for getFeature<br>
#$queryFeature = $queryLayer->getFeature($queryResult->{shapeindex}, $queryResult->{tileindex}); <br> $queryFeature = $queryLayer->getShape($queryResult->{tileindex}, $queryResult->{shapeindex}); <br>
# Here's where the array from before becomes very handy. The column *name* is passed<br> # into the CGI, so we need to result the shapefile-column index and the name,<br> # which is query %queryColumns does! So now, we can just pull the ID column from the object.<br>
$v = $queryFeature->{values}[$queryColumn];<br> # And put that ID onto the stack of results...<br> array_push($resultContents, $v);<br> }<br> } else {<br>
appError('选定图层没有任何查询结果');<br> }<br><br> $queryLayer->close(); # Close the layer<br> }<br>}<br><br># Process the query template from the mapfile and return it to the user<br># This way the results are displayed exactly as they are definied in the mapfile.<br>
$template = $queryMap->processQueryTemplate(array(), array());<br><br>if($output == 'xml') {<br> header('Content-type: text/xml; charset=gbk');<br> # Return the XML that tells GeoMOOSE what to do!<br>
#<br> # By passing "mapbook fragments" back to GeoMOOSE we can change the behavior and <br> # definition of the maps being displayed. $layer contains the mapbook name of the <br> # layer we were selecting-against. The "<param.../>" line will set the mapshape parameter for<br>
# the layer we selected against.<br> print "<return>";<br> printf("<map title='Highlight' default='true'>", $layer);<br> printf(" <file>%s</file>", $identifyMap);<br>
$strippedLayer = preg_replace("/ /",'',$layer);<br> printf(" <param name='layers' value='%s'/>", $strippedLayer);<br> printf(" <param name='qlayer' value='%s'/>", $strippedLayer);<br>
printf(" <param name='mapshape' value='%s'/>", $coordString);<br><br> # This takes the ID's from the results stack and puts it inside the layer.<br> foreach ($resultContents as $id) {<br>
# print "\t\t<selected id='$id'/>\n";<br> printf(" <selected id='%s'/>", $id);<br> }<br><br> print "\t</map>";<br><br> # Print some header information.<br>
print '<results title="Select Results">';<br> print ' <header><col value="Selected Objects:"/></header>';<br> print " <row><col value='".count($resultContents)."'/></row>";<br>
print '</results>';<br><br><br> print $template;<br><br> print "</return>"; # End the XML Page.<br>} elseif($output == 'html') {<br> header('Content-type: text/html; charset=gbk');<br>
#gbk is charset sopport Chinese<br> ## HTML OUTPUT<br> # This is a HTML/XML trick that uses XML namespaces in order to embed a GeoMOOSE<br> # mapbook into a HTML document.<br> print '<html xmlns:moose="<a href="http://geomoose.org/">http://geomoose.org/</a>">';<br>
print "<head>\n";<br> print "<moose:mapbook>\n";<br> # print "<moose:map title="'.$layer.'" default="true">\n";<br> printf("<moose:map title='Highlight' default='true'>\n",$layer);<br>
printf(" <moose:file>%s</moose:file>", $identifyMap);<br> $strippedLayer = preg_replace("/ /",'',$layer);<br> printf(" <moose:param name='layers' value='%s'/>", $strippedLayer);<br>
printf(" <moose:param name='qlayer' value='%s'/>", $strippedLayer);<br># print " <moose:param name='mapshape' value='".$coordString."'/>\n";<br>
printf ("<moose:param name='mapshape' value='%s'/>\n", $coordString);<br> foreach ($resultContents as $id) {<br> printf(" <moose:selected id='%s'/>\n", $id);<br>
}<br> print "</moose:map>\n";<br> print "</moose:mapbook>\n";<br> print "</head>";<br> print "<body>";<br> print "<![CDATA[";<br>
print $template;<br> print "]]>";<br> print "</body>";<br> print "</html>";<br>} else {<br> appError('Unrecognized output option: '.$output);<br>}<br><br>
exit; # End the Program!<br>?><br><br><br>but it doesn't work,Someone can help me?<br>-- <br>Leopard<br>