[mapguide-users] Dynamically Modify SDF Source at runtime problem

Bob Cassarly bob.cassarly at famis.com
Thu Mar 6 18:27:01 EST 2008


I am a MapGuide 6.5 Dynamic Authoring Toolkit developer trying to rewrite
some of my DAT code.  

What I want to do is modify the source SDF of a layer from
FLOOR-01_Space.SDF to FLOOR-02_Space.SDF for the current session only (I do
not want to update the MapGuide repository).  I know I am probably missing
something very simple but all I have not been able to find a way to do this. 
The code included below does change the SDF source file BUT it updates the
MapGuide repository and this is something I definitely do not want to do.

Any help you could give me would be GREATLY appreciated!

<?php
 require_once('../mapviewerphp/common.php');
 require_once('../mapviewerphp/constants.php');

 $mgSessionId = ($_SERVER['REQUEST_METHOD'] == "POST")?$_POST['SESSION']:
$_GET['SESSION'];
 $mgMapName = ($_SERVER['REQUEST_METHOD'] == "POST")?$_POST['MAPNAME']:
$_GET['MAPNAME'];

 try
 {
  // Initialize the Web Extensions and connect to the Server using
  // the Web Extensions session identifier stored in PHP
  // session state.

  MgInitializeWebTier ($webconfigFilePath);
  $userInfo = new MgUserInformation($mgSessionId);
  $siteConnection = new MgSiteConnection();
  $siteConnection->Open($userInfo);
  $resourceService =
$siteConnection->CreateService(MgServiceType::ResourceService);
  $map = new MgMap();
  $map->Open($resourceService, $mgMapName);

  $layers = $map->GetLayers();
  $layer = $layers->GetItem('Space');
  $schemaClass = explode(':', $layer->GetFeatureClassName());

  $fileName = 'FLOOR-02_Space';
  $pathAlias = 'SDF_PATH';

  //set the file name of the SDF file for the layer feature source
  $resId = new MgResourceIdentifier($layer->GetFeatureSourceId());  
  $byteReader = $resourceService->GetResourceContent($resId);
  $doc = DOMDocument::loadXML($byteReader->ToString());
  $node = $doc->getElementsByTagName('Value')->item(0);
  $node->nodeValue = '%MG_DATA_PATH_ALIAS[' . $pathAlias . ']%/' . $fileName
. '.sdf';
  $sdfDataDefinition = $doc->saveXML();
  $byteSource = new MgByteSource($sdfDataDefinition,
strlen($sdfDataDefinition)); 
  $byteSource->SetMimeType(MgMimeType::Xml);
  $resourceService->SetResource($resId, $byteSource->GetReader(), null); 


  //set the feature name of the layer (usually the same as the SDF file
minus the file extension)
  $layerDefResId = $layer->GetLayerDefinition();
  $byteReader = $resourceService->GetResourceContent($layerDefResId);
  $doc = DOMDocument::loadXML($byteReader->ToString());
  $node = $doc->getElementsByTagName('FeatureName')->item(0);
  $node->nodeValue = $schemaClass[0] . ':' . $fileName;
  $sdfLayerDefinition = $doc->saveXML();
  $byteSource = new MgByteSource($sdfLayerDefinition,
strlen($sdfLayerDefinition)); 
  $byteSource->SetMimeType(MgMimeType::Xml);
  $resourceService->SetResource($layerDefResId, $byteSource->GetReader(),
null); 


  //save the map
  //$map->Save($resourceService);

  echo '<br/>Class0:' . $schemaClass[0] . 'X<br/>Class1:' . $schemaClass[1]
. '<br/>FSId:' . $layer->GetFeatureSourceId() . '<br/>FCName:' .
$layer->GetFeatureClassName(); 
 }
 catch (MgLayerNotFoundException $e)
     {
  echo '<p>Layer not found</p>';
 }
   catch (MgObjectNotFoundException $e)
 {
  echo '<p>Layer not found</p>';
 }
  catch (MgException $e)
     {
  echo 'error';
  echo $e->GetMessage();
  echo $e->GetDetails();
     }
?>


-- 
View this message in context: http://www.nabble.com/Dynamically-Modify-SDF-Source-at-runtime-problem-tp15885393s16610p15885393.html
Sent from the MapGuide Users mailing list archive at Nabble.com.



More information about the mapguide-users mailing list