internal static string ToJson(ThemeLabel themeLabel)
{
string json = "{";
List<string> list = new List<string>();
if (themeLabel.AlongLine != null)
{
list.Add(ThemeLabelAlongLine.ToJson(themeLabel.AlongLine));
}
else
{
list.Add(string.Format("\"alongLineDirection\":\"{0}\"", AlongLineDirection.ALONG_LINE_NORMAL));
list.Add("\"labelRepeatInterval\":0.0");
}
if (themeLabel.BackSetting != null)
{
list.Add(ThemeLabelBackSetting.ToJson(themeLabel.BackSetting));
}
else
{
list.Add(string.Format("\"backStyle\":{0}", ServerStyle.ToJson(new ServerStyle())));
list.Add("\"labelBackShape\":\"ROUNDRECT\"");
}
if (themeLabel.Flow != null)
{
list.Add(ThemeFlow.ToJson(themeLabel.Flow));
}
else
{
list.Add(string.Format("\"leaderLineStyle\":{0}", ServerStyle.ToJson(new ServerStyle())));
}
if (themeLabel.Items != null && themeLabel.Items.Count > 1)
{
List<string> itemList = new List<string>();
foreach (var item in themeLabel.Items)
{
itemList.Add(ThemeLabelItem.ToJson(item));
}
list.Add(string.Format("\"items\":[{0}]", string.Join(",", itemList.ToArray())));
}
else
{
list.Add("\"items\":[]");
}
if (!string.IsNullOrEmpty(themeLabel.LabelExpression))
{
list.Add(string.Format("\"labelExpression\":\"{0}\"", themeLabel.LabelExpression));
}
else
{
list.Add("\"labelExpression\":\"\"");
}
list.Add(string.Format("\"labelOverLengthMode\":\"{0}\"", themeLabel.LabelOverLengthMode));
list.Add(string.Format("\"maxLabelLength\":{0}", themeLabel.MaxLabelLength.ToString(System.Globalization.CultureInfo.InvariantCulture)));
list.Add(string.Format("\"numericPrecision\":{0}", themeLabel.NumericPrecision.ToString(System.Globalization.CultureInfo.InvariantCulture)));
if (themeLabel.Offset != null)
{
list.Add(ThemeOffset.ToJson(themeLabel.Offset));
}
else
{
list.Add("\"offsetX\":\"\"");
list.Add("\"offsetY\":\"\"");
}
list.Add(string.Format("\"overlapAvoided\":{0}", themeLabel.OverlapAvoided.ToString(System.Globalization.CultureInfo.InvariantCulture).ToLower()));
if (!string.IsNullOrEmpty(themeLabel.RangeExpression))
{
list.Add(string.Format("\"rangeExpression\":\"{0}\"", themeLabel.RangeExpression));
}
else
{
list.Add("\"rangeExpression\":\"\"");
}
list.Add(string.Format("\"smallGeometryLabeled\":{0}", themeLabel.SmallGeometryLabeled.ToString(System.Globalization.CultureInfo.InvariantCulture).ToLower()));
if (themeLabel.Text != null)
{
list.Add(ThemeLabelText.ToJson(themeLabel.Text));
}
else
{
list.Add("\"minTextHeight\":0");
list.Add("\"maxTextWidth\":0");
list.Add("\"minTextWidth\":0");
list.Add("\"maxTextHeight\":0");
list.Add(string.Format("\"uniformStyle\":{0}", ServerTextStyle.ToJson(new ServerTextStyle())));
list.Add("\"uniformMixedStyle\":null");
}
if (themeLabel.MatrixCells != null)
{
List<string> cellList = new List<string>();
for (int column = 0; column < themeLabel.MatrixCells.GetLength(1); column++) //列
{
List<string> columnList = new List<string>();
for (int row = 0; row < themeLabel.MatrixCells.GetLength(0); row++) //行
{
if (themeLabel.MatrixCells[row, column] is LabelImageCell)
{
columnList.Add(LabelImageCell.ToJson((LabelImageCell)themeLabel.MatrixCells[row, column]));
}
else if (themeLabel.MatrixCells[row, column] is LabelSymbolCell)
{
columnList.Add(LabelSymbolCell.ToJson((LabelSymbolCell)themeLabel.MatrixCells[row, column]));
}
else if (themeLabel.MatrixCells[row, column] is LabelThemeCell)
{
columnList.Add(LabelThemeCell.ToJson((LabelThemeCell)themeLabel.MatrixCells[row, column]));
}
}
cellList.Add(string.Format("[{0}]", string.Join(",", columnList.ToArray())));
}
list.Add(string.Format("\"matrixCells\":[{0}]", string.Join(",", cellList.ToArray())));
}
else
{
list.Add("\"matrixCells\":null");
}
if (themeLabel.MemoryData != null)
{
list.Add("\"memoryData\":" + themeLabel.ToJson(themeLabel.MemoryData));
}
else
{
list.Add("\"memoryData\":null");
}
list.Add("\"type\":\"LABEL\"");
json += string.Join(",", list.ToArray());
json += "}";
return json;
}