internal static string ToJson(ServerGeometry serverGeometry) { if (serverGeometry == null) { return null; } string json = "{"; List<string> list = new List<string>(); list.Add(string.Format(CultureInfo.InvariantCulture, "\"type\":\"{0}\"", serverGeometry.Type)); list.Add(string.Format(CultureInfo.InvariantCulture, "\"id\":{0}", serverGeometry.ID)); if (serverGeometry.Parts != null && serverGeometry.Parts.Count > 0) { List<string> parts = new List<string>(); foreach (int i in serverGeometry.Parts) { parts.Add(i.ToString(CultureInfo.InvariantCulture)); } list.Add(string.Format(CultureInfo.InvariantCulture, "\"parts\":[{0}]", string.Join(",", parts.ToArray()))); } else { list.Add(string.Format(CultureInfo.InvariantCulture, "\"parts\":null")); } if (serverGeometry.Points != null && serverGeometry.Points.Count > 0) { List<string> ps = new List<string>(); foreach (Point2D p in serverGeometry.Points) { ps.Add(JsonHelper.FromPoint2D(p)); } list.Add(string.Format(CultureInfo.InvariantCulture, "\"points\":[{0}]", string.Join(",", ps.ToArray()))); } else { list.Add(string.Format(CultureInfo.InvariantCulture, "\"points\":null")); } if (serverGeometry.Style != null) { list.Add(string.Format(CultureInfo.InvariantCulture, "\"style\":{0}", ServerStyle.ToJson(serverGeometry.Style))); } else { list.Add(string.Format(CultureInfo.InvariantCulture, "\"style\":null")); } json += string.Join(",", list.ToArray()); json += "}"; return json; }
/// <summary>${REST_Bridge_method_GeometryToServerGeometry_D}</summary> /// <returns>${REST_Bridge_method_GeometryToServerGeometry_return}</returns> /// <param name="geo">${REST_Bridge_method_GeometryToServerGeometry_param_geo}</param> public static ServerGeometry ToServerGeometry(this SuperMap.WinRT.Core.Geometry geo) { if (geo == null) { return null; } ServerGeometry sg = new ServerGeometry(); Point2DCollection list = new Point2DCollection(); List<int> parts = new List<int>(); if (geo is GeoRegion) { for (int i = 0; i < ((GeoRegion)geo).Parts.Count; i++) { for (int j = 0; j < ((GeoRegion)geo).Parts[i].Count; j++) { list.Add(new Point2D(((GeoRegion)geo).Parts[i][j].X, ((GeoRegion)geo).Parts[i][j].Y)); } parts.Add(((GeoRegion)geo).Parts[i].Count); } sg.Type = ServerGeometryType.REGION; } if (geo is GeoCircle) { for (int i = 0; i < ((GeoCircle)geo).Parts.Count; i++) { for (int j = 0; j < ((GeoCircle)geo).Parts[i].Count; j++) { list.Add(new Point2D(((GeoCircle)geo).Parts[i][j].X, ((GeoCircle)geo).Parts[i][j].Y)); } parts.Add(((GeoCircle)geo).Parts[i].Count); } sg.Type = ServerGeometryType.REGION; } if (geo is GeoLine) { for (int i = 0; i < ((GeoLine)geo).Parts.Count; i++) { for (int j = 0; j < ((GeoLine)geo).Parts[i].Count; j++) { list.Add(new Point2D(((GeoLine)geo).Parts[i][j].X, ((GeoLine)geo).Parts[i][j].Y)); } parts.Add(((GeoLine)geo).Parts[i].Count); } sg.Type = ServerGeometryType.LINE; } if (geo is GeoPoint) { list.Add(new Point2D(((GeoPoint)geo).X, ((GeoPoint)geo).Y)); parts.Add(list.Count); sg.Type = ServerGeometryType.POINT; } sg.Points = list; sg.Parts = parts; sg.ID = -1; return sg; }
/// <summary>${REST_ServerType_method_FromJson_D}</summary> /// <returns>${REST_ServerType_method_FromJson_return}</returns> /// <param name="json">${REST_ServerType_method_FromJson_param_jsonObject}</param> internal static ServerGeometry FromJson(JsonObject json) { if (json == null) { return null; } ServerGeometry geometry = new ServerGeometry(); ServerGeometryType type; bool isSuccess = Enum.TryParse<ServerGeometryType>(json["type"].GetStringEx(), true, out type); if (isSuccess) { geometry.Type = type; } else { return geometry; } geometry.ID = (int)json["id"].GetNumberEx(); geometry.Style = ServerStyle.FromJson(json["style"].GetObjectEx()); JsonArray parts = json["parts"].GetArray(); if (parts != null && parts.Count > 0) { geometry.Parts = new List<int>(); for (int i = 0; i < parts.Count; i++) { geometry.Parts.Add((int)parts[i].GetNumberEx()); } } JsonArray point2Ds = json["points"].GetArray(); if (point2Ds != null && point2Ds.Count > 0) { geometry.Points = new Point2DCollection(); for (int i = 0; i < point2Ds.Count; i++) { geometry.Points.Add(JsonHelper.ToPoint2D(point2Ds[i].GetObjectEx())); } } return geometry; }