У меня есть этот код тега xml, который выглядит следующим образом:
<FeatureLayerExtension>
<WhereString>(ZONE ='A') or (ZONE ='V')</WhereString>
<OutFields>ZONE</OutFields>
<UniqueDataCount>2</UniqueDataCount>
<UniqueValueRenderer>
<SimpleFillSymbol Color="White" Fill="Yellow" Width="1.5" Fvalue ='A' />
<SimpleFillSymbol Color="White" Fill="Green" Width="1.5" Fvalue ='V' />
</UniqueValueRenderer>
</FeatureLayerExtension>
Я использую это на странице.Cs с помощью сериализации следующим образом:
if (projectMap.FeatureLayerConfig != null && projectMap.FeatureLayerConfig.UniqueValueRenderer != null)
{
agisFeatureLayer.RendererTakesPrecedence = true;
var renderer = new UniqueValueRenderer();
renderer.Field = projectMap.FeatureLayerConfig.OutFields;
for (int i = 0; i <= projectMap.FeatureLayerConfig.UniqueDataCount - 1; i++)
{
UniqueValueInfo info = new UniqueValueInfo();
if (projectMap.FeatureLayerConfig.UniqueValueRenderer.SimpleFillSymbol != null)
{
var fill = GlobalConfigs.ColorToStringDic[projectMap.FeatureLayerConfig.UniqueValueRenderer.SimpleFillSymbol.Fill];
var borderBrush = GlobalConfigs.ColorToStringDic[projectMap.FeatureLayerConfig.UniqueValueRenderer.SimpleFillSymbol.Color];
var borderThickness = projectMap.FeatureLayerConfig.UniqueValueRenderer.SimpleFillSymbol.Width;
var fillSymbol = new SimpleFillSymbol() { Fill = new SolidColorBrush(fill), BorderBrush = new SolidColorBrush(borderBrush), BorderThickness = borderThickness };
info.Value = PojectMap.FeatureLayerConfig.UniqueValueRenderer.UniqueValueInfo.SimpleFillSymbol.Fvalue;
info.Symbol = fillSymbol;
renderer.Infos.Add(info);
}
}
agisFeatureLayer.Renderer = renderer;
}
}
Для второго дочернего элемента SimpleFillSymbol значения Fvalue 'V' я не могу получить его во время рендеринга. Значение SimpleFillSymbol "A" отображается дважды, как показано в оглавлении. Как я могу сделать второй символ заполнения, отображаемый путем повторения через дочерние элементы
Код для сериализации объекта xml:
using System.Xml.Serialization;
using System.Windows.Media;
namespace My.GIS.Viewer.Configuration.Map
{
public partial class PortalFeatureLayer
{
[XmlElement(typeof(uvRendererConfig), ElementName = "UniqueValueRenderer")]
public uvRendererConfig UniqueValueRenderer { get; set; }
[XmlElement(typeof(int), ElementName = "UniqueDataCount")]
public int UniqueDataCount { get; set; }
}
public class uvRendererConfig
{
[XmlElement(typeof(mySimpleFillSymbol), ElementName = "SimpleFillSymbol")]
public mySimpleFillSymbol SimpleFillSymbol { get; set; }
[XmlElement(typeof(mySimpleMarkerSymbol), ElementName = "SimpleMarkerSymbol")]
public mySimpleMarkerSymbol SimpleMarkerSymbol { get; set; }
[XmlElement(typeof(mySimpleLineSymbol), ElementName = "SimpleLineSymbol")]
public mySimpleLineSymbol SimpleLineSymbol { get; set; }
}
public class mySimpleFillSymbol : SymbolBase {
[XmlAttribute(AttributeName = "Fill")]
public string Fill { get; set; }
[XmlAttribute(AttributeName = "FieldValue")]
public string FieldValue { get; set; }
}
public class SymbolBase
{
[XmlAttribute(AttributeName = "Color")]
public string Color { get; set; }
[XmlAttribute(AttributeName = "Width")]
public double Width { get; set; }
}
}
Вам необходимо изменить классы десериализации XML следующим образом:
namespace My.GIS.Viewer.Configuration.Map
{
[Serializable()]
public class FeatureLayerExtension
{
public string WhereString{ get; set; }
public string OutFields { get; set; }
public string UniqueDataCount { get; set; }
//SimpleFillSymbol should be a list
[XmlElement("SimpleFillSymbol")]
public List<SimpleFillSymbol> SimpleFillSymbolList = new List<SimpleFillSymbol>();
}
[Serializable()]
public class SimpleFillSymbol
{
[XmlAttribute("Color")]
public string Color { get; set; }
[XmlAttribute("Fill")]
public string Fill { get; set; }
[XmlAttribute("Width")]
public string Width { get; set; }
[XmlAttribute("Fvalue")]
public string Fvalue { get; set; }
}
}
Используйте следующий код для извлечения списка объектов SimpleFillSymbol
public class DeserializeFeatureLayerExtension
{
public void desiralizeXML()
{
XmlSerializer fledeserializer = new XmlSerializer(typeof(FeatureLayerExtension));
TextReader reader = new StreamReader(file path);
FeatureLayerExtension fleData = (FeatureLayerExtension)deserializer.Deserialize(reader);
reader.Close();
//Fetch the list of SimpleFillSymbol objects
List<SimpleFillSymbol> listSimpleFillSymbol = (from e in fleData
select e.SimpleFillSymbolList);
}
}
Попробуйте использовать linq:
XElement xelement = XElement.Load(document path);
var ell = from e in xelement.Descendants("SimpleFillSymbol")
select e.Attribute("Fvalue");
Вернет оба атрибута Fvalue для элемента SimpleFillSymbol