Ejemplo n.º 1
0
function DuplicateSessionLayer($map, $resourceService, $sourceLayerId, $suffix)
{
    //create the new session MgResourceIdentifier
    $destinationLayerId = CreateSessionResourceId($sourceLayerId, $suffix);
    //copy content from source layer
    $contentReader = $resourceService->GetResourceContent($sourceLayerId);
    $layerContent = $contentReader->ToString();
    //set the feature source this layer references -- must be in the session
    //the feature source need not exist before calling this function
    $sourceLayer = new MgLayer($sourceLayerId, $resourceService);
    $sourceFeatureSourceId = new MgResourceIdentifier($sourceLayer->GetFeatureSourceId());
    $destinationFeatureSourceId = CreateSessionResourceId($sourceFeatureSourceId, $suffix);
    //replace the featuresourceid and write xml to the session copy
    $layerContent = str_replace($sourceFeatureSourceId->ToString(), $destinationFeatureSourceId->ToString(), $layerContent);
    $byteSource = new MgByteSource($layerContent, strlen($layerContent));
    $resourceService->SetResource($destinationLayerId, $byteSource->GetReader(), null);
    //instantiate the new layer from its MgResourceIdentifier
    $layer = new MgLayer($destinationLayerId, $resourceService);
    //add the edit layer to the session map and set it to redraw but not be visible in the legend
    $layerCollection = $map->GetLayers();
    $originalLayer = FindLayer($layerCollection, $sourceLayer->GetLayerDefinition()->ToString());
    $nPosition = $layerCollection->IndexOf($originalLayer);
    $layerCollection->Insert($nPosition, $layer);
    $layer->SetDisplayInLegend(false);
    $layer->SetSelectable(true);
    $layer->ForceRefresh();
    //OR
    //remove the source layer from the session map and replace it with the
    //session copy
    //ReplaceLayer($map, $sourceLayer, $layer);
    //save the session map
    try {
        $map->Save($resourceService);
    } catch (MgException $e) {
        echo "ERROR: " . $e->GetExceptionMessage() . "n";
        echo $e->GetDetails() . "n";
        echo $e->GetStackTrace() . "n";
    }
    return $layer;
}
Ejemplo n.º 2
0
    *****************************************************************************/
 /*****************************************************************************
    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();