CreateService(MgServiceType::FeatureService); // Converts a boolean to "yes" or "no" // --from MG Web Tier API Reference function BooleanToString($boolean) { if (is_bool($boolean)) return ($boolean ? "true" : "false"); else return "ERROR in BooleanToString."; } //Get a runtime map from a map definition $map = new MgMap(); $map->Open($resourceService, $mapName); //Get the layer $layerCollection=$map->GetLayers(); try { $layer = $layerCollection->GetItem($_REQUEST['layer']); if ($layer == null) { echo 'Layer '.$_REQUEST['layer'].' Not Found'; exit; } if (isset($_REQUEST['selectable'])) { if (strcasecmp($_REQUEST['selectable'], 'true') == 0) { $layer->SetSelectable(true); } else { $layer->SetSelectable(false); } $map->Save($resourceService); } //property mappings from the session if (isset($_SESSION['property_mappings'])) { $mappings = $_SESSION['property_mappings'][$layer->GetObjectId()]; } $dataSourceId = new MgResourceIdentifier($layer->GetFeatureSourceId()); //echo $dataSourceId->ToString();exit; $agf = new MgAgfReaderWriter(); /***************************************************************************** TODO: check GetCapabilities of the feature provider to ensure that it has the appropriate capability to insert and update *****************************************************************************/ /***************************************************************************** TODO: check user permissions to edit the resource *****************************************************************************/ /***************************************************************************** get the layer's geometric type(s) *****************************************************************************/ /***************************************************************************** get the layer's attributes and types *****************************************************************************/ $attributes = GetFeatureSourceAttributes($map, $layer->GetLayerDefinition(), $featureService); /***************************************************************************** determine whether a shadow feature source has been created for the layer *****************************************************************************/ // convert the feature resource for the selected layer to the shadow version $shadowResourceId = CreateSessionResourceId($dataSourceId, '-shadow'); $hasShadow = 'false'; if (DataSourceExists($resourceService, $shadowResourceId)) { $hasShadow = 'true'; } //get class definition from the featureSource $classDefinition = GetFeatureClassDefinition($featureService, $layer, $dataSourceId); //MgPropertyDefinition classProps $classProps = $classDefinition->GetProperties(); $featureGeometryName = $layer->GetFeatureGeometryName(); $aLayerTypes = array(); $aProperties = array(); for ($i=0; $i< $classProps->GetCount(); $i++) { $prop = $classProps->GetItem($i); if ($prop->GetPropertyType() == MgFeaturePropertyType::GeometricProperty) { $featureClass = $prop->GetGeometryTypes(); if ($featureClass & MgFeatureGeometricType::Surface) { array_push($aLayerTypes, 'surface'); } else if ($featureClass & MgFeatureGeometricType::Curve) { array_push($aLayerTypes, 'curve'); } else if ($featureClass & MgFeatureGeometricType::Solid) { array_push($aLayerTypes, 'solid'); //could use surface here for editing purposes? } else if ($featureClass & MgFeatureGeometricType::Point){ array_push($aLayerTypes, 'point'); } break; } } //Get layer collection as xml header('content-type: text/xml'); echo "\n"; for ( $i=0; $i < count($aLayerTypes); $i++ ) { echo "".$aLayerTypes[$i]."\n"; } echo ""; if (IsLayerEditable($resourceService, $layer)) { echo "true\n"; } else { echo "false\n"; } echo "$hasShadow\n"; echo "\n"; foreach($attributes as $attribute) { if (!is_array($attribute)) { continue; } echo "\n"; echo "".$attribute['name'].""; echo "".$attribute['description'].""; echo "".$attribute['datatype'].""; echo "".$attribute['readonly'].""; echo "".$attribute['length'].""; echo "".$attribute['default'].""; echo "".$attribute['precision'].""; echo "".$attribute['scale'].""; echo "".$attribute['nullable'].""; echo "\n"; } echo "\n"; echo ""; exit; } catch (MgException $e) { echo "ERROR: " . $e->GetMessage() . "\n"; echo $e->GetDetails() . "\n"; echo $e->GetStackTrace() . "\n"; exit; } ?>