User Tools

Site Tools


source_code_wpf_desktopeditionsample_mapsuitesiteselection_cs.zip

Source Code Wpf DesktopEditionSample MapSuiteSiteSelection CS.zip

MainWindow.xaml

 <Window x:Class="ThinkGeo.MapSuite.SiteSelection.MainWindow"  
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
         xmlns:local="clr-namespace:ThinkGeo.MapSuite.SiteSelection"  
         xmlns:wpf="clr-namespace:ThinkGeo.MapSuite.WpfDesktopEdition;assembly=WpfDesktopEdition"  
         Title="Site Selection"  
         Width="1155"  
         Height="675"  
         MinWidth="150"  
         MinHeight="150"  
         Icon="/MapSuiteSiteSelection;component/Image/MapSuite.ico"  
         Loaded="Window_Loaded"  
         WindowState="Maximized">  
     <Window.Resources>  
         <ResourceDictionary>  
             <local:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />  
             <local:CreateAreaModeToBoolConverter x:Key="CreateAreaModeToBoolConverter" />  
             <local:DistanceUnitToTextConverter x:Key="DistanceUnitToTextConverter" />  
             <local:TrackModeToBoolConverter x:Key="TrackModeToBoolConverter" />  
         </ResourceDictionary>  
     </Window.Resources>  
     <Grid Style="{StaticResource sampleBody}">  
         <Grid.RowDefinitions>  
             <RowDefinition Height="auto" />  
             <RowDefinition Height="*" />  
             <RowDefinition Height="auto" />  
         </Grid.RowDefinitions>  
         <Border BorderThickness="0,0,0,5"  
                 CornerRadius="2"  
                 KeyboardNavigation.DirectionalNavigation="Contained"  
                 KeyboardNavigation.TabIndex="2"  
                 KeyboardNavigation.TabNavigation="Local"  
                 Padding="10">  
             <Border.Background>  
                 <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">  
                     <LinearGradientBrush.GradientStops>  
                         <GradientStop Offset="0" Color="#ffffff" />  
                         <GradientStop Offset="0.4" Color="#fafafa" />  
                         <GradientStop Offset="0.55" Color="#f2f2f2" />  
                         <GradientStop Offset="0.6" Color="#f0f0f0" />  
                         <GradientStop Offset="0.9" Color="#e2e2e2" />  
                     </LinearGradientBrush.GradientStops>  
                 </LinearGradientBrush>  
             </Border.Background>  
             <Border.BorderBrush>  
                 <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">  
                     <LinearGradientBrush.GradientStops>  
                         <GradientStop Offset="0.85" Color="#5c707d" />  
                         <GradientStop Offset="1" Color="#305c707d" />  
                     </LinearGradientBrush.GradientStops>  
                 </LinearGradientBrush>  
             </Border.BorderBrush>  
             <StackPanel Orientation="Horizontal">  
                 <TextBlock Margin="{StaticResource TitleMargin}">  
                     <Run FontSize="16">Map Suite</Run>  
                     <Run FontSize="20">Site Selection</Run>  
                 </TextBlock>  
             </StackPanel>  
         </Border>  
         <Grid Grid.Row="1">  
             <Grid.ColumnDefinitions>  
                 <ColumnDefinition Width="auto" />  
                 <ColumnDefinition Width="*" />  
             </Grid.ColumnDefinitions>  
             <Grid Grid.Row="0" Grid.Column="0">  
                 <Grid.ColumnDefinitions>  
                     <ColumnDefinition Width="*" />  
                     <ColumnDefinition Width="auto" />  
                     <ColumnDefinition Width="5" />  
                 </Grid.ColumnDefinitions>  
                 <ToggleButton x:Name="ExpandToggleButton"  
                               Grid.Row="0"  
                               Grid.Column="1"  
                               VerticalAlignment="Center"  
                               Background="Transparent"  
                               BorderBrush="Transparent"  
                               Cursor="Hand"  
                               IsChecked="True">  
                     <Image x:Name="toggleImage" Stretch="None">  
                         <Image.Style>  
                             <Style>  
                                 <Style.Triggers>  
                                     <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=ToggleButton}, Path=IsChecked}" Value="True">  
                                         <Setter Property="Image.Source" Value="/MapSuiteSiteSelection;component/Image/collapse.gif" />  
                                     </DataTrigger>  
                                     <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=ToggleButton}, Path=IsChecked}" Value="False">  
                                         <Setter Property="Image.Source" Value="/MapSuiteSiteSelection;component/Image/expand.gif" />  
                                     </DataTrigger>  
                                 </Style.Triggers>  
                             </Style>  
                         </Image.Style>  
                     </Image>  
                 </ToggleButton>  
                 <Grid x:Name="gridDockPanel"  
                       Grid.Column="0"  
                       Width="300"  
                       HorizontalAlignment="Left"  
                       Visibility="{Binding ElementName=ExpandToggleButton, Path=IsChecked, Converter={StaticResource BoolToVisibilityConverter}}">  
                     <Grid Margin="5 10 5 10">  
                         <Grid.RowDefinitions>  
                             <RowDefinition Height="auto" />  
                             <RowDefinition Height="*" />  
                         </Grid.RowDefinitions>  
                         <StackPanel Grid.Row="0">  
                             <StackPanel>  
                                 <TextBlock Margin="0 0 0 10"  
                                            HorizontalAlignment="Left"  
                                            VerticalAlignment="Center"  
                                            Style="{StaticResource h4}"  
                                            Text="Highlight points of this type:" />  
                                 <Border Grid.Row="1" Style="{StaticResource fileset}">  
                                     <StackPanel>  
                                         <ComboBox ItemsSource="{Binding PoiFeatureLayers}"  
                                                   SelectedItem="{Binding SelectedPoiFeatureLayer, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"  
                                                   SelectedValue="Medical Facilities"  
                                                   Style="{StaticResource msComboBox}"  
                                                   Text="Medical Facilities">  
                                             <ComboBox.ItemTemplate>  
                                                 <DataTemplate>  
                                                     <TextBlock Text="{Binding Name}" />  
                                                 </DataTemplate>  
                                             </ComboBox.ItemTemplate>  
                                         </ComboBox>  
                                         <ComboBox ItemsSource="{Binding PoiTypeCandidates}"  
                                                   SelectedItem="{Binding SelectedPoiType, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"  
                                                   SelectedValue="HOSP"  
                                                   Style="{StaticResource msComboBox}"  
                                                   Text="HOSP" />  
                                     </StackPanel>  
                                 </Border>  
                             </StackPanel>  
 
                             <TextBlock Margin="0 10 0 0"  
                                        Style="{StaticResource h4}"  
                                        Text="Place the center pin on the map to highlight points of interest within a specified area around where you clicked:"  
                                        TextWrapping="Wrap" />  
                             <Border Grid.Row="3" Style="{StaticResource fileset}">  
                                 <StackPanel Orientation="Horizontal">  
                                     <CheckBox Margin="{StaticResource TitleImageCheckBoxMargin}"  
                                               IsChecked="{Binding TrackMode, Converter={StaticResource TrackModeToBoolConverter}, ConverterParameter=Pan, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"  
                                               Style="{StaticResource ImageCheckBoxStyleKey}"  
                                               ToolTip="Switch current map to pan mode.">  
                                         <Image Source="/MapSuiteSiteSelection;component/Image/pan.png" Stretch="None" />  
                                     </CheckBox>  
 
                                     <CheckBox Margin="{StaticResource TitleImageCheckBoxMargin}"  
                                               IsChecked="{Binding TrackMode, Converter={StaticResource TrackModeToBoolConverter}, ConverterParameter=DrawPoint, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"  
                                               Style="{StaticResource ImageCheckBoxStyleKey}"  
                                               ToolTip="Place the center pin on the map.">  
                                         <Image Source="/MapSuiteSiteSelection;component/Image/drawPoint.png" Stretch="None" />  
                                     </CheckBox>  
 
                                     <Button Command="{Binding ClearAllCommand}"  
                                             Style="{StaticResource ImageButtonStyleKey}"  
                                             ToolTip="Reset your selection.">  
                                         <Image Source="/MapSuiteSiteSelection;component/Image/clear.png" />  
                                     </Button>  
                                 </StackPanel>  
                             </Border>  
 
                             <TextBlock Margin="0 10 0 10"  
                                        Style="{StaticResource h4}"  
                                        Text="Area Type:" />  
                             <Border Grid.Row="1" Style="{StaticResource fileset}">  
                                 <StackPanel IsEnabled="{Binding QueryEnabled, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">  
                                     <RadioButton x:Name="rbtRouteArea"  
                                                  VerticalContentAlignment="Center"  
                                                  Content="Service Area"  
                                                  GroupName="ServiceAreaCfg"  
                                                  IsChecked="{Binding CreateAreasMode, Converter={StaticResource CreateAreaModeToBoolConverter}, ConverterParameter=Route}"  
                                                  Style="{StaticResource msRadioButton}" />  
                                     <StackPanel Margin="15 0 0 0"  
                                                 IsEnabled="{Binding CanSetBufferProperty, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"  
                                                 Orientation="Horizontal"  
                                                 Visibility="{Binding IsChecked, ElementName=rbtRouteArea, Converter={StaticResource BoolToVisibilityConverter}}">  
                                         <TextBlock Style="{StaticResource bodyTextWithDisable}" Text="Service Area in" />  
                                         <TextBox Width="50"  
                                                  Height="25"  
                                                  Style="{StaticResource msTextBox}"  
                                                  Text="{Binding DrivingTimeInMinute, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />  
                                         <TextBlock Style="{StaticResource bodyTextWithDisable}" Text="Minutes Driving" />  
                                     </StackPanel>  
                                     <RadioButton x:Name="rbtBufferArea"  
                                                  VerticalContentAlignment="Center"  
                                                  Content="Buffered Area"  
                                                  GroupName="ServiceAreaCfg"  
                                                  IsChecked="{Binding CreateAreasMode, Converter={StaticResource CreateAreaModeToBoolConverter}, ConverterParameter=Buffer}"  
                                                  Style="{StaticResource msRadioButton}" />  
                                     <StackPanel Margin="15 0 0 0"  
                                                 IsEnabled="{Binding CanSetBufferProperty, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"  
                                                 Orientation="Horizontal"  
                                                 Visibility="{Binding IsChecked, ElementName=rbtBufferArea, Converter={StaticResource BoolToVisibilityConverter}}">  
                                         <TextBlock Style="{StaticResource bodyTextWithDisable}" Text="Buffer Distance:" />  
                                         <TextBox Width="60"  
                                                  Height="25"  
                                                  Style="{StaticResource msTextBox}"  
                                                  Text="{Binding BufferDistance, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />  
                                         <ComboBox Width="90"  
                                                   Height="25"  
                                                   ItemsSource="{Binding BufferDistanceUnits}"  
                                                   SelectedItem="{Binding BufferDistanceUnit, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">  
                                             <ComboBox.ItemTemplate>  
                                                 <DataTemplate>  
                                                     <TextBlock Text="{Binding ., Converter={StaticResource DistanceUnitToTextConverter}}" />  
                                                 </DataTemplate>  
                                             </ComboBox.ItemTemplate>  
                                         </ComboBox>  
                                     </StackPanel>  
                                     <Button Width="90"  
                                             Height="25"  
                                             Margin="0 0 2 0"  
                                             HorizontalAlignment="Right"  
                                             VerticalContentAlignment="Center"  
                                             Command="{Binding ApplySettingsCommand}"  
                                             Content="Apply" />  
                                 </StackPanel>  
                             </Border>  
                             <Border Grid.Row="5" Style="{StaticResource headerBanner}">  
                                 <TextBlock Style="{StaticResource headerText2}" Text="Potential Similar Sites" />  
                             </Border>  
                         </StackPanel>  
                         <ListView Grid.Row="1"  
                                   Margin="0 10 0 10"  
                                   ItemsSource="{Binding QueryResult}"  
                                   SelectedItem="{Binding SelectedHistory, Mode=TwoWay}">  
                             <ListView.Style>  
                                 <Style>  
                                     <Style.Triggers>  
                                         <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self},Path=ItemsSource.Count}" Value="0">  
                                             <Setter Property="ListView.Visibility" Value="Collapsed"/>  
                                         </DataTrigger>  
                                     </Style.Triggers>  
                                 </Style>  
                             </ListView.Style>  
                             <ListView.View>  
                                 <GridView>  
                                     <GridViewColumn Width="36" Header="">  
                                         <GridViewColumn.CellTemplate>  
                                             <DataTemplate>  
                                                 <Button Command="{Binding ZoomToFeatureCommand}"  
                                                         Style="{StaticResource ImageButtonStyleKey}"  
                                                         Visibility="{Binding CanZoomToFeature, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource BoolToVisibilityConverter}}">  
                                                     <Image Source="/MapSuiteSiteSelection;component/Image/Find.png" Stretch="None" />  
                                                 </Button>  
                                             </DataTemplate>  
                                         </GridViewColumn.CellTemplate>  
                                     </GridViewColumn>  
                                     <GridViewColumn Width="220"  
                                                     DisplayMemberBinding="{Binding Name}"  
                                                     Header="Name" />  
                                 </GridView>  
                             </ListView.View>  
                         </ListView>  
                     </Grid>  
                 </Grid>  
                 <Rectangle Grid.Row="0" Grid.Column="2">  
                     <Rectangle.Fill>  
                         <LinearGradientBrush StartPoint="0,0" EndPoint="1,0">  
                             <GradientStop Offset="0" Color="#5c707d" />  
                             <GradientStop Offset="1" Color="#305c707d" />  
                         </LinearGradientBrush>  
                     </Rectangle.Fill>  
                 </Rectangle>  
             </Grid>  
             <Grid Grid.Column="1">  
                 <wpf:WpfMap x:Name="wpfMap1" Panel.ZIndex="-1" />  
             </Grid>  
 
             <Grid Grid.Column="1"  
                   Background="#30D6D6D6"  
                   Visibility="{Binding Visibility, ElementName=loadingControl}">  
                 <local:LoadingImageUserControl x:Name="loadingControl" Visibility="{Binding IsBusy, Converter={StaticResource BoolToVisibilityConverter}}" />  
             </Grid>  
         </Grid>  
         <Grid Grid.Row="2">  
             <Border BorderBrush="Gray" BorderThickness="0 1 0 0">  
                 <StatusBar Height="30">  
                     <StatusBarItem HorizontalContentAlignment="Stretch">  
                         <Grid HorizontalAlignment="Right">  
                             <Grid.ColumnDefinitions>  
                                 <ColumnDefinition Width="auto" />  
                                 <ColumnDefinition Width="5" />  
                                 <ColumnDefinition Width="auto" />  
                             </Grid.ColumnDefinitions>  
                             <TextBlock x:Name="tblCoordinateX"  
                                        Grid.Column="0"  
                                        Width="95"  
                                        HorizontalAlignment="Right"  
                                        VerticalAlignment="Center"  
                                        Text="{Binding CoordinateX, StringFormat=X:{0:N2}}" />  
                             <TextBlock x:Name="tblCoordinateY"  
                                        Grid.Column="2"  
                                        Width="100"  
                                        VerticalAlignment="Center"  
                                        Text="{Binding CoordinateY, StringFormat=Y:{0:N2}}" />  
                         </Grid>  
                     </StatusBarItem>  
                 </StatusBar>  
             </Border>  
         </Grid>  
     </Grid>  
 </Window>  
 

MainWindow.xaml

 using System.Windows;  
 
 namespace ThinkGeo.MapSuite.SiteSelection  
 {  
     /// <summary>  
     /// Interaction logic for MainWindow.xaml  
     /// </summary>  
     public partial class MainWindow : Window  
     {  
         private MapModel mapModel;  
 
         public MainWindow()  
         {  
             InitializeComponent();  
         }  
 
         private void Window_Loaded(object sender, RoutedEventArgs e)  
         {  
             mapModel = new MapModel(wpfMap1);  
             DataContext = new MainWindowViewModel(mapModel);  
         }  
     }  
 }  
 

MainWindowViewModel.cs

 using System;  
 using System.Collections.Generic;  
 using System.Collections.ObjectModel;  
 using System.Configuration;  
 using System.Linq;  
 using System.Threading.Tasks;  
 using System.Windows;  
 using System.Windows.Input;  
 using ThinkGeo.MapSuite.Core;  
 using ThinkGeo.MapSuite.SiteSelection.Properties;  
 using ThinkGeo.MapSuite.WpfDesktopEdition;  
 
 namespace ThinkGeo.MapSuite.SiteSelection  
 {  
     public class MainWindowViewModel : ViewModelBase  
     {  
         private static readonly string findAllTextKey = "All";  
         private static readonly string noResultKey = "No results found.";  
 
         private bool isBusy;  
         private double coordinateX;  
         private double coordinateY;  
         private double bufferDistance;  
         private int driveTimeInMinute;  
         private string selectedPoiType;  
         private MapModel mapModel;  
         private CommandBase clearAllCommand;  
         private CommandBase applySettingsCommand;  
         private DistanceUnit bufferDistanceUnit;  
         private CreateAreasMode createAreasMode;  
         private Collection<DistanceUnit> bufferDistanceUnits;  
         private ObservableCollection<string> poiTypeCandidates;  
         private ObservableCollection<QueryResultItemViewModel> queryResult;  
 
         public MainWindowViewModel(MapModel mapModel)  
             : base()  
         {  
             this.mapModel = mapModel;  
             this.mapModel.TrackMode = TrackMode.None;  
             this.mapModel.PlottedPointChanged += MapModel_PlacedPositionChanged;  
             this.mapModel.MapControl.MapTools.MouseCoordinate.CustomFormatted += MapModel_MapMouseCoordinateChanged;  
             this.mapModel.PlottedPoint = new PointShape(-10776838.0796536, 3912346.50475619);  
 
             bufferDistance = 2;  
             driveTimeInMinute = 6;  
             coordinateX = mapModel.PlottedPoint.X;  
             coordinateY = mapModel.PlottedPoint.Y;  
             createAreasMode = CreateAreasMode.Route;  
             bufferDistanceUnit = DistanceUnit.Mile;  
             poiTypeCandidates = new ObservableCollection<string>();  
             queryResult = new ObservableCollection<QueryResultItemViewModel>();  
             SelectedPoiFeatureLayer = mapModel.PoiFeatureLayers[Resources.RestaurantsLayerKey];  
             bufferDistanceUnits = new Collection<DistanceUnit>(new[] { DistanceUnit.Mile, DistanceUnit.Kilometer });  
 
             SearchPointOfInterests();  
         }  
 
         public CommandBase ApplySettingsCommand  
         {  
             get  
             {  
                 return applySettingsCommand ?? (applySettingsCommand = new CommandBase(SearchPointOfInterests));  
             }  
         }  
 
         public double BufferDistance  
         {  
             get { return bufferDistance; }  
             set  
             {  
                 bufferDistance = value;  
                 RaisePropertyChanged(() => BufferDistance);  
             }  
         }  
 
         public DistanceUnit BufferDistanceUnit  
         {  
             get { return bufferDistanceUnit; }  
             set  
             {  
                 bufferDistanceUnit = value;  
                 RaisePropertyChanged(() => BufferDistanceUnit);  
                 UpdateUnitSystem(value);  
             }  
         }  
 
         public Collection<DistanceUnit> BufferDistanceUnits  
         {  
             get { return bufferDistanceUnits; }  
         }  
 
         public ObservableCollection<string> PoiTypeCandidates  
         {  
             get { return poiTypeCandidates; }  
         }  
 
         public CommandBase ClearAllCommand  
         {  
             get  
             {  
                 return clearAllCommand ?? (clearAllCommand = new CommandBase(() =>  
                 {  
                     QueryResult.Clear();  
                     mapModel.PlottedPoint = null;  
                     mapModel.ServiceAreaFeatures.Clear();  
                     mapModel.AddMarkersByFeatures(null);  
                     mapModel.MapControl.Refresh();  
                 }));  
             }  
         }  
 
         public double CoordinateX  
         {  
             get { return coordinateX; }  
             set  
             {  
                 coordinateX = value;  
                 RaisePropertyChanged(() => CoordinateX);  
             }  
         }  
 
         public double CoordinateY  
         {  
             get { return coordinateY; }  
             set  
             {  
                 coordinateY = value;  
                 RaisePropertyChanged(() => CoordinateY);  
             }  
         }  
 
         public CreateAreasMode CreateAreasMode  
         {  
             get { return createAreasMode; }  
             set  
             {  
                 createAreasMode = value;  
                 RaisePropertyChanged(() => CreateAreasMode);  
             }  
         }  
 
         public int DrivingTimeInMinute  
         {  
             get { return driveTimeInMinute; }  
             set  
             {  
                 driveTimeInMinute = value;  
                 RaisePropertyChanged(() => DrivingTimeInMinute);  
             }  
         }  
 
         public bool IsBusy  
         {  
             get { return isBusy; }  
             protected set  
             {  
                 isBusy = value;  
                 RaisePropertyChanged(() => IsBusy);  
             }  
         }  
 
         public TrackMode TrackMode  
         {  
             get { return mapModel.TrackMode; }  
             set  
             {  
                 mapModel.TrackMode = value;  
                 RaisePropertyChanged(() => TrackMode);  
             }  
         }  
 
         public ObservableCollection<ShapeFileFeatureLayer> PoiFeatureLayers  
         {  
             get { return new ObservableCollection<ShapeFileFeatureLayer>(mapModel.PoiFeatureLayers); }  
         }  
 
         public ObservableCollection<QueryResultItemViewModel> QueryResult  
         {  
             get { return queryResult; }  
         }  
 
         public string SelectedPoiType  
         {  
             get { return selectedPoiType; }  
             set  
             {  
                 selectedPoiType = value;  
                 RaisePropertyChanged(() => SelectedPoiType);  
 
                 UpdateQueryResult();  
             }  
         }  
 
         public ShapeFileFeatureLayer SelectedPoiFeatureLayer  
         {  
             get { return mapModel.QueryingFeatureLayer; }  
             set  
             {  
                 mapModel.QueryingFeatureLayer = value;  
                 RaisePropertyChanged(() => SelectedPoiFeatureLayer);  
 
                 UpdatePoiTypeCandidates();  
             }  
         }  
 
         private Dictionary<string, object> CollectServiceAnalysisParameters(CreateAreasMode targetMode)  
         {  
             Dictionary<string, object> parameters = new Dictionary<string, object>();  
             switch (targetMode)  
             {  
                 case CreateAreasMode.Route:  
                     parameters[Resources.StreetShapePathFilenameKey] = ConfigurationManager.AppSettings["StreetShapeFilePathName"];  
                     parameters[Resources.DriveTimeInMinutesKey] = driveTimeInMinute;  
                     break;  
 
                 default:  
                     parameters[Resources.DistanceKey] = BufferDistance;  
                     parameters[Resources.DistanceUnitKey] = BufferDistanceUnit;  
                     break;  
             }  
 
             return parameters;  
         }  
 
         private void FilterHotelFeatures(IEnumerable<Feature> selectedFeatures)  
         {  
             if (string.IsNullOrEmpty(SelectedPoiType)) return;  
 
             string property = SelectedPoiType.Trim();  
             string[] values = property.Split('~');  
             foreach (var feature in selectedFeatures)  
             {  
                 double min, max, columnValue;  
                 if ((double.TryParse(values[0], out min)  
                     && double.TryParse(values[1], out max)  
                     && double.TryParse(feature.ColumnValues["ROOMS"], out columnValue)  
                     && columnValue >= min && columnValue < max)  
                     || string.IsNullOrEmpty(feature.ColumnValues["ROOMS"]))  
                 {  
                     QueryResult.Add(new QueryResultItemViewModel(feature, mapModel));  
                 }  
             }  
         }  
 
         private void MapModel_MapMouseCoordinateChanged(object sender, CustomFormattedMouseCoordinateMapToolEventArgs e)  
         {  
             CoordinateX = e.WorldCoordinate.X;  
             CoordinateY = e.WorldCoordinate.Y;  
         }  
 
         private void MapModel_PlacedPositionChanged(object sender, PlottedPointChangedMapModelEventArgs e)  
         {  
             mapModel.PlottedPoint = e.PlottedPoint;  
             SearchPointOfInterests();  
         }  
 
         private void SearchPointOfInterests()  
         {  
             PointShape queryingPoint = mapModel.PlottedPoint;  
             if (queryingPoint == null) return;  
 
             IsBusy = true;  
             Task.Factory.StartNew(() =>  
             {  
                 Dictionary<string, object> parameters = CollectServiceAnalysisParameters(CreateAreasMode);  
                 ServiceAreaAnalysis analysis = MapSuiteSampleHelper.GetAreaAnalysis(CreateAreasMode);  
                 Feature serviceArea = analysis.CreateServiceAreaFeature(queryingPoint, mapModel.MapControl.MapUnit, parameters);  
                 if (serviceArea != null)  
                 {  
                     mapModel.ServiceAreaFeatures.Clear();  
                     mapModel.ServiceAreaFeatures.Add(serviceArea);  
                 }  
 
                 Application.Current.Dispatcher.BeginInvoke(new Action(() =>  
                 {  
                     mapModel.QueryingFeatureLayer.Open();  
                     if (mapModel.ServiceAreaFeatures.Count > 0)  
                     {  
                         mapModel.MapControl.CurrentExtent = mapModel.ServiceAreaFeatures[0].GetBoundingBox();  
                         UpdateQueryResult();  
                     }  
 
                     IsBusy = false;  
                 }));  
             });  
         }  
 
         private void UpdatePoiTypeCandidates()  
         {  
             poiTypeCandidates.Clear();  
             poiTypeCandidates.Add(findAllTextKey);  
 
             Collection<string> candidateColumnValues = mapModel.GetColumnValueCandidates();  
             foreach (var columnValue in candidateColumnValues)  
             {  
                 poiTypeCandidates.Add(columnValue);  
             }  
 
             SelectedPoiType = PoiTypeCandidates.First();  
         }  
 
         private void UpdateQueryResult()  
         {  
             Collection<Feature> selectedFeatures = mapModel.GetFeaturesWithinServiceArea();  
 
             QueryResult.Clear();  
             if (SelectedPoiType == findAllTextKey)  
             {  
                 foreach (var feature in selectedFeatures)  
                 {  
                     QueryResult.Add(new QueryResultItemViewModel(feature, mapModel));  
                 }  
             }  
             else if (mapModel.QueryingFeatureLayer != mapModel.PoiFeatureLayers[Resources.HotelsLayerKey])  
             {  
                 string columnName = MapSuiteSampleHelper.GetDefaultColumnNameByPoiType(mapModel.QueryingFeatureLayer.Name);  
                 foreach (var feature in selectedFeatures)  
                 {  
                     string columnValue = feature.ColumnValues[columnName];  
                     if (columnValue == SelectedPoiType || string.IsNullOrEmpty(columnValue))  
                     {  
                         QueryResult.Add(new QueryResultItemViewModel(feature, mapModel));  
                     }  
                 }  
             }  
             else  
             {  
                 FilterHotelFeatures(selectedFeatures);  
             }  
 
             mapModel.AddMarkersByFeatures(QueryResult.Select(q => q.Feature));  
             mapModel.MapControl.Refresh();  
 
             CommandManager.InvalidateRequerySuggested();  
             if (QueryResult.Count == 0)  
             {  
                 QueryResult.Add(new QueryResultItemViewModel(noResultKey));  
             }  
         }  
 
         private void UpdateUnitSystem(DistanceUnit value)  
         {  
             switch (value)  
             {  
                 case DistanceUnit.Kilometer:  
                     mapModel.UpdateUnitSystem(UnitSystem.Metric);  
                     break;  
 
                 case DistanceUnit.Mile:  
                     mapModel.UpdateUnitSystem(UnitSystem.Imperial);  
                     break;  
             }  
         }  
     }  
 }  
 

PopupUserControlViewModel.cs

 using System.Collections.ObjectModel;  
 using System.Globalization;  
 using ThinkGeo.MapSuite.Core;  
 
 namespace ThinkGeo.MapSuite.SiteSelection  
 {  
     public class PopupUserControlViewModel : ViewModelBase  
     {  
         private string name;  
         private string address;  
         private Feature feature;  
         private ObservableCollection<string> informations;  
 
         public PopupUserControlViewModel()  
             : this(null)  
         { }  
 
         public PopupUserControlViewModel(Feature feature)  
             : base()  
         {  
             informations = new ObservableCollection<string>();  
             Feature = feature;  
         }  
 
         public Feature Feature  
         {  
             get { return feature; }  
             set  
             {  
                 feature = value;  
                 LoadInformation();  
             }  
         }  
 
         public string Address  
         {  
             get { return string.Format(CultureInfo.InvariantCulture, "Addr: {0} ,TX", address); }  
         }  
 
         public string Header  
         {  
             get { return name; }  
         }  
 
         public ObservableCollection<string> Informations  
         {  
             get { return informations; }  
         }  
 
         private void LoadInformation()  
         {  
             if (feature == null) return;  
 
             name = string.Empty;  
             address = string.Empty;  
             Informations.Clear();  
 
             foreach (var item in feature.ColumnValues)  
             {  
                 string key = item.Key.ToUpperInvariant();  
                 if (key == "NAME")  
                 {  
                     name = item.Value;  
                 }  
                 else if (key == "ADDRESS")  
                 {  
                     address = item.Value;  
                 }  
                 else  
                 {  
                     Informations.Add(string.Format(CultureInfo.InvariantCulture, "{0} : {1}", item.Key, item.Value));  
                 }  
             }  
 
             RaisePropertyChanged(() => Header);  
             RaisePropertyChanged(() => Address);  
             RaisePropertyChanged(() => Informations);  
         }  
     }  
 }  
 

QueryResultItemViewModel.cs

 using System;  
 using System.Linq;  
 using ThinkGeo.MapSuite.Core;  
 
 namespace ThinkGeo.MapSuite.SiteSelection  
 {  
     public class QueryResultItemViewModel : ViewModelBase  
     {  
         private static readonly double zoomLevel19Scale = 2252.9288864135742;  
 
         private string name;  
         private bool canZoomToFeature;  
         private Feature feature;  
         private MapModel mapModel;  
         private CommandBase zoomToFeatureCommand;  
 
         public QueryResultItemViewModel(string displayName)  
             : base()  
         {  
             Name = displayName;  
             CanZoomToFeature = false;  
         }  
 
         public QueryResultItemViewModel(Feature feature, MapModel mapModel)  
             : base()  
         {  
             this.CanZoomToFeature = true;  
             this.feature = feature;  
             this.mapModel = mapModel;  
             this.name = feature.ColumnValues.FirstOrDefault(item => item.Key.Equals("NAME", StringComparison.InvariantCultureIgnoreCase)).Value;  
         }  
 
         public Feature Feature  
         {  
             get { return feature; }  
             set { feature = value; }  
         }  
 
         public bool CanZoomToFeature  
         {  
             get { return canZoomToFeature; }  
             set  
             {  
                 canZoomToFeature = value;  
                 RaisePropertyChanged(() => CanZoomToFeature);  
             }  
         }  
 
         public string Name  
         {  
             get { return name; }  
             set { name = value; }  
         }  
 
         public CommandBase ZoomToFeatureCommand  
         {  
             get  
             {  
                 return zoomToFeatureCommand ?? (zoomToFeatureCommand = new CommandBase(()  
                     => mapModel.MapControl.ZoomTo(feature.GetShape().GetCenterPoint(), zoomLevel19Scale)));  
             }  
         }  
     }  
 }  
 

BingMapsApplicationIdPromptWindow.xaml

 <Window x:Class="ThinkGeo.MapSuite.SiteSelection.BingMapsApplicationIdPromptWindow"  
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
         Title="Input Key Window" Height="136" Width="501"  
         ResizeMode="NoResize"  
         Icon="/MapSuiteSiteSelection;component/Image/MapSuite.ico">  
     <Grid Margin="0 7 0 8">  
         <Grid.RowDefinitions>  
             <RowDefinition Height="*" />  
             <RowDefinition Height="auto" />  
             <RowDefinition Height="auto" />  
         </Grid.RowDefinitions>  
         <Grid Grid.Row="0" Margin="6 0 6 0">  
             <Grid.ColumnDefinitions>  
                 <ColumnDefinition Width="auto" />  
                 <ColumnDefinition Width="*" />  
             </Grid.ColumnDefinitions>  
             <Grid.RowDefinitions>  
                 <RowDefinition Height="auto" />  
                 <RowDefinition Height="auto" />  
             </Grid.RowDefinitions>  
             <TextBlock Grid.Row="0" Grid.Column="0" Text="Bing Maps Application Key: " />  
             <TextBox x:Name="txtkeyBox" Grid.Row="0" Grid.Column="1" />  
             <TextBlock Grid.Row="1" Grid.Column="1" Margin="0 8 0 8" Style="{StaticResource explanText}">  
                 Don't have a Bing Maps Appliction Key?  
                 <Hyperlink Click="Hyperlink_Click">  
                     <TextBlock Style="{StaticResource explanText}">Create One now</TextBlock>  
                 </Hyperlink>  
             </TextBlock>  
         </Grid>  
         <Separator Grid.Row="1" Margin="0 8 0 8" />  
         <StackPanel Grid.Row="2" Margin="6 0 6 0" HorizontalAlignment="Right" Orientation="Horizontal">  
             <Button Content="OK" Width="80" Click="OkButton_Click" />  
             <Button Content="Cancel" IsCancel="True" Width="80" Margin="10 0 0 0" />  
         </StackPanel>  
     </Grid>  
 </Window>  
 

BingMapsApplicationIdPromptWindow.xaml.cs

 using System.Diagnostics;  
 using System.Windows;  
 
 namespace ThinkGeo.MapSuite.SiteSelection  
 {  
     /// <summary>  
     /// Interaction logic for InputBingMapKeyWindow.xaml  
     /// </summary>  
     public partial class BingMapsApplicationIdPromptWindow : Window  
     {  
         public BingMapsApplicationIdPromptWindow()  
         {  
             InitializeComponent();  
         }  
 
         public string ApplicationId  
         {  
             get { return txtkeyBox.Text; }  
         }  
 
         private void OkButton_Click(object sender, RoutedEventArgs e)  
         {  
             DialogResult = true;  
         }  
 
         private void Hyperlink_Click(object sender, RoutedEventArgs e)  
         {  
             Process.Start("https://www.bingmapsportal.com/");  
         }  
     }  
 }  
 

PopupUserControl.xaml

 <UserControl x:Class="ThinkGeo.MapSuite.SiteSelection.PopupUserControl"  
              xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"  
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008"  
              xmlns:local="clr-namespace:ThinkGeo.MapSuite.SiteSelection"  
              mc:Ignorable="d"  
              d:DesignHeight="300" d:DesignWidth="300">  
     <Grid>  
         <StackPanel Margin="5 10 5 10">  
             <TextBlock Grid.Column="0" Text="{Binding Header}" Style="{StaticResource h4}" FontWeight="SemiBold" />  
             <TextBlock Text="{Binding Address}" Style="{StaticResource bodyText}" Margin="0 5 0 0" FontSize="12" />  
             <Separator Margin="0 5 0 5" />  
             <ListBox IsEnabled="False" ItemsSource="{Binding Informations}" Margin="0 0 0 0">  
                 <ListBox.Template>  
                     <ControlTemplate>  
                         <StackPanel IsItemsHost="True" />  
                     </ControlTemplate>  
                 </ListBox.Template>  
             </ListBox>  
         </StackPanel>  
     </Grid>  
 </UserControl>  
 

PopupUserControl.xaml.cs

 using System.Windows.Controls;  
 using ThinkGeo.MapSuite.Core;  
 
 namespace ThinkGeo.MapSuite.SiteSelection  
 {  
     /// <summary>  
     /// Interaction logic for PopupUserControl.xaml  
     /// </summary>  
     public partial class PopupUserControl : UserControl  
     {  
         public PopupUserControl(Feature feature)  
         {  
             InitializeComponent();  
             DataContext = new PopupUserControlViewModel(feature);  
         }  
     }  
 }  
 

CreateAreasMode.cs

 namespace ThinkGeo.MapSuite.SiteSelection  
 {  
     public enum CreateAreasMode  
     {  
         Buffer,  
         Route  
     }  
 }  
 

MapModel.cs

 using System;  
 using System.Collections.Generic;  
 using System.Collections.ObjectModel;  
 using System.Configuration;  
 using System.Globalization;  
 using System.IO;  
 using System.Linq;  
 using System.Windows;  
 using System.Windows.Input;  
 using System.Windows.Media.Imaging;  
 using System.Windows.Resources;  
 using ThinkGeo.MapSuite.Core;  
 using ThinkGeo.MapSuite.SiteSelection.Properties;  
 using ThinkGeo.MapSuite.WpfDesktopEdition;  
 
 namespace ThinkGeo.MapSuite.SiteSelection  
 {  
     public class MapModel  
     {  
         private static readonly string imageUriTemplate = @"pack://application:,,,/MapSuiteSiteSelection;component/Image/{0}";  
         private static readonly Cursor handCursor = new Cursor(GetImageStream("cursor_hand.cur"));  
         private static readonly RectangleShape globeExtent = new RectangleShape(-10782584.5066971, 3916291.54400321, -10769504.2529497, 3907774.56943023);  
 
         private WpfMap mapControl;  
         private PointShape plottedPoint;  
         private BaseShape restrictionShape;  
         private ShapeFileFeatureLayer hotelsLayer;  
         private SimpleMarkerOverlay markerOverlay;  
         private ShapeFileFeatureLayer schoolsLayer;  
         private ShapeFileFeatureLayer restrictedLayer;  
         private InMemoryFeatureLayer serviceAreaLayer;  
         private ShapeFileFeatureLayer restaurantsLayer;  
         private ShapeFileFeatureLayer medicalFacilitesLayer;  
         private ShapeFileFeatureLayer publicFacilitesLayer;  
         private ShapeFileFeatureLayer queryingFeatureLayer;  
         private InMemoryFeatureLayer highlightFeatureLayer;  
         private GeoCollection<ShapeFileFeatureLayer> poiFeatureLayers;  
 
         public event EventHandler<PlottedPointChangedMapModelEventArgs> PlottedPointChanged;  
 
         public MapModel()  
             : this(null)  
         { }  
 
         public MapModel(WpfMap wpfMap)  
             : base()  
         {  
             mapControl = wpfMap;  
 
             InitializeMapControl();  
             InitializeMapTools();  
             InitializeOverlays();  
             InitializeAdornments();  
         }  
 
         public WpfMap MapControl  
         {  
             get { return mapControl; }  
             set { mapControl = value; }  
         }  
 
         public TrackMode TrackMode  
         {  
             get { return mapControl.TrackOverlay.TrackMode; }  
             set  
             {  
                 mapControl.TrackOverlay.TrackMode = value;  
                 mapControl.Cursor = mapControl.TrackOverlay.TrackMode == TrackMode.None ? handCursor : Cursors.Arrow;  
             }  
         }  
 
         public PointShape PlottedPoint  
         {  
             get { return plottedPoint; }  
             set { plottedPoint = value; }  
         }  
 
         public Collection<Feature> ServiceAreaFeatures  
         {  
             get { return serviceAreaLayer.InternalFeatures; }  
         }  
 
         public ShapeFileFeatureLayer QueryingFeatureLayer  
         {  
             get { return queryingFeatureLayer; }  
             set { queryingFeatureLayer = value; }  
         }  
 
         public GeoCollection<ShapeFileFeatureLayer> PoiFeatureLayers  
         {  
             get { return poiFeatureLayers; }  
         }  
 
         public void UpdateUnitSystem(UnitSystem unitSystem)  
         {  
             ScaleBarAdornmentLayer adornmentLayer = mapControl.AdornmentOverlay.Layers[Resources.ScaleBarLayerKey] as ScaleBarAdornmentLayer;  
             if (adornmentLayer != null)  
             {  
                 adornmentLayer.UnitFamily = unitSystem;  
                 mapControl.AdornmentOverlay.Refresh();  
             }  
         }  
 
         public Collection<string> GetColumnValueCandidates()  
         {  
             string columnName = MapSuiteSampleHelper.GetDefaultColumnNameByPoiType(queryingFeatureLayer.Name);  
             Collection<string> candidates = new Collection<string>();  
             if (columnName.Equals("Hotels"))  
             {  
                 candidates.Add("1 ~ 50");  
                 candidates.Add("50 ~ 100");  
                 candidates.Add("100 ~ 150");  
                 candidates.Add("150 ~ 200");  
                 candidates.Add("200 ~ 300");  
                 candidates.Add("300 ~ 400");  
                 candidates.Add("400 ~ 500");  
                 candidates.Add(">= 500");  
             }  
             else  
             {  
                 QueryingFeatureLayer.Open();  
                 IEnumerable<string> distinctColumnValues = QueryingFeatureLayer.FeatureSource.GetDistinctColumnValues(columnName).Select(v => v.ColumnValue);  
                 foreach (var distinctColumnValue in distinctColumnValues)  
                 {  
                     candidates.Add(distinctColumnValue);  
                 }  
             }  
             return candidates;  
         }  
 
         public void AddMarkersByFeatures(IEnumerable<Feature> features)  
         {  
             markerOverlay.Markers.Clear();  
 
             highlightFeatureLayer.InternalFeatures.Clear();  
             highlightFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = queryingFeatureLayer.ZoomLevelSet.ZoomLevel10.DefaultPointStyle;  
 
             if (plottedPoint != null)  
             {  
                 markerOverlay.Markers.Add(CreateMarker(plottedPoint, "drawPoint.png"));  
             }  
 
             if (features != null)  
             {  
                 foreach (Feature feature in features)  
                 {  
                     highlightFeatureLayer.InternalFeatures.Add(feature);  
                     PopupUserControl toolTip = new PopupUserControl(feature);  
                     Marker marker = CreateMarker((PointShape)feature.GetShape(), "selectedHalo.png", 0, toolTip);  
                     markerOverlay.Markers.Add(marker);  
                 }  
             }  
         }  
 
         public Collection<Feature> GetFeaturesWithinServiceArea()  
         {  
             Collection<Feature> resultFeatures = new Collection<Feature>();  
             if (queryingFeatureLayer != null && ServiceAreaFeatures.Count > 0)  
             {  
                 queryingFeatureLayer.Open();  
                 BaseShape pinnedServiceArea = ServiceAreaFeatures[0].GetShape();  
                 Collection<Feature> tempFeatures = QueryingFeatureLayer.QueryTools.GetFeaturesWithin(pinnedServiceArea, ReturningColumnsType.AllColumns);  
                 foreach (var tempFeature in tempFeatures)  
                 {  
                     resultFeatures.Add(tempFeature);  
                 }  
             }  
 
             return resultFeatures;  
         }  
 
         protected void OnPlacedPositionChanged(PointShape point)  
         {  
             EventHandler<PlottedPointChangedMapModelEventArgs> handler = PlottedPointChanged;  
             if (handler != null)  
             {  
                 handler(this, new PlottedPointChangedMapModelEventArgs(point));  
             }  
         }  
 
         private void InitializeMapControl()  
         {  
             mapControl.MapUnit = GeographyUnit.Meter;  
             mapControl.CurrentExtent = globeExtent;  
             mapControl.TrackOverlay.TrackEnded += TrackOverlay_TrackEnded;  
         }  
 
         private void InitializeOverlays()  
         {  
             poiFeatureLayers = new GeoCollection<ShapeFileFeatureLayer>();  
             string cacheFolder = Path.Combine(Path.GetTempPath(), "TileCache");  
 
             WorldMapKitWmsWpfOverlay worldMapKitOverlay = new WorldMapKitWmsWpfOverlay();  
             worldMapKitOverlay.Name = Resources.WorldMapKitOverlayName;  
             worldMapKitOverlay.TileWidth = 512;  
             worldMapKitOverlay.TileHeight = 512;  
             worldMapKitOverlay.IsVisible = true;  
             worldMapKitOverlay.Projection = WorldMapKitProjection.SphericalMercator;  
             worldMapKitOverlay.TileCache = new FileBitmapTileCache(cacheFolder, Resources.WorldMapKitOverlayName);  
             mapControl.Overlays.Add(Resources.WorldMapKitOverlayName, worldMapKitOverlay);  
 
             OpenStreetMapOverlay openStreetMapOverlay = new OpenStreetMapOverlay();  
             openStreetMapOverlay.Name = Resources.OSMOverlayName;  
             openStreetMapOverlay.TileWidth = 512;  
             openStreetMapOverlay.TileHeight = 512;  
             openStreetMapOverlay.IsVisible = false;  
             openStreetMapOverlay.TileCache = new FileBitmapTileCache(cacheFolder, Resources.OSMOverlayName);  
             mapControl.Overlays.Add(Resources.OSMOverlayName, openStreetMapOverlay);  
 
             BingMapsOverlay bingMapsAerialOverlay = new BingMapsOverlay();  
             bingMapsAerialOverlay.Name = Resources.BingMapsAerialOverlayName;  
             bingMapsAerialOverlay.TileWidth = 512;  
             bingMapsAerialOverlay.TileHeight = 512;  
             bingMapsAerialOverlay.IsVisible = false;  
             bingMapsAerialOverlay.MapType = BingMapsMapType.Aerial;  
             bingMapsAerialOverlay.TileCache = new FileBitmapTileCache(cacheFolder, Resources.BingMapsAerialOverlayName);  
             mapControl.Overlays.Add(Resources.BingMapsAerialOverlayName, bingMapsAerialOverlay);  
 
             BingMapsOverlay bingMapsRoadOverlay = new BingMapsOverlay();  
             bingMapsRoadOverlay.Name = Resources.BingMapsRoadOverlayName;  
             bingMapsRoadOverlay.TileWidth = 512;  
             bingMapsRoadOverlay.TileHeight = 512;  
             bingMapsRoadOverlay.IsVisible = false;  
             bingMapsRoadOverlay.MapType = BingMapsMapType.Road;  
             bingMapsRoadOverlay.TileCache = new FileBitmapTileCache(cacheFolder, Resources.BingMapsRoadOverlayName);  
             mapControl.Overlays.Add(Resources.BingMapsRoadOverlayName, bingMapsRoadOverlay);  
 
             LayerOverlay customOverlay = new LayerOverlay();  
             customOverlay.Name = Resources.CustomOverlayKey;  
             customOverlay.TileType = TileType.SingleTile;  
             mapControl.Overlays.Add(Resources.CustomOverlayKey, customOverlay);  
 
             ManagedProj4Projection wgs84ToMercatorProj4Projection = new ManagedProj4Projection();  
             wgs84ToMercatorProj4Projection.InternalProjectionParametersString = Proj4Projection.GetDecimalDegreesParametersString();  
             wgs84ToMercatorProj4Projection.ExternalProjectionParametersString = Proj4Projection.GetSphericalMercatorParametersString();  
             wgs84ToMercatorProj4Projection.Open();  
 
             restrictedLayer = new ShapeFileFeatureLayer(ConfigurationManager.AppSettings["RestrictedShapeFilePathName"]);  
             restrictedLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(new AreaStyle(new GeoPen(GeoColor.SimpleColors.White, 5.5f), new GeoSolidBrush(GeoColor.SimpleColors.Transparent)));  
             restrictedLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(new AreaStyle(new GeoPen(GeoColor.SimpleColors.Red, 1.5f) { DashStyle = LineDashStyle.Dash }, new GeoSolidBrush(GeoColor.SimpleColors.Transparent)));  
             restrictedLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
             restrictedLayer.FeatureSource.Projection = wgs84ToMercatorProj4Projection;  
             customOverlay.Layers.Add(Resources.RestrictedLayerKey, restrictedLayer);  
 
             serviceAreaLayer = new InMemoryFeatureLayer();  
             serviceAreaLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(new GeoColor(120, GeoColor.FromHtml("#1749c9")), GeoColor.FromHtml("#fefec1"), 3, LineDashStyle.Solid);  
             serviceAreaLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
             customOverlay.Layers.Add(Resources.ServiceAreaLayerKey, serviceAreaLayer);  
 
             LayerOverlay poiOverlay = new LayerOverlay();  
             poiOverlay.TileType = TileType.SingleTile;  
             mapControl.Overlays.Add(Resources.PoiOverlayKey, poiOverlay);  
 
             hotelsLayer = new ShapeFileFeatureLayer(ConfigurationManager.AppSettings["HotelsShapeFilePathName"]);  
             hotelsLayer.Name = Resources.HotelsLayerKey;  
             hotelsLayer.Transparency = 120f;  
             hotelsLayer.ZoomLevelSet.ZoomLevel10.DefaultPointStyle = new PointStyle(new GeoImage(GetImageStream("Hotel.png")));  
             hotelsLayer.ZoomLevelSet.ZoomLevel10.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
             hotelsLayer.FeatureSource.Projection = wgs84ToMercatorProj4Projection;  
             poiOverlay.Layers.Add(Resources.HotelsLayerKey, hotelsLayer);  
 
             medicalFacilitesLayer = new ShapeFileFeatureLayer(ConfigurationManager.AppSettings["MedicalFacilitiesShapeFilePathName"]);  
             medicalFacilitesLayer.Name = Resources.MedicalFacilitesLayerKey;  
             medicalFacilitesLayer.Transparency = 120f;  
             medicalFacilitesLayer.ZoomLevelSet.ZoomLevel10.DefaultPointStyle = new PointStyle(new GeoImage(GetImageStream("DrugStore.png")));  
             medicalFacilitesLayer.ZoomLevelSet.ZoomLevel10.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
             medicalFacilitesLayer.FeatureSource.Projection = wgs84ToMercatorProj4Projection;  
             poiOverlay.Layers.Add(Resources.MedicalFacilitesLayerKey, medicalFacilitesLayer);  
 
             publicFacilitesLayer = new ShapeFileFeatureLayer(ConfigurationManager.AppSettings["PublicFacilitiesShapeFilePathName"]);  
             publicFacilitesLayer.Name = Resources.PublicFacilitesLayerKey;  
             publicFacilitesLayer.Transparency = 120f;  
             publicFacilitesLayer.ZoomLevelSet.ZoomLevel10.DefaultPointStyle = new PointStyle(new GeoImage(GetImageStream("public_facility.png")));  
             publicFacilitesLayer.ZoomLevelSet.ZoomLevel10.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
             publicFacilitesLayer.FeatureSource.Projection = wgs84ToMercatorProj4Projection;  
             poiOverlay.Layers.Add(Resources.PublicFacilitesLayerKey, publicFacilitesLayer);  
 
             restaurantsLayer = new ShapeFileFeatureLayer(ConfigurationManager.AppSettings["RestaurantsShapeFilePathName"]);  
             restaurantsLayer.Name = Resources.RestaurantsLayerKey;  
             restaurantsLayer.Transparency = 120f;  
             restaurantsLayer.ZoomLevelSet.ZoomLevel10.DefaultPointStyle = new PointStyle(new GeoImage(GetImageStream("restaurant.png")));  
             restaurantsLayer.ZoomLevelSet.ZoomLevel10.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
             restaurantsLayer.FeatureSource.Projection = wgs84ToMercatorProj4Projection;  
             poiOverlay.Layers.Add(Resources.RestaurantsLayerKey, restaurantsLayer);  
 
             schoolsLayer = new ShapeFileFeatureLayer(ConfigurationManager.AppSettings["SchoolsShapeFilePathName"]);  
             schoolsLayer.Name = Resources.SchoolsLayerKey;  
             schoolsLayer.Transparency = 120f;  
             schoolsLayer.ZoomLevelSet.ZoomLevel10.DefaultPointStyle = new PointStyle(new GeoImage(GetImageStream("school.png")));  
             schoolsLayer.ZoomLevelSet.ZoomLevel10.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
             schoolsLayer.FeatureSource.Projection = wgs84ToMercatorProj4Projection;  
             poiOverlay.Layers.Add(Resources.SchoolsLayerKey, schoolsLayer);  
 
             highlightFeatureLayer = new InMemoryFeatureLayer();  
             highlightFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
 
             markerOverlay = new SimpleMarkerOverlay();  
             mapControl.Overlays.Add(Resources.MakerOverlayKey, markerOverlay);  
 
             poiFeatureLayers.Add(hotelsLayer.Name, hotelsLayer);  
             poiFeatureLayers.Add(medicalFacilitesLayer.Name, medicalFacilitesLayer);  
             poiFeatureLayers.Add(restaurantsLayer.Name, restaurantsLayer);  
             poiFeatureLayers.Add(schoolsLayer.Name, schoolsLayer);  
             poiOverlay.Layers.Add(Resources.HighlightFeatureLayerKey, highlightFeatureLayer);  
         }  
 
         private void InitializeAdornments()  
         {  
             LegendAdornmentLayer legendlayer = new LegendAdornmentLayer();  
             legendlayer.Height = 135;  
             legendlayer.Location = AdornmentLocation.LowerRight;  
             mapControl.AdornmentOverlay.Layers.Add(legendlayer);  
 
             AddLegendItem(hotelsLayer, legendlayer);  
             AddLegendItem(medicalFacilitesLayer, legendlayer);  
             AddLegendItem(publicFacilitesLayer, legendlayer);  
             AddLegendItem(restaurantsLayer, legendlayer);  
             AddLegendItem(schoolsLayer, legendlayer);  
 
             ScaleBarAdornmentLayer scaleBar = new ScaleBarAdornmentLayer();  
             scaleBar.Location = AdornmentLocation.LowerLeft;  
             mapControl.AdornmentOverlay.Layers.Add(Resources.ScaleBarLayerKey, scaleBar);  
         }  
 
         private void InitializeMapTools()  
         {  
             mapControl.MapTools.Logo.IsEnabled = false;  
             mapControl.MapTools.MouseCoordinate.IsEnabled = true;  
             mapControl.MapTools.MouseCoordinate.Visibility = Visibility.Hidden;  
             mapControl.MapTools.MouseCoordinate.Margin = new Thickness(0, 0, 180, 5);  
             mapControl.MapTools.MouseCoordinate.MouseCoordinateType = MouseCoordinateType.Custom;  
             mapControl.MapTools.PanZoomBar.GlobeButtonClick += (s, e) => e.NewExtent = globeExtent;  
 
             OverlaySwitcher overlaySwitcher = new OverlaySwitcher();  
             overlaySwitcher.Initialize(mapControl);  
             overlaySwitcher.OverlayChanged += OverlaySwitcher_BaseOverlayChanged;  
             mapControl.MapTools.Add(overlaySwitcher);  
         }  
 
         private BaseShape GetRestictionShape()  
         {  
             if (restrictionShape == null)  
             {  
                 restrictedLayer.Open();  
                 restrictionShape = restrictedLayer.QueryTools.GetFeatureById("1", ReturningColumnsType.NoColumns).GetShape();  
             }  
 
             return restrictionShape;  
         }  
 
         private void OverlaySwitcher_BaseOverlayChanged(object sender, OverlayChangedOverlaySwitcherEventArgs e)  
         {  
             BingMapsOverlay bingMapsOverlay = e.Overlay as BingMapsOverlay;  
             if (bingMapsOverlay != null)  
             {  
                 bool cancel = false;  
                 string bingMapsKey = MapSuiteSampleHelper.GetBingMapsApplicationId();  
                 if (!string.IsNullOrEmpty(bingMapsKey))  
                 {  
                     foreach (var bingOverlay in MapControl.Overlays.OfType<BingMapsOverlay>())  
                     {  
                         bingOverlay.ApplicationId = bingMapsKey;  
                     }  
                 }  
                 else  
                 {  
                     cancel = true;  
                 }  
 
                 e.Cancel = cancel;  
             }  
         }  
 
         private void TrackOverlay_TrackEnded(object sender, TrackEndedTrackInteractiveOverlayEventArgs e)  
         {  
             if (mapControl.TrackOverlay.TrackShapeLayer.InternalFeatures.Count > 0)  
             {  
                 restrictionShape = GetRestictionShape();  
 
                 PointShape clickedShape = mapControl.TrackOverlay.TrackShapeLayer.InternalFeatures[0].GetShape() as PointShape;  
                 if (QueryingFeatureLayer != null && clickedShape != null && restrictionShape != null && clickedShape.IsWithin(restrictionShape))  
                 {  
                     plottedPoint = clickedShape;  
                     OnPlacedPositionChanged(plottedPoint);  
                 }  
                 else  
                 {  
                     SiteSelectionWarningWindow warningWindow = new SiteSelectionWarningWindow();  
                     warningWindow.Owner = Application.Current.MainWindow;  
                     warningWindow.WindowStartupLocation = WindowStartupLocation.CenterOwner;  
                     warningWindow.ShowDialog();  
                 }  
 
                 mapControl.TrackOverlay.TrackShapeLayer.InternalFeatures.Clear();  
             }  
         }  
 
         private static Stream GetImageStream(string imageName)  
         {  
             Stream imageStream = null;  
             Uri imageUri = new Uri(string.Format(CultureInfo.InvariantCulture, imageUriTemplate, imageName), UriKind.RelativeOrAbsolute);  
             StreamResourceInfo imageStreamInfo = Application.GetResourceStream(imageUri);  
             if (imageStreamInfo != null) imageStream = imageStreamInfo.Stream;  
             return imageStream;  
         }  
 
         private static Marker CreateMarker(PointShape point, string imageName, double yOffsetRatio = 0.5, object toolTip = null)  
         {  
             Marker marker = new Marker(point);  
             marker.ImageSource = new BitmapImage(new Uri(string.Format(CultureInfo.InvariantCulture, imageUriTemplate, imageName), UriKind.RelativeOrAbsolute));  
             marker.YOffset = -marker.ImageSource.Height * yOffsetRatio;  
             if (toolTip != null) marker.ToolTip = toolTip;  
 
             return marker;  
         }  
 
         private static void AddLegendItem(FeatureLayer featureLayer, LegendAdornmentLayer legendLayer)  
         {  
             LegendItem legendItem = new LegendItem();  
             legendItem.ImageStyle = featureLayer.ZoomLevelSet.ZoomLevel10.DefaultPointStyle;  
             legendItem.TextStyle = TextStyles.NoData1(featureLayer.Name);  
             legendLayer.LegendItems.Add(featureLayer.Name, legendItem);  
         }  
     }  
 }  
 

PlottedPointChangedMapModelEventArgs.cs

 using System;  
 using ThinkGeo.MapSuite.Core;  
 
 namespace ThinkGeo.MapSuite.SiteSelection  
 {  
     [Serializable]  
     public class PlottedPointChangedMapModelEventArgs : EventArgs  
     {  
         private PointShape plottedPoint;  
 
         public PlottedPointChangedMapModelEventArgs()  
             : this(null)  
         { }  
 
         public PlottedPointChangedMapModelEventArgs(PointShape plottedPoint)  
         {  
             this.plottedPoint = plottedPoint;  
         }  
 
         public PointShape PlottedPoint  
         {  
             get { return plottedPoint; }  
         }  
     }  
 }  
 
source_code_wpf_desktopeditionsample_mapsuitesiteselection_cs.zip.txt · Last modified: 2015/09/09 03:39 by admin