Skip to content

Commit

Permalink
Updated the Crowd Planner sample
Browse files Browse the repository at this point in the history
  • Loading branch information
arcgisprosdk committed May 26, 2017
1 parent a725a8a commit 74a8083
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 59 deletions.
36 changes: 3 additions & 33 deletions Editing/CrowdPlannerTool/CPDockpane.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@
<Label x:Name="Label_Copy" Content="High Estimate:" HorizontalAlignment="Center" Height="25" VerticalAlignment="Top" Width="113" Grid.Row="0" Grid.Column="0" FontWeight="Bold"/>
<Label x:Name="Label_Copy1" Content="Medium Estimate:" HorizontalAlignment="Center" Height="25" VerticalAlignment="Top" Width="113" Grid.Row="1" Grid.Column="0" FontWeight="Bold"/>
<Label x:Name="Label_Copy2" Content="Low Estimate:" HorizontalAlignment="Center" Height="25" VerticalAlignment="Top" Width="113" Grid.Row="2" Grid.Column="0" FontWeight="Bold"/>
<TextBox x:Name="textBoxHigh" HorizontalAlignment="Left" Height="31" Grid.Row="0" TextWrapping="Wrap" Text="{Binding TotalHigh, StringFormat='#,#.'}" VerticalAlignment="Top" Width="126" Grid.Column="1" FontSize="14"/>
<TextBox x:Name="textBoxMedium" HorizontalAlignment="Left" Height="31" Grid.Row="1" TextWrapping="Wrap" Text="{Binding TotalMedium, StringFormat='#,#.'}" VerticalAlignment="Top" Width="126" Grid.Column="1" FontSize="14"/>
<TextBox x:Name="textBoxLow" HorizontalAlignment="Left" Height="31" Grid.Row="2" TextWrapping="Wrap" Text="{Binding TotalLow, StringFormat='#,#.'}" VerticalAlignment="Top" Width="126" Grid.Column="1" FontSize="14"/>
<TextBox x:Name="textBoxHigh" HorizontalAlignment="Left" Height="31" Grid.Row="0" TextWrapping="Wrap" Text="{Binding TotalHigh, StringFormat='#,#.'}" Background="{Binding ColorBrush}" VerticalAlignment="Top" Width="126" Grid.Column="1" FontSize="14" IsReadOnly="True" FontWeight="Bold"/>
<TextBox x:Name="textBoxMedium" HorizontalAlignment="Left" Height="31" Grid.Row="1" TextWrapping="Wrap" Text="{Binding TotalMedium, StringFormat='#,#.'}" Background="{Binding ColorBrushMedium}" VerticalAlignment="Top" Width="126" Grid.Column="1" FontSize="14" IsReadOnly="True" FontWeight="Bold"/>
<TextBox x:Name="textBoxLow" HorizontalAlignment="Left" Height="31" Grid.Row="2" TextWrapping="Wrap" Text="{Binding TotalLow, StringFormat='#,#.'}" Background="{Binding ColorBrushLow}" VerticalAlignment="Top" Width="126" Grid.Column="1" FontSize="14" IsReadOnly="True" FontWeight="Bold"/>

</Grid>

Expand Down Expand Up @@ -144,16 +144,6 @@
<Setter Property="Background" Value="#FF4F81BD"/>
</Style>
</ResourceDictionary>
<ResourceDictionary>
<Style x:Key="DataPointStyle" TargetType="Control">
<Setter Property="Background" Value="#FF8064A2"/>
</Style>
</ResourceDictionary>
<ResourceDictionary>
<Style x:Key="DataPointStyle" TargetType="Control">
<Setter Property="Background" Value="#FFC0504D"/>
</Style>
</ResourceDictionary>
</DV:ResourceDictionaryCollection>
</DVC:PieSeries.Palette>
</DVC:PieSeries>
Expand Down Expand Up @@ -189,16 +179,6 @@
<Setter Property="Background" Value="#FF4F81BD"/>
</Style>
</ResourceDictionary>
<ResourceDictionary>
<Style x:Key="DataPointStyle" TargetType="Control">
<Setter Property="Background" Value="#FF8064A2"/>
</Style>
</ResourceDictionary>
<ResourceDictionary>
<Style x:Key="DataPointStyle" TargetType="Control">
<Setter Property="Background" Value="#FFC0504D"/>
</Style>
</ResourceDictionary>
</DV:ResourceDictionaryCollection>
</DVC:PieSeries.Palette>
</DVC:PieSeries>
Expand Down Expand Up @@ -234,16 +214,6 @@
<Setter Property="Background" Value="#FF4F81BD"/>
</Style>
</ResourceDictionary>
<ResourceDictionary>
<Style x:Key="DataPointStyle" TargetType="Control">
<Setter Property="Background" Value="#FF8064A2"/>
</Style>
</ResourceDictionary>
<ResourceDictionary>
<Style x:Key="DataPointStyle" TargetType="Control">
<Setter Property="Background" Value="#FFC0504D"/>
</Style>
</ResourceDictionary>
</DV:ResourceDictionaryCollection>
</DVC:PieSeries.Palette>
</DVC:PieSeries>
Expand Down
160 changes: 139 additions & 21 deletions Editing/CrowdPlannerTool/CPDockpaneViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ limitations under the License.
using System.Windows.Input;
using System.Windows;
using ArcGIS.Desktop.Editing;
using System.Windows.Media;

namespace CrowdPlannerTool
{

#region Showbutton
/// <summary>
/// Button implementation to show the DockPane.
/// </summary>
Expand All @@ -43,26 +46,31 @@ protected override void OnClick()
CPDockpaneViewModel.Show();
}
}
#endregion

#region DockPane Activate
internal class CPDockpaneViewModel : DockPane
{
private const string _dockPaneID = "CrowdPlannerTool_CPDockpane";
private KeyValuePair<string, int>[] _piechartResult;
private KeyValuePair<string, int>[] _piechartResultMedium;
private KeyValuePair<string, int>[] _piechartResultLow;
private string textboxBackground;

/// <summary>
/// Show the DockPane.
/// Show the DockPane
/// </summary>
internal static void Show()
{
DockPane pane = FrameworkApplication.DockPaneManager.Find(_dockPaneID);
CPDockpaneViewModel pane = FrameworkApplication.DockPaneManager.Find(_dockPaneID) as CPDockpaneViewModel;
if (pane == null)
return;

pane.Activate();

}


protected CPDockpaneViewModel()
{
_updateSettingsCmd = new RelayCommand(() => GetTotalValues(), () => true);
Expand All @@ -75,8 +83,20 @@ protected CPDockpaneViewModel()

_setDefaultSettingsCmd = new RelayCommand(() => SetDefaultSettings(), () => true);

//string textboxBackground;
if (FrameworkApplication.ApplicationTheme == ApplicationTheme.Dark ||
FrameworkApplication.ApplicationTheme == ApplicationTheme.HighContrast)
textboxBackground = "#323232";
else textboxBackground = "#FFFFFF";
//set background value for textboxes
_highBackground = textboxBackground;
_mediumBackground = textboxBackground;
_lowBackground = textboxBackground;

}

#endregion

#region Commands
// ** COMMANDS **
private RelayCommand _updateSettingsCmd;
Expand Down Expand Up @@ -132,15 +152,15 @@ public ICommand SetDefaultSettingsCmd
/// <summary>
/// Text shown near the top of the DockPane.
/// </summary>
private string _heading = "Crowd Estimate Summary";
public string Heading
{
get { return _heading; }
set
{
SetProperty(ref _heading, value, () => Heading);
}
}
//private string _heading = "Crowd Estimate Summary";
//public string Heading
//{
// get { return _heading; }
// set
// {
// SetProperty(ref _heading, value, () => Heading);
// }
//}


private long _totalHigh = 0;
Expand Down Expand Up @@ -241,6 +261,54 @@ public long TotalLow
}
}

// High total background
private string _highBackground; // "#FFFFFF";
public string HighBackground
{
get
{
return _highBackground;
}
set
{
_highBackground = value;
NotifyPropertyChanged("ColorBrush");
}
}

public Brush ColorBrush => new SolidColorBrush((Color)ColorConverter.ConvertFromString(_highBackground));

// Medium total background
private string _mediumBackground; // = "#FFFFFF";
public string MediumBackground
{
get
{
return _mediumBackground;
}
set
{
_mediumBackground = value;
NotifyPropertyChanged("ColorBrushMedium");
}
}
public Brush ColorBrushMedium => new SolidColorBrush((Color)ColorConverter.ConvertFromString(_mediumBackground));

// Low total background
private string _lowBackground; // = "#FFFFFF";
public string LowBackground
{
get
{
return _lowBackground;
}
set
{
_lowBackground = value;
NotifyPropertyChanged("ColorBrushLow");
}
}
public Brush ColorBrushLow => new SolidColorBrush((Color)ColorConverter.ConvertFromString(_lowBackground));

// High Estimate Chart
public KeyValuePair<string, int>[] PieChartResult
Expand Down Expand Up @@ -319,6 +387,14 @@ public void SetDefaultSettings()
public async void ResetValues(string settingsValue)
{

// Check for CrowdPlanning layer, exit if not present in current Map.
var CrowdLayerTest = MapView.Active.Map.FindLayers("CrowdPlanning").FirstOrDefault() as BasicFeatureLayer;
if (CrowdLayerTest == null)
{
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("CrowdPlanning Layer is not found. Please use with the Crowd Planner data project.", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
return;
}

// *** Check to ensure the densitysettings are set. If not, show a warning and deactivate tool.
if (HighSetting == 0 || MediumSetting == 0 || LowSetting == 0 || TargetSetting == 0)
{
Expand Down Expand Up @@ -432,17 +508,20 @@ public async void GetTotalValues()
double lowSettingValue = 0;
double mediumSettingValue = 0;
double highSettingValue = 0;
double targetRemaining = 0;

// Check for CrowdPlanning layer, exit if not present in current Map.
var CrowdLayerTest = MapView.Active.Map.FindLayers("CrowdPlanning").FirstOrDefault() as BasicFeatureLayer;
if (CrowdLayerTest == null)
{
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("CrowdPlanning Layer is not found. Please use with the Crowd Planner data project.", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
return;
}

await QueuedTask.Run(() =>
{
// FeatureLayer CrowdLayer = MapView.Active.Map.FindLayer("CrowdPlanning") as FeatureLayer;
FeatureLayer CrowdLayer = MapView.Active.Map.Layers.First(layer => layer.Name.Equals("CrowdPlanning")) as FeatureLayer;
if (CrowdLayer == null)
{
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show("Layer is not found");
return;
}
FeatureLayer CrowdLayer = MapView.Active.Map.GetLayersAsFlattenedList().FirstOrDefault(layer => layer.Name.Equals("CrowdPlanning")) as FeatureLayer;
//CrowdLayer.Search(null)
ArcGIS.Core.Data.Table CrowdTable = CrowdLayer.GetTable();
Expand Down Expand Up @@ -485,7 +564,7 @@ await QueuedTask.Run(() =>
});

// Assign values to properties
// Assign total values
TotalHigh = TotalValueHigh;
TotalMedium = TotalValueMedium;
TotalLow = TotalValueLow;
Expand All @@ -498,28 +577,67 @@ await QueuedTask.Run(() =>

// UPDATE PIE CHARTS
// Chart 1 - High Estimate
if (TotalValueHigh > TargetSetting)
{
targetRemaining = 0;
_highBackground = "#9BBB59";
NotifyPropertyChanged(() => ColorBrush);

}
else
{
targetRemaining = (TargetSetting - TotalValueHigh);
_highBackground = textboxBackground;
NotifyPropertyChanged(() => ColorBrush);
}
KeyValuePair<string, int>[] myKeyValuePairHigh = new KeyValuePair<string, int>[]
{
new KeyValuePair<string,int>("High Estimate Allocated", Convert.ToInt32(TotalValueHigh)),
new KeyValuePair<string,int>("Remaining to Estimate", Convert.ToInt32(TargetSetting))
new KeyValuePair<string,int>("Remaining to Estimate", Convert.ToInt32(targetRemaining))
};
PieChartResult = myKeyValuePairHigh;
NotifyPropertyChanged(() => PieChartResult);

// Chart 2 - Medium Estimate
if (TotalValueMedium > TargetSetting)
{
targetRemaining = 0;
_mediumBackground = "#9BBB59";
NotifyPropertyChanged(() => ColorBrushMedium);
}
else
{
targetRemaining = (TargetSetting - TotalValueMedium);
_mediumBackground = textboxBackground;
NotifyPropertyChanged(() => ColorBrushMedium);
}

KeyValuePair<string, int>[] myKeyValuePairMedium = new KeyValuePair<string, int>[]
{
new KeyValuePair<string,int>("Medium Estimate Allocated", Convert.ToInt32(TotalValueMedium)),
new KeyValuePair<string,int>("Remaining to Estimate", Convert.ToInt32(TargetSetting))
new KeyValuePair<string,int>("Remaining to Estimate", Convert.ToInt32(targetRemaining))
};
PieChartResultMedium = myKeyValuePairMedium;
NotifyPropertyChanged(() => PieChartResultMedium);

// Chart 3 - Low Estimate
if (TotalValueLow > TargetSetting)
{
targetRemaining = 0;
_lowBackground = "#9BBB59";
NotifyPropertyChanged(() => ColorBrushLow);
}
else
{
targetRemaining = (TargetSetting - TotalValueLow);
_lowBackground = textboxBackground;
NotifyPropertyChanged(() => ColorBrushLow);
}

KeyValuePair<string, int>[] myKeyValuePairLow = new KeyValuePair<string, int>[]
{
new KeyValuePair<string,int>("Low Estimate Allocated", Convert.ToInt32(TotalValueLow)),
new KeyValuePair<string,int>("Remaining to Estimate", Convert.ToInt32(TargetSetting))
new KeyValuePair<string,int>("Remaining to Estimate", Convert.ToInt32(targetRemaining))
};
PieChartResultLow = myKeyValuePairLow;
NotifyPropertyChanged(() => PieChartResultLow);
Expand Down
2 changes: 1 addition & 1 deletion Editing/CrowdPlannerTool/Config.daml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
</button>
</controls>
<dockPanes>
<dockPane id="CrowdPlannerTool_CPDockpane" caption="Crowd Planner" className="CPDockpaneViewModel" dock="group" dockWith="esri_core_contentsDockPane">
<dockPane id="CrowdPlannerTool_CPDockpane" caption="Crowd Planner Summary" className="CPDockpaneViewModel" dock="group" dockWith="esri_core_contentsDockPane">
<content className="CPDockpaneView" />
</dockPane>
</dockPanes>
Expand Down
9 changes: 7 additions & 2 deletions Editing/CrowdPlannerTool/CrowdPlannerTool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Windows.Controls.DataVisualization.Toolkit, Version=4.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\System.Windows.Controls.DataVisualization.Toolkit.4.0.0.0\lib\net40-Client\System.Windows.Controls.DataVisualization.Toolkit.dll</HintPath>
<HintPath>packages\System.Windows.Controls.DataVisualization.Toolkit.4.0.0.0\lib\net40-Client\System.Windows.Controls.DataVisualization.Toolkit.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Xml.Linq" />
Expand Down Expand Up @@ -153,8 +153,13 @@
<None Include="packages.config" />
<None Include="ReadMe.md" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Folder Include="Screenshots\" />
<None Include="Screenshots\Screen1.png" />
<None Include="Screenshots\Screen2.png" />
<None Include="Screenshots\Screen3.png" />
<None Include="Screenshots\Screen4.png" />
<None Include="Screenshots\Screen5.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!--
Expand Down
4 changes: 2 additions & 2 deletions Editing/CrowdPlannerTool/CrowdPlannerTool.xml

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

0 comments on commit 74a8083

Please sign in to comment.