private void CreateScene(MapboxJson styleJson) { var layers = styleJson.Layers; if (layers != null && styleJson.Layers.Count > 0) { var backgroundLayer = layers.FirstOrDefault(item => item.Id == Background); if (backgroundLayer != null) { AppendLine("scene:"); _indent = 1; AppendLine($"{Background}:"); _indent = 2; // background colors don't do stops string color = backgroundLayer.Paint.BackgroundColor as string; if (backgroundLayer.Paint.BackgroundColor is JObject) { color = ((JObject)backgroundLayer.Paint.BackgroundColor).Last.Last.Last.Last.ToString(); } string colorStr = Helper.ProcessColor(color, null); AppendLine($"color: " + colorStr); // use this for blending to turn ARGB colors to RBG ColorUtils.BackgroundColor = ColorUtils.ColorFromString(colorStr); } } _indent = 0; }
private void CreateLayers(MapboxJson styleJson) { var layers = styleJson.Layers; if (layers != null && layers.Count > 0) { foreach (var layer in layers) { if (layer.Id.EndsWith("-copy")) // road_minor-copy in OSM Liberty.. pretty sure it wasn't supposed to include '-copy' { layer.Id = layer.Id.Replace("-copy", ""); } } AppendLine("layers:"); _indent = 1; List <TangramLayerGroup> tangramLayers = LayerUtils.ProcessLayers(_replacedSources, layers); foreach (TangramLayerGroup group in tangramLayers) { var lines = group.CreateLines(); var split = lines.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); if (split[0] == ":") { // invalid layer as it has no name AppendDebug("Warning: Ignored Layer"); continue; } foreach (string str in split) { if (str.Trim().Length > 0) { AppendLine(str); } } } _indent = 0; } }
public string Convert(string style, string jsonIn, out string debug) { _sb = new StringBuilder(); _debugSb = new StringBuilder(); _indent = 0; MapboxJson styleJson = JsonConvert.DeserializeObject <MapboxJson>(jsonIn); AppendLine($"#'{styleJson.Name}' Version:{styleJson.Version} (Converted: {DateTime.Now.ToShortDateString()} { DateTime.Now.ToShortTimeString() })"); CreateGlobals(style); CreateScene(styleJson); CreateSources(styleJson); CreateLayers(styleJson); debug = _debugSb.ToString(); return(_sb.ToString()); }
private void CreateSources(MapboxJson styleJson) { if (ExcludeCommon) { return; } _replacedSources.Clear(); JObject sources = styleJson.Sources as JObject; if (sources != null) { AppendLine("sources:"); _indent++; int i = 0; JProperty source1 = (JProperty)sources.First; foreach (var inSource in sources) { JProperty source = (JProperty)inSource.Value.Parent; string sourceType = source.Value["type"].ToString(); if (sourceType != "vector") { AppendDebug("Source " + source.Name + " ignored"); continue; } i++; if (!source.Name.StartsWith("mapbox://")) { AppendLine(source.Name + ":"); } else { string newName = "source-" + i; AppendLine(newName + ":"); _replacedSources.Add(source.Name, newName); } _indent++; foreach (JProperty valEntry in source.Value) { string prop = valEntry.Name; string val = valEntry.Value.ToString(); if (prop == "type") { string type = val == "vector" ? "MVT" : "?"; AppendLine($"type: '{type}'"); } else if (prop == "url") { if (ForcedUrl != null) { val = ForcedUrl; } else if (val.Contains("mapbox.mapbox-streets")) { val = MapboxUrl; } //else if (val.Contains("mapbox://") && ForcedUrl != null) //{ // val = ForcedUrl; //} else if (val.StartsWith("https://free.tilehosting.com/data/v3.json")) { AppendLine($"max_zoom: 14"); val = "https://free.tilehosting.com/data/v3/{z}/{x}/{y}.pbf?key=tXiQqN3lIgskyDErJCeY"; } AppendLine($"url: '{val}'"); } } _indent--; } } _indent = 0; }