-
Notifications
You must be signed in to change notification settings - Fork 225
Preload names from tile json {WIP DO NOT MERGE} #727
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
78f415f
d6acdc5
57a35b1
bf56527
3d6551d
e8c8139
2e3e622
ff19f3e
8d3f29d
a4b0018
6849b5b
7e6dd65
f940aee
2070520
613c9ac
866a01b
f467a2c
549f1e2
5854e85
eccfc52
110476c
23d58eb
79cd30b
543ccf9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
namespace Mapbox.Unity.Map | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using Mapbox.Platform.TilesetTileJSON; | ||
using UnityEngine; | ||
|
||
[Serializable] | ||
public class TileJsonData | ||
{ | ||
public readonly string commonLayersKey = "(layer found in more than one data source)"; | ||
public readonly string optionalPropertiesString = "(may not appear across all locations)"; | ||
/// <summary> | ||
/// This boolean is to check if tile JSON data has loaded after the data source has changed | ||
/// </summary> | ||
public bool tileJSONLoaded = false; | ||
|
||
/// <summary> | ||
/// Layer Display Names seen in the editor | ||
/// </summary> | ||
public List<string> LayerDisplayNames = new List<string>(); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unnecessary newline |
||
/// <summary> | ||
/// Property Display Names seen in the editor | ||
/// </summary> | ||
public Dictionary<string, List<string>> PropertyDisplayNames = new Dictionary<string, List<string>>(); | ||
|
||
/// <summary> | ||
/// The description of the property in a layer | ||
/// </summary> | ||
public Dictionary<string, Dictionary<string, string>> LayerPropertyDescriptionDictionary = new Dictionary<string, Dictionary<string, string>>(); | ||
|
||
/// <summary> | ||
/// List of data sources (tileset ids) linked to a layer name | ||
/// </summary> | ||
public Dictionary<string, List<string>> LayerSourcesDictionary = new Dictionary<string, List<string>>(); | ||
|
||
/// <summary> | ||
/// Dictionary containting the list of layers in a source | ||
/// </summary> | ||
public Dictionary<string, List<string>> SourceLayersDictionary = new Dictionary<string, List<string>>(); | ||
|
||
public void ClearData() | ||
{ | ||
tileJSONLoaded = false; | ||
LayerPropertyDescriptionDictionary.Clear(); | ||
LayerSourcesDictionary.Clear(); | ||
SourceLayersDictionary.Clear(); | ||
LayerDisplayNames.Clear(); | ||
PropertyDisplayNames.Clear(); | ||
} | ||
|
||
public void ProcessTileJSONData(TileJSONResponse tjr) | ||
{ | ||
tileJSONLoaded = true; | ||
List<string> layerPropertiesList = new List<string>(); | ||
List<string> sourceLayersList = new List<string>(); | ||
|
||
if (tjr == null || tjr.VectorLayers == null || tjr.VectorLayers.Length == 0) | ||
{ | ||
return; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a loading or error state for this response? It seems like editor scripts should know if a request is pending vs a request has returned null. In one case, things are working as expected and we're within tile timeout set in the setup window. In the other case, we should show an error. |
||
} | ||
|
||
ClearData(); | ||
|
||
var propertyName = ""; | ||
var propertyDescription = ""; | ||
var layerSource = ""; | ||
|
||
foreach (var layer in tjr.VectorLayers) | ||
{ | ||
//load layer names | ||
var layerName = layer.Id; | ||
layerPropertiesList = new List<string>(); | ||
layerSource = layer.Source; | ||
if (layer.Fields.Count == 0) | ||
continue; | ||
|
||
//loading layer sources | ||
if (LayerSourcesDictionary.ContainsKey(layerName)) | ||
{ | ||
LayerSourcesDictionary[layerName].Add(layerSource); | ||
} | ||
else | ||
{ | ||
LayerSourcesDictionary.Add(layerName, new List<string>() { layerSource }); | ||
} | ||
|
||
//loading layers to a data source | ||
if (SourceLayersDictionary.ContainsKey(layerSource)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reading through this, I realized there's a lot of nested if-else statements (to the point where I lost track of where I was). Can we rewrite this to avoid so much nesting? |
||
{ | ||
List<string> sourceList = new List<string>(); | ||
LayerSourcesDictionary.TryGetValue(layerName, out sourceList); | ||
|
||
if (sourceList.Count > 1 && sourceList.Contains(layerSource)) // the current layerName has more than one source | ||
{ | ||
if (SourceLayersDictionary.ContainsKey(commonLayersKey)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like |
||
{ | ||
SourceLayersDictionary[commonLayersKey].Add(layerName); | ||
} | ||
else | ||
{ | ||
SourceLayersDictionary.Add(commonLayersKey, new List<string>() { layerName }); | ||
} | ||
|
||
if (LayerDisplayNames.Contains(layerName)) | ||
{ | ||
LayerDisplayNames.Remove(layerName); | ||
} | ||
LayerDisplayNames.Add(layerName + " " + commonLayersKey); | ||
} | ||
else | ||
{ | ||
SourceLayersDictionary[layerSource].Add(layerName); | ||
LayerDisplayNames.Add(layerName); | ||
} | ||
} | ||
else | ||
{ | ||
SourceLayersDictionary.Add(layerSource, new List<string>() { layerName }); | ||
LayerDisplayNames.Add(layerName); | ||
} | ||
|
||
|
||
//Load properties | ||
foreach (var property in layer.Fields) | ||
{ | ||
propertyName = property.Key; | ||
propertyDescription = property.Value; | ||
layerPropertiesList.Add(propertyName); | ||
|
||
//adding property descriptions | ||
if (LayerPropertyDescriptionDictionary.ContainsKey(layerName)) | ||
{ | ||
if (!LayerPropertyDescriptionDictionary[layerName].ContainsKey(propertyName)) | ||
{ | ||
LayerPropertyDescriptionDictionary[layerName].Add(propertyName, propertyDescription); | ||
} | ||
} | ||
else | ||
{ | ||
LayerPropertyDescriptionDictionary.Add(layerName, new Dictionary<string, string>() { { propertyName, propertyDescription } }); | ||
} | ||
|
||
//Loading display names for properties | ||
if (PropertyDisplayNames.ContainsKey(layerName)) | ||
{ | ||
if (!PropertyDisplayNames[layerName].Contains(propertyName)) | ||
{ | ||
PropertyDisplayNames[layerName].Add(propertyName); | ||
|
||
//logic to add the list of masked properties from all sources that are not #1 | ||
if (LayerSourcesDictionary[layerName].Count > 1 && !string.IsNullOrEmpty(tjr.Source)) | ||
{ | ||
var firstSource = tjr.Source.Split(new string[] { "," }, System.StringSplitOptions.None)[0].Trim(); | ||
if (layerSource != firstSource) | ||
{ | ||
if (PropertyDisplayNames[layerName].Contains(propertyName)) | ||
{ | ||
PropertyDisplayNames[layerName].Remove(propertyName); | ||
} | ||
|
||
PropertyDisplayNames[layerName].Add(propertyName + " " + optionalPropertiesString); | ||
} | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
PropertyDisplayNames.Add(layerName, new List<string> { propertyName }); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was
3d-buildings
removed from the default prefab settings?