[mapguide-users] Having problem in adding a layer to the map
permanently
James Card
James.Card at calcad.com
Sat Aug 1 01:27:19 EDT 2009
On Fri, 31 Jul 2009 21:50:33 -0700, chandany5 <chandany5 at gmail.com> wrote:
> Thank you for your quick reply. Can you tell me which API should I use
> to modify the mapDefinitions. I tried many things but still I could not
> get the layer appear on the map permanently.
OK, I dug up some code where we did something similar, only writing into
the Session repository instead of the Library. Actually, in my first
version of this code I made the mistake of writing to the Library, which
caused all sorts of confusion if there were two or more people trying to
use the map at the same time; since you WANT to write into Library I can
tell you from my mistake that it is possible. :-)
Note that, for this project, we saved the FeatureSources,
LayerDefinitions, MapDefinition, and LayoutDefinition as XML files, and
then loaded them. If I were to rewrite this code today I would just
retrieve the XML directly from the Library and then modify it, so I
wouldn't have to maintain those XML files separately.
// Modify the FeatureSources to point to the appropriate SDF file and
save
// them to the session repository, then update all the objects that
depend
// on them to look for their data in the session repository instead of
the
// library. Unfortunately, that means ALL the layers, maps, and
layouts.
// First the FeatureSources
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Load the Background layer FeatureSource template into a PHP DOM
object
// and modify its file-name node so we're displaying the right
building and floor.
$doc = DOMDocument::load('FloorPlans_Background.FeatureSource.xml');
$FileNode = $doc->getElementsByTagName('Value')->item(0);
$SdfPath = $FileNode->nodeValue;
$FileNode->nodeValue =
dirname($SdfPath).'\\'.$BuildingID.'_'.$Floor.'_Background.sdf';
// Get the updated FeatureSource definition from the DOM object and
save it to the repository using the ResourceService object.
$FeatSrcDefinition = $doc->saveXML();
$byteSource = new MgByteSource($FeatSrcDefinition,
strlen($FeatSrcDefinition));
$byteSource->SetMimeType(MgMimeType::Xml);
$tempResourceID = new
MgResourceIdentifier("Session:".$HTTP_SESSION_VARS['mgSessionId']."//FloorPlans_Background.FeatureSource");
$resourceService->SetResource($tempResourceID,
$byteSource->GetReader(), null);
// Load the Rooms layer FeatureSource template into a PHP DOM object
and
// modify its file-name node so we're displaying the right building
and floor.
$doc = DOMDocument::load('FloorPlans_Room_Polys.FeatureSource.xml');
$FileNode = $doc->getElementsByTagName('Value')->item(0);
$SdfPath = $FileNode->nodeValue;
$FileNode->nodeValue =
dirname($SdfPath).'\\'.$BuildingID.'_'.$Floor.'_Rooms.sdf';
// Get the updated FeatureSource definition from the DOM object and
save it to the repository using the ResourceService object.
$FeatSrcDefinition = $doc->saveXML();
$byteSource = new MgByteSource($FeatSrcDefinition,
strlen($FeatSrcDefinition));
$byteSource->SetMimeType(MgMimeType::Xml);
$tempResourceID = new
MgResourceIdentifier("Session:".$HTTP_SESSION_VARS['mgSessionId']."//FloorPlans_Room_Polys.FeatureSource");
$resourceService->SetResource($tempResourceID,
$byteSource->GetReader(), null);
// Next, the LayerDefinitions
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Load the Background Layer Definition template into a PHP DOM object
and
// modify its Resource node to read from our modified FeatureSources in
// the session repository
$doc = DOMDocument::load('Background.LayerDefinition.xml');
$ResourceNode = $doc->getElementsByTagName('ResourceId')->item(0);
$ResourceNode->nodeValue =
'Session:'.$HTTP_SESSION_VARS["mgSessionId"].'//FloorPlans_Background.FeatureSource';
// Get the updated Layer definition from the DOM object and save it to
the repository using the ResourceService object.
$LayerDefinition = $doc->saveXML();
$byteSource = new MgByteSource($LayerDefinition,
strlen($LayerDefinition));
$byteSource->SetMimeType(MgMimeType::Xml);
$tempResourceID = new
MgResourceIdentifier("Session:".$HTTP_SESSION_VARS['mgSessionId']."//Background.LayerDefinition");
$resourceService->SetResource($tempResourceID,
$byteSource->GetReader(), null);
// Load the Rooms Layer Definition template into a PHP DOM object and
// modify its Resource node to read from our modified FeatureSources in
// the session repository
$doc = DOMDocument::load('Rooms.LayerDefinition.xml');
$ResourceNode = $doc->getElementsByTagName('ResourceId')->item(0);
$ResourceNode->nodeValue =
'Session:'.$HTTP_SESSION_VARS["mgSessionId"].'//FloorPlans_Room_Polys.FeatureSource';
// Get the updated Layer definition from the DOM object and save it to
the repository using the ResourceService object.
$LayerDefinition = $doc->saveXML();
$byteSource = new MgByteSource($LayerDefinition,
strlen($LayerDefinition));
$byteSource->SetMimeType(MgMimeType::Xml);
$tempResourceID = new
MgResourceIdentifier("Session:".$HTTP_SESSION_VARS['mgSessionId']."//Rooms.LayerDefinition");
$resourceService->SetResource($tempResourceID,
$byteSource->GetReader(), null);
// Load the SpaceCategory Layer Definition template into a PHP DOM
object
// and modify its Resource node to read from our modified
FeatureSources
// in the session repository
$doc = DOMDocument::load('SpaceCategory.LayerDefinition.xml');
$ResourceNode = $doc->getElementsByTagName('ResourceId')->item(0);
$ResourceNode->nodeValue =
'Session:'.$HTTP_SESSION_VARS["mgSessionId"].'//FloorPlans_Room_Polys.FeatureSource';
// Get the updated Layer definition from the DOM object and save it to
the repository using the ResourceService object.
$LayerDefinition = $doc->saveXML();
$byteSource = new MgByteSource($LayerDefinition,
strlen($LayerDefinition));
$byteSource->SetMimeType(MgMimeType::Xml);
$tempResourceID = new
MgResourceIdentifier("Session:".$HTTP_SESSION_VARS['mgSessionId']."//SpaceCategory.LayerDefinition");
$resourceService->SetResource($tempResourceID,
$byteSource->GetReader(), null);
// Load the SpaceType Layer Definition template into a PHP DOM object
and
// modify its Resource node to read from our modified FeatureSources in
// the session repository
$doc = DOMDocument::load('SpaceType.LayerDefinition.xml');
$ResourceNode = $doc->getElementsByTagName('ResourceId')->item(0);
$ResourceNode->nodeValue =
'Session:'.$HTTP_SESSION_VARS["mgSessionId"].'//FloorPlans_Room_Polys.FeatureSource';
// Get the updated Layer definition from the DOM object and save it to
the repository using the ResourceService object.
$LayerDefinition = $doc->saveXML();
$byteSource = new MgByteSource($LayerDefinition,
strlen($LayerDefinition));
$byteSource->SetMimeType(MgMimeType::Xml);
$tempResourceID = new
MgResourceIdentifier("Session:".$HTTP_SESSION_VARS['mgSessionId']."//SpaceType.LayerDefinition");
$resourceService->SetResource($tempResourceID,
$byteSource->GetReader(), null);
// Load the Query Match Layer Definition template into a PHP DOM
object,
// modify its Resource node to read from our modified FeatureSources in
// the session repository, and modify its Filter node so we're
displaying
// records that match the user's query
$doc = DOMDocument::load('QueryMatch.LayerDefinition.xml');
$ResourceNode = $doc->getElementsByTagName('ResourceId')->item(0);
$ResourceNode->nodeValue =
'Session:'.$HTTP_SESSION_VARS["mgSessionId"].'//FloorPlans_Room_Polys.FeatureSource';
$FilterNode = $doc->getElementsByTagName('Filter')->item(0);
$FilterNode->nodeValue = 'SPID IN ('.$SPID.')';
// Get the updated Layer definition from the DOM object and save it to
the repository using the ResourceService object.
$LayerDefinition = $doc->saveXML();
$byteSource = new MgByteSource($LayerDefinition,
strlen($LayerDefinition));
$byteSource->SetMimeType(MgMimeType::Xml);
$tempResourceID = new
MgResourceIdentifier("Session:".$HTTP_SESSION_VARS['mgSessionId']."//QueryMatch.LayerDefinition");
$resourceService->SetResource($tempResourceID,
$byteSource->GetReader(), null);
// Then the MapDefinition
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// Load the FloorPlans Map definition template into a PHP DOM object
and modify its Extents nodes.
$doc = DOMDocument::load('FloorPlans.MapDefinition.xml');
$ResourceNodes = $doc->getElementsByTagName('ResourceId');
foreach ($ResourceNodes as $ResourceNode)
{
$ResourceNode->nodeValue =
str_replace('Library://FloorPlans/Layers/',"Session:".$HTTP_SESSION_VARS['mgSessionId']."//",$ResourceNode->nodeValue);
}
if ($gotBBox)
{
$MinXNode = $doc->getElementsByTagName('MinX')->item(0);
$MinXNode->nodeValue = $BldgMinX;
$MinYNode = $doc->getElementsByTagName('MinY')->item(0);
$MinYNode->nodeValue = $BldgMinY;
$MaxXNode = $doc->getElementsByTagName('MaxX')->item(0);
$MaxXNode->nodeValue = $BldgMaxX;
$MaxYNode = $doc->getElementsByTagName('MaxY')->item(0);
$MaxYNode->nodeValue = $BldgMaxY;
} else {
echo '<pre class="error">Unable to retrieve a valid bounding box for
the map. Please report this to the system administrator.</pre>';
}
// Get the updated Map definition from the DOM object and save it to
the repository using the ResourceService object.
$MapDefinition = $doc->saveXML();
$byteSource = new MgByteSource($MapDefinition, strlen($MapDefinition));
$byteSource->SetMimeType(MgMimeType::Xml);
$tempResourceID = new
MgResourceIdentifier("Session:".$HTTP_SESSION_VARS['mgSessionId']."//FloorPlans.MapDefinition");
$resourceService->SetResource($tempResourceID,
$byteSource->GetReader(), null);
// Finally, the WebLayout
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
$doc = DOMDocument::load('FloorPlans.WebLayout.xml');
$ResourceNode = $doc->getElementsByTagName('ResourceId')->item(0);
$ResourceNode->nodeValue =
'Session:'.$HTTP_SESSION_VARS["mgSessionId"].'//FloorPlans.MapDefinition';
// Get the updated Layout definition from the DOM object and save it
to the repository using the ResourceService object.
$LayerDefinition = $doc->saveXML();
$byteSource = new MgByteSource($LayerDefinition,
strlen($LayerDefinition));
$byteSource->SetMimeType(MgMimeType::Xml);
$tempResourceID = new
MgResourceIdentifier("Session:".$HTTP_SESSION_VARS['mgSessionId']."//FloorPlans.WebLayout");
$resourceService->SetResource($tempResourceID,
$byteSource->GetReader(), null);
--
James Card
California CAD Solutions, Inc.
209-578-5580 - Voice
209-521-6493 - FAX
More information about the mapguide-users
mailing list