[mapguide-users] MgLayerBase::GetClassDefinition fails on
MGOS1.2RC2
Rex Szeto (Intern)
Rex.Szeto at autodesk.com
Fri Aug 24 11:37:37 EDT 2007
Hi Takashige,
In your code, instead of using MgLayerBase, cast it to MgLayer.
MgLayer layer = (MgLayer)GetLayerByName(map, layerName);
MgClassDefinition classDef = layer.GetClassDefinition();
Regards,
Rex
-----Original Message-----
From: mapguide-users-bounces at lists.osgeo.org
[mailto:mapguide-users-bounces at lists.osgeo.org] On Behalf Of Takashige
Nakagawa
Sent: Thursday, August 23, 2007 11:58 PM
To: MapGuide Users Mail List
Subject: [mapguide-users] MgLayerBase::GetClassDefinition fails on
MGOS1.2RC2
Hi, all.
Now I'm writing some test programs on MGOS 1.2 RC2. In the codes below,
MgLayerBase::GetClassDefinition causes an exception "Class not found."
When I use MgFeatureService ( as I do on Ver 1.1 ) instead , everything
works fine.
Is there something I do wrong?
Regards.
Takashige
----Codes-------------------------------------------
String doTest()
{
NameValueCollection parameters = GetRequestParameters(Request);
String sessionId = GetParameter(parameters, "_session_id_");
String mapName = GetParameter(parameters, "_mapname_");
String layerName = GetParameter(parameters, "_layername_");
MgUserInformation userInfo = new MgUserInformation(sessionId);
MgSiteConnection siteConnection = new MgSiteConnection();
siteConnection.Open(userInfo);
MgMap map = new MgMap(siteConnection);
map.Open(mapName);
MgLayerBase layer = GetLayerByName(map, layerName);
// Version1.1 ******* Works fine on ver 1.2 !
//MgFeatureService featureService = _
//
siteConnection.CreateService(MgServiceType.FeatureService) as
MgFeatureService;
//MgClassDefinition classDef =
GetClassDefinitionV11(featureService,
layer);
// Version1.2 ******* Fails! What's wrong??
*******************
MgClassDefinition classDef = layer.GetClassDefinition();
return layerName;
}
MgClassDefinition GetClassDefinitionV11(MgFeatureService
featureService,
MgLayerBase layer)
{
String featureSourceId = layer.GetFeatureSourceId();
MgResourceIdentifier featureSourceResId = new
MgResourceIdentifier(featureSourceId);
String featureClassName = layer.GetFeatureClassName();
String[] schemaClass = featureClassName.Split(new char[] { ':'
});
String schemaName = schemaClass[0];
String className = schemaClass[1];
return featureService.GetClassDefinition(featureSourceResId,
schemaName, className);
}
NameValueCollection GetRequestParameters(HttpRequest request)
{
if ("POST" == request.HttpMethod)
{
return request.Form;
}
else
{
return request.QueryString;
}
}
String GetParameter(NameValueCollection parameters, String name)
{
String strval = parameters[name];
if (null == strval)
return "";
return strval.Trim();
}
MgLayerBase GetLayerByName(MgMap map, String layerName)
{
MgLayerCollection layers = map.GetLayers();
MgLayerBase layer = null;
for (int i = 0; i < layers.GetCount(); i++)
{
MgLayerBase nextLayer = layers.GetItem(i);
if (nextLayer.GetName() == layerName)
{
layer = nextLayer;
break;
}
}
return layer;
}
------------------------------------------------------------------------
_______________________________________________
mapguide-users mailing list
mapguide-users at lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapguide-users
More information about the mapguide-users
mailing list