[mapguide-users] Load Layer Definition XML
Kenneth Skovhede, GEOGRAF A/S
ks at geograf.dk
Thu Jan 22 14:55:43 EST 2009
If you want to modify the layer xml, you just read the xml like this:
MgByteReader rd = resourceSrvc.GetResource(new
If you want to work seriously with layerdefinitions (and the MapGuide
xml), I have created the MaestroAPI,
which lets you manipulate classes instead of xml:
Using the MaestroAPI, you can just do:
LayerDefinition ldef =
VectorLayerDefinition vldef = ldef.Item as VectorLayerDefinition;
foreach(VectorScaleRangeType vsr in vldef.ScaleRanges)
foreach(object o in vsr.Item)
if (o is PointTypeStyleType)
; //Layer has points
else if (o is LineTypeStyleType)
; //Layer has lines
else if (o is AreaTypeStyleType)
; //Layer has polygons
Also, changing a style is easy, eg:
PointTypeStyleType point = vldef.ScaleRanges.Item as
p.PointRule.Label.BackgroundColor = System.Drawing.Color.Red;
All is fully intellisense supported in VS.
Regards, Kenneth Skovhede, GEOGRAF A/S
> Hey Everyone;
> Fairly new to MGOS.
> Here is what I am trying to do.
> I have a map with many Layers. One of my requirements is to allow users to
> be able to change the layer styles via a web wizard. The user will be able
> to adjust certain styles for line/point/polygon (surface). Ie font, symbol,
> line thickness, color etc.
> Already my site allows a user to select the layer they want to change, then
> change the styles for a point only. The changing doesn't seem to be a
> problem right now.
> The problem I have:
> Once a user selects the layer they want to load. How would I get the layer
> and use XML document or XPATH or something to allow the users edit XML
> Here is my code that checks to see what layer type I have when the user
> selects the layer. I have 3 different user controls (one for line, one for
> poly, one for line). What I really want, is to load the layer and populate
> the appropriate controls inside the user control.
> MgSiteConnection conn = InitializeGisWebTier();
> string resource = "Library://MUNICIPALITIES/" + Municipality +
> "/2_DATA/" + LayerName + ".FeatureSource";
> MgResourceService svc =
> (MgResourceService)conn.CreateService(MgServiceType.ResourceService );
> // Populate some values that we will need.
> MgResourceIdentifier resourceId = new
> MgFeatureReader featureReader =
> LayerDefinitionFactory.MakeAFeatureReader(conn, resourceId);
> // Find out what type of Geometric property the FeatureSource we
> uploaded has.
> string geometricPropertyType =
> switch (geometricPropertyType)
> case "SURFACE":
> // We load the Polygon usercontrol
> case "POINT":
> // we load the point usercontrol
> PointStyleBuilder control =
> txtSymbol.Enabled = true;
> txtSymbolSize.Enabled = true;
> case "CURVE":
> // we load the line user control
> Thanks for any help in advance.
More information about the mapguide-users