Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
78f415f
adding the data structure for processing tilejson response
apavani Apr 25, 2018
d6acdc5
removed datatype... cleaned the class for ease of use in the future
apavani Apr 25, 2018
57a35b1
new architecture works
apavani Apr 27, 2018
bf56527
wip
apavani Apr 27, 2018
3d6551d
all visible features in for now..
apavani Apr 28, 2018
e8c8139
hacky fix
apavani May 1, 2018
2e3e622
fixed indices
apavani May 1, 2018
ff19f3e
adding unity objectId to editorprefs
apavani May 1, 2018
8d3f29d
mysterious unexplained behaviour.. handled it with a hack
apavani May 3, 2018
a4b0018
solid fix this time.. mystery resolved
apavani May 3, 2018
6849b5b
added warning for invalid tilejson response
apavani May 3, 2018
7e6dd65
basic cosmetic changes in
apavani May 4, 2018
f940aee
ui issue fixed
apavani May 4, 2018
2070520
duplicate layers taken care of
apavani May 4, 2018
613c9ac
fixed indentation issues and checkboxes
apavani May 4, 2018
866a01b
add check for loaded tileJSON
May 5, 2018
f467a2c
added the new UI to the common area
apavani May 5, 2018
549f1e2
cosmetic changes done
apavani May 5, 2018
5854e85
adding formatting changes
apavani May 5, 2018
eccfc52
Update 05-changelog.md
apavani May 5, 2018
110476c
Switch to EditorGuiLayout and some UI formatting changes.
abhishektrip May 6, 2018
23d58eb
Merge commit '7924e699988850c0d8bfd621dd2b387b85ad987d' into ui-forma…
abhishektrip May 6, 2018
79cd30b
Merge commit '23d58eb61e4718efccb61e47f10a1da1aa2f3866' into PreloadN…
abhishektrip May 7, 2018
543ccf9
merging develop
abhishektrip May 7, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions documentation/docs/05-changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## CHANGELOG
### v.1.4.2
*??/??/2018*
- Layer names and property names are preloaded from the data source into a dropdown.

##### BREAKING CHANGES
- Property `Heading` on `Location` object has been split into `UserHeading` and `DeviceOrientation`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public IAsyncRequest Get(string tilesetName, Action<TileJSONResponse> callback)
{
string json = Encoding.UTF8.GetString(response.Data);
TileJSONResponse tileJSONResponse = JsonConvert.DeserializeObject<TileJSONResponse>(json);
if (tileJSONResponse != null)
{
tileJSONResponse.Source = tilesetName;
}
callback(tileJSONResponse);
}
, _timeout
Expand Down
7 changes: 4 additions & 3 deletions sdkproject/Assets/Mapbox/Prefabs/Map.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: cd961b1c9541a4cee99686069ecce852, type: 3}
m_Name:
m_EditorClassIdentifier:
_initializeOnStart: 1
_options:
locationOptions:
latitudeLongitude: 37.784179, -122.401583
Expand Down Expand Up @@ -120,12 +121,12 @@ MonoBehaviour:
wallMaterial: {fileID: 0}
_vectorData:
_layerProperty:
sourceType: 3
sourceType: 1
sourceOptions:
isActive: 0
isActive: 1
layerSource:
Name: Mapbox Terrain
Id: mapbox.3d-buildings,mapbox.mapbox-streets-v7
Id: mapbox.mapbox-streets-v7

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?

Modified:
UserName:
useOptimizedStyle: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public override Type ModifierType
return typeof(HeightModifier);
}
}

[SerializeField]
private string _selectedLayerName = "";
public ExtrusionType extrusionType = ExtrusionType.None;
public ExtrusionGeometryType extrusionGeometryType = ExtrusionGeometryType.RoofAndSide;
[Tooltip("Property name in feature layer to use for extrusion.")]
Expand Down
176 changes: 176 additions & 0 deletions sdkproject/Assets/Mapbox/Unity/DataContainers/TileJsonData.cs
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>();

Copy link
Contributor

Choose a reason for hiding this comment

The 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;

Choose a reason for hiding this comment

The 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))
Copy link
Contributor

Choose a reason for hiding this comment

The 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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like if (SourceLayersDictionary.ContainsKey(commonLayersKey)) only really impacts lines 98 and 107 (aka adding something to SourceLayersDictionary), and the other if-statement is repeated twice. Let's pull out the repeated if-statement to avoid this redundancy, and only write it once.

{
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 });
}
}
}
}
}
}
13 changes: 13 additions & 0 deletions sdkproject/Assets/Mapbox/Unity/DataContainers/TileJsonData.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 15 additions & 10 deletions sdkproject/Assets/Mapbox/Unity/Editor/MapManagerEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
using UnityEngine;
using UnityEditor;
using Mapbox.Unity.Map;
using Mapbox.Platform.TilesetTileJSON;
using System.Collections.Generic;
using Mapbox.VectorTile.ExtensionMethods;

[CustomEditor(typeof(AbstractMap))]
[CanEditMultipleObjects]
public class MapManagerEditor : Editor
{

private string objectId = "";
/// <summary>
/// Gets or sets a value indicating whether to show general section <see cref="T:Mapbox.Editor.MapManagerEditor"/>.
/// </summary>
Expand All @@ -17,11 +21,11 @@ bool ShowGeneral
{
get
{
return EditorPrefs.GetBool("MapManagerEditor_showGeneral");
return EditorPrefs.GetBool(objectId + "MapManagerEditor_showGeneral");
}
set
{
EditorPrefs.SetBool("MapManagerEditor_showGeneral", value);
EditorPrefs.SetBool(objectId + "MapManagerEditor_showGeneral", value);
}
}
/// <summary>
Expand All @@ -32,11 +36,11 @@ bool ShowImage
{
get
{
return EditorPrefs.GetBool("MapManagerEditor_showImage");
return EditorPrefs.GetBool(objectId + "MapManagerEditor_showImage");
}
set
{
EditorPrefs.SetBool("MapManagerEditor_showImage", value);
EditorPrefs.SetBool(objectId + "MapManagerEditor_showImage", value);
}
}
/// <summary>
Expand All @@ -47,11 +51,11 @@ bool ShowTerrain
{
get
{
return EditorPrefs.GetBool("MapManagerEditor_showTerrain");
return EditorPrefs.GetBool(objectId + "MapManagerEditor_showTerrain");
}
set
{
EditorPrefs.SetBool("MapManagerEditor_showTerrain", value);
EditorPrefs.SetBool(objectId + "MapManagerEditor_showTerrain", value);
}
}

Expand Down Expand Up @@ -95,23 +99,23 @@ bool ShowFeatures
{
get
{
return EditorPrefs.GetBool("MapManagerEditor_showVector");
return EditorPrefs.GetBool(objectId + "MapManagerEditor_showVector");
}
set
{
EditorPrefs.SetBool("MapManagerEditor_showVector", value);
EditorPrefs.SetBool(objectId + "MapManagerEditor_showVector", value);
}
}

bool ShowPosition
{
get
{
return EditorPrefs.GetBool("MapManagerEditor_showPosition");
return EditorPrefs.GetBool(objectId + "MapManagerEditor_showPosition");
}
set
{
EditorPrefs.SetBool("MapManagerEditor_showPosition", value);
EditorPrefs.SetBool(objectId + "MapManagerEditor_showPosition", value);
}
}

Expand Down Expand Up @@ -139,6 +143,7 @@ string CustomSourceMapId

public override void OnInspectorGUI()
{
objectId = serializedObject.targetObject.GetInstanceID().ToString();
serializedObject.Update();
EditorGUILayout.BeginVertical();
EditorGUILayout.Space();
Expand Down
Loading