hasSelection = false; $result->layers = array(); $oLayer = $oMap->GetLayerByName($szLayer); if (@$oLayer->queryByAttributes($szAttribute,$szPattern, MS_MULTIPLE) == MS_SUCCESS) { if ( ($iMatchLimit != -1) && ($oLayer->getNumResults() > $iMatchLimit) ) $numResults = $iMatchLimit; else $numResults = $oLayer->getNumResults(); $result->hasSelection = true; $layerName = $oLayer->name; array_push($result->layers, $layerName); $result->$layerName->featureCount = $numResults; } header('Content-type: text/x-json'); header('X-JSON: true'); if ($result->hasSelection) { $oMap->savequery(getSessionSavePath()."query.qry"); $result->queryFile = getSessionSavePath()."query.qry"; //holds selection array $properties = NULL; $properties->layers = array(); $totalminx = 0; $totalminy = 0; $totalmaxx = 0; $totalmaxy = 0; $bFirstElement = 1; $oLayer->open(); array_push($properties->layers, $layerName); $properties->$layerName->numelements = $numResults; $properties->$layerName->propertynames = array(); $properties->$layerName->propertyvalues = array(); $properties->$layerName->propertytypes = array(); $properties->$layerName->values = array(); $properties->$layerName->metadatanames= array(); array_push($properties->$layerName->metadatanames, 'dimension'); array_push($properties->$layerName->metadatanames, 'bbox'); array_push($properties->$layerName->metadatanames, 'center'); array_push($properties->$layerName->metadatanames, 'area'); array_push($properties->$layerName->metadatanames, 'length'); //get first shape to get the attributes $oResultSet = $oLayer->getResult(0); $oShape = $oLayer->getShape($oResultSet->tileindex,$oResultSet->shapeindex); $selFields = array(); if (isset($_SESSION[$mapName][$layerName]['query_items'])) { $aQueryItems = $_SESSION[$mapName][$layerName]['query_items']; } else { //token separator (for parsing displayed attributes on a query) $tokenSeparator = ","; // checking if metadata "query_include_items" is set $metadataItems = $oLayer->getMetaData('query_include_items'); if ( ($metadataItems == "") || ($metadataItems == "all") ) { while ( list($key,$val) = each($oShape->values) ) { $aQueryItems[$key] = NULL; } } else { $token = strtok($metadataItems, $tokenSeparator); while ($token !== false) { $aQueryItems[trim($token)] = NULL; $token = strtok($tokenSeparator); } } // checking if metadata "query_exclude_items" is set $metadataItems = $oLayer->getMetaData('query_exclude_items'); if ($metadataItems != "") { $token = strtok($metadataItems, $tokenSeparator); while ($token !== false) { if (array_key_exists($token, $aQueryItems)) { unset($aQueryItems[$token]); } $token = strtok($tokenSeparator); } } // get all alias while ( list($key,$val) = each($aQueryItems) ) { $keyAlias = $oLayer->getMetaData("query_".$key."_alias"); trim($keyAlias); if ($keyAlias != "") { $aQueryItems[$key] = $keyAlias; } } $_SESSION[$mapName][$layerName]['query_items'] = $aQueryItems; } $oShape = $oLayer->getShape($oResultSet->tileindex,$oResultSet->shapeindex); while ( list($key,$val) = each($oShape->values) ) { if (array_key_exists($key, $aQueryItems)) { array_push($selFields, $key); //we check if an alias if provided if (isset($aQueryItems[$key]) && ($aQueryItems[$key] != "")) $key = $aQueryItems[$key]; array_push($properties->$layerName->propertynames, $key); array_push($properties->$layerName->propertyvalues, $key); array_push($properties->$layerName->propertytypes, 0); } } for ($iRes=0; $iRes < $numResults; $iRes++) { $properties->$layerName->values[$iRes] = array(); $properties->$layerName->metadata[$iRes] = array(); $oResultSet = $oLayer->getResult($iRes); $oShape = $oLayer->getShape($oResultSet->tileindex,$oResultSet->shapeindex); //TODO : area, length and distance are not set $minx = $oShape->bounds->minx; $miny = $oShape->bounds->miny; $maxx = $oShape->bounds->maxx; $maxy = $oShape->bounds->maxy; if ($bFirstElement) { $bFirstElement = 0; $totalminx = $minx; $totalminy = $miny; $totalmaxx = $maxx; $totalmaxy = $maxy; } else { if ($totalminx > $minx) $totalminx = $minx; if ($totalminy > $miny) $totalminy = $miny; if ($totalmaxx < $maxx) $totalmaxx = $maxx; if ($totalmaxy < $maxy) $totalmaxy = $maxy; } //metadata : TODO dimension, area, length and distance are not set $dimension = 0; $center = 0; $area = 0; $length = 0; $bbox = $minx.','.$miny.','.$maxx.','.$maxy; array_push($properties->$layerName->metadata[$iRes], $dimension); array_push($properties->$layerName->metadata[$iRes], $bbox); array_push($properties->$layerName->metadata[$iRes], $center); array_push($properties->$layerName->metadata[$iRes], $area); array_push($properties->$layerName->metadata[$iRes], $length); //field values for($iField=0; $iField < count($selFields); $iField++) { $value = $oShape->values[$selFields[$iField]]; //$value = preg_replace( "/\r?\n/", "
", $value ); $value = str_replace("'", "\'", $value); array_push($properties->$layerName->values[$iRes], $value); } } $oLayer->close(); //extents $properties->extents = NULL; $properties->extents->minx = $totalminx; $properties->extents->miny = $totalminy; $properties->extents->maxx = $totalmaxx; $properties->extents->maxy = $totalmaxy; //save selection in the session $_SESSION['selection_array'] = $properties; } echo var2json($result); ?>