type != MS_SHAPE_POLYGON) { # Small buffer converts points and lines to polygons $selectShapes[$j] = $selectShapes[$j]->buffer(.01); } array_push($queryShapes, $selectShapes[$j]->buffer($shape_buffer)); } # This is the layer where shapes are selected from $selectLayer = $_REQUEST['select_layer']; # Load the mapbook $mapbook = getMapbook(); $selectMap = getMapfile($mapbook, $selectLayer); $map = ms_newMapObj($CONFIGURATION['root'].$selectMap); $layersToQuery = array(); $shapesFound = array(); $layer = array_reverse(explode('/', $selectLayer)); $layer = $layer[0]; if($layer == 'all') { for($i = 0; $i < $map->numlayers; $i++) { array_push($layersToQuery, $map->getLayer($i)); } } else { array_push($layersToQuery, $map->getLayerByName($layer)); } # Build a massive shape $queryShape = array_pop($queryShapes); # this should be the initial selection area. foreach($queryShapes as $shape) { if($shape->type != MS_SHAPE_POLYGON and $selection_buffer == 0) { $shape = $shape->buffer(.0001); } //LK This takes all the query shapes and creates a MULTIPOLYGON for queryByShape and to send back to client to draw $queryShape = $queryShape->union($shape->buffer($selection_buffer)); } //LK Add queryShape to vector layer $wkt = $queryShape->toWkt(); $id = 'drawn'; $vector_js .= "highlight.draw(\"" . $wkt . "\",\"" . $id . "\",\"\",\"select\");"; $foundShapes = array(); $attributes = false; $results = ''; $result_feature = $queryShape; for($i = 0; $i < $map->numlayers; $i++) { $layer = $map->getLayer($i); $layer->set('status', MS_OFF); # Turn off extraneous layers } foreach($layersToQuery as $layer) { $layer->set('template', $CONFIGURATION['root'].$template); if(!$usejQuery) { $layer->set('header', $CONFIGURATION['root'].$template_header); $layer->set('footer', $CONFIGURATION['root'].$template_footer); } $layer->set('status', MS_DEFAULT); $map->queryByShape($queryShape); $results = $map->processquerytemplate(array(), false); $layer->open(); $attributes = $layer->getItems(); for($r = 0; $r < $layer->getNumResults(); $r++) { $result = $layer->getResult($r); $res = $layer->getResult(0); $firstResult = $layer->getFeature($res->shapeindex); $parcelWkt = $firstResult->toWkt(); array_push($foundShapes, $layer->getFeature($result->shapeindex, $result->tileindex)); #$sh = $lay->getFeature($res->shapeindex, $res->tileindex); if($result_feature) { $result_feature = $result_feature->union($layer->getFeature($result->shapeindex, $result->tileindex)); } else { $html = "Sorry, the selection did not work, please try again"; //exit(); } } $layer->close(); } if($result_feature) { $result_feature = $result_feature->toWkt(); } else { $html = "Sorry, the selection did not work, please try again"; //exit(); } $dict['parcel'] = $_REQUEST['parcel']; foreach($foundShapes as $shape) { //LK Add found shapes to vector layer $wkt = $shape->toWkt(); $id = $shape->values[$_REQUEST['id']]; $values = json_encode($shape->values); $vector_js .= "highlight.draw(\"" . $wkt . "\",\"" . $id . "\",\"\",\"highlight\",$values);"; } # All that work for a dozen lines of output. header('Content-type: text/xml'); print ""; print ""; print "Results"; } else { print processTemplate($results, $dict); print $html; } print "]]>"; function processTemplate($str, $dict) { foreach($dict as $k => $v) { $str = str_replace('['.$k.']', $v, $str); } return $str; } ?>