[mapguide-users] Change Raster Layer ResourceSourceId

Liglio liglio at pobox.com
Thu Mar 31 12:12:46 PDT 2016


Hi,

I am trying to change dinamically the raster image of a layer, following the
steps:
1 - Copy the xml content of the original Resource Source and change the
raster file path.
2 - Create a Session Resource Source with the above modified xml content.
3 - Copy the xml content of the original Layer and change the ResourceId
pointing to the above created Session Resource Source.
4 - Create a Session Layer with the above modified xml contente.
5 - Save the changes to the map session.

I used this steps to do the same to shape layers and worked, but to raster
layers. I am using c# and mapguide 2.5.2. Here is the code: (Thanks for any
help)

strFeatureSourceId = layer.GetFeatureSourceId();

//Read the feature source content 
resIdFeat = new MgResourceIdentifier(strFeatureSourceId);
if (resourceService.ResourceExists(resIdFeat))
{
    strXml = (resourceService.GetResourceContent(resIdFeat)).ToString();
}

//Manipulate xml, set the Tags Filter
strXml = Util.SetTagTextContent(strXml, "/FeatureSource/Parameter/Value",
strFileName, true);

//Create temporary feature source resource
strFeatureSourceName =
strFeatureSourceId.Substring(strFeatureSourceId.LastIndexOf("/") + 1);
strFeatureSourceIdForSession = "Session:" + strSessionMap + "//" +
strFeatureSourceName;
resIdFeat = new MgResourceIdentifier(strFeatureSourceIdForSession);

//Write the featrure source content
encoding = new System.Text.ASCIIEncoding();
ByteSource = new MgByteSource(encoding.GetBytes(strXml), strXml.Length);
resourceService.SetResource(resIdFeat, ByteSource.GetReader(), null);

//Read the layer resource 
resIdLayer = layer.GetLayerDefinition();
if (resourceService.ResourceExists(resIdFeat))
{
    strXml = (resourceService.GetResourceContent(resIdLayer)).ToString();
}

//Manipulate xml, set the Tags Filter
strXml = Util.SetTagTextContent(strXml,
"/LayerDefinition/GridLayerDefinition/ResourceId",
strFeatureSourceIdForSession);

//Create temporary layer resource
strLayerIdForsession = "Session:" + strSessionMap + "//" + strLayerName +
"." + MgResourceType.LayerDefinition;
resIdLayer = new MgResourceIdentifier(strLayerIdForsession);

//Write the layer content
encoding = new System.Text.ASCIIEncoding();
ByteSource = new MgByteSource(encoding.GetBytes(strXml), strXml.Length);
resourceService.SetResource(resIdLayer, ByteSource.GetReader(), null);

//Get the temp layer
layerTemp = GetLayerByName(map, strLayerNameForSession);
layerTemp.ForceRefresh();
map.Save(resourceService);



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/Change-Raster-Layer-ResourceSourceId-tp5259045.html
Sent from the MapGuide Users mailing list archive at Nabble.com.


More information about the mapguide-users mailing list