Example #1
0
function CopyLayerFromSession($map, $resourceService, $sessionLayerId)
{
    $destinationLayerId = ToggleRepository($sessionLayerId);
    //copy content from session layer
    $contentReader = $resourceService->GetResourceContent($sessionLayerId);
    $layerContent = $contentReader->ToString();
    $byteSource = new MgByteSource($layerContent, strlen($layerContent));
    $resourceService->SetResource($destinationLayerId, $byteSource->GetReader(), null);
    //instantiate the new layer from its MgResourceIdentifier
    $layer = new MgLayer($destinationLayerId, $resourceService);
    //set the feature source this layer references -- must be in the session
    $sessionLayer = new MgLayer($sessionLayerId, $resourceService);
    $destinationFeatureSourceId = ToggleRepository($sessionLayer->GetFeatureSourceId());
    $layer->SetFeatureSourceId($destinationFeatureSourceId);
    $layer->ForceRefresh();
    //remove the session layer from the session map and replace it with the
    //library copy
    ReplaceLayer($map, $sessionLayer, $layer);
    //save the session map
    $map->Save($resourceService);
    return $layer;
}