Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
anti79 committed Jul 22, 2022
2 parents cfe752b + 4b69aff commit 16d4ce9
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 116 deletions.
2 changes: 2 additions & 0 deletions GoogleMapsApi.Test/GoogleMapsApi.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="AutoCompleteTextBox" Version="1.5.0" />
<PackageReference Include="MaterialDesignExtensions" Version="3.3.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0" />
Expand Down
4 changes: 2 additions & 2 deletions GoogleMapsApi.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30804.86
# Visual Studio Version 17
VisualStudioVersion = 17.2.32408.312
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GoogleMapsApi.Test", "GoogleMapsApi.Test\GoogleMapsApi.Test.csproj", "{AD9AD8E9-0E2C-470E-9004-373679F9D954}"
EndProject
Expand Down
10 changes: 9 additions & 1 deletion google-maps-api/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:google_maps_api"
xmlns:materialDesign="https://materialdesigninxaml.net/winfx/xaml/themes"
StartupUri="MainWindow.xaml">
<Application.Resources>

<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.DeepPurple.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Lime.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
76 changes: 70 additions & 6 deletions google-maps-api/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace google_maps_api
{
public class MainViewModel:INotifyPropertyChanged
{
private RouteMapRequest _routemaprequest;
private readonly string apikey = "AIzaSyDikeBAymgSWrWz-9Y7Danr2mNewZV_MwI";
private RelayCommand _drawcommand;
public RelayCommand DrawCommand
Expand All @@ -23,6 +25,27 @@ public RelayCommand DrawCommand
NotifyPropertyChanged();
}
}
private RelayCommand _zoomincommand;
public RelayCommand ZoomInCommand
{
get => _zoomincommand;
set
{
_zoomincommand = value;
NotifyPropertyChanged();
}
}
private RelayCommand _zoomoutcommand;
public RelayCommand ZoomOutCommand
{
get => _zoomoutcommand;
set
{
_zoomoutcommand = value;
NotifyPropertyChanged();
}
}

private string _imageSource;
public string ImageSource
{
Expand Down Expand Up @@ -68,14 +91,55 @@ public MainViewModel()
ImageSource = "https://media.discordapp.net/attachments/917760526094856212/1000076529226752072/unknown.png";
DrawCommand = new RelayCommand((_) => {

RouteMapRequest routeMapRequest = new RouteMapRequest(new AddressLocation($"{Origin}"), new ImageSize(800, 400), $"{Origin}", $"{Destination}")
try
{
_routemaprequest = new RouteMapRequest(new AddressLocation($"{Origin}"), new ImageSize(800, 400), $"{Origin}", $"{Destination}")
{ Scale = 2 };
routeMapRequest.CalculateZoom = true;
routeMapRequest.ApiKey = apikey;
routeMapRequest.CalculateZoom = true;
ImageSource = new RouteMapsEngine().GenerateRouteMapURL(routeMapRequest);

_routemaprequest.CalculateZoom = true;
_routemaprequest.ApiKey = apikey;
ImageSource = new RouteMapsEngine().GenerateRouteMapURL(_routemaprequest);
}
catch (NullReferenceException)
{
MessageBox.Show("Route not found");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
});

ZoomInCommand = new RelayCommand((_) =>
{
try
{
_routemaprequest.CalculateZoom = false;
_routemaprequest.Zoom += 1;
ImageSource = new RouteMapsEngine().GenerateRouteMapURL(_routemaprequest);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}


});
ZoomOutCommand = new RelayCommand((_) =>
{
try
{
_routemaprequest.CalculateZoom = false;
_routemaprequest.Zoom -= 1;
ImageSource = new RouteMapsEngine().GenerateRouteMapURL(_routemaprequest);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

});


}


Expand Down
217 changes: 110 additions & 107 deletions google-maps-api/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,113 +11,116 @@
Background="Transparent"
WindowStartupLocation="CenterScreen"
Title="MapsRouter" Height="620" Width="800">
<Window.DataContext>
<local:MainViewModel/>
</Window.DataContext>
<Grid>
<Border Margin="30" x:Name="border_main" Background="White" CornerRadius="10" BorderThickness="1" BorderBrush="White">
<Border.Effect>
<DropShadowEffect BlurRadius="40" ShadowDepth="0" Opacity="0.2"
<Window.DataContext>
<local:MainViewModel/>
</Window.DataContext>
<Grid>
<Border Margin="30" x:Name="border_main" Background="White" CornerRadius="10" BorderThickness="1" BorderBrush="White">
<Border.Effect>
<DropShadowEffect BlurRadius="40" ShadowDepth="0" Opacity="0.2"
Color="Black" />
</Border.Effect>
<Grid>
<Border x:Name="border_titlebar" Background="#F3F3F3" BorderBrush="#F3F3F3" BorderThickness="1,1,1,0" MouseDown="TitleBar_MouseDown" Height="40" VerticalAlignment="Top" CornerRadius="7,7,0,0" Margin="-1,-1,-1,0">
<Grid x:Name="grid_titlebar" Margin="-1,-1,-1,0" Height="40" VerticalAlignment="Top">
<StackPanel Margin="641,0,0,0" Orientation="Horizontal" Height="40" VerticalAlignment="Center" HorizontalAlignment="Left" Width="100">
<StackPanel.Resources>
<Style TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Background" Value="Transparent"></Setter>
<Setter Property="Margin" Value="3,0,0,0"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#CACACA"/>
</Trigger>
</Style.Triggers>
</Style>
</StackPanel.Resources>
<Button Name="btn_minimize" Click="btn_minimize_Click" Width="48" Height="40">
<Path Fill="#919191" Width="12" Height="2" Stretch="Fill">
<Path.Data>
<PathGeometry Figures="M3 9.25H13V8.25H3V9.25Z" FillRule="EvenOdd"/>
</Path.Data>
</Path>
</Button>
<Button Click="btn_close_Click" Name="btn_close" Width="48" Height="40">
<Path VerticalAlignment="Center" Width="12" Height="12" Stretch="Fill">
<Path.Data>
<PathGeometry Figures="M12.5 3.00003L8.354 7.14703L4.207 3.00003L3.5 3.70703L7.646 7.85403L3.5 12L4.207 12.707L8.354 8.56103L12.5 12.707L13.207 12L9.06 7.85403L13.207 3.70703L12.5 3.00003Z" FillRule="EvenOdd"/>
</Path.Data>
<Path.Style>
<Style TargetType="{x:Type Path}">
<Setter Property="Fill" Value="#919191"></Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=btn_close, Path=IsMouseOver}" Value="True">
<Setter Property="Fill" Value="White"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Path.Style>
</Path>
<Button.Style>
<Style TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Background="{TemplateBinding Background}" CornerRadius="0,7,0,0">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Margin" Value="0,0,0,0"></Setter>
<Setter Property="Background" Value="Transparent"></Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#EB4C42"/>
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
</StackPanel>
</Grid>
</Border>
<StackPanel Orientation='Vertical' Margin="19,59,460,270">
<controls:AutoCompleteBox Text="{Binding Origin, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" x:Name='tb_origin'>
</controls:AutoCompleteBox>
</StackPanel>
<StackPanel Orientation='Vertical' Margin="297,59,182,270">
<controls:AutoCompleteBox Text="{Binding Destination, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" x:Name='tb_destination'>
</controls:AutoCompleteBox>
</StackPanel>
<Button Command="{Binding DrawCommand}" Click="btn_drawroute" Content="Draw route" Margin="574,55,19,474"/>
</Grid>
</Border>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="33*"></ColumnDefinition>
<ColumnDefinition Width="7*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="41*"></RowDefinition>
<RowDefinition Height="21*"></RowDefinition>
</Grid.RowDefinitions>
<Image Grid.ColumnSpan="2" Source="{Binding ImageSource, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Grid.RowSpan="2" Margin="50,100,50,24">
</Image>
<StackPanel Grid.Row="1" Grid.Column="1" Margin="15,10,65,40" >
<Button Padding="10,20" Margin="0,0,0,10">+</Button>
<Button Padding="10,20">-</Button>
</StackPanel>
</Grid>
</Border.Effect>
<Grid>
<Border x:Name="border_titlebar" Background="#F3F3F3" BorderBrush="#F3F3F3" BorderThickness="1,1,1,0" MouseDown="TitleBar_MouseDown" Height="40" VerticalAlignment="Top" CornerRadius="7,7,0,0" Margin="-1,-1,-1,0">
<Grid x:Name="grid_titlebar" Margin="-1,-1,-1,0" Height="40" VerticalAlignment="Top">
<StackPanel Margin="641,0,0,0" Orientation="Horizontal" Height="40" VerticalAlignment="Center" HorizontalAlignment="Left" Width="100">
<StackPanel.Resources>
<Style TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Background" Value="Transparent"></Setter>
<Setter Property="Margin" Value="3,0,0,0"/>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#CACACA"/>
</Trigger>
</Style.Triggers>
</Style>
</StackPanel.Resources>
<Button Name="btn_minimize" Click="btn_minimize_Click" Width="48" Height="40">
<Path Fill="#919191" Width="12" Height="2" Stretch="Fill">
<Path.Data>
<PathGeometry Figures="M3 9.25H13V8.25H3V9.25Z" FillRule="EvenOdd"/>
</Path.Data>
</Path>
</Button>
<Button Click="btn_close_Click" Name="btn_close" Width="48" Height="40">
<Path VerticalAlignment="Center" Width="12" Height="12" Stretch="Fill">
<Path.Data>
<PathGeometry Figures="M12.5 3.00003L8.354 7.14703L4.207 3.00003L3.5 3.70703L7.646 7.85403L3.5 12L4.207 12.707L8.354 8.56103L12.5 12.707L13.207 12L9.06 7.85403L13.207 3.70703L12.5 3.00003Z" FillRule="EvenOdd"/>
</Path.Data>
<Path.Style>
<Style TargetType="{x:Type Path}">
<Setter Property="Fill" Value="#919191"></Setter>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=btn_close, Path=IsMouseOver}" Value="True">
<Setter Property="Fill" Value="White"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Path.Style>
</Path>
<Button.Style>
<Style TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border Background="{TemplateBinding Background}" CornerRadius="0,7,0,0">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Margin" Value="0,0,0,0"></Setter>
<Setter Property="Background" Value="Transparent"></Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="#EB4C42"/>
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
</StackPanel>
</Grid>
</Border>
<StackPanel Orientation='Vertical' Margin="19,59,460,270">
<controls:AutoCompleteBox Text="{Binding Origin, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" x:Name='tb_origin'>
</controls:AutoCompleteBox>
</StackPanel>
<StackPanel Orientation='Vertical' Margin="297,59,182,270">
<controls:AutoCompleteBox Text="{Binding Destination, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" x:Name='tb_destination'>
</controls:AutoCompleteBox>
</StackPanel>
<Button Command="{Binding DrawCommand}" Click="btn_drawroute" Content="Draw route" Margin="574,55,19,471"/>
</Grid>
</Border>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="33*"></ColumnDefinition>
<ColumnDefinition Width="7*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="41*"></RowDefinition>
<RowDefinition Height="21*"></RowDefinition>
</Grid.RowDefinitions>
<Image Grid.ColumnSpan="2" Source="{Binding ImageSource, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Grid.RowSpan="2" Margin="50,100,50,24">
</Image>
<StackPanel Grid.Column="1" Margin="14,24,66,26" Grid.Row="1" >
<Button Command="{Binding ZoomInCommand}" Margin="0,0,0,10" FontSize="20" Height="50" HorizontalContentAlignment="Center" Width="50">+</Button>
<Button Command="{Binding ZoomOutCommand}" Margin="0,6,0,0" FontSize="20" Width="50" Height="50">-</Button>
</StackPanel>



</Grid>

</Grid>
</Grid>
</Window>
2 changes: 2 additions & 0 deletions google-maps-api/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public MainWindow()
InitializeComponent();
tb_origin.FilterMode = AutoCompleteFilterMode.Contains;
tb_origin.ItemsSource = new string[] { "New York", "Ukraine", "Odesa" };
tb_destination.FilterMode = AutoCompleteFilterMode.Contains;
tb_destination.ItemsSource = new string[] { "New York", "Kyiv", "Odesa" };
}

private void TitleBar_MouseDown(object sender, MouseButtonEventArgs e)
Expand Down
3 changes: 3 additions & 0 deletions google-maps-api/UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
<ItemGroup>
<PackageReference Include="DotNetProjects.WpfToolkit.Input" Version="6.1.94" />
<PackageReference Include="GoogleMapsApi" Version="1.2.0" />
<PackageReference Include="MaterialDesignColors" Version="2.0.7-ci246" />
<PackageReference Include="MaterialDesignExtensions" Version="3.3.0" />
<PackageReference Include="MaterialDesignThemes" Version="4.6.0-ci246" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit 16d4ce9

Please sign in to comment.