diff --git a/sdkproject/Assets/ApiFilterTest.cs b/sdkproject/Assets/ApiFilterTest.cs new file mode 100644 index 000000000..7f8c8fb95 --- /dev/null +++ b/sdkproject/Assets/ApiFilterTest.cs @@ -0,0 +1,367 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using Mapbox.Unity.Map; +using Mapbox.Unity.MeshGeneration.Interfaces; +using Mapbox.Unity.MeshGeneration.Filters; +using UnityEngine; + +public class ApiFilterTest : MonoBehaviour +{ + private AbstractMap _abstractMap; + + private VectorSubLayerProperties[] _layers; + + public string layerToWorkWith; + + public string Key; + public LayerFilterOperationType layerFilterOperationType; + public float min; + public float max; + public string property; + + public LayerFilterCombinerOperationType layerFilterCombinerOperationType; + + void Start() + { + _abstractMap = FindObjectOfType(); + } + + private VectorSubLayerProperties[] GetLayers() + { + VectorSubLayerProperties[] vectorSubLayers; + if(!string.IsNullOrEmpty(layerToWorkWith)) + { + vectorSubLayers = new VectorSubLayerProperties[] { _abstractMap.VectorData.FindFeatureLayerWithName(layerToWorkWith) }; + } + else + { + vectorSubLayers = _abstractMap.VectorData.GetAllFeatureLayers().ToArray(); + } + return vectorSubLayers; + } + + private void DebugFilterInfo(ILayerFilter layerFilter) + { + Debug.Log("Key : " + layerFilter.GetKey); + Debug.Log("Operator : " + layerFilter.GetFilterOperationType.ToString()); + Debug.Log("Property : " + layerFilter.GetPropertyValue); + Debug.Log("Min/Max : " + layerFilter.GetMinValue + ", " + layerFilter.GetMaxValue); + } + + [ContextMenu("Check Filter ALL")] + public void CheckFilterAll() + { + VectorSubLayerProperties[] layers = GetLayers(); + for (int i = 0; i < layers.Length; i++) + { + ILayerFilter[] filters = layers[i].Filtering.GetFiltersByQuery(x => (x.FilterKeyMatchesExact(Key) && x.FilterUsesOperationType(layerFilterOperationType) && x.FilterNumberValueEquals(min))).ToArray(); + if (filters.Length == 0) + { + continue; + } + Debug.Log(layers[i].Key); + for (int j = 0; j < filters.Length; j++) + { + ILayerFilter layerFilter = filters[j]; + DebugFilterInfo(layerFilter); + } + } + } + + [ContextMenu("Check Filter ANY")] + public void CheckFilterAny() + { + VectorSubLayerProperties[] layers = GetLayers(); + for (int i = 0; i < layers.Length; i++) + { + ILayerFilter[] filters = layers[i].Filtering.GetFiltersByQuery(x => (x.FilterKeyMatchesExact(Key) || x.FilterUsesOperationType(layerFilterOperationType) || x.FilterNumberValueEquals(min))).ToArray(); + if (filters.Length == 0) + { + continue; + } + Debug.Log(layers[i].Key); + for (int j = 0; j < filters.Length; j++) + { + ILayerFilter layerFilter = filters[j]; + DebugFilterInfo(layerFilter); + } + } + } + + [ContextMenu("Check Filter Key Exact")] + public void CheckFilterKeyExact() + { + VectorSubLayerProperties[] layers = GetLayers(); + for (int i = 0; i < layers.Length; i++) + { + ILayerFilter[] filters = layers[i].Filtering.GetFiltersByQuery(x => (x.FilterKeyMatchesExact(Key))).ToArray(); + if(filters.Length == 0) + { + continue; + } + Debug.Log(layers[i].Key); + for (int j = 0; j < filters.Length; j++) + { + ILayerFilter layerFilter = filters[j]; + DebugFilterInfo(layerFilter); + } + } + } + + [ContextMenu("Check Filter Key Contains")] + public void CheckFilterKeyContains() + { + VectorSubLayerProperties[] layers = GetLayers(); + for (int i = 0; i < layers.Length; i++) + { + ILayerFilter[] filters = layers[i].Filtering.GetFiltersByQuery(x => (x.FilterKeyContains(Key))).ToArray(); + if (filters.Length == 0) + { + continue; + } + Debug.Log(layers[i].Key); + for (int j = 0; j < filters.Length; j++) + { + ILayerFilter layerFilter = filters[j]; + DebugFilterInfo(layerFilter); + } + } + } + + [ContextMenu("Check Filter Uses Operation Type")] + public void CheckFilterUsesOperationType() + { + VectorSubLayerProperties[] layers = GetLayers(); + for (int i = 0; i < layers.Length; i++) + { + ILayerFilter[] filters = layers[i].Filtering.GetFiltersByQuery(x => (x.FilterUsesOperationType(layerFilterOperationType))).ToArray(); + if (filters.Length == 0) + { + continue; + } + Debug.Log(layers[i].Key); + for (int j = 0; j < filters.Length; j++) + { + ILayerFilter layerFilter = filters[j]; + DebugFilterInfo(layerFilter); + } + } + } + + [ContextMenu("Check Filter Has Exact Property")] + public void CheckFilterHasExactProperty() + { + VectorSubLayerProperties[] layers = GetLayers(); + for (int i = 0; i < layers.Length; i++) + { + ILayerFilter[] filters = layers[i].Filtering.GetFiltersByQuery(x => (x.FilterPropertyMatchesExact(property))).ToArray(); + if (filters.Length == 0) + { + continue; + } + Debug.Log(layers[i].Key); + for (int j = 0; j < filters.Length; j++) + { + ILayerFilter layerFilter = filters[j]; + DebugFilterInfo(layerFilter); + } + } + } + + [ContextMenu("Check Filter Contains Property")] + public void CheckFilterContainsProperty() + { + VectorSubLayerProperties[] layers = GetLayers(); + for (int i = 0; i < layers.Length; i++) + { + ILayerFilter[] filters = layers[i].Filtering.GetFiltersByQuery(x => (x.FilterPropertyContains(property))).ToArray(); + if (filters.Length == 0) + { + continue; + } + Debug.Log(layers[i].Key); + for (int j = 0; j < filters.Length; j++) + { + ILayerFilter layerFilter = filters[j]; + DebugFilterInfo(layerFilter); + } + } + } + + [ContextMenu("Check Filter Num Is Equal")] + public void CheckFilterNumValueIsEqual() + { + VectorSubLayerProperties[] layers = GetLayers(); + for (int i = 0; i < layers.Length; i++) + { + ILayerFilter[] filters = layers[i].Filtering.GetFiltersByQuery(x => (x.FilterNumberValueEquals(min))).ToArray(); + if (filters.Length == 0) + { + continue; + } + Debug.Log(layers[i].Key); + for (int j = 0; j < filters.Length; j++) + { + ILayerFilter layerFilter = filters[j]; + DebugFilterInfo(layerFilter); + } + } + } + + [ContextMenu("Check Filter Num Is Less")] + public void CheckFilterNumValueIsLess() + { + VectorSubLayerProperties[] layers = GetLayers(); + for (int i = 0; i < layers.Length; i++) + { + ILayerFilter[] filters = layers[i].Filtering.GetFiltersByQuery(x => (x.FilterNumberValueIsLessThan(min))).ToArray(); + if (filters.Length == 0) + { + continue; + } + Debug.Log(layers[i].Key); + for (int j = 0; j < filters.Length; j++) + { + ILayerFilter layerFilter = filters[j]; + DebugFilterInfo(layerFilter); + } + } + } + + [ContextMenu("Check Filter Num Is Greater")] + public void CheckFilterNumValueIsGreater() + { + VectorSubLayerProperties[] layers = GetLayers(); + for (int i = 0; i < layers.Length; i++) + { + ILayerFilter[] filters = layers[i].Filtering.GetFiltersByQuery(x => (x.FilterNumberValueIsGreaterThan(min))).ToArray(); + if (filters.Length == 0) + { + continue; + } + Debug.Log(layers[i].Key); + for (int j = 0; j < filters.Length; j++) + { + ILayerFilter layerFilter = filters[j]; + DebugFilterInfo(layerFilter); + } + } + } + + [ContextMenu("Set String Contains")] + public void SetStringContains() + { + VectorSubLayerProperties[] layers = GetLayers(); + for (int i = 0; i < layers.Length; i++) + { + ILayerFilter[] filters = layers[i].Filtering.GetAllFilters().ToArray(); + if (filters.Length != 0) + { + ILayerFilter layerFilter = filters[i]; + layerFilter.SetStringContains(Key, property); + } + } + } + + [ContextMenu("Set Number Is Equal")] + public void SetNumberIsEqual() + { + VectorSubLayerProperties[] layers = GetLayers(); + for (int i = 0; i < layers.Length; i++) + { + ILayerFilter[] filters = layers[i].Filtering.GetAllFilters().ToArray(); + if (filters.Length != 0) + { + ILayerFilter layerFilter = filters[i]; + layerFilter.SetNumberIsEqual(Key, min); + } + } + } + + [ContextMenu("Set Number Is Less Than")] + public void SetNumberIsLessThan() + { + VectorSubLayerProperties[] layers = GetLayers(); + for (int i = 0; i < layers.Length; i++) + { + ILayerFilter[] filters = layers[i].Filtering.GetAllFilters().ToArray(); + if (filters.Length != 0) + { + ILayerFilter layerFilter = filters[i]; + layerFilter.SetNumberIsLessThan(Key, min); + } + } + } + + [ContextMenu("Set Number Is Greater Than")] + public void SetNumberIsGreaterThan() + { + VectorSubLayerProperties[] layers = GetLayers(); + for (int i = 0; i < layers.Length; i++) + { + ILayerFilter[] filters = layers[i].Filtering.GetAllFilters().ToArray(); + if (filters.Length != 0) + { + ILayerFilter layerFilter = filters[i]; + layerFilter.SetNumberIsGreaterThan(Key, min); + } + } + } + + [ContextMenu("Set Number Is In Range")] + public void SetNumberIsInRange() + { + VectorSubLayerProperties[] layers = GetLayers(); + for (int i = 0; i < layers.Length; i++) + { + ILayerFilter[] filters = layers[i].Filtering.GetAllFilters().ToArray(); + if (filters.Length != 0) + { + ILayerFilter layerFilter = filters[i]; + layerFilter.SetNumberIsInRange(Key, min, max); + } + } + } + + [ContextMenu("Add String Filter Contains")] + public void AddStringFilterContains() + { + VectorSubLayerProperties[] layers = GetLayers(); + for (int i = 0; i < layers.Length; i++) + { + layers[i].Filtering.AddStringFilterContains(Key, property); + } + } + + [ContextMenu("Add Numeric Filter Equals")] + public void AddNumericFilterEquals() + { + VectorSubLayerProperties[] layers = GetLayers(); + for (int i = 0; i < layers.Length; i++) + { + layers[i].Filtering.AddNumericFilterEquals(Key, min); + } + } + + [ContextMenu("Add Numeric Filter Is Less Than")] + public void AddNumericFilterLessThan() + { + VectorSubLayerProperties[] layers = GetLayers(); + for (int i = 0; i < layers.Length; i++) + { + layers[i].Filtering.AddNumericFilterLessThan(Key, min); + } + } + + [ContextMenu("Add Numeric Filter Is Greater Than")] + public void AddNumericFilterGreaterThan() + { + VectorSubLayerProperties[] layers = GetLayers(); + for (int i = 0; i < layers.Length; i++) + { + layers[i].Filtering.AddNumericFilterGreaterThan(Key, min); + } + } +} diff --git a/sdkproject/Assets/ApiFilterTest.cs.meta b/sdkproject/Assets/ApiFilterTest.cs.meta new file mode 100644 index 000000000..d57be81d8 --- /dev/null +++ b/sdkproject/Assets/ApiFilterTest.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3f047eb8e4504463ebb726ccb48da992 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/sdkproject/Assets/ApiTest.cs b/sdkproject/Assets/ApiTest.cs index cf1b3a014..b1848018f 100644 --- a/sdkproject/Assets/ApiTest.cs +++ b/sdkproject/Assets/ApiTest.cs @@ -127,7 +127,7 @@ public void ChangeBuildingMaterial() var layer = _abstractMap.VectorData.FindFeatureLayerWithName("ExtrudedBuildings"); if (layer != null) { - layer.SetStyleType(testStyles[styleId]); + layer.Texturing.SetStyleType(testStyles[styleId]); } else { diff --git a/sdkproject/Assets/Mapbox/Unity/Editor/PropertyDrawers/VectorFilterOptionsDrawer.cs b/sdkproject/Assets/Mapbox/Unity/Editor/PropertyDrawers/VectorFilterOptionsDrawer.cs index d397fba67..a98e0b5d7 100644 --- a/sdkproject/Assets/Mapbox/Unity/Editor/PropertyDrawers/VectorFilterOptionsDrawer.cs +++ b/sdkproject/Assets/Mapbox/Unity/Editor/PropertyDrawers/VectorFilterOptionsDrawer.cs @@ -39,6 +39,7 @@ bool showFilters public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { objectId = property.serializedObject.targetObject.GetInstanceID().ToString(); + VectorFilterOptions options = (VectorFilterOptions)EditorHelper.GetTargetObjectOfProperty(property); showFilters = EditorGUILayout.Foldout(showFilters, new GUIContent { text = "Filters", tooltip = "Filter features in a vector layer based on criterion specified. " }); if (showFilters) @@ -47,10 +48,7 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten for (int i = 0; i < propertyFilters.arraySize; i++) { - if(DrawLayerFilter(property, propertyFilters, i)) - { - EditorHelper.CheckForModifiedProperty(property); - } + DrawLayerFilter(property, propertyFilters, i, options); } if (propertyFilters.arraySize > 0) { @@ -68,7 +66,7 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten EditorGUI.BeginChangeCheck(); if (GUILayout.Button(new GUIContent("Add New Empty"), (GUIStyle)"minibutton")) { - propertyFilters.arraySize++; + options.AddFilter(); } if (EditorGUI.EndChangeCheck()) { @@ -84,10 +82,10 @@ public override float GetPropertyHeight(SerializedProperty property, GUIContent return lineHeight; } - private bool DrawLayerFilter(SerializedProperty originalProperty, SerializedProperty propertyFilters, int index) + private void DrawLayerFilter(SerializedProperty originalProperty, SerializedProperty propertyFilters, int index, VectorFilterOptions vectorFilterOptions) { - bool hasChanged = false; var property = propertyFilters.GetArrayElementAtIndex(index); + var filterOperatorProp = property.FindPropertyRelative("filterOperator"); EditorGUILayout.BeginVertical(); @@ -96,7 +94,6 @@ private bool DrawLayerFilter(SerializedProperty originalProperty, SerializedProp EditorGUILayout.LabelField(new GUIContent { text = "Key", tooltip = "Name of the property to use as key. This property is case sensitive." }, GUILayout.MaxWidth(150)); - switch ((LayerFilterOperationType)filterOperatorProp.enumValueIndex) { case LayerFilterOperationType.IsEqual: @@ -124,16 +121,13 @@ private bool DrawLayerFilter(SerializedProperty originalProperty, SerializedProp var selectedLayerName = originalProperty.FindPropertyRelative("_selectedLayerName").stringValue; - if(DrawPropertyDropDown(originalProperty, property)) - { - hasChanged = true; - } + DrawPropertyDropDown(originalProperty, property); EditorGUI.BeginChangeCheck(); filterOperatorProp.enumValueIndex = EditorGUILayout.Popup(filterOperatorProp.enumValueIndex, filterOperatorProp.enumDisplayNames, GUILayout.MaxWidth(150)); if (EditorGUI.EndChangeCheck()) { - hasChanged = true; + EditorHelper.CheckForModifiedProperty(property); } EditorGUI.BeginChangeCheck(); @@ -156,29 +150,21 @@ private bool DrawLayerFilter(SerializedProperty originalProperty, SerializedProp } if (EditorGUI.EndChangeCheck()) { - hasChanged = true; + EditorHelper.CheckForModifiedProperty(property); } - EditorGUI.BeginChangeCheck(); if (GUILayout.Button(new GUIContent(" X "), (GUIStyle)"minibuttonright", GUILayout.Width(30))) { - propertyFilters.DeleteArrayElementAtIndex(index); - } - if (EditorGUI.EndChangeCheck()) - { - hasChanged = true; + vectorFilterOptions.RemoveFilter(index); } EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); - - return hasChanged; } - private bool DrawPropertyDropDown(SerializedProperty originalProperty, SerializedProperty filterProperty) + private void DrawPropertyDropDown(SerializedProperty originalProperty, SerializedProperty filterProperty) { - bool hasChanged = false; var selectedLayerName = originalProperty.FindPropertyRelative("_selectedLayerName").stringValue; AbstractMap mapObject = (AbstractMap)originalProperty.serializedObject.targetObject; @@ -187,7 +173,7 @@ private bool DrawPropertyDropDown(SerializedProperty originalProperty, Serialize if (string.IsNullOrEmpty(selectedLayerName) || !tileJsonData.PropertyDisplayNames.ContainsKey(selectedLayerName)) { DrawWarningMessage(); - return false; + return; } var parsedString = "no property selected"; @@ -219,7 +205,7 @@ private bool DrawPropertyDropDown(SerializedProperty originalProperty, Serialize _propertyIndex = EditorGUILayout.Popup(_propertyIndex, _propertyNameContent, GUILayout.MaxWidth(150)); if (EditorGUI.EndChangeCheck()) { - hasChanged = true; + EditorHelper.CheckForModifiedProperty(filterProperty); } //set new string values based on selection @@ -258,7 +244,7 @@ private bool DrawPropertyDropDown(SerializedProperty originalProperty, Serialize _propertyIndex = EditorGUILayout.Popup(_propertyIndex, _propertyNameContent, GUILayout.MaxWidth(150)); if (EditorGUI.EndChangeCheck()) { - hasChanged = true; + EditorHelper.CheckForModifiedProperty(filterProperty); } //set new string values based on the offset @@ -270,11 +256,9 @@ private bool DrawPropertyDropDown(SerializedProperty originalProperty, Serialize filterProperty.FindPropertyRelative("Key").stringValue = parsedString; if (EditorGUI.EndChangeCheck()) { - hasChanged = true; + EditorHelper.CheckForModifiedProperty(filterProperty); } filterProperty.FindPropertyRelative("KeyDescription").stringValue = descriptionString; - - return hasChanged; } private void DrawWarningMessage() diff --git a/sdkproject/Assets/Mapbox/Unity/LayerProperties/CoreVectorLayerProperties.cs b/sdkproject/Assets/Mapbox/Unity/LayerProperties/CoreVectorLayerProperties.cs index 9d651580b..81c49257c 100644 --- a/sdkproject/Assets/Mapbox/Unity/LayerProperties/CoreVectorLayerProperties.cs +++ b/sdkproject/Assets/Mapbox/Unity/LayerProperties/CoreVectorLayerProperties.cs @@ -1,11 +1,10 @@ namespace Mapbox.Unity.Map { using System; - using System.Collections.Generic; - using Mapbox.Unity.MeshGeneration.Filters; using Mapbox.Unity.MeshGeneration.Modifiers; using UnityEngine; + [Serializable] public class CoreVectorLayerProperties : MapboxDataProperty, ISubLayerCoreOptions { @@ -24,6 +23,7 @@ public class CoreVectorLayerProperties : MapboxDataProperty, ISubLayerCoreOption [Tooltip("Groups features into one Unity GameObject.")] public bool combineMeshes = false; + public override bool HasChanged { set @@ -50,16 +50,6 @@ public virtual void SetPrimitiveType(VectorPrimitiveType type) HasChanged = true; } } - } - [Serializable] - public class VectorFilterOptions : MapboxDataProperty, ISubLayerFiltering - { - [SerializeField] - private string _selectedLayerName; - public List filters = new List(); - [Tooltip("Operator to combine filters. ")] - public LayerFilterCombinerOperationType combinerType = LayerFilterCombinerOperationType.All; } - } diff --git a/sdkproject/Assets/Mapbox/Unity/LayerProperties/VectorFilterOptions.cs b/sdkproject/Assets/Mapbox/Unity/LayerProperties/VectorFilterOptions.cs new file mode 100644 index 000000000..3b4449830 --- /dev/null +++ b/sdkproject/Assets/Mapbox/Unity/LayerProperties/VectorFilterOptions.cs @@ -0,0 +1,193 @@ +namespace Mapbox.Unity.Map +{ + using System; + using System.Collections.Generic; + using Mapbox.Unity.MeshGeneration.Filters; + using UnityEngine; + using System.Linq; + + [Serializable] + public class VectorFilterOptions : MapboxDataProperty, ISubLayerFiltering + { + [SerializeField] + private string _selectedLayerName; + public List filters = new List(); + [Tooltip("Operator to combine filters. ")] + public LayerFilterCombinerOperationType combinerType = LayerFilterCombinerOperationType.All; + + public override bool HasChanged + { + set + { + if (value == true) + { + OnPropertyHasChanged(new VectorLayerUpdateArgs { property = this }); + } + } + } + + public void UnRegisterFilters() + { + for (int i = 0; i < filters.Count; i++) + { + filters[i].PropertyHasChanged -= OnLayerFilterChanged; + } + } + + public void RegisterFilters() + { + for (int i = 0; i < filters.Count; i++) + { + filters[i].PropertyHasChanged += OnLayerFilterChanged; + } + } + + private void OnLayerFilterChanged(object sender, System.EventArgs eventArgs) + { + HasChanged = true; + } + + private void AddFilterToList(LayerFilter layerFilter) + { + filters.Add(layerFilter); + HasChanged = true; + } + + public virtual ILayerFilter AddStringFilterContains(string key, string property) + { + LayerFilter layerFilter = new LayerFilter() + { + Key = key, + filterOperator = LayerFilterOperationType.Contains, + PropertyValue = property + }; + AddFilterToList(layerFilter); + return layerFilter; + + } + + public virtual ILayerFilter AddNumericFilterEquals(string key, float value) + { + LayerFilter layerFilter = new LayerFilter() + { + Key = key, + filterOperator = LayerFilterOperationType.IsEqual, + Min = value + }; + AddFilterToList(layerFilter); + return layerFilter; + } + + public virtual ILayerFilter AddNumericFilterLessThan(string key, float value) + { + LayerFilter layerFilter = new LayerFilter() + { + Key = key, + filterOperator = LayerFilterOperationType.IsLess, + Min = value + }; + AddFilterToList(layerFilter); + return layerFilter; + } + + public virtual ILayerFilter AddNumericFilterGreaterThan(string key, float value) + { + LayerFilter layerFilter = new LayerFilter() + { + Key = key, + filterOperator = LayerFilterOperationType.IsGreater, + Min = value + }; + AddFilterToList(layerFilter); + return layerFilter; + } + + public virtual ILayerFilter AddNumericFilterInRange(string key, float min, float max) + { + LayerFilter layerFilter = new LayerFilter() + { + Key = key, + filterOperator = LayerFilterOperationType.IsInRange, + Min = min, + Max = max + }; + AddFilterToList(layerFilter); + return layerFilter; + } + + public void AddFilter() + { + AddFilterToList(new LayerFilter()); + } + + public virtual void RemoveAllFilters() + { + for (int i = 0; i < filters.Count; i++) + { + LayerFilter filter = filters[i]; + if (filter != null) + { + RemoveFilter(filter); + } + } + } + + public virtual void RemoveFilter(LayerFilter layerFilter) + { + layerFilter.PropertyHasChanged -= OnLayerFilterChanged; + if (filters.Contains(layerFilter)) + { + filters.Remove(layerFilter); + HasChanged = true; + } + } + + public virtual void RemoveFilter(ILayerFilter filter) + { + RemoveFilter((LayerFilter)filter); + } + + public virtual void RemoveFilter(int index) + { + if (index < filters.Count && filters[index] != null) + { + RemoveFilter(filters[index]); + } + } + + public virtual ILayerFilter GetFilter(int index) + { + if (index < filters.Count && filters[index] != null) + { + return filters[index]; + } + return null; + } + + public virtual IEnumerable GetAllFilters() + { + return (IEnumerable)filters.AsEnumerable(); + } + + public virtual IEnumerable GetFiltersByQuery(Func query) + { + foreach (var filter in filters) + { + if (query(filter)) + { + yield return filter; + } + } + } + + public virtual LayerFilterCombinerOperationType GetFilterCombinerType() + { + return combinerType; + } + + public virtual void SetFilterCombinerType(LayerFilterCombinerOperationType layerFilterCombinerOperationType) + { + combinerType = layerFilterCombinerOperationType; + } + } +} diff --git a/sdkproject/Assets/Mapbox/Unity/LayerProperties/VectorFilterOptions.cs.meta b/sdkproject/Assets/Mapbox/Unity/LayerProperties/VectorFilterOptions.cs.meta new file mode 100644 index 000000000..18afa0783 --- /dev/null +++ b/sdkproject/Assets/Mapbox/Unity/LayerProperties/VectorFilterOptions.cs.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +guid: e9aaba31e5228477fa26423d86426c63 +timeCreated: 1538538304 +licenseType: Pro +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/sdkproject/Assets/Mapbox/Unity/LayerProperties/VectorSubLayerProperties.cs b/sdkproject/Assets/Mapbox/Unity/LayerProperties/VectorSubLayerProperties.cs index d9ff074cc..a92a203ad 100644 --- a/sdkproject/Assets/Mapbox/Unity/LayerProperties/VectorSubLayerProperties.cs +++ b/sdkproject/Assets/Mapbox/Unity/LayerProperties/VectorSubLayerProperties.cs @@ -146,243 +146,26 @@ public virtual void SetActive(bool active) } /// - /// Sets the type of the style. + /// Switch layer to custom style using provided mesh and game object modifier /// - /// Style. - public virtual void SetStyleType(StyleTypes style) - { - materialOptions.style = style; - materialOptions.HasChanged = true; - } - - - /// - /// Sets the layer to use the realistic style. - /// - public virtual void SetRealisticStyle() - { - materialOptions.style = StyleTypes.Realistic; - materialOptions.HasChanged = true; - } - - /// - /// Sets the layer to use the fantasy style. - /// - public virtual void SetFantasyStyle() - { - materialOptions.style = StyleTypes.Fantasy; - materialOptions.HasChanged = true; - } - - /// - /// Sets the type of the simple style palette. - /// - /// Palette. - public virtual void SetSimpleStylePaletteType(SamplePalettes palette) - { - materialOptions.samplePalettes = palette; - materialOptions.HasChanged = true; - } - - /// - /// Sets the light style opacity. - /// - /// Opacity. - public virtual void SetLightStyleOpacity(float opacity) - { - materialOptions.lightStyleOpacity = Mathf.Clamp(opacity, 0.0f, 1.0f); - materialOptions.HasChanged = true; - } - - /// - /// Sets the dark style opacity. - /// - /// Opacity. - public virtual void SetDarkStyleOpacity(float opacity) - { - materialOptions.darkStyleOpacity = Mathf.Clamp(opacity, 0.0f, 1.0f); - materialOptions.HasChanged = true; - } - - /// - /// Sets the color of the color style. - /// - /// Color. - public virtual void SetColorStyleColor(Color color) + /// Mesh modifiers to be used in layer + /// Game object modifiers to be used in layer + public virtual void CreateCustomStyle(List meshModifiers, List gameObjectModifiers) { - materialOptions.colorStyleColor = color; - materialOptions.HasChanged = true; - } - - /// - /// Sets the texturing (UV) type of the custom style. - /// - /// Uv map type. - public virtual void SetCustomTexturingType(UvMapType uvMapType) - { - materialOptions.texturingType = uvMapType; - materialOptions.HasChanged = true; - } - - /// - /// Sets the custom style top material. - /// - /// Material. - public virtual void SetCustomTopMaterial(Material material) - { - materialOptions.materials[0].Materials[0] = material; - materialOptions.HasChanged = true; - } - - /// - /// Sets the custom style side material. - /// - /// Material. - public virtual void SetCustomSideMaterial(Material material) - { - materialOptions.materials[1].Materials[0] = material; - materialOptions.HasChanged = true; - } - - /// - /// Sets the custom style top and side materials. - /// - /// Top material. - /// Side material. - public virtual void SetCustomMaterials(Material topMaterial, Material sideMaterial) - { - materialOptions.materials[0].Materials[0] = topMaterial; - materialOptions.materials[1].Materials[0] = sideMaterial; - materialOptions.HasChanged = true; - } - - /// - /// Sets the custom style uv atlas. - /// - /// Atlas. - public virtual void SetCustomUvAtlas(AtlasInfo atlas) - { - materialOptions.atlasInfo = atlas; - materialOptions.HasChanged = true; - } - - /// - /// Sets the custom style color palette. - /// - /// Palette. - public virtual void SetCustomColorPalette(ScriptablePalette palette) - { - materialOptions.colorPalette = palette; - materialOptions.HasChanged = true; - } - - /// - /// Sets the custom style assets using a CustomStyleBundle object. - /// - /// Custom style bundle. - public virtual void SetCustomStyleAssets(CustomStyleBundle customStyleBundle) - { - materialOptions.materials[0].Materials[0] = (customStyleBundle.sideMaterial != null) ? customStyleBundle.sideMaterial : materialOptions.materials[0].Materials[0]; - materialOptions.materials[1].Materials[0] = (customStyleBundle.topMaterial != null) ? customStyleBundle.topMaterial : materialOptions.materials[1].Materials[0]; - materialOptions.atlasInfo = (customStyleBundle.atlasInfo != null) ? customStyleBundle.atlasInfo : materialOptions.atlasInfo; - materialOptions.colorPalette = (customStyleBundle.colorPalette != null) ? customStyleBundle.colorPalette : materialOptions.colorPalette; - materialOptions.HasChanged = true; - } - - #endregion - - #region Getters - - /// - /// Gets the type of style used in the layer. - /// - /// The style type. - public virtual StyleTypes GetStyleType() - { - return materialOptions.style; - } - - /// - /// Gets the type of simple style palette used in the layer. - /// - /// The simple style palette type. - public virtual SamplePalettes GetSimpleStylePaletteType() - { - return materialOptions.samplePalettes; - } - - /// - /// Gets the light style opacity. - /// - /// The light style opacity. - public virtual float GetLightStyleOpacity() - { - return materialOptions.lightStyleOpacity; - } - - /// - /// Gets the dark style opacity. - /// - /// The dark style opacity. - public virtual float GetDarkStyleOpacity() - { - return materialOptions.darkStyleOpacity; - } - - /// - /// Gets the color of the color style. - /// - /// The color style color. - public virtual Color GetColorStyleColor() - { - return materialOptions.colorStyleColor; - } - - /// - /// Gets the type of the custom style texturing. - /// - /// The custom texturing type. - public virtual UvMapType GetTexturingType() - { - return materialOptions.texturingType; - } - - /// - /// Gets the custom top material. - /// - /// The custom top material. - public virtual Material GetTopMaterial() - { - return materialOptions.materials[0].Materials[0]; - } - - /// - /// Gets the custom side material. - /// - /// The custom side material. - public virtual Material GetSideMaterial() - { - return materialOptions.materials[1].Materials[0]; - } - - /// - /// Gets the custom uv atlas. - /// - /// The custom uv atlas. - public virtual AtlasInfo GetUvAtlas() - { - return materialOptions.atlasInfo; - } + coreOptions.geometryType = VectorPrimitiveType.Custom; + coreOptions.HasChanged = true; - /// - /// Gets the custom color palette. - /// - /// The custom color palette. - public virtual ScriptablePalette GetColorPalette() - { - return materialOptions.colorPalette; + MeshModifiers.Clear(); + foreach (var meshModifier in meshModifiers) + { + MeshModifiers.Add(meshModifier); + } + foreach (var goModifier in gameObjectModifiers) + { + GoModifiers.Add(goModifier); + } + HasChanged = true; } - #endregion } } diff --git a/sdkproject/Assets/Mapbox/Unity/Map/AbstractMap.cs b/sdkproject/Assets/Mapbox/Unity/Map/AbstractMap.cs index ccf827e61..eb82d789a 100644 --- a/sdkproject/Assets/Mapbox/Unity/Map/AbstractMap.cs +++ b/sdkproject/Assets/Mapbox/Unity/Map/AbstractMap.cs @@ -420,11 +420,12 @@ protected virtual void SetUpMap() } _vectorData.Initialize(); - _mapVisualizer.Factories = new List(); - - _mapVisualizer.Factories.Add(_terrain.Factory); - _mapVisualizer.Factories.Add(_imagery.Factory); - _mapVisualizer.Factories.Add(_vectorData.Factory); + _mapVisualizer.Factories = new List + { + _terrain.Factory, + _imagery.Factory, + _vectorData.Factory + }; InitializeMap(_options); } @@ -549,84 +550,16 @@ protected virtual void InitializeMap(MapOptions options) _initialZoom = (int)options.locationOptions.zoom; options.scalingOptions.scalingStrategy.SetUpScaling(this); - options.placementOptions.placementStrategy.SetUpPlacement(this); - _imagery.UpdateLayer += (object sender, System.EventArgs eventArgs) => - { - LayerUpdateArgs layerUpdateArgs = eventArgs as LayerUpdateArgs; - if (layerUpdateArgs != null) - { - Debug.Log("Image"); - _mapVisualizer.UpdateTileForProperty(layerUpdateArgs.factory, layerUpdateArgs); - if (layerUpdateArgs.effectsVectorLayer) - { - _mapVisualizer.UnregisterTilesFrom(VectorData.Factory); - VectorData.UpdateFactorySettings(); - _mapVisualizer.ReregisterTilesTo(VectorData.Factory); - } - OnMapRedrawn(); - } - }; - _terrain.UpdateLayer += (object sender, System.EventArgs eventArgs) => - { - LayerUpdateArgs layerUpdateArgs = eventArgs as LayerUpdateArgs; - if (layerUpdateArgs != null) - { - Debug.Log("Terrain"); - _mapVisualizer.UpdateTileForProperty(layerUpdateArgs.factory, layerUpdateArgs); - if (layerUpdateArgs.effectsVectorLayer) - { - _mapVisualizer.UnregisterTilesFrom(VectorData.Factory); - VectorData.UpdateFactorySettings(); - _mapVisualizer.ReregisterTilesTo(VectorData.Factory); - } - OnMapRedrawn(); - } - }; + //Set up events for changes. + _imagery.UpdateLayer += OnImageOrTerrainUpdateLayer; + _terrain.UpdateLayer += OnImageOrTerrainUpdateLayer; - _vectorData.SubLayerRemoved += (object sender, EventArgs eventArgs) => - { - VectorLayerUpdateArgs layerUpdateArgs = eventArgs as VectorLayerUpdateArgs; - - if (layerUpdateArgs.visualizer != null) - { - _mapVisualizer.RemoveTilesFromLayer((VectorTileFactory)layerUpdateArgs.factory, layerUpdateArgs.visualizer); - } - - Debug.Log("Vector"); - OnMapRedrawn(); - }; - _vectorData.SubLayerAdded += (object sender, EventArgs eventArgs) => - { - _mapVisualizer.UnregisterTilesFrom(VectorData.Factory); - VectorData.UpdateFactorySettings(); - _mapVisualizer.ReregisterTilesTo(VectorData.Factory); - - Debug.Log("Vector"); - OnMapRedrawn(); - }; - _vectorData.UpdateLayer += (object sender, System.EventArgs eventArgs) => - { - VectorLayerUpdateArgs layerUpdateArgs = eventArgs as VectorLayerUpdateArgs; - - if (layerUpdateArgs.visualizer != null) - { - Debug.Log("UnregisterTiles"); - //we got a visualizer. Update only the visualizer. - // No need to unload the entire factory to apply changes. - _mapVisualizer.UnregisterTilesFromLayer((VectorTileFactory)layerUpdateArgs.factory, layerUpdateArgs.visualizer); - } - else - { - //We are updating a core property of vector section. - //All vector features need to get unloaded and re-created. - _mapVisualizer.UpdateTileForProperty(layerUpdateArgs.factory, layerUpdateArgs); - } - Debug.Log("Vector"); - OnMapRedrawn(); - }; + _vectorData.SubLayerRemoved += OnVectorDataSubLayerRemoved; + _vectorData.SubLayerAdded += OnVectorDataSubLayerAdded; + _vectorData.UpdateLayer += OnVectorDataUpdateLayer; _options.PropertyHasChanged += (object sender, System.EventArgs eventArgs) => { @@ -679,6 +612,68 @@ protected virtual void InitializeMap(MapOptions options) _tileProvider.UpdateTileExtent(); } + private void OnImageOrTerrainUpdateLayer(object sender, System.EventArgs eventArgs) + { + LayerUpdateArgs layerUpdateArgs = eventArgs as LayerUpdateArgs; + if (layerUpdateArgs != null) + { + _mapVisualizer.UpdateTileForProperty(layerUpdateArgs.factory, layerUpdateArgs); + if (layerUpdateArgs.effectsVectorLayer) + { + RedrawVectorDataLayer(); + } + OnMapRedrawn(); + } + } + + private void RedrawVectorDataLayer() + { + _mapVisualizer.UnregisterTilesFrom(VectorData.Factory); + VectorData.UpdateFactorySettings(); + _mapVisualizer.ReregisterTilesTo(VectorData.Factory); + } + + private void OnVectorDataSubLayerRemoved(object sender, EventArgs eventArgs) + { + VectorLayerUpdateArgs layerUpdateArgs = eventArgs as VectorLayerUpdateArgs; + + if (layerUpdateArgs.visualizer != null) + { + _mapVisualizer.RemoveTilesFromLayer((VectorTileFactory)layerUpdateArgs.factory, layerUpdateArgs.visualizer); + } + Debug.Log("Vector"); + OnMapRedrawn(); + } + + private void OnVectorDataSubLayerAdded(object sender, EventArgs eventArgs) + { + RedrawVectorDataLayer(); + + Debug.Log("Vector"); + OnMapRedrawn(); + } + private void OnVectorDataUpdateLayer(object sender, System.EventArgs eventArgs) + { + + VectorLayerUpdateArgs layerUpdateArgs = eventArgs as VectorLayerUpdateArgs; + + if (layerUpdateArgs.visualizer != null) + { + Debug.Log("UnregisterTiles"); + //we got a visualizer. Update only the visualizer. + // No need to unload the entire factory to apply changes. + _mapVisualizer.UnregisterAndRedrawTilesFromLayer((VectorTileFactory)layerUpdateArgs.factory, layerUpdateArgs.visualizer); + } + else + { + //We are updating a core property of vector section. + //All vector features need to get unloaded and re-created. + RedrawVectorDataLayer(); + } + Debug.Log("Vector"); + OnMapRedrawn(); + } + private void OnTileProviderChanged() { var currentTileProvider = gameObject.GetComponent(); diff --git a/sdkproject/Assets/Mapbox/Unity/Map/AbstractMapVisualizer.cs b/sdkproject/Assets/Mapbox/Unity/Map/AbstractMapVisualizer.cs index 5ebd0e4b2..8ec8762ae 100644 --- a/sdkproject/Assets/Mapbox/Unity/Map/AbstractMapVisualizer.cs +++ b/sdkproject/Assets/Mapbox/Unity/Map/AbstractMapVisualizer.cs @@ -280,7 +280,7 @@ public void UnregisterTilesFrom(AbstractTileFactory factory) } } - public void UnregisterTilesFromLayer(VectorTileFactory factory, LayerVisualizerBase layerVisualizer) + public void UnregisterAndRedrawTilesFromLayer(VectorTileFactory factory, LayerVisualizerBase layerVisualizer) { foreach (KeyValuePair tileBundle in _activeTiles) { @@ -299,8 +299,8 @@ public void RemoveTilesFromLayer(VectorTileFactory factory, LayerVisualizerBase foreach (KeyValuePair tileBundle in _activeTiles) { factory.UnregisterLayer(tileBundle.Value, layerVisualizer); - factory.RemoveVectorLayerVisualizer(layerVisualizer); } + factory.RemoveVectorLayerVisualizer(layerVisualizer); } public void ReregisterTilesTo(VectorTileFactory factory) diff --git a/sdkproject/Assets/Mapbox/Unity/MeshGeneration/Factories/VectorTileFactory.cs b/sdkproject/Assets/Mapbox/Unity/MeshGeneration/Factories/VectorTileFactory.cs index 9aed7a3f0..c256bc934 100644 --- a/sdkproject/Assets/Mapbox/Unity/MeshGeneration/Factories/VectorTileFactory.cs +++ b/sdkproject/Assets/Mapbox/Unity/MeshGeneration/Factories/VectorTileFactory.cs @@ -173,7 +173,7 @@ public virtual void RemoveVectorLayerVisualizer(LayerVisualizerBase subLayer) { Properties.locationPrefabList.Remove(subLayer.SubLayerProperties as PrefabItemOptions); } - + subLayer.LayerVisualizerHasChanged -= UpdateTileFactory; _layerBuilder[subLayer.Key].Remove(subLayer); } } @@ -268,6 +268,7 @@ protected override void OnUnregistered(UnityTile tile) foreach (var visualizer in layer) { visualizer.UnregisterTile(tile); + visualizer.LayerVisualizerHasChanged -= UpdateTileFactory; } } } @@ -376,23 +377,6 @@ private void CreateMeshes(UnityTile tile) foreach (var builder in _layerBuilder[emptyLayer]) { CreateFeatureWithBuilder(tile, emptyLayer, builder); - //if (builder.Active) - //{ - // if (_layerProgress.ContainsKey(tile)) - // { - // _layerProgress[tile].Add(builder); - // } - // else - // { - // _layerProgress.Add(tile, new HashSet { builder }); - // if (!_tilesWaitingProcessing.Contains(tile)) - // { - // _tilesWaitingProcessing.Add(tile); - // } - // } - // //just pass the first available layer - we should create a static null layer for this - // builder.Create(tile.VectorData.Data.GetLayer(tile.VectorData.Data.LayerNames()[0]), tile, DecreaseProgressCounter); - //} } } diff --git a/sdkproject/Assets/Mapbox/Unity/MeshGeneration/Filters/TypeFilter.cs b/sdkproject/Assets/Mapbox/Unity/MeshGeneration/Filters/TypeFilter.cs index 9594569ad..266dcc39e 100644 --- a/sdkproject/Assets/Mapbox/Unity/MeshGeneration/Filters/TypeFilter.cs +++ b/sdkproject/Assets/Mapbox/Unity/MeshGeneration/Filters/TypeFilter.cs @@ -5,6 +5,7 @@ namespace Mapbox.Unity.MeshGeneration.Filters using System; using System.Linq; using System.Collections.Generic; + using Mapbox.Unity.Map; public class TypeFilter : FilterBase { @@ -290,7 +291,7 @@ protected override bool PropertyComparer(object property) } [Serializable] - public class LayerFilter + public class LayerFilter : MapboxDataProperty, ILayerFilter { [Tooltip("Name of the property to use as key. This property is case sensitive.")] public string Key; @@ -305,7 +306,8 @@ public class LayerFilter [Tooltip("Filter operator to apply. ")] public LayerFilterOperationType filterOperator; private char[] _delimiters = new char[] { ',' }; - public LayerFilter(LayerFilterOperationType filterOperation) + + public LayerFilter(LayerFilterOperationType filterOperation = LayerFilterOperationType.Contains) { filterOperator = filterOperation; } @@ -345,5 +347,234 @@ public ILayerFeatureFilterComparer GetFilterComparer() } return filterComparer; } + + /// + /// Sets the string contains. + /// + /// Key. + /// Property. + public virtual void SetStringContains(string key, string property) + { + filterOperator = LayerFilterOperationType.Contains; + Key = key; + PropertyValue = property; + HasChanged = true; + } + + /// + /// Sets the number is equal. + /// + /// Key. + /// Value. + public virtual void SetNumberIsEqual(string key, float value) + { + filterOperator = LayerFilterOperationType.IsEqual; + Key = key; + Min = value; + HasChanged = true; + } + + /// + /// Sets the number is less than. + /// + /// Key. + /// Value. + public virtual void SetNumberIsLessThan(string key, float value) + { + filterOperator = LayerFilterOperationType.IsLess; + Key = key; + Min = value; + HasChanged = true; + } + + /// + /// Sets the number is greater than. + /// + /// Key. + /// Value. + public virtual void SetNumberIsGreaterThan(string key, float value) + { + filterOperator = LayerFilterOperationType.IsGreater; + Key = key; + Min = value; + HasChanged = true; + } + + /// + /// Sets the number is in range. + /// + /// Key. + /// Minimum. + /// Max. + public virtual void SetNumberIsInRange(string key, float min, float max) + { + filterOperator = LayerFilterOperationType.IsInRange; + Key = key; + Min = min; + Max = max; + HasChanged = true; + } + + /// + /// Gets the key. + /// + /// The key. + public virtual string GetKey + { + get + { + return Key; + } + } + + /// + /// Gets the type of the filter operation. + /// + /// The filter operation type. + public virtual LayerFilterOperationType GetFilterOperationType + { + get + { + return filterOperator; + } + } + + /// + /// Gets the property value. + /// + /// The property value. + public virtual string GetPropertyValue + { + get + { + return PropertyValue; + } + } + + /// + /// Gets the minimum value. + /// + /// The minimum value. + public virtual float GetNumberValue + { + get + { + return Min; + } + } + + /// + /// Gets the minimum value. + /// + /// The minimum value. + public virtual float GetMinValue + { + get + { + return Min; + } + } + + /// + /// Gets the max value. + /// + /// The max value. + public virtual float GetMaxValue + { + get + { + return Max; + } + } + + /// + /// Returns true if filter key contains a given string. + /// + /// true, if key contains was filtered, false otherwise. + /// Key. + public virtual bool FilterKeyContains(string key) + { + return Key.Contains(key); + } + + /// + /// Returns true if filter key matches a given string exactly. + /// + /// true, if key matches exact was filtered, false otherwise. + /// Key. + public virtual bool FilterKeyMatchesExact(string key) + { + return Key == key; + } + + /// + /// Returns true if filter uses a given operation type. + /// + /// true, if uses operation type was filtered, false otherwise. + /// Layer filter operation type. + public virtual bool FilterUsesOperationType(LayerFilterOperationType layerFilterOperationType) + { + return filterOperator == layerFilterOperationType; + } + + /// + /// Returns true if filter property contains a given string. + /// + /// true, if property contains was filtered, false otherwise. + /// Property. + public virtual bool FilterPropertyContains(string property) + { + return PropertyValue.Contains(property); + } + + /// + /// Returns true if filter property matches a given string exactly. + /// + /// true, if property matches exact was filtered, false otherwise. + /// Property. + public virtual bool FilterPropertyMatchesExact(string property) + { + return PropertyValue == property; + } + + /// + /// Returns true if filter number value is equal to a given number. + /// + /// true, if number value equals was filtered, false otherwise. + /// Value. + public virtual bool FilterNumberValueEquals(float value) + { + return Mathf.Approximately(Min, value); + } + + /// + /// Returns true if filter number value is greater than a given number. + /// + /// true, if number value is greater than was filtered, false otherwise. + /// Value. + public virtual bool FilterNumberValueIsGreaterThan(float value) + { + return Min > value; + } + + /// + /// Returns true if filter number value is less than a given number. + /// + /// true, if number value is less than was filtered, false otherwise. + /// Value. + public virtual bool FilterNumberValueIsLessThan(float value) + { + return Min < value; + } + + /// + /// Returns true if filter range values contain a given number. + /// + /// true, if is in range value contains was filtered, false otherwise. + /// Value. + public virtual bool FilterIsInRangeValueContains(float value) + { + return Min < value && value < Max; + } } } diff --git a/sdkproject/Assets/Mapbox/Unity/MeshGeneration/LayerVisualizers/VectorLayerVisualizer.cs b/sdkproject/Assets/Mapbox/Unity/MeshGeneration/LayerVisualizers/VectorLayerVisualizer.cs index 94c6cd396..a32dbb55d 100644 --- a/sdkproject/Assets/Mapbox/Unity/MeshGeneration/LayerVisualizers/VectorLayerVisualizer.cs +++ b/sdkproject/Assets/Mapbox/Unity/MeshGeneration/LayerVisualizers/VectorLayerVisualizer.cs @@ -1,4 +1,4 @@ -using Mapbox.VectorTile.Geometry; +using Mapbox.VectorTile.Geometry; namespace Mapbox.Unity.MeshGeneration.Interfaces { @@ -121,7 +121,13 @@ private void UpdateVector(object sender, System.EventArgs eventArgs) { layerUpdateArgs.property.PropertyHasChanged -= UpdateVector; } + UnbindSubLayerEvents(); + OnUpdateLayerVisualizer(layerUpdateArgs); + } + + private void UnbindSubLayerEvents() + { foreach (var modifier in _defaultStack.MeshModifiers) { modifier.UnbindProperties(); @@ -135,11 +141,11 @@ private void UpdateVector(object sender, System.EventArgs eventArgs) _layerProperties.extrusionOptions.PropertyHasChanged -= UpdateVector; _layerProperties.coreOptions.PropertyHasChanged -= UpdateVector; + _layerProperties.filterOptions.PropertyHasChanged -= UpdateVector; + _layerProperties.filterOptions.UnRegisterFilters(); _layerProperties.materialOptions.PropertyHasChanged -= UpdateVector; _layerProperties.PropertyHasChanged -= UpdateVector; - - OnUpdateLayerVisualizer(layerUpdateArgs); } public override void SetProperties(VectorSubLayerProperties properties) @@ -302,7 +308,9 @@ public override void SetProperties(VectorSubLayerProperties properties) } _layerProperties.coreOptions.PropertyHasChanged += UpdateVector; + _layerProperties.filterOptions.PropertyHasChanged += UpdateVector; + _layerProperties.filterOptions.RegisterFilters(); if (_layerProperties.MeshModifiers != null) { _defaultStack.MeshModifiers.AddRange(_layerProperties.MeshModifiers); @@ -736,6 +744,7 @@ public override void OnUnregisterTile(UnityTile tile) } _idPool[tile].Clear(); } + UnbindSubLayerEvents(); } } } diff --git a/sdkproject/Assets/Mapbox/Unity/SourceLayers/IImageryLayer.cs.meta b/sdkproject/Assets/Mapbox/Unity/SourceLayers/IImageryLayer.cs.meta new file mode 100644 index 000000000..da90cc6d5 --- /dev/null +++ b/sdkproject/Assets/Mapbox/Unity/SourceLayers/IImageryLayer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 80a22b06fd73b4e009a924a0be131391 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/sdkproject/Assets/Mapbox/Unity/SourceLayers/ILayer.cs b/sdkproject/Assets/Mapbox/Unity/SourceLayers/ILayer.cs index 84d348a6d..0b60374ee 100644 --- a/sdkproject/Assets/Mapbox/Unity/SourceLayers/ILayer.cs +++ b/sdkproject/Assets/Mapbox/Unity/SourceLayers/ILayer.cs @@ -5,6 +5,9 @@ namespace Mapbox.Unity.Map { //public class Terrain // Layer Interfaces + using System.Collections.Generic; + using Mapbox.Unity.MeshGeneration.Filters; + public interface ILayer { MapLayerType LayerType { get; } @@ -36,6 +39,53 @@ public interface ISubLayerPolygonGeometryOptions public interface ISubLayerFiltering { + ILayerFilter AddStringFilterContains(string key, string property); + ILayerFilter AddNumericFilterEquals(string key, float value); + ILayerFilter AddNumericFilterLessThan(string key, float value); + ILayerFilter AddNumericFilterGreaterThan(string key, float value); + ILayerFilter AddNumericFilterInRange(string key, float min, float max); + + ILayerFilter GetFilter(int index); + + void RemoveFilter(int index); + void RemoveFilter(LayerFilter filter); + void RemoveFilter(ILayerFilter filter); + void RemoveAllFilters(); + + IEnumerable GetAllFilters(); + IEnumerable GetFiltersByQuery(System.Func query); + + LayerFilterCombinerOperationType GetFilterCombinerType(); + + void SetFilterCombinerType(LayerFilterCombinerOperationType layerFilterCombinerOperationType); + } + + public interface ILayerFilter + { + bool FilterKeyContains(string key); + bool FilterKeyMatchesExact(string key); + bool FilterUsesOperationType(LayerFilterOperationType layerFilterOperationType); + bool FilterPropertyContains(string property); + bool FilterPropertyMatchesExact(string property); + bool FilterNumberValueEquals(float value); + bool FilterNumberValueIsGreaterThan(float value); + bool FilterNumberValueIsLessThan(float value); + bool FilterIsInRangeValueContains(float value); + + string GetKey { get; } + LayerFilterOperationType GetFilterOperationType { get; } + + string GetPropertyValue { get; } + float GetNumberValue { get; } + + float GetMinValue { get; } + float GetMaxValue { get; } + + void SetStringContains(string key, string property); + void SetNumberIsEqual(string key, float value); + void SetNumberIsLessThan(string key, float value); + void SetNumberIsGreaterThan(string key, float value); + void SetNumberIsInRange(string key, float min, float max); } diff --git a/sdkproject/Assets/Mapbox/Unity/SourceLayers/ITerrainLayer.cs.meta b/sdkproject/Assets/Mapbox/Unity/SourceLayers/ITerrainLayer.cs.meta new file mode 100644 index 000000000..7ba4ddb9b --- /dev/null +++ b/sdkproject/Assets/Mapbox/Unity/SourceLayers/ITerrainLayer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 187ce6c4b50f5417890e85afdfe403c4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/sdkproject/Assets/Mapbox/Unity/SourceLayers/TerrainLayer.cs b/sdkproject/Assets/Mapbox/Unity/SourceLayers/TerrainLayer.cs index 8b48a88d9..fbc5b4668 100644 --- a/sdkproject/Assets/Mapbox/Unity/SourceLayers/TerrainLayer.cs +++ b/sdkproject/Assets/Mapbox/Unity/SourceLayers/TerrainLayer.cs @@ -128,15 +128,15 @@ public void Initialize() _layerProperty.colliderOptions.PropertyHasChanged += (property, e) => { - NotifyUpdateLayer(_elevationFactory, property as MapboxDataProperty, false); + NotifyUpdateLayer(_elevationFactory, property as MapboxDataProperty, true); }; _layerProperty.requiredOptions.PropertyHasChanged += (property, e) => { - NotifyUpdateLayer(_elevationFactory, property as MapboxDataProperty, false); + NotifyUpdateLayer(_elevationFactory, property as MapboxDataProperty, true); }; _layerProperty.unityLayerOptions.PropertyHasChanged += (property, e) => { - NotifyUpdateLayer(_elevationFactory, property as MapboxDataProperty, false); + NotifyUpdateLayer(_elevationFactory, property as MapboxDataProperty, true); }; _layerProperty.PropertyHasChanged += (property, e) => { @@ -145,7 +145,7 @@ public void Initialize() //pushing new settings to factory directly SetFactoryOptions(); //notifying map to reload existing tiles - NotifyUpdateLayer(_elevationFactory, property as MapboxDataProperty, false); + NotifyUpdateLayer(_elevationFactory, property as MapboxDataProperty, true); }; } // public void RedrawLayer(object sender, System.EventArgs e) diff --git a/sdkproject/Assets/Mapbox/User/Modifiers.meta b/sdkproject/Assets/Mapbox/User/Modifiers.meta new file mode 100644 index 000000000..866bab694 --- /dev/null +++ b/sdkproject/Assets/Mapbox/User/Modifiers.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 87262f77eae1e407fbb890d0487ec6bd +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: