[mapguide-users] Load Layer Definition XML
wordsy
mwordell at gmail.com
Fri Jan 23 10:10:32 EST 2009
Thanks for the quick response. It was exactly what I needed.
Cheers!
Kenneth Skovhede, GEOGRAF A/S wrote:
>
> If you want to modify the layer xml, you just read the xml like this:
>
> MgByteReader rd = resourceSrvc.GetResource(new
> MgResourceIdentifier("Library://layer.LayerDefinition"));
>
> 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:
> http://trac.osgeo.org/mapguide/wiki/maestro/MaestroAPI
>
> Using the MaestroAPI, you can just do:
> LayerDefinition ldef =
> con.GetLayerDefinition("Library://layer.LayerDefinition");
> 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[0].Item[0] as
> PointTypeStyleType;
> p.PointRule[0].Label.BackgroundColor = System.Drawing.Color.Red;
>
> Then save:
> con.SaveResource(ldef);
>
> All is fully intellisense supported in VS.
>
>
> Regards, Kenneth Skovhede, GEOGRAF A/S
>
>
>
> wordsy skrev:
>> 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
>> nodes.
>>
>> 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
>> MgResourceIdentifier(resource);
>> MgFeatureReader featureReader =
>> LayerDefinitionFactory.MakeAFeatureReader(conn, resourceId);
>>
>> // Find out what type of Geometric property the FeatureSource
>> we
>> uploaded has.
>> string geometricPropertyType =
>> LayerDefinitionFactory.GetFeatureSourceGeometricPropertyType(featureReader);
>>
>> switch (geometricPropertyType)
>> {
>> case "SURFACE":
>> // We load the Polygon usercontrol
>> this.phStylizeLayerControl.Controls.Add(new
>> PolygonStyleBuilder());
>> break;
>> case "POINT":
>> // we load the point usercontrol
>> //this.phStylizeLayerControl.Controls.Add(new
>> PointStyleBuilder());
>> PointStyleBuilder control =
>> (PointStyleBuilder)LoadControl("~/Pages/Controls/PointStyleBuilder.ascx");
>> this.phStylizeLayerControl.Controls.Add(control);
>> txtSymbol.Enabled = true;
>> txtSymbolSize.Enabled = true;
>> break;
>> case "CURVE":
>> // we load the line user control
>> this.phStylizeLayerControl.Controls.Add(new
>> LineStyleBuilder());
>> break;
>> }
>>
>> Thanks for any help in advance.
>>
> _______________________________________________
> mapguide-users mailing list
> mapguide-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapguide-users
>
>
--
View this message in context: http://n2.nabble.com/Load-Layer-Definition-XML-tp2199703p2203703.html
Sent from the MapGuide Users mailing list archive at Nabble.com.
More information about the mapguide-users
mailing list