Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #331 from Esri/csm-327-change-SR-probs
Browse files Browse the repository at this point in the history
Address #327 - Reproject points if SR changed
  • Loading branch information
dfoll authored Aug 6, 2019
2 parents 0affc4e + e3aa6da commit 57e6de2
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
42 changes: 42 additions & 0 deletions source/addins/ArcMapAddinVisibility/ViewModels/LOSBaseViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public LOSBaseViewModel()

Mediator.Register(Constants.MAP_TOC_UPDATED, OnMapTocUpdated);
Mediator.Register(Constants.DISPLAY_COORDINATE_TYPE_CHANGED, OnDisplayCoordinateTypeChanged);
Mediator.Register(Constants.MAP_SPATIAL_REFERENCED_CHANGED, OnMapSpatialReferenceChanged);


DeletePointCommand = new RelayCommand(OnDeletePointCommand);
DeleteAllPointsCommand = new RelayCommand(OnDeleteAllPointsCommand);
Expand Down Expand Up @@ -487,6 +489,46 @@ private void OnMapTocUpdated(object obj)
ResetSurfaceNames(map);
}

/// <summary>
/// Method called when the map Spatial Reference is changed
/// </summary>
/// <param name="obj">not used</param>
private void OnMapSpatialReferenceChanged(object obj)
{
if ((ArcMap.Document == null) || (ArcMap.Document.FocusMap == null) ||
(GraphicsList == null) || (GraphicsList.Count == 0))
return;

var map = ArcMap.Document.FocusMap;
var av = (IActiveView)map;
var gc = (IGraphicsContainer)av;

// reproject the graphics in the GraphicsContained and GraphicsList
gc.Reset();
var element = gc.Next();
while (element != null)
{
var geom = element.Geometry;
geom.Project(ArcMap.Document.FocusMap.SpatialReference);
element.Geometry = geom;

element = gc.Next();
}

// remove from master graphics list
lock (GraphicsList)
{
foreach (var graphic in GraphicsList)
{
var geom = graphic.Geometry;
geom.Project(ArcMap.Document.FocusMap.SpatialReference);
graphic.Geometry = geom;
}
}

av.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}

/// <summary>
/// Override this method to implement a "Mode" to separate the input of
/// observer points and target points
Expand Down
10 changes: 10 additions & 0 deletions source/addins/ArcMapAddinVisibility/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ void Events_ActiveViewChanged()
viewEvents.FocusMapChanged += viewEvents_FocusMapChanged;
viewEvents.ItemAdded += viewEvents_ItemAdded;
viewEvents.ItemDeleted += viewEvents_ItemDeleted;
viewEvents.SpatialReferenceChanged += viewEvents_SpatialReferenceChanged;

NotifyMapTOCUpdated();
}
Expand All @@ -89,11 +90,20 @@ void viewEvents_FocusMapChanged()
NotifyMapTOCUpdated();
}

void viewEvents_SpatialReferenceChanged()
{
NotifySpatialReferenceChanged();
}

private void NotifyMapTOCUpdated()
{
Mediator.NotifyColleagues(Constants.MAP_TOC_UPDATED, null);
}

private void NotifySpatialReferenceChanged()
{
Mediator.NotifyColleagues(Constants.MAP_SPATIAL_REFERENCED_CHANGED, null);
}
#region Properties

object selectedTab = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected virtual void OnActiveToolChanged(object obj)
private string lastActiveToolName;

// lists to store GUIDs of graphics, temp feedback and map graphics
private static List<AMGraphic> GraphicsList = new List<AMGraphic>();
protected static List<AMGraphic> GraphicsList = new List<AMGraphic>();

/// <summary>
/// Property used to determine if there are non temp graphics
Expand Down Expand Up @@ -374,6 +374,7 @@ internal void ClearTempGraphics()

av.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
}

/// <summary>
/// Method used to remove graphics from the graphics container
/// Elements are tagged with a GUID on the IElementProperties.Name property
Expand Down
1 change: 1 addition & 0 deletions source/addins/VisibilityLibrary/Helpers/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ public class Constants
public const string MAP_POINT_TOOL_ACTIVATED = "MAP_POINT_TOOL_ACTIVATED";
public const string MAP_POINT_TOOL_DEACTIVATED = "MAP_POINT_TOOL_DEACTIVATED";
public const string MAP_TOOL_CHANGED = "MAP_TOOL_CHANGED";
public const string MAP_SPATIAL_REFERENCED_CHANGED = "MAP_SPATIAL_REFERENCED_CHANGED";
}
}

0 comments on commit 57e6de2

Please sign in to comment.