Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,13 @@ public class ImageryLayerPropertiesDrawer : PropertyDrawer
tooltip = "Map Id corresponding to the tileset."
};

private void UpdateProperty(SerializedProperty property)
{
property.serializedObject.ApplyModifiedProperties();
var map = (AbstractMap)property.serializedObject.targetObject;
map.ImageLayer.LayerProperty.UpdateProperty();
}

public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
var sourceTypeProperty = property.FindPropertyRelative("sourceType");
var sourceTypeValue = (ImagerySourceType)sourceTypeProperty.enumValueIndex;

ImageryLayerProperties imageryLayerProperties = (ImageryLayerProperties)EditorHelper.GetTargetObjectOfProperty(property);

var displayNames = sourceTypeProperty.enumDisplayNames;
int count = sourceTypeProperty.enumDisplayNames.Length;
if (!isGUIContentSet)
Expand All @@ -48,14 +43,12 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten
// Draw label.
var sourceTypeLabel = new GUIContent { text = "Data Source", tooltip = "Source tileset for Imagery." };

EditorGUI.BeginChangeCheck();
sourceTypeProperty.enumValueIndex = EditorGUILayout.Popup(sourceTypeLabel, sourceTypeProperty.enumValueIndex, sourceTypeContent);

sourceTypeValue = (ImagerySourceType)sourceTypeProperty.enumValueIndex;
if(EditorGUI.EndChangeCheck())
{
UpdateProperty(property);
}

EditorHelper.CheckForModifiedProperty(sourceTypeProperty, imageryLayerProperties);

var sourceOptionsProperty = property.FindPropertyRelative("sourceOptions");
var layerSourceProperty = sourceOptionsProperty.FindPropertyRelative("layerSource");
var layerSourceId = layerSourceProperty.FindPropertyRelative("Id");
Expand Down Expand Up @@ -85,11 +78,12 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten

if (sourceTypeValue != ImagerySourceType.None)
{
EditorGUI.BeginChangeCheck();
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(property.FindPropertyRelative("rasterOptions"));
if (EditorGUI.EndChangeCheck())
if(EditorGUI.EndChangeCheck())
{
UpdateProperty(property);
imageryLayerProperties.HasChanged = true;
}
}
}
Expand Down
50 changes: 31 additions & 19 deletions sdkproject/Assets/Mapbox/Unity/Map/AbstractMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -516,36 +516,48 @@ protected virtual void InitializeMap(MapOptions options)

options.placementOptions.placementStrategy.SetUpPlacement(this);

_imagery.UpdateLayer += (factory, updateVector) =>
_imagery.UpdateLayer += (object sender, System.EventArgs eventArgs)=>
{
_mapVisualizer.ReregisterTilesTo(factory);
if(updateVector)
LayerUpdateArgs layerUpdateArgs = eventArgs as LayerUpdateArgs;
if (layerUpdateArgs != null)
{
_mapVisualizer.UnregisterTilesFrom(VectorData.Factory);
VectorData.UpdateFactorySettings();
_mapVisualizer.ReregisterTilesTo(VectorData.Factory);
_mapVisualizer.ReregisterTilesTo(layerUpdateArgs.factory);
if (layerUpdateArgs.effectsVectorLayer)
{
_mapVisualizer.UnregisterTilesFrom(VectorData.Factory);
VectorData.UpdateFactorySettings();
_mapVisualizer.ReregisterTilesTo(VectorData.Factory);
}
OnMapRedrawn();
}
OnMapRedrawn();
};

_terrain.UpdateLayer += (factory, updateVector) =>
_terrain.UpdateLayer += (object sender, System.EventArgs eventArgs) =>
{
_mapVisualizer.ReregisterTilesTo(factory);
if (updateVector)
LayerUpdateArgs layerUpdateArgs = eventArgs as LayerUpdateArgs;
if (layerUpdateArgs != null)
{
_mapVisualizer.UnregisterTilesFrom(VectorData.Factory);
VectorData.UpdateFactorySettings();
_mapVisualizer.ReregisterTilesTo(VectorData.Factory);
_mapVisualizer.ReregisterTilesTo(layerUpdateArgs.factory);
if (layerUpdateArgs.effectsVectorLayer)
{
_mapVisualizer.UnregisterTilesFrom(VectorData.Factory);
VectorData.UpdateFactorySettings();
_mapVisualizer.ReregisterTilesTo(VectorData.Factory);
}
OnMapRedrawn();
}
OnMapRedrawn();
};

_vectorData.UpdateLayer += (factory, updateVector) =>
_vectorData.UpdateLayer += (object sender, System.EventArgs eventArgs) =>
{
_mapVisualizer.UnregisterTilesFrom(factory);
VectorData.UpdateFactorySettings();
_mapVisualizer.ReregisterTilesTo(VectorData.Factory);
OnMapRedrawn();
LayerUpdateArgs layerUpdateArgs = eventArgs as LayerUpdateArgs;
if(layerUpdateArgs != null)
{
_mapVisualizer.UnregisterTilesFrom(layerUpdateArgs.factory);
VectorData.UpdateFactorySettings();
_mapVisualizer.ReregisterTilesTo(VectorData.Factory);
OnMapRedrawn();
}
};

_mapVisualizer.Initialize(this, _fileSource);
Expand Down
22 changes: 16 additions & 6 deletions sdkproject/Assets/Mapbox/Unity/SourceLayers/AbstractLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,27 @@
{
using Mapbox.Unity.MeshGeneration.Factories;

public class LayerUpdateArgs : System.EventArgs
{
public AbstractTileFactory factory;
public bool effectsVectorLayer;
}

public class AbstractLayer
{
public void NotifyUpdateLayer(AbstractTileFactory factory, bool effectsVectorLayer = false)
public event System.EventHandler UpdateLayer;
protected virtual void NotifyUpdateLayer(AbstractTileFactory factory, bool effectsVectorLayer = false)
{
if(UpdateLayer != null)
System.EventHandler handler = UpdateLayer;
if (handler != null)
{
UpdateLayer(factory, effectsVectorLayer);
LayerUpdateArgs layerUpdateArgs = new LayerUpdateArgs()
{
factory = factory,
effectsVectorLayer = effectsVectorLayer
};
handler(this, layerUpdateArgs);
}
}

public event UpdateLayerHandler UpdateLayer;
public delegate void UpdateLayerHandler(AbstractTileFactory factory, bool effectsVectorLayer);
}
}
5 changes: 2 additions & 3 deletions sdkproject/Assets/Mapbox/Unity/SourceLayers/ImageryLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public ImageryLayerProperties LayerProperty
}
set
{
Debug.Log("Image Layer");
_layerProperty = value;
}
}
Expand Down Expand Up @@ -110,10 +109,10 @@ public void Initialize()
_imageFactory.SetOptions(_layerProperty);

//updating image layer on settings change
_layerProperty.OnPropertyUpdated += Refresh;
_layerProperty.PropertyHasChanged += RedrawLayer;
}

public void Refresh()
public void RedrawLayer(object sender, System.EventArgs e)
{
Factory.SetOptions(_layerProperty);
NotifyUpdateLayer(_imageFactory);
Expand Down