Initial check in of project
This commit is contained in:
Коммит
f1a9c3c197
|
@ -0,0 +1,276 @@
|
|||
## Ignore Visual Studio temporary files, build results, and
|
||||
## files generated by popular Visual Studio add-ons.
|
||||
##
|
||||
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
||||
|
||||
# User-specific files
|
||||
*.suo
|
||||
*.user
|
||||
*.userosscache
|
||||
*.sln.docstates
|
||||
*.vcxproj.filters
|
||||
|
||||
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||
*.userprefs
|
||||
|
||||
# Build results
|
||||
[Dd]ebug/
|
||||
[Dd]ebugPublic/
|
||||
[Rr]elease/
|
||||
[Rr]eleases/
|
||||
x64/
|
||||
x86/
|
||||
bld/
|
||||
[Bb]in/
|
||||
[Oo]bj/
|
||||
[Ll]og/
|
||||
|
||||
# Visual Studio 2015 cache/options directory
|
||||
.vs/
|
||||
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||
#wwwroot/
|
||||
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
[Bb]uild[Ll]og.*
|
||||
|
||||
# NUNIT
|
||||
*.VisualState.xml
|
||||
TestResult.xml
|
||||
|
||||
# Build Results of an ATL Project
|
||||
[Dd]ebugPS/
|
||||
[Rr]eleasePS/
|
||||
dlldata.c
|
||||
|
||||
# .NET Core
|
||||
project.lock.json
|
||||
project.fragment.lock.json
|
||||
artifacts/
|
||||
**/Properties/launchSettings.json
|
||||
|
||||
*_i.c
|
||||
*_p.c
|
||||
*_i.h
|
||||
*.ilk
|
||||
*.meta
|
||||
*.obj
|
||||
*.pch
|
||||
*.pdb
|
||||
*.pgc
|
||||
*.pgd
|
||||
*.rsp
|
||||
*.sbr
|
||||
*.tlb
|
||||
*.tli
|
||||
*.tlh
|
||||
*.tmp
|
||||
*.tmp_proj
|
||||
*.log
|
||||
*.vspscc
|
||||
*.vssscc
|
||||
.builds
|
||||
*.pidb
|
||||
*.svclog
|
||||
*.scc
|
||||
|
||||
# Chutzpah Test files
|
||||
_Chutzpah*
|
||||
|
||||
# Visual C++ cache files
|
||||
ipch/
|
||||
*.aps
|
||||
*.ncb
|
||||
*.opendb
|
||||
*.opensdf
|
||||
*.sdf
|
||||
*.cachefile
|
||||
*.VC.db
|
||||
*.VC.VC.opendb
|
||||
|
||||
# Visual Studio profiler
|
||||
*.psess
|
||||
*.vsp
|
||||
*.vspx
|
||||
*.sap
|
||||
|
||||
# TFS 2012 Local Workspace
|
||||
$tf/
|
||||
|
||||
# Guidance Automation Toolkit
|
||||
*.gpState
|
||||
|
||||
# ReSharper is a .NET coding add-in
|
||||
_ReSharper*/
|
||||
*.[Rr]e[Ss]harper
|
||||
*.DotSettings.user
|
||||
|
||||
# JustCode is a .NET coding add-in
|
||||
.JustCode
|
||||
|
||||
# TeamCity is a build add-in
|
||||
_TeamCity*
|
||||
|
||||
# DotCover is a Code Coverage Tool
|
||||
*.dotCover
|
||||
|
||||
# Visual Studio code coverage results
|
||||
*.coverage
|
||||
*.coveragexml
|
||||
|
||||
# NCrunch
|
||||
_NCrunch_*
|
||||
.*crunch*.local.xml
|
||||
nCrunchTemp_*
|
||||
|
||||
# MightyMoose
|
||||
*.mm.*
|
||||
AutoTest.Net/
|
||||
|
||||
# Web workbench (sass)
|
||||
.sass-cache/
|
||||
|
||||
# Installshield output folder
|
||||
[Ee]xpress/
|
||||
|
||||
# DocProject is a documentation generator add-in
|
||||
DocProject/buildhelp/
|
||||
DocProject/Help/*.HxT
|
||||
DocProject/Help/*.HxC
|
||||
DocProject/Help/*.hhc
|
||||
DocProject/Help/*.hhk
|
||||
DocProject/Help/*.hhp
|
||||
DocProject/Help/Html2
|
||||
DocProject/Help/html
|
||||
|
||||
# Click-Once directory
|
||||
publish/
|
||||
|
||||
# Publish Web Output
|
||||
*.[Pp]ublish.xml
|
||||
*.azurePubxml
|
||||
# TODO: Comment the next line if you want to checkin your web deploy settings
|
||||
# but database connection strings (with potential passwords) will be unencrypted
|
||||
*.pubxml
|
||||
*.publishproj
|
||||
|
||||
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||
# in these scripts will be unencrypted
|
||||
PublishScripts/
|
||||
|
||||
# NuGet Packages
|
||||
*.nupkg
|
||||
# The packages folder can be ignored because of Package Restore
|
||||
**/packages/*
|
||||
# except build/, which is used as an MSBuild target.
|
||||
!**/packages/build/
|
||||
# Uncomment if necessary however generally it will be regenerated when needed
|
||||
#!**/packages/repositories.config
|
||||
# NuGet v3's project.json files produces more ignoreable files
|
||||
*.nuget.props
|
||||
*.nuget.targets
|
||||
|
||||
# Microsoft Azure Build Output
|
||||
csx/
|
||||
*.build.csdef
|
||||
|
||||
# Microsoft Azure Emulator
|
||||
ecf/
|
||||
rcf/
|
||||
|
||||
# Windows Store app package directories and files
|
||||
AppPackages/
|
||||
BundleArtifacts/
|
||||
Package.StoreAssociation.xml
|
||||
_pkginfo.txt
|
||||
|
||||
# Visual Studio cache files
|
||||
# files ending in .cache can be ignored
|
||||
*.[Cc]ache
|
||||
# but keep track of directories ending in .cache
|
||||
!*.[Cc]ache/
|
||||
|
||||
# Others
|
||||
ClientBin/
|
||||
~$*
|
||||
*~
|
||||
*.dbmdl
|
||||
*.dbproj.schemaview
|
||||
*.jfm
|
||||
*.pfx
|
||||
*.publishsettings
|
||||
node_modules/
|
||||
orleans.codegen.cs
|
||||
|
||||
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||
#bower_components/
|
||||
|
||||
# RIA/Silverlight projects
|
||||
Generated_Code/
|
||||
|
||||
# Backup & report files from converting an old project file
|
||||
# to a newer Visual Studio version. Backup files are not needed,
|
||||
# because we have git ;-)
|
||||
_UpgradeReport_Files/
|
||||
Backup*/
|
||||
UpgradeLog*.XML
|
||||
UpgradeLog*.htm
|
||||
|
||||
# SQL Server files
|
||||
*.mdf
|
||||
*.ldf
|
||||
|
||||
# Business Intelligence projects
|
||||
*.rdl.data
|
||||
*.bim.layout
|
||||
*.bim_*.settings
|
||||
|
||||
# Microsoft Fakes
|
||||
FakesAssemblies/
|
||||
|
||||
# GhostDoc plugin setting file
|
||||
*.GhostDoc.xml
|
||||
|
||||
# Node.js Tools for Visual Studio
|
||||
.ntvs_analysis.dat
|
||||
|
||||
# Visual Studio 6 build log
|
||||
*.plg
|
||||
|
||||
# Visual Studio 6 workspace options file
|
||||
*.opt
|
||||
|
||||
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
||||
*.vbw
|
||||
|
||||
# Visual Studio LightSwitch build output
|
||||
**/*.HTMLClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/GeneratedArtifacts
|
||||
**/*.DesktopClient/ModelManifest.xml
|
||||
**/*.Server/GeneratedArtifacts
|
||||
**/*.Server/ModelManifest.xml
|
||||
_Pvt_Extensions
|
||||
|
||||
# Paket dependency manager
|
||||
.paket/paket.exe
|
||||
paket-files/
|
||||
|
||||
# FAKE - F# Make
|
||||
.fake/
|
||||
|
||||
# JetBrains Rider
|
||||
.idea/
|
||||
*.sln.iml
|
||||
|
||||
# CodeRush
|
||||
.cr/
|
||||
|
||||
# Python Tools for Visual Studio (PTVS)
|
||||
__pycache__/
|
||||
*.pyc
|
||||
|
||||
# Cake - Uncomment if you are using it
|
||||
# tools/
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.25420.1
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{EE7ACF1F-56D3-4A01-8262-A49A8B444639}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Source", "Source", "{A155C82A-42DC-4206-8DA8-C9C8CC3BFFE2}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{833D0345-46F0-486E-9BEF-5269405683F8}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
..\..\..\..\Source\Repos\Bing-Maps-V8-TypeScript-Definitions\.gitignore = ..\..\..\..\Source\Repos\Bing-Maps-V8-TypeScript-Definitions\.gitignore
|
||||
CONTRIBUTING.md = CONTRIBUTING.md
|
||||
Documentation.md = Documentation.md
|
||||
LICENSE.txt = LICENSE.txt
|
||||
README.txt = README.txt
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "WPF", "WPF", "{26E65B0F-9554-408A-95D4-BDEC52945FC3}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RESTToolkitTestApp", "Samples\WPF\RESTToolkitTestApp\RESTToolkitTestApp.csproj", "{4E8E6F9A-14C5-4758-B96F-D18B5B923075}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BingMapsRESTToolkit", "Source\BingMapsRESTToolkit.csproj", "{AC15CCAC-63B7-43EB-A1CB-25925F04398B}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{4E8E6F9A-14C5-4758-B96F-D18B5B923075}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4E8E6F9A-14C5-4758-B96F-D18B5B923075}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4E8E6F9A-14C5-4758-B96F-D18B5B923075}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4E8E6F9A-14C5-4758-B96F-D18B5B923075}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{AC15CCAC-63B7-43EB-A1CB-25925F04398B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{AC15CCAC-63B7-43EB-A1CB-25925F04398B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{AC15CCAC-63B7-43EB-A1CB-25925F04398B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{AC15CCAC-63B7-43EB-A1CB-25925F04398B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{26E65B0F-9554-408A-95D4-BDEC52945FC3} = {EE7ACF1F-56D3-4A01-8262-A49A8B444639}
|
||||
{4E8E6F9A-14C5-4758-B96F-D18B5B923075} = {26E65B0F-9554-408A-95D4-BDEC52945FC3}
|
||||
{AC15CCAC-63B7-43EB-A1CB-25925F04398B} = {A155C82A-42DC-4206-8DA8-C9C8CC3BFFE2}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -0,0 +1,56 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<package xmlns="http://schemas.microsoft.com/packaging/2013/01/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>BingMapsRESTToolkit</id>
|
||||
<version>1.0.1</version>
|
||||
<title>Bing Maps REST Services Toolkit</title>
|
||||
<authors>Microsoft</authors>
|
||||
<owners>microsoft bingmaps</owners>
|
||||
<iconUrl>https://www.bing.com/sa/simg/bing_p_rr_teal_min.ico</iconUrl>
|
||||
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
||||
<description>This is a portable class library which makes it easy to access the Bing Maps REST services from .NET.</description>
|
||||
<summary>This is a portable class library which makes it easy to access the Bing Maps REST services from .NET.</summary>
|
||||
<copyright>© Microsoft Corporation. All rights reserved.</copyright>
|
||||
<tags>Microsoft "Bing Maps" Maps GIS Map Geospatial VB C# .NET REST</tags>
|
||||
<references>
|
||||
<group targetFramework=".NETFramework4.5">
|
||||
<reference file="BingMapsRESTToolkit.dll" />
|
||||
</group>
|
||||
<group targetFramework="WindowsPhone8.0">
|
||||
<reference file="BingMapsRESTToolkit.dll" />
|
||||
</group>
|
||||
<group targetFramework=".NETCore4.5">
|
||||
<reference file="BingMapsRESTToolkit.dll" />
|
||||
</group>
|
||||
<group targetFramework=".NETPortable0.0-net45+win+wpa81+wp80+MonoAndroid10+xamarinios10+MonoTouch10">
|
||||
<reference file="BingMapsRESTToolkit.dll" />
|
||||
</group>
|
||||
<group targetFramework="Xamarin iOS1.0">
|
||||
<reference file="BingMapsRESTToolkit.dll" />
|
||||
</group>
|
||||
<group targetFramework="WindowsPhone8.1">
|
||||
<reference file="BingMapsRESTToolkit.dll" />
|
||||
</group>
|
||||
<group targetFramework="Windows4.5.1">
|
||||
<reference file="BingMapsRESTToolkit.dll" />
|
||||
</group>
|
||||
<group targetFramework="Unsupported0.0">
|
||||
<reference file="BingMapsRESTToolkit.dll" />
|
||||
</group>
|
||||
</references>
|
||||
</metadata>
|
||||
<files>
|
||||
<file src="BingMapsRESTToolkit\bin\Release\BingMapsRESTToolkit.dll" target="lib\dotnet\BingMapsRESTToolkit.dll" />
|
||||
<file src="BingMapsRESTToolkit\bin\Release\BingMapsRESTToolkit.XML" target="lib\dotnet\BingMapsRESTToolkit.XML" />
|
||||
<file src="BingMapsRESTToolkit\bin\Release\BingMapsRESTToolkit.dll" target="lib\net45\BingMapsRESTToolkit.dll" />
|
||||
<file src="BingMapsRESTToolkit\bin\Release\BingMapsRESTToolkit.XML" target="lib\net45\BingMapsRESTToolkit.XML" />
|
||||
<file src="BingMapsRESTToolkit\bin\Release\BingMapsRESTToolkit.dll" target="lib\portable-net45+wp8+win8\BingMapsRESTToolkit.dll" />
|
||||
<file src="BingMapsRESTToolkit\bin\Release\BingMapsRESTToolkit.XML" target="lib\portable-net45+wp8+win8\BingMapsRESTToolkit.XML" />
|
||||
<file src="BingMapsRESTToolkit\bin\Release\BingMapsRESTToolkit.dll" target="lib\uap10.0\BingMapsRESTToolkit.dll" />
|
||||
<file src="BingMapsRESTToolkit\bin\Release\BingMapsRESTToolkit.XML" target="lib\uap10.0\BingMapsRESTToolkit.XML" />
|
||||
<file src="BingMapsRESTToolkit\bin\Release\BingMapsRESTToolkit.dll" target="lib\wpa81\BingMapsRESTToolkit.dll" />
|
||||
<file src="BingMapsRESTToolkit\bin\Release\BingMapsRESTToolkit.XML" target="lib\wpa81\BingMapsRESTToolkit.XML" />
|
||||
<file src="BingMapsRESTToolkit\bin\Release\BingMapsRESTToolkit.dll" target="lib\xamarinios\BingMapsRESTToolkit.dll" />
|
||||
<file src="BingMapsRESTToolkit\bin\Release\BingMapsRESTToolkit.XML" target="lib\xamarinios\BingMapsRESTToolkit.XML" />
|
||||
</files>
|
||||
</package>
|
|
@ -0,0 +1,13 @@
|
|||
# Contributing to the Bing Maps REST Sevices Toolkit
|
||||
|
||||
## Code of Conduct
|
||||
|
||||
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
|
||||
|
||||
## How to contribute
|
||||
|
||||
There are a couple of ways you can contribute to this repo:
|
||||
* **Ideas, feature requests and bugs**: We are open to all ideas and we want to get rid of bugs! Use the [Issues section](https://github.com/Microsoft/Bing-Maps-V8-TypeScript-Definitions/issues) to either report a new issue, provide your ideas or contribute to existing threads
|
||||
* **Documentation**: Found a typo or strangely worded sentences? Submit a PR!
|
||||
|
||||
**Note:** If the issue you are experiencing is with the Bing Maps SDK itself, please report in the [MSDN forums](https://social.msdn.microsoft.com/Forums/en-US/home?forum=bingmapsajax&filter=alltypes&sort=lastpostdesc), or if you license Bing Maps, contact the [Bing Maps Enterprise support team](https://www.microsoft.com/maps/support.aspx).
|
|
@ -0,0 +1,47 @@
|
|||
Documentation
|
||||
==============
|
||||
|
||||
## Table of Contents ##
|
||||
|
||||
* [API Reference](#ApiReference)
|
||||
- [ServiceManager Class](#ServiceManager)
|
||||
- [BaseImageryRestRequest Class](#BaseImageryRestRequest)
|
||||
- [BaseRestRequest Class](#BaseRestRequest)
|
||||
- [BaseRestRequest Class](#BaseRestRequest)
|
||||
|
||||
|
||||
## <a name="ApiReference"></a> API Reference ##
|
||||
|
||||
### <a name="ServiceManager"></a> ServiceManager Class ###
|
||||
|
||||
A static class that processes requests to the Bing Maps REST services.
|
||||
|
||||
Name | Returns | Description
|
||||
-----------------------------------------------------|----------|--------------------------------------------------------
|
||||
GetResponseAsync(BaseRestRequest request) | Response | Processes a REST request that returns a data response.
|
||||
GetImageAsync(BaseImageryRestRequest imageryRequest) | Stream | Processes a REST request that returns an image stream.
|
||||
|
||||
|
||||
### <a name="BaseRestRequest"></a> BaseRestRequest Class ###
|
||||
|
||||
An abstract class in which all REST service requests derive from.
|
||||
|
||||
#### Constants ####
|
||||
|
||||
Name | Type | Description
|
||||
---------------|----------|--------------------------------------------------------
|
||||
baseServiceUrl | string |
|
||||
|
||||
|
||||
#### Properties ####
|
||||
|
||||
Name | Type | Description
|
||||
-------------|-------------|--------------------------------------------------------
|
||||
BingMapsKey | string | The Bing Maps key for making the request.
|
||||
Culture | string | The culture to use for the request.
|
||||
UserMapView | BoundingBox | The geographic region that corresponds to the current viewport.
|
||||
UserLocation | Coordinate | The user’s current position.
|
||||
UserIp | string | An Internet Protocol version 4 (IPv4) address.
|
||||
|
||||
|
||||
### <a name="BaseImageryRestRequest"></a> BaseImageryRestRequest Class ###
|
|
@ -0,0 +1,21 @@
|
|||
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
|
||||
|
||||
This code is licensed under the MIT License (MIT).
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
|
@ -0,0 +1,13 @@
|
|||
Please report any bugs or issues to Ricky Brundritt: richbrun@microsoft.com
|
||||
|
||||
Features:
|
||||
---------
|
||||
|
||||
- Uses HTTPS by default.
|
||||
- Imagery Metadata allows HTTPS tile urls to be returned.
|
||||
- Automatically encodes query parameters.
|
||||
- Handles errors and rate limiting by catching exception and returning response with error message.
|
||||
|
||||
ElevationRequest
|
||||
- Method to get the coordinates that relate to each elevation data point.
|
||||
- Automatically determines if a POST request should be made.
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<appSettings>
|
||||
<add key="BingMapsKey" value="YOUR_BING_MAPS_KEY"/>
|
||||
</appSettings>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
|
||||
</startup>
|
||||
</configuration>
|
|
@ -0,0 +1,8 @@
|
|||
<Application x:Class="RESTToolkitTestApp.App"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
StartupUri="MainWindow.xaml">
|
||||
<Application.Resources>
|
||||
|
||||
</Application.Resources>
|
||||
</Application>
|
|
@ -0,0 +1,17 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace RESTToolkitTestApp
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for App.xaml
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
<Window x:Class="RESTToolkitTestApp.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="clr-namespace:RESTToolkitTestApp"
|
||||
Title="Bing Maps REST Service Toolkit Test app" Height="600" Width="800">
|
||||
|
||||
<Window.Resources>
|
||||
<Style TargetType="Button">
|
||||
<Setter Property="Padding" Value="10,3"/>
|
||||
<Setter Property="Margin" Value="5"/>
|
||||
</Style>
|
||||
</Window.Resources>
|
||||
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="130"/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<StackPanel>
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
|
||||
<Button Content="Geocode" Click="GeocodeBtn_Clicked"/>
|
||||
<Button Content="Reverse Geocode" Click="ReverseGeocodeBtn_Clicked"/>
|
||||
<Button Content="Elevation" Click="ElevationBtn_Clicked"/>
|
||||
<Button Content="Route" Click="RouteBtn_Clicked"/>
|
||||
<Button Content="Transit Route" Click="TransitRouteBtn_Clicked"/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
|
||||
<Button Content="Traffic" Click="TrafficBtn_Clicked"/>
|
||||
<Button Content="Imagery Metadata" Click="ImageMetadataBtn_Clicked"/>
|
||||
<Button Content="Static Image" Click="StaticImageBtn_Clicked"/>
|
||||
<Button Content="Static Image Metadata" Click="StaticImageMetadataBtn_Clicked"/>
|
||||
</StackPanel>
|
||||
|
||||
<Grid Margin="5,10,5,5">
|
||||
<TextBlock Text="Request URL:"/>
|
||||
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Width="170">
|
||||
<TextBlock Text="Processing Time: "/>
|
||||
<TextBlock Name="ProcessingTimeTbx"/>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
||||
<TextBox Name="RequestUrlTbx" Height="25"/>
|
||||
</StackPanel>
|
||||
|
||||
<TabControl Grid.Row="1">
|
||||
<TabItem Name="ResponseTab" Header="Response">
|
||||
<TreeView Name="ResultTreeView" BorderThickness="0">
|
||||
<TreeView.Resources>
|
||||
<HierarchicalDataTemplate DataType="{x:Type local:ObjectNode}" ItemsSource="{Binding Path=Children}">
|
||||
<TreeViewItem>
|
||||
<TreeViewItem.Header>
|
||||
<StackPanel Orientation="Horizontal" Margin="-10,0,0,0">
|
||||
<TextBlock Text="{Binding Path=Name}"/>
|
||||
<TextBlock Text=" : "/>
|
||||
<TextBlock Text="{Binding Path=Value}"/>
|
||||
</StackPanel>
|
||||
</TreeViewItem.Header>
|
||||
</TreeViewItem>
|
||||
</HierarchicalDataTemplate>
|
||||
</TreeView.Resources>
|
||||
</TreeView>
|
||||
</TabItem>
|
||||
<TabItem Name="ImageTab" Header="Image Response">
|
||||
<Image Name="ImageBox" Stretch="None"/>
|
||||
</TabItem>
|
||||
</TabControl>
|
||||
</Grid>
|
||||
</Window>
|
|
@ -0,0 +1,363 @@
|
|||
/*
|
||||
* Copyright(c) 2017 Microsoft Corporation. All rights reserved.
|
||||
*
|
||||
* This code is licensed under the MIT License (MIT).
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
using BingMapsRESTToolkit;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows;
|
||||
using System.Windows.Media.Imaging;
|
||||
|
||||
namespace RESTToolkitTestApp
|
||||
{
|
||||
public partial class MainWindow : Window
|
||||
{
|
||||
#region Private Properties
|
||||
|
||||
private string BingMapsKey = System.Configuration.ConfigurationManager.AppSettings.Get("BingMapsKey");
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Example Requests
|
||||
|
||||
/// <summary>
|
||||
/// Demostrates how to make a Geocode Request.
|
||||
/// </summary>
|
||||
private void GeocodeBtn_Clicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var r = new GeocodeRequest()
|
||||
{
|
||||
Query = "New York, NY",
|
||||
IncludeIso2 = true,
|
||||
IncludeNeighborhood = true,
|
||||
MaxResults = 25,
|
||||
BingMapsKey = BingMapsKey
|
||||
};
|
||||
|
||||
ProcessRequest(r);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Demostrates how to make a Reverse Geocode Request.
|
||||
/// </summary>
|
||||
private void ReverseGeocodeBtn_Clicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var r = new ReverseGeocodeRequest()
|
||||
{
|
||||
Point = new Coordinate(45, -110),
|
||||
IncludeEntityTypes = new List<EntityType>(){
|
||||
EntityType.AdminDivision1,
|
||||
EntityType.CountryRegion
|
||||
},
|
||||
IncludeNeighborhood = true,
|
||||
IncludeIso2 = true,
|
||||
BingMapsKey = BingMapsKey
|
||||
};
|
||||
|
||||
ProcessRequest(r);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Demostrates how to make an Elevation Request.
|
||||
/// </summary>
|
||||
private void ElevationBtn_Clicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var r = new ElevationRequest()
|
||||
{
|
||||
Points = new List<Coordinate>(){
|
||||
new Coordinate(45, -100),
|
||||
new Coordinate(50, -100),
|
||||
new Coordinate(45, -110)
|
||||
},
|
||||
Samples = 1024,
|
||||
BingMapsKey = BingMapsKey
|
||||
};
|
||||
|
||||
ProcessRequest(r);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Demostrates how to make a Driving Route Request.
|
||||
/// </summary>
|
||||
private void RouteBtn_Clicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var r = new RouteRequest()
|
||||
{
|
||||
RouteOptions = new RouteOptions(){
|
||||
Avoid = new List<AvoidType>()
|
||||
{
|
||||
AvoidType.MinimizeTolls
|
||||
},
|
||||
TravelMode = TravelModeType.Driving,
|
||||
DistanceUnits = DistanceUnitType.Miles,
|
||||
Heading = 45,
|
||||
RouteAttributes = new List<RouteAttributeType>()
|
||||
{
|
||||
RouteAttributeType.RoutePath
|
||||
},
|
||||
Optimize = RouteOptimizationType.TimeWithTraffic
|
||||
},
|
||||
Waypoints = new List<SimpleWaypoint>()
|
||||
{
|
||||
new SimpleWaypoint(){
|
||||
Address = "Seattle, WA"
|
||||
},
|
||||
new SimpleWaypoint(){
|
||||
Address = "Bellevue, WA",
|
||||
IsViaPoint = true
|
||||
},
|
||||
new SimpleWaypoint(){
|
||||
Address = "Redmond, WA"
|
||||
}
|
||||
},
|
||||
BingMapsKey = BingMapsKey
|
||||
};
|
||||
|
||||
ProcessRequest(r);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Demostrates how to make a Transit Route Request.
|
||||
/// </summary>
|
||||
private void TransitRouteBtn_Clicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var r = new RouteRequest()
|
||||
{
|
||||
RouteOptions = new RouteOptions()
|
||||
{
|
||||
TravelMode = TravelModeType.Transit,
|
||||
DistanceUnits = DistanceUnitType.Miles,
|
||||
RouteAttributes = new List<RouteAttributeType>()
|
||||
{
|
||||
RouteAttributeType.RoutePath,
|
||||
RouteAttributeType.TransitStops
|
||||
},
|
||||
Optimize = RouteOptimizationType.TimeAvoidClosure,
|
||||
DateTime = new DateTime(2016, 6, 30, 8, 0, 0, DateTimeKind.Utc),
|
||||
TimeType = RouteTimeType.Departure
|
||||
},
|
||||
Waypoints = new List<SimpleWaypoint>()
|
||||
{
|
||||
new SimpleWaypoint(){
|
||||
Address = "London, UK"
|
||||
},
|
||||
new SimpleWaypoint(){
|
||||
Address = "E14 3SP"
|
||||
}
|
||||
},
|
||||
BingMapsKey = BingMapsKey
|
||||
};
|
||||
|
||||
ProcessRequest(r);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Demostrates how to make a Traffic Request.
|
||||
/// </summary>
|
||||
private void TrafficBtn_Clicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var r = new TrafficRequest()
|
||||
{
|
||||
Culture = "en-US",
|
||||
TrafficType = new List<TrafficType>()
|
||||
{
|
||||
TrafficType.Accident,
|
||||
TrafficType.Congestion
|
||||
},
|
||||
//Severity = new List<SeverityType>()
|
||||
//{
|
||||
// SeverityType.LowImpact,
|
||||
// SeverityType.Minor
|
||||
//},
|
||||
MapArea = new BoundingBox()
|
||||
{
|
||||
SouthLatitude = 46,
|
||||
WestLongitude = -124,
|
||||
NorthLatitude = 50,
|
||||
EastLongitude = -117
|
||||
},
|
||||
IncludeLocationCodes = true,
|
||||
BingMapsKey = BingMapsKey
|
||||
};
|
||||
|
||||
ProcessRequest(r);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Demostrates how to make an Imagery Metadata Request.
|
||||
/// </summary>
|
||||
private void ImageMetadataBtn_Clicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var r = new ImageryMetadataRequest()
|
||||
{
|
||||
CenterPoint = new Coordinate(45, -110),
|
||||
ZoomLevel = 12,
|
||||
ImagerySet = ImageryType.AerialWithLabels,
|
||||
BingMapsKey = BingMapsKey
|
||||
};
|
||||
|
||||
ProcessRequest(r);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Demostrates how to make a Static Imagery Metadata Request.
|
||||
/// </summary>
|
||||
private void StaticImageMetadataBtn_Clicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var r = new ImageryRequest()
|
||||
{
|
||||
CenterPoint = new Coordinate(45, -110),
|
||||
ZoomLevel = 12,
|
||||
ImagerySet = ImageryType.AerialWithLabels,
|
||||
Pushpins = new List<ImageryPushpin>(){
|
||||
new ImageryPushpin(){
|
||||
Location = new Coordinate(45, -110.01),
|
||||
Label = "hi"
|
||||
},
|
||||
new ImageryPushpin(){
|
||||
Location = new Coordinate(45, -110.02),
|
||||
IconStyle = 3
|
||||
},
|
||||
new ImageryPushpin(){
|
||||
Location = new Coordinate(45, -110.03),
|
||||
IconStyle = 20
|
||||
},
|
||||
new ImageryPushpin(){
|
||||
Location = new Coordinate(45, -110.04),
|
||||
IconStyle = 24
|
||||
}
|
||||
},
|
||||
BingMapsKey = BingMapsKey
|
||||
};
|
||||
|
||||
ProcessRequest(r);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Demostrates how to make a Static Imagery Request.
|
||||
/// </summary>
|
||||
private void StaticImageBtn_Clicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var r = new ImageryRequest()
|
||||
{
|
||||
CenterPoint = new Coordinate(45, -110),
|
||||
ZoomLevel = 12,
|
||||
ImagerySet = ImageryType.AerialWithLabels,
|
||||
Pushpins = new List<ImageryPushpin>(){
|
||||
new ImageryPushpin(){
|
||||
Location = new Coordinate(45, -110.01),
|
||||
Label = "hi"
|
||||
},
|
||||
new ImageryPushpin(){
|
||||
Location = new Coordinate(45, -110.02),
|
||||
IconStyle = 3
|
||||
},
|
||||
new ImageryPushpin(){
|
||||
Location = new Coordinate(45, -110.03),
|
||||
IconStyle = 20
|
||||
},
|
||||
new ImageryPushpin(){
|
||||
Location = new Coordinate(45, -110.04),
|
||||
IconStyle = 24
|
||||
}
|
||||
},
|
||||
BingMapsKey = BingMapsKey
|
||||
};
|
||||
|
||||
ProcessImageRequest(r);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
|
||||
private async void ProcessRequest(BaseRestRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
ProcessingTimeTbx.Text = "";
|
||||
ResultTreeView.ItemsSource = null;
|
||||
|
||||
RequestUrlTbx.Text = request.GetRequestUrl();
|
||||
|
||||
var start = DateTime.Now;
|
||||
|
||||
//Process the request by using the ServiceManager.
|
||||
var response = await ServiceManager.GetResponseAsync(request);
|
||||
|
||||
var end = DateTime.Now;
|
||||
|
||||
var processingTime = end - start;
|
||||
|
||||
ProcessingTimeTbx.Text = string.Format("{0:0} ms", processingTime.TotalMilliseconds);
|
||||
|
||||
List<ObjectNode> nodes = new List<ObjectNode>();
|
||||
nodes.Add(new ObjectNode("result", response));
|
||||
ResultTreeView.ItemsSource = nodes;
|
||||
|
||||
ResponseTab.IsSelected = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private async void ProcessImageRequest(BaseImageryRestRequest imageRequest)
|
||||
{
|
||||
try
|
||||
{
|
||||
RequestUrlTbx.Text = imageRequest.GetRequestUrl();
|
||||
|
||||
//Process the request by using the ServiceManager.
|
||||
using (var s = await ServiceManager.GetImageAsync(imageRequest))
|
||||
{
|
||||
var bitmapImage = new BitmapImage();
|
||||
bitmapImage.BeginInit();
|
||||
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
|
||||
bitmapImage.StreamSource = s;
|
||||
bitmapImage.EndInit();
|
||||
ImageBox.Source = bitmapImage;
|
||||
}
|
||||
|
||||
ImageTab.IsSelected = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,265 @@
|
|||
/*
|
||||
* Copyright(c) 2017 Microsoft Corporation. All rights reserved.
|
||||
*
|
||||
* This code is licensed under the MIT License (MIT).
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
|
||||
namespace RESTToolkitTestApp
|
||||
{
|
||||
/// <summary>
|
||||
/// Takes any Object and generates an Object Tree.
|
||||
/// </summary>
|
||||
public class ObjectNode
|
||||
{
|
||||
#region Private Properties
|
||||
|
||||
private string _name;
|
||||
private object _value;
|
||||
private Type _type;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
||||
/// <summary>
|
||||
/// Takes any Object and generates an Object Tree.
|
||||
/// </summary>
|
||||
/// <param name="value">The object to parse into an Object Tree.</param>
|
||||
public ObjectNode(object value)
|
||||
{
|
||||
ParseObjectTree("root", value, value.GetType());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Takes any Object and generates an Object Tree.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the root node.</param>
|
||||
/// <param name="value">The object to parse into an Object Tree.</param>
|
||||
public ObjectNode(string name, object value)
|
||||
{
|
||||
ParseObjectTree(name, value, value.GetType());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Takes any Object and generates an Object Tree.
|
||||
/// </summary>
|
||||
/// <param name="value">The object to parse into an Object Tree.</param>
|
||||
/// <param name="t">The known type of the object.</param>
|
||||
public ObjectNode(object value, Type t)
|
||||
{
|
||||
ParseObjectTree("root", value, t);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Takes any Object and generates an Object Tree.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the root node.</param>
|
||||
/// <param name="value">The object to parse into an Object Tree.</param>
|
||||
/// <param name="t">The known type of the object.</param>
|
||||
public ObjectNode(string name, object value, Type t)
|
||||
{
|
||||
ParseObjectTree(name, value, t);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
|
||||
/// <summary>
|
||||
/// The property name of the object.
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The value of the object.
|
||||
/// </summary>
|
||||
public object Value
|
||||
{
|
||||
get
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The type of the object.
|
||||
/// </summary>
|
||||
public Type Type
|
||||
{
|
||||
get
|
||||
{
|
||||
return _type;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A list of child objects in the object.
|
||||
/// </summary>
|
||||
public List<ObjectNode> Children { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private void ParseObjectTree(string name, object value, Type type)
|
||||
{
|
||||
Children = new List<ObjectNode>();
|
||||
|
||||
_type = type;
|
||||
_name = name;
|
||||
|
||||
if (value != null)
|
||||
{
|
||||
if (value is string && type != typeof(object))
|
||||
{
|
||||
if (value != null)
|
||||
{
|
||||
_value = "\"" + value + "\"";
|
||||
}
|
||||
}
|
||||
else if (value is double || value is bool || value is int || value is float || value is long || value is decimal)
|
||||
{
|
||||
_value = value;
|
||||
}
|
||||
else if (value is DateTime)
|
||||
{
|
||||
try
|
||||
{
|
||||
_value = ((DateTime)value).ToString("o");
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
else
|
||||
{
|
||||
_value = "{" + value.ToString() + "}";
|
||||
}
|
||||
}
|
||||
|
||||
PropertyInfo[] props = type.GetProperties();
|
||||
|
||||
if (props.Length == 0 && type.IsClass && value is IEnumerable && !(value is string))
|
||||
{
|
||||
IEnumerable arr = value as IEnumerable;
|
||||
|
||||
if (arr != null)
|
||||
{
|
||||
int i = 0;
|
||||
foreach (object element in arr)
|
||||
{
|
||||
Children.Add(new ObjectNode("[" + i + "]", element, element.GetType()));
|
||||
i++;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
foreach (PropertyInfo p in props)
|
||||
{
|
||||
if (p.PropertyType.IsPublic)
|
||||
{
|
||||
if (p.PropertyType.IsClass || p.PropertyType.IsArray)
|
||||
{
|
||||
if (p.PropertyType.IsArray)
|
||||
{
|
||||
try
|
||||
{
|
||||
object v = p.GetValue(value, null);
|
||||
IEnumerable arr = v as IEnumerable;
|
||||
|
||||
ObjectNode arrayNode = new ObjectNode(p.Name, arr.ToString(), typeof(object));
|
||||
|
||||
if (arr != null)
|
||||
{
|
||||
int i = 0, k = 0;
|
||||
ObjectNode arrayNode2;
|
||||
|
||||
foreach (object element in arr)
|
||||
{
|
||||
//Handle 2D arrays
|
||||
if (element is IEnumerable && !(element is string))
|
||||
{
|
||||
arrayNode2 = new ObjectNode("[" + i + "]", element.ToString(), typeof(object));
|
||||
|
||||
IEnumerable arr2 = element as IEnumerable;
|
||||
k = 0;
|
||||
|
||||
foreach (object e in arr2)
|
||||
{
|
||||
arrayNode2.Children.Add(new ObjectNode("[" + k + "]", e, e.GetType()));
|
||||
k++;
|
||||
}
|
||||
|
||||
arrayNode.Children.Add(arrayNode2);
|
||||
}
|
||||
else
|
||||
{
|
||||
arrayNode.Children.Add(new ObjectNode("[" + i + "]", element, element.GetType()));
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Children.Add(arrayNode);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
else
|
||||
{
|
||||
object v = p.GetValue(value, null);
|
||||
|
||||
if (v != null)
|
||||
{
|
||||
Children.Add(new ObjectNode(p.Name, v, p.PropertyType));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (p.PropertyType.IsValueType && !(value is string) && !(value is DateTime))
|
||||
{
|
||||
try
|
||||
{
|
||||
object v = p.GetValue(value, null);
|
||||
|
||||
if (v != null)
|
||||
{
|
||||
Children.Add(new ObjectNode(p.Name, v, p.PropertyType));
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
using System.Reflection;
|
||||
using System.Resources;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("RESTToolkitTestApp")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("RESTToolkitTestApp")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2015")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
//In order to begin building localizable applications, set
|
||||
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
|
||||
//inside a <PropertyGroup>. For example, if you are using US english
|
||||
//in your source files, set the <UICulture> to en-US. Then uncomment
|
||||
//the NeutralResourceLanguage attribute below. Update the "en-US" in
|
||||
//the line below to match the UICulture setting in the project file.
|
||||
|
||||
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
|
||||
|
||||
|
||||
[assembly: ThemeInfo(
|
||||
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
|
||||
//(used if a resource is not found in the page,
|
||||
// or application resource dictionaries)
|
||||
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
|
||||
//(used if a resource is not found in the page,
|
||||
// app, or any theme specific resource dictionaries)
|
||||
)]
|
||||
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
|
@ -0,0 +1,71 @@
|
|||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.34209
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace RESTToolkitTestApp.Properties
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||
/// </summary>
|
||||
// This class was auto-generated by the StronglyTypedResourceBuilder
|
||||
// class via a tool like ResGen or Visual Studio.
|
||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
// with the /str option, or rebuild your VS project.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources
|
||||
{
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the cached ResourceManager instance used by this class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager
|
||||
{
|
||||
get
|
||||
{
|
||||
if ((resourceMan == null))
|
||||
{
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("RESTToolkitTestApp.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the current thread's CurrentUICulture property for all
|
||||
/// resource lookups using this strongly typed resource class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture
|
||||
{
|
||||
get
|
||||
{
|
||||
return resourceCulture;
|
||||
}
|
||||
set
|
||||
{
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,117 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
|
@ -0,0 +1,30 @@
|
|||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.34209
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace RESTToolkitTestApp.Properties
|
||||
{
|
||||
|
||||
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
|
||||
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
|
||||
{
|
||||
|
||||
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||
|
||||
public static Settings Default
|
||||
{
|
||||
get
|
||||
{
|
||||
return defaultInstance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
|
||||
<Profiles>
|
||||
<Profile Name="(Default)" />
|
||||
</Profiles>
|
||||
<Settings />
|
||||
</SettingsFile>
|
|
@ -0,0 +1,112 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{4E8E6F9A-14C5-4758-B96F-D18B5B923075}</ProjectGuid>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>RESTToolkitTestApp</RootNamespace>
|
||||
<AssemblyName>RESTToolkitTestApp</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.Xaml">
|
||||
<RequiredTargetFramework>4.0</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="WindowsBase" />
|
||||
<Reference Include="PresentationCore" />
|
||||
<Reference Include="PresentationFramework" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ApplicationDefinition Include="App.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</ApplicationDefinition>
|
||||
<Page Include="MainWindow.xaml">
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</Page>
|
||||
<Compile Include="App.xaml.cs">
|
||||
<DependentUpon>App.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="MainWindow.xaml.cs">
|
||||
<DependentUpon>MainWindow.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ObjectNode.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Properties\Resources.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Properties\Settings.Designer.cs">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
<None Include="Properties\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||
</None>
|
||||
<AppDesigner Include="Properties\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\Source\BingMapsRESTToolkit.csproj">
|
||||
<Project>{ac15ccac-63b7-43eb-a1cb-25925f04398b}</Project>
|
||||
<Name>BingMapsRESTToolkit</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
|
@ -0,0 +1,87 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<MinimumVisualStudioVersion>11.0</MinimumVisualStudioVersion>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{AC15CCAC-63B7-43EB-A1CB-25925F04398B}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>BingMapsRESTToolkit</RootNamespace>
|
||||
<AssemblyName>BingMapsRESTToolkit</AssemblyName>
|
||||
<DefaultLanguage>en-US</DefaultLanguage>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<TargetFrameworkProfile>Profile259</TargetFrameworkProfile>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DocumentationFile>bin\Debug\BingMapsRESTToolkit.XML</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DocumentationFile>bin\Release\BingMapsRESTToolkit.XML</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SignAssembly>false</SignAssembly>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Enums\AvoidType.cs" />
|
||||
<Compile Include="Enums\ConfidenceLevel.cs" />
|
||||
<Compile Include="Enums\ImageFormatType.cs" />
|
||||
<Compile Include="Enums\ImageryType.cs" />
|
||||
<Compile Include="Enums\RouteAttributeType.cs" />
|
||||
<Compile Include="Enums\RouteOptimizationType.cs" />
|
||||
<Compile Include="Enums\RouteTimeType.cs" />
|
||||
<Compile Include="Enums\TravelModeType.cs" />
|
||||
<Compile Include="Enums\SeverityType.cs" />
|
||||
<Compile Include="Enums\TrafficType.cs" />
|
||||
<Compile Include="Internal\DateTimeHelper.cs" />
|
||||
<Compile Include="Models\ImageryPushpin.cs" />
|
||||
<Compile Include="Models\RouteOptions.cs" />
|
||||
<Compile Include="Requests\ImageryMetadataRequest.cs" />
|
||||
<Compile Include="Requests\ImageryRequest.cs" />
|
||||
<Compile Include="Models\PointCompression.cs" />
|
||||
<Compile Include="Models\SimpleWaypoint.cs" />
|
||||
<Compile Include="Requests\BaseImageryRestRequest.cs" />
|
||||
<Compile Include="Requests\ElevationRequest.cs" />
|
||||
<Compile Include="Enums\DistanceUnitType.cs" />
|
||||
<Compile Include="Enums\ElevationType.cs" />
|
||||
<Compile Include="Enums\EntityType.cs" />
|
||||
<Compile Include="Internal\ServiceHelper.cs" />
|
||||
<Compile Include="Internal\SpatialTools.cs" />
|
||||
<Compile Include="Models\SimpleAddress.cs" />
|
||||
<Compile Include="Requests\BaseRestRequest.cs" />
|
||||
<Compile Include="Requests\RouteMajorRoadsRequest.cs" />
|
||||
<Compile Include="Requests\RouteRequest.cs" />
|
||||
<Compile Include="ServiceManager.cs" />
|
||||
<Compile Include="Requests\GeocodeRequest.cs" />
|
||||
<Compile Include="Models\Coordinate.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Models\RestServiceModels.cs" />
|
||||
<Compile Include="Requests\ReverseGeocodeRequest.cs" />
|
||||
<Compile Include="Requests\TrafficRequest.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright(c) 2017 Microsoft Corporation. All rights reserved.
|
||||
*
|
||||
* This code is licensed under the MIT License (MIT).
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// Specifies the road types to minimize or avoid when the route is created for the driving travel mode.
|
||||
/// </summary>
|
||||
public enum AvoidType
|
||||
{
|
||||
/// <summary>
|
||||
/// Avoids the use of highways in the route.
|
||||
/// </summary>
|
||||
Highways,
|
||||
|
||||
/// <summary>
|
||||
/// Avoids the use of toll roads in the route.
|
||||
/// </summary>
|
||||
Tolls,
|
||||
|
||||
/// <summary>
|
||||
/// Minimizes (tries to avoid) the use of highways in the route.
|
||||
/// </summary>
|
||||
MinimizeHighways,
|
||||
|
||||
/// <summary>
|
||||
/// Minimizes (tries to avoid) the use of toll roads in the route.
|
||||
/// </summary>
|
||||
MinimizeTolls
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright(c) 2017 Microsoft Corporation. All rights reserved.
|
||||
*
|
||||
* This code is licensed under the MIT License (MIT).
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// The level of confidence that the geocoded location result is a match.
|
||||
/// </summary>
|
||||
public enum ConfidenceLevel
|
||||
{
|
||||
/// <summary>
|
||||
/// No confidence level set.
|
||||
/// </summary>
|
||||
None,
|
||||
|
||||
/// <summary>
|
||||
/// High confience match.
|
||||
/// </summary>
|
||||
High,
|
||||
|
||||
/// <summary>
|
||||
/// Medium confience match.
|
||||
/// </summary>
|
||||
Medium,
|
||||
|
||||
/// <summary>
|
||||
/// Low confience match.
|
||||
/// </summary>
|
||||
Low
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright(c) 2017 Microsoft Corporation. All rights reserved.
|
||||
*
|
||||
* This code is licensed under the MIT License (MIT).
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// Units of measurements for distances.
|
||||
/// </summary>
|
||||
public enum DistanceUnitType
|
||||
{
|
||||
/// <summary>
|
||||
/// Distances in Kilometers.
|
||||
/// </summary>
|
||||
KM,
|
||||
|
||||
/// <summary>
|
||||
/// Distances in Miles
|
||||
/// </summary>
|
||||
Miles
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright(c) 2017 Microsoft Corporation. All rights reserved.
|
||||
*
|
||||
* This code is licensed under the MIT License (MIT).
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// Relative elevation type.
|
||||
/// </summary>
|
||||
public enum ElevationType
|
||||
{
|
||||
/// <summary>
|
||||
/// Geoid Earth model (EGM2008 2.5’).
|
||||
/// </summary>
|
||||
Sealevel,
|
||||
|
||||
/// <summary>
|
||||
/// Ellipsoid Earth model (WGS84).
|
||||
/// </summary>
|
||||
Ellipsoid
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Copyright(c) 2017 Microsoft Corporation. All rights reserved.
|
||||
*
|
||||
* This code is licensed under the MIT License (MIT).
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// Types of location based entities.
|
||||
/// </summary>
|
||||
public enum EntityType
|
||||
{
|
||||
/// <summary>
|
||||
/// A street address or RoadBlock.
|
||||
/// </summary>
|
||||
Address,
|
||||
|
||||
/// <summary>
|
||||
/// A section of a populated place that is typically well-known, but often with indistinct boundaries.
|
||||
/// </summary>
|
||||
Neighborhood,
|
||||
|
||||
/// <summary>
|
||||
/// A concentrated area of human settlement, such as a city, town or village.
|
||||
/// </summary>
|
||||
PopulatedPlace,
|
||||
|
||||
/// <summary>
|
||||
/// The smallest post code category, such as a zip code.
|
||||
/// </summary>
|
||||
Postcode1,
|
||||
|
||||
/// <summary>
|
||||
/// First administrative level within the country/region level, such as a state or a province.
|
||||
/// </summary>
|
||||
AdminDivision1,
|
||||
|
||||
/// <summary>
|
||||
/// Second administrative level within the country/region level, such as a county.
|
||||
/// </summary>
|
||||
AdminDivision2,
|
||||
|
||||
/// <summary>
|
||||
/// Country or region
|
||||
/// </summary>
|
||||
CountryRegion,
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright(c) 2017 Microsoft Corporation. All rights reserved.
|
||||
*
|
||||
* This code is licensed under the MIT License (MIT).
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// Imagery format types.
|
||||
/// </summary>
|
||||
public enum ImageFormatType
|
||||
{
|
||||
/// <summary>
|
||||
/// GIF image format.
|
||||
/// </summary>
|
||||
GIF,
|
||||
|
||||
/// <summary>
|
||||
/// JPEG image format. JPEG format is the default for Road, Aerial and AerialWithLabels imagery.
|
||||
/// </summary>
|
||||
JPEG,
|
||||
|
||||
/// <summary>
|
||||
/// PNG image format. PNG is the default format for CollinsBart and OrdnanceSurvey imagery.
|
||||
/// </summary>
|
||||
PNG
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Copyright(c) 2017 Microsoft Corporation. All rights reserved.
|
||||
*
|
||||
* This code is licensed under the MIT License (MIT).
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// Types of map imagery.
|
||||
/// </summary>
|
||||
public enum ImageryType
|
||||
{
|
||||
/// <summary>
|
||||
/// Aerial imagery.
|
||||
/// </summary>
|
||||
Aerial,
|
||||
|
||||
/// <summary>
|
||||
/// Aerial imagery with a road overlay.
|
||||
/// </summary>
|
||||
AerialWithLabels,
|
||||
|
||||
/// <summary>
|
||||
/// Bird’s eye (oblique-angle) imagery
|
||||
/// </summary>
|
||||
Birdseye,
|
||||
|
||||
/// <summary>
|
||||
/// Bird’s eye imagery with a road overlay.
|
||||
/// </summary>
|
||||
BirdseyeWithLabels,
|
||||
|
||||
/// <summary>
|
||||
/// Roads without additional imagery.
|
||||
/// </summary>
|
||||
Road,
|
||||
|
||||
/// <summary>
|
||||
/// Ordnance Survey imagery.
|
||||
/// </summary>
|
||||
OrdnanceSurvey,
|
||||
|
||||
/// <summary>
|
||||
/// Collins Bart imagery
|
||||
/// </summary>
|
||||
CollinsBart
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Copyright(c) 2017 Microsoft Corporation. All rights reserved.
|
||||
*
|
||||
* This code is licensed under the MIT License (MIT).
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// The type of route attributes to include in a route response.
|
||||
/// </summary>
|
||||
public enum RouteAttributeType
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to specify the following attributes as a group: excluteItinerary, routePath, and transitStops.
|
||||
/// </summary>
|
||||
All,
|
||||
|
||||
/// <summary>
|
||||
/// Do not include detailed directions in the response. Detailed directions are provided as itinerary items and contain details such as written instructions and traffic location codes.
|
||||
/// </summary>
|
||||
ExcludeItinerary,
|
||||
|
||||
/// <summary>
|
||||
/// Include a set of point (latitude and longitude) values that describe the route’s path in the response.
|
||||
/// </summary>
|
||||
RoutePath,
|
||||
|
||||
/// <summary>
|
||||
/// Include only travel time and distance for the route, and does not provide other information.
|
||||
/// </summary>
|
||||
RouteSummariesOnly,
|
||||
|
||||
/// <summary>
|
||||
/// Include information about transit stops for transit routes.
|
||||
/// </summary>
|
||||
TransitStops
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright(c) 2017 Microsoft Corporation. All rights reserved.
|
||||
*
|
||||
* This code is licensed under the MIT License (MIT).
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// Specifies what parameters to use to optimize the route on the map.
|
||||
/// </summary>
|
||||
public enum RouteOptimizationType
|
||||
{
|
||||
/// <summary>
|
||||
/// Optimizes route for shortest distance.
|
||||
/// </summary>
|
||||
Distance,
|
||||
|
||||
/// <summary>
|
||||
/// Optimizes route for shortst travel time.
|
||||
/// </summary>
|
||||
Time,
|
||||
|
||||
/// <summary>
|
||||
/// Optimizes route for shortst travel time with respect to current traffic conditions.
|
||||
/// </summary>
|
||||
TimeWithTraffic,
|
||||
|
||||
/// <summary>
|
||||
/// The route is calculated to minimize the time and avoid road closures. Traffic information is not used in the calculation.
|
||||
/// </summary>
|
||||
TimeAvoidClosure
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright(c) 2017 Microsoft Corporation. All rights reserved.
|
||||
*
|
||||
* This code is licensed under the MIT License (MIT).
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// Specifies how to interpret the date and transit time value that is specified by the dateTime parameter.
|
||||
/// </summary>
|
||||
public enum RouteTimeType
|
||||
{
|
||||
/// <summary>
|
||||
/// The dateTime parameter contains the desired arrival time for a transit request.
|
||||
/// </summary>
|
||||
Arrival,
|
||||
|
||||
/// <summary>
|
||||
/// The dateTime parameter contains the desired departure time for a transit request.
|
||||
/// </summary>
|
||||
Departure,
|
||||
|
||||
/// <summary>
|
||||
/// The dateTime parameter contains the latest departure time available for a transit request.
|
||||
/// </summary>
|
||||
LastAvailable
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright(c) 2017 Microsoft Corporation. All rights reserved.
|
||||
*
|
||||
* This code is licensed under the MIT License (MIT).
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// Specifies the severity level of a traffic incident.
|
||||
/// </summary>
|
||||
public enum SeverityType
|
||||
{
|
||||
/// <summary>
|
||||
/// Low impact severity.
|
||||
/// </summary>
|
||||
LowImpact = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Minor severity.
|
||||
/// </summary>
|
||||
Minor = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Moderate severity.
|
||||
/// </summary>
|
||||
Moderate = 3,
|
||||
|
||||
/// <summary>
|
||||
/// Serious severity.
|
||||
/// </summary>
|
||||
Serious = 4
|
||||
}
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
/*
|
||||
* Copyright(c) 2017 Microsoft Corporation. All rights reserved.
|
||||
*
|
||||
* This code is licensed under the MIT License (MIT).
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// Specifies the type of a traffic incident.
|
||||
/// </summary>
|
||||
public enum TrafficType
|
||||
{
|
||||
/// <summary>
|
||||
/// Accident incident type.
|
||||
/// </summary>
|
||||
Accident = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Congestion incident type.
|
||||
/// </summary>
|
||||
Congestion = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Disabled vehicle incident type.
|
||||
/// </summary>
|
||||
DisabledVehicle = 3,
|
||||
|
||||
/// <summary>
|
||||
/// Mass transit incident type.
|
||||
/// </summary>
|
||||
MassTransit = 4,
|
||||
|
||||
/// <summary>
|
||||
/// Miscellaneous incident type.
|
||||
/// </summary>
|
||||
Miscellaneous = 5,
|
||||
|
||||
/// <summary>
|
||||
/// Other news incident type.
|
||||
/// </summary>
|
||||
OtherNews = 6,
|
||||
|
||||
/// <summary>
|
||||
/// Planned event incident type.
|
||||
/// </summary>
|
||||
PlannedEvent = 7,
|
||||
|
||||
/// <summary>
|
||||
/// Road hazard incident type.
|
||||
/// </summary>
|
||||
RoadHazard = 8,
|
||||
|
||||
/// <summary>
|
||||
/// Construction incident type.
|
||||
/// </summary>
|
||||
Construction = 9,
|
||||
|
||||
/// <summary>
|
||||
/// Alert incident type.
|
||||
/// </summary>
|
||||
Alert = 10,
|
||||
|
||||
/// <summary>
|
||||
/// Weather incident type.
|
||||
/// </summary>
|
||||
Weather = 11
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright(c) 2017 Microsoft Corporation. All rights reserved.
|
||||
*
|
||||
* This code is licensed under the MIT License (MIT).
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// The mode of travel for the route.
|
||||
/// </summary>
|
||||
public enum TravelModeType
|
||||
{
|
||||
/// <summary>
|
||||
/// Driving mode.
|
||||
/// </summary>
|
||||
Driving,
|
||||
|
||||
/// <summary>
|
||||
/// Walking mode.
|
||||
/// </summary>
|
||||
Walking,
|
||||
|
||||
/// <summary>
|
||||
/// Transit mode.
|
||||
/// </summary>
|
||||
Transit
|
||||
}
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* Copyright(c) 2017 Microsoft Corporation. All rights reserved.
|
||||
*
|
||||
* This code is licensed under the MIT License (MIT).
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// A helper class for working iwth OData Dates.
|
||||
/// </summary>
|
||||
internal static class DateTimeHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts a DateTime object into an OData date.
|
||||
/// </summary>
|
||||
/// <param name="dateTime">The DateTime to convert.</param>
|
||||
/// <returns>An OData version of the DateTime.</returns>
|
||||
public static string ToOdataJson(DateTime dateTime)
|
||||
{
|
||||
DateTime d1 = new DateTime(1970, 1, 1);
|
||||
DateTime d2 = dateTime.ToUniversalTime();
|
||||
TimeSpan ts = new TimeSpan(d2.Ticks - d1.Ticks);
|
||||
return "\\/Date(" + ts.TotalMilliseconds.ToString("#") + ")\\/";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts an OData Date into a DateTime object.
|
||||
/// </summary>
|
||||
/// <param name="jsonDate">OData Date to convert.</param>
|
||||
/// <returns>The converted DateTime object.</returns>
|
||||
public static DateTime FromOdataJson(string jsonDate)
|
||||
{
|
||||
// /Date(1235764800000)/
|
||||
// /Date(1467298867000-0700)/
|
||||
|
||||
jsonDate = jsonDate.Replace("/Date(", "").Replace(")/", "");
|
||||
|
||||
long ms = 0; // number of milliseconds since midnight Jan 1, 1970
|
||||
long hours = 0;
|
||||
|
||||
int pIdx = jsonDate.IndexOf("+");
|
||||
int mIdx = jsonDate.IndexOf("-");
|
||||
|
||||
if (pIdx > 0)
|
||||
{
|
||||
ms = long.Parse(jsonDate.Substring(0, pIdx));
|
||||
|
||||
//Hack: The offset is meant to be in minutes, but for some reason the response from the REST services uses 700 which is meant to be 7 hours.
|
||||
hours = long.Parse(jsonDate.Substring(mIdx)) / 100;
|
||||
}
|
||||
else if (mIdx > 0)
|
||||
{
|
||||
ms = long.Parse(jsonDate.Substring(0, mIdx));
|
||||
|
||||
//Hack: The offset is meant to be in minutes, but for some reason the response from the REST services uses 700 which is meant to be 7 hours.
|
||||
hours = long.Parse(jsonDate.Substring(mIdx)) / 100;
|
||||
}
|
||||
else
|
||||
{
|
||||
ms = long.Parse(jsonDate);
|
||||
}
|
||||
|
||||
return new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(ms).AddHours(hours);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,207 @@
|
|||
/*
|
||||
* Copyright(c) 2017 Microsoft Corporation. All rights reserved.
|
||||
*
|
||||
* This code is licensed under the MIT License (MIT).
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// A helper class for making asynchronous requests to REST services.
|
||||
/// </summary>
|
||||
internal class ServiceHelper
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Downloads data as a string from a URL.
|
||||
/// </summary>
|
||||
/// <param name="url">URL that points to data to download.</param>
|
||||
/// <returns>A string with the data.</returns>
|
||||
public static Task<string> GetStringAsync(Uri url)
|
||||
{
|
||||
var tcs = new TaskCompletionSource<string>();
|
||||
|
||||
var request = HttpWebRequest.Create(url);
|
||||
request.BeginGetResponse((a) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var r = (HttpWebRequest)a.AsyncState;
|
||||
using (var response = (HttpWebResponse)r.EndGetResponse(a))
|
||||
{
|
||||
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
|
||||
{
|
||||
tcs.SetResult(reader.ReadToEnd());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (WebException ex)
|
||||
{
|
||||
if (ex.Response != null)
|
||||
{
|
||||
using (var reader = new StreamReader(ex.Response.GetResponseStream()))
|
||||
{
|
||||
tcs.SetResult(reader.ReadToEnd());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
tcs.SetException(ex);
|
||||
}
|
||||
}, request);
|
||||
|
||||
return tcs.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Downloads data as a stream from a URL.
|
||||
/// </summary>
|
||||
/// <param name="url">URL that points to data to download.</param>
|
||||
/// <returns>A stream with the data.</returns>
|
||||
public static Task<Stream> GetStreamAsync(Uri url)
|
||||
{
|
||||
var tcs = new TaskCompletionSource<Stream>();
|
||||
|
||||
var request = HttpWebRequest.Create(url);
|
||||
request.BeginGetResponse((a) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var r = (HttpWebRequest)a.AsyncState;
|
||||
using (var response = (HttpWebResponse)r.EndGetResponse(a))
|
||||
{
|
||||
tcs.SetResult(CopyToMemoryStream(response.GetResponseStream()));
|
||||
}
|
||||
}
|
||||
catch (WebException ex)
|
||||
{
|
||||
if (ex.Response != null)
|
||||
{
|
||||
tcs.SetResult(CopyToMemoryStream(ex.Response.GetResponseStream()));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
tcs.SetException(ex);
|
||||
}
|
||||
}, request);
|
||||
|
||||
return tcs.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Makes a post request using string data.
|
||||
/// </summary>
|
||||
/// <param name="url">URL to post data to.</param>
|
||||
/// <param name="data">String representation of data to be posted to service.</param>
|
||||
/// <returns>Response stream.</returns>
|
||||
public static Task<Stream> PostStringAsync(Uri url, string data, string contentType)
|
||||
{
|
||||
var tcs = new TaskCompletionSource<Stream>();
|
||||
|
||||
var request = HttpWebRequest.Create(url);
|
||||
|
||||
request.Method = "POST";
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(contentType))
|
||||
{
|
||||
request.ContentType = contentType;
|
||||
}
|
||||
else
|
||||
{
|
||||
request.ContentType = "text/plain;charset=utf-8";
|
||||
}
|
||||
|
||||
request.BeginGetRequestStream((a) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var r = (HttpWebRequest)a.AsyncState;
|
||||
|
||||
//Add data to request stream
|
||||
using (var requestStream = r.EndGetRequestStream(a))
|
||||
{
|
||||
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(data);
|
||||
requestStream.Write(bytes, 0, bytes.Length);
|
||||
}
|
||||
|
||||
request.BeginGetResponse((a2) =>
|
||||
{
|
||||
try
|
||||
{
|
||||
var r2 = (HttpWebRequest)a2.AsyncState;
|
||||
|
||||
using (var response = (HttpWebResponse)r2.EndGetResponse(a2))
|
||||
{
|
||||
tcs.SetResult(CopyToMemoryStream(response.GetResponseStream()));
|
||||
}
|
||||
}
|
||||
catch (WebException ex)
|
||||
{
|
||||
if (ex.Response != null)
|
||||
{
|
||||
tcs.SetResult(CopyToMemoryStream(ex.Response.GetResponseStream()));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
tcs.SetException(ex);
|
||||
}
|
||||
}, request);
|
||||
}
|
||||
catch (WebException ex)
|
||||
{
|
||||
if (ex.Response != null)
|
||||
{
|
||||
tcs.SetResult(CopyToMemoryStream(ex.Response.GetResponseStream()));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
tcs.SetException(ex);
|
||||
}
|
||||
}, request);
|
||||
|
||||
return tcs.Task;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private static MemoryStream CopyToMemoryStream(Stream inputStream)
|
||||
{
|
||||
var ms = new MemoryStream();
|
||||
inputStream.CopyTo(ms);
|
||||
ms.Position = 0;
|
||||
return ms;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,217 @@
|
|||
/*
|
||||
* Copyright(c) 2017 Microsoft Corporation. All rights reserved.
|
||||
*
|
||||
* This code is licensed under the MIT License (MIT).
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// A set of useful spatial math tools.
|
||||
/// </summary>
|
||||
internal static class SpatialTools
|
||||
{
|
||||
#region Earth Related Constants
|
||||
|
||||
/// <summary>
|
||||
/// The approximate spherical radius of the Earth
|
||||
/// </summary>
|
||||
public static class EarthRadius
|
||||
{
|
||||
/// <summary>
|
||||
/// Earth Radius in Kilometers
|
||||
/// </summary>
|
||||
public const double KM = 6378.135;
|
||||
|
||||
/// <summary>
|
||||
/// Earth Radius in Meters
|
||||
/// </summary>
|
||||
public const double Meters = 6378135;
|
||||
|
||||
/// <summary>
|
||||
/// Earth Radius in Miles
|
||||
/// </summary>
|
||||
public const double Miles = 3963.189;
|
||||
|
||||
/// <summary>
|
||||
/// Earth Radius in Feet
|
||||
/// </summary>
|
||||
public const double Feet = 20925640;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Earth Radius
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the radius of the earth in a specific distance unit for WGS84.
|
||||
/// </summary>
|
||||
/// <param name="units">Unit of distance measurement.</param>
|
||||
/// <returns>The radius of the earth in a specified distance units.</returns>
|
||||
public static double GetEarthRadius(DistanceUnitType units)
|
||||
{
|
||||
switch (units)
|
||||
{
|
||||
case DistanceUnitType.Miles:
|
||||
return EarthRadius.Miles;
|
||||
case DistanceUnitType.KM:
|
||||
default:
|
||||
return EarthRadius.KM;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Distance Conversion
|
||||
|
||||
/// <summary>
|
||||
/// Converts distances from miles to km or km to miles.
|
||||
/// </summary>
|
||||
/// <param name="distance">Distance to convert.</param>
|
||||
/// <param name="fromUnits">The units that the distance is in.</param>
|
||||
/// <param name="toUnits">The units to convert the distance to.</param>
|
||||
/// <returns>A distance in the specified unit of measurement.</returns>
|
||||
public static double ConvertDistance(double distance, DistanceUnitType fromUnits, DistanceUnitType toUnits)
|
||||
{
|
||||
if(fromUnits == toUnits || double.IsNaN(distance))
|
||||
{
|
||||
return distance;
|
||||
}
|
||||
|
||||
//Convert the distance to kilometers
|
||||
if (fromUnits == DistanceUnitType.Miles)
|
||||
{
|
||||
distance *= 1.609344;
|
||||
}
|
||||
|
||||
if (toUnits == DistanceUnitType.Miles)
|
||||
{
|
||||
distance /= 1.609344;
|
||||
}
|
||||
|
||||
return distance;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Degree and Radian Conversions
|
||||
|
||||
/// <summary>
|
||||
/// Converts an angle that is in degrees to radians. Angle * (PI / 180)
|
||||
/// </summary>
|
||||
/// <param name="angle">An angle in degrees</param>
|
||||
/// <returns>An angle in radians</returns>
|
||||
public static double ToRadians(double angle)
|
||||
{
|
||||
return angle * (Math.PI / 180);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts an angle that is in radians to degress. Angle * (180 / PI)
|
||||
/// </summary>
|
||||
/// <param name="angle">An angle in radians</param>
|
||||
/// <returns>An angle in degrees</returns>
|
||||
public static double ToDegrees(double angle)
|
||||
{
|
||||
return angle * (180 / Math.PI);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Haversine Distance Calculation method
|
||||
|
||||
/// <summary>
|
||||
/// Calculate the distance between two coordinates on the surface of a sphere (Earth).
|
||||
/// </summary>
|
||||
/// <param name="origin">First coordinate to calculate distance between.</param>
|
||||
/// <param name="destination">Second coordinate to calculate distance between.</param>
|
||||
/// <param name="units">Unit of distance measurement.</param>
|
||||
/// <returns>The shortest distance in the specifed units.</returns>
|
||||
public static double HaversineDistance(Coordinate origin, Coordinate destination, DistanceUnitType units)
|
||||
{
|
||||
return HaversineDistance(origin.Latitude, origin.Longitude, destination.Latitude, destination.Longitude, units);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculate the distance between two coordinates on the surface of a sphere (Earth).
|
||||
/// </summary>
|
||||
/// <param name="origLat">Origin Latitude.</param>
|
||||
/// <param name="origLon">Origin Longitude.</param>
|
||||
/// <param name="destLat">Destination Latitude.</param>
|
||||
/// <param name="destLon">Destination Longitude.</param>
|
||||
/// <param name="units">Unit of distance measurement.</param>
|
||||
/// <returns>The shortest distance in the specifed units.</returns>
|
||||
public static double HaversineDistance(double origLat, double origLon, double destLat, double destLon, DistanceUnitType units)
|
||||
{
|
||||
double radius = GetEarthRadius(units);
|
||||
|
||||
double dLat = ToRadians(destLat - origLat);
|
||||
double dLon = ToRadians(destLon - origLon);
|
||||
|
||||
double a = Math.Pow(Math.Sin(dLat / 2), 2) + Math.Pow(Math.Cos(ToRadians(origLat)), 2) * Math.Pow(Math.Sin(dLon / 2), 2);
|
||||
double centralAngle = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
|
||||
|
||||
return radius * centralAngle;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>Calculates the bearing between two coordinates.</summary>
|
||||
/// <param name="origin" type="Coordinate">Initial location.</param>
|
||||
/// <param name="dest" type="Coordinate">Second location.</param>
|
||||
/// <returns>The bearing angle between two coordinates.</returns>
|
||||
public static double CalculateBearing(Coordinate origin, Coordinate dest)
|
||||
{
|
||||
var lat1 = ToRadians(origin.Latitude);
|
||||
var lon1 = origin.Longitude;
|
||||
var lat2 = ToRadians(dest.Latitude);
|
||||
var lon2 = dest.Longitude;
|
||||
var dLon = ToRadians(lon2 - lon1);
|
||||
var y = Math.Sin(dLon) * Math.Cos(lat2);
|
||||
var x = Math.Cos(lat1) * Math.Sin(lat2) - Math.Sin(lat1) * Math.Cos(lat2) * Math.Cos(dLon);
|
||||
return (ToDegrees(Math.Atan2(y, x)) + 360) % 360;
|
||||
}
|
||||
|
||||
/// <summary>Calculates a destination coordinate given a starting coordinate, bearing, and distance in KM's.</summary>
|
||||
/// <param name="origin" type="Coordinate">Initial location.</param>
|
||||
/// <param name="brng" type="Number">Bearing pointing towards new location.</param>
|
||||
/// <param name="arcLength" type="Number">A distance in KM's.</param>
|
||||
/// <param name="units" type="DistanceUnitType">Unit of measurement of the arcLength</param>
|
||||
/// <returns>A destination coordinate based on an origin point, bearing and distance.</returns>
|
||||
public static Coordinate CalculateCoord(Coordinate origin, double brng, double arcLength, DistanceUnitType units)
|
||||
{
|
||||
double earthRadius = GetEarthRadius(units);
|
||||
double lat1 = ToRadians(origin.Latitude),
|
||||
lon1 = ToRadians(origin.Longitude),
|
||||
centralAngle = arcLength / earthRadius;
|
||||
|
||||
var lat2 = Math.Asin(Math.Sin(lat1) * Math.Cos(centralAngle) + Math.Cos(lat1) * Math.Sin(centralAngle) * Math.Cos(ToRadians(brng)));
|
||||
var lon2 = lon1 + Math.Atan2(Math.Sin(ToRadians(brng)) * Math.Sin(centralAngle) * Math.Cos(lat1), Math.Cos(centralAngle) - Math.Sin(lat1) * Math.Sin(lat2));
|
||||
|
||||
return new Coordinate(){
|
||||
Latitude = ToDegrees(lat2),
|
||||
Longitude = ToDegrees(lon2)
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,108 @@
|
|||
/*
|
||||
* Copyright(c) 2017 Microsoft Corporation. All rights reserved.
|
||||
*
|
||||
* This code is licensed under the MIT License (MIT).
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// A class that defines location coordinate value.
|
||||
/// </summary>
|
||||
[DataContract]
|
||||
public class Coordinate
|
||||
{
|
||||
#region Private Properties
|
||||
|
||||
private double _latitude, _longitude;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
||||
/// <summary>
|
||||
/// A location coordinate.
|
||||
/// </summary>
|
||||
public Coordinate()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A location coordinate.
|
||||
/// </summary>
|
||||
/// <param name="latitude">Latitude coordinate vlaue.</param>
|
||||
/// <param name="longitude">Longitude coordinate value.</param>
|
||||
public Coordinate(double latitude, double longitude)
|
||||
{
|
||||
Latitude = latitude;
|
||||
Longitude = longitude;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
|
||||
/// <summary>
|
||||
/// Latitude coordinate.
|
||||
/// </summary>
|
||||
[DataMember(Name = "lat", EmitDefaultValue = false)]
|
||||
public double Latitude
|
||||
{
|
||||
get
|
||||
{
|
||||
return _latitude;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!double.IsNaN(value) && value <= 90 && value >= -90)
|
||||
{
|
||||
//Only need to keep the first 5 decimal places. Any more just adds more data being passed around.
|
||||
_latitude = Math.Round(value, 5, MidpointRounding.AwayFromZero);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Longitude coordinate.
|
||||
/// </summary>
|
||||
[DataMember(Name = "lon", EmitDefaultValue = false)]
|
||||
public double Longitude
|
||||
{
|
||||
get
|
||||
{
|
||||
return _longitude;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (!double.IsNaN(value) && value <= 180 && value >= -180)
|
||||
{
|
||||
//Only need to keep the first 5 decimal places. Any more just adds more data being passed around.
|
||||
_longitude = Math.Round(value, 5, MidpointRounding.AwayFromZero);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
* Copyright(c) 2017 Microsoft Corporation. All rights reserved.
|
||||
*
|
||||
* This code is licensed under the MIT License (MIT).
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// Pushpin defination for Bing Maps REST imagery service: https://msdn.microsoft.com/en-us/library/ff701719.aspx
|
||||
/// </summary>
|
||||
public class ImageryPushpin
|
||||
{
|
||||
#region Private Properties
|
||||
|
||||
private int iconStyle = 1;
|
||||
private string label = string.Empty;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
|
||||
/// <summary>
|
||||
/// Coordinate to display pushpin.
|
||||
/// </summary>
|
||||
public Coordinate Location { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The icon style to use for the pushpin.
|
||||
/// </summary>
|
||||
public int IconStyle
|
||||
{
|
||||
get { return iconStyle; }
|
||||
set
|
||||
{
|
||||
if (value < 0)
|
||||
{
|
||||
iconStyle = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
iconStyle = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Label to display on top of pushpin.
|
||||
/// </summary>
|
||||
public string Label
|
||||
{
|
||||
get { return label; }
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
label = string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
label = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
if (Location != null)
|
||||
{
|
||||
return string.Format("pp={0:0.#####},{1:0.#####};{2};{3}", Location.Latitude, Location.Longitude, iconStyle, label);
|
||||
}
|
||||
else
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,182 @@
|
|||
/*
|
||||
* Copyright(c) 2017 Microsoft Corporation. All rights reserved.
|
||||
*
|
||||
* This code is licensed under the MIT License (MIT).
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// This compression algorithm encodes/decodes a collections of coordinates into a string.
|
||||
/// This algorithm is used for generating a compressed collection of coordinates for use
|
||||
/// with the Bing Maps REST Elevation Service. This algorithm is also used for decoding
|
||||
/// the compressed coordinates returned by the GeoData API.
|
||||
///
|
||||
/// These algorithms come from the following documentation:
|
||||
/// http://msdn.microsoft.com/en-us/library/jj158958.aspx
|
||||
/// http://msdn.microsoft.com/en-us/library/dn306801.aspx
|
||||
/// </summary>
|
||||
public static class PointCompression
|
||||
{
|
||||
#region Private Properties
|
||||
|
||||
private const string LookUpTable = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-";
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Compresses a list of coordinates into a string.
|
||||
/// Based on: http://msdn.microsoft.com/en-us/library/jj158958.aspx
|
||||
/// </summary>
|
||||
/// <param name="points">Collection of coordinates to compress.</param>
|
||||
/// <returns>A compressed string representing a collection coordinates.</returns>
|
||||
public static string Encode(List<Coordinate> points)
|
||||
{
|
||||
long latitude = 0;
|
||||
long longitude = 0;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
foreach (var point in points)
|
||||
{
|
||||
// step 2
|
||||
var newLatitude = (long)Math.Round(point.Latitude * 100000);
|
||||
var newLongitude = (long)Math.Round(point.Longitude * 100000);
|
||||
|
||||
// step 3
|
||||
long dy = newLatitude - latitude;
|
||||
long dx = newLongitude - longitude;
|
||||
latitude = newLatitude;
|
||||
longitude = newLongitude;
|
||||
|
||||
// step 4 and 5
|
||||
dy = (dy << 1) ^ (dy >> 31);
|
||||
dx = (dx << 1) ^ (dx >> 31);
|
||||
|
||||
// step 6
|
||||
long index = ((dy + dx) * (dy + dx + 1) / 2) + dy;
|
||||
|
||||
while (index > 0)
|
||||
{
|
||||
// step 7
|
||||
long rem = index & 31;
|
||||
index = (index - rem) / 32;
|
||||
|
||||
// step 8
|
||||
if (index > 0)
|
||||
{
|
||||
rem += 32;
|
||||
}
|
||||
|
||||
// step 9
|
||||
sb.Append(LookUpTable[(int)rem]);
|
||||
}
|
||||
}
|
||||
|
||||
// step 10
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Decodes a collection of coordinates from a compressed string.
|
||||
/// Based on: http://msdn.microsoft.com/en-us/library/dn306801.aspx
|
||||
/// </summary>
|
||||
/// <param name="value">Compressed string to decode</param>
|
||||
/// <param name="parsedValue">Collection of decoded coordinates.</param>
|
||||
/// <returns>A boolean indicating if the algorithm was able to decode the compressed coordinates or not.</returns>
|
||||
public static bool TryDecode(string value, out List<Coordinate> parsedValue)
|
||||
{
|
||||
parsedValue = null;
|
||||
var list = new List<Coordinate>();
|
||||
int index = 0;
|
||||
int xsum = 0, ysum = 0;
|
||||
|
||||
while (index < value.Length) // While we have more data,
|
||||
{
|
||||
long n = 0; // initialize the accumulator
|
||||
int k = 0; // initialize the count of bits
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (index >= value.Length) // If we ran out of data mid-number
|
||||
return false; // indicate failure.
|
||||
|
||||
int b = LookUpTable.IndexOf(value[index++]);
|
||||
|
||||
if (b == -1) // If the character wasn't on the valid list,
|
||||
return false; // indicate failure.
|
||||
|
||||
n |= ((long)b & 31) << k; // mask off the top bit and append the rest to the accumulator
|
||||
k += 5; // move to the next position
|
||||
if (b < 32) break; // If the top bit was not set, we're done with this number.
|
||||
}
|
||||
|
||||
// The resulting number encodes an x, y pair in the following way:
|
||||
//
|
||||
// ^ Y
|
||||
// |
|
||||
// 14
|
||||
// 9 13
|
||||
// 5 8 12
|
||||
// 2 4 7 11
|
||||
// 0 1 3 6 10 ---> X
|
||||
|
||||
// determine which diagonal it's on
|
||||
int diagonal = (int)((Math.Sqrt(8 * n + 5) - 1) / 2);
|
||||
|
||||
// subtract the total number of points from lower diagonals
|
||||
n -= diagonal * (diagonal + 1L) / 2;
|
||||
|
||||
// get the X and Y from what's left over
|
||||
int ny = (int)n;
|
||||
int nx = diagonal - ny;
|
||||
|
||||
// undo the sign encoding
|
||||
nx = (nx >> 1) ^ -(nx & 1);
|
||||
ny = (ny >> 1) ^ -(ny & 1);
|
||||
|
||||
// undo the delta encoding
|
||||
xsum += nx;
|
||||
ysum += ny;
|
||||
|
||||
double lat = ysum * 0.00001;
|
||||
double lon = xsum * 0.00001;
|
||||
|
||||
//Trim latlong values to supported ranges
|
||||
lat = Math.Max(-85, Math.Min(85, lat));
|
||||
lon = Math.Max(-180, Math.Min(180, lon));
|
||||
|
||||
list.Add(new Coordinate(lat, lon));
|
||||
}
|
||||
|
||||
parsedValue = list;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,986 @@
|
|||
/*
|
||||
* Copyright(c) 2017 Microsoft Corporation. All rights reserved.
|
||||
*
|
||||
* This code is licensed under the MIT License (MIT).
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
/*
|
||||
* Data Contracts generated for the Bing Maps REST service Response object.
|
||||
*/
|
||||
|
||||
[DataContract]
|
||||
public class Address
|
||||
{
|
||||
[DataMember(Name = "addressLine", EmitDefaultValue = false)]
|
||||
public string AddressLine { get; set; }
|
||||
|
||||
[DataMember(Name = "adminDistrict", EmitDefaultValue = false)]
|
||||
public string AdminDistrict { get; set; }
|
||||
|
||||
[DataMember(Name = "adminDistrict2", EmitDefaultValue = false)]
|
||||
public string AdminDistrict2 { get; set; }
|
||||
|
||||
[DataMember(Name = "countryRegion", EmitDefaultValue = false)]
|
||||
public string CountryRegion { get; set; }
|
||||
|
||||
[DataMember(Name = "locality", EmitDefaultValue = false)]
|
||||
public string Locality { get; set; }
|
||||
|
||||
[DataMember(Name = "postalCode", EmitDefaultValue = false)]
|
||||
public string PostalCode { get; set; }
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class DetailedAddress
|
||||
{
|
||||
[DataMember(Name = "countryRegionIso2", EmitDefaultValue = false)]
|
||||
public string CountryRegionIso2 { get; set; }
|
||||
|
||||
[DataMember(Name = "formattedAddress", EmitDefaultValue = false)]
|
||||
public string FormattedAddress { get; set; }
|
||||
|
||||
[DataMember(Name = "neighborhood", EmitDefaultValue = false)]
|
||||
public string Neighborhood { get; set; }
|
||||
|
||||
[DataMember(Name = "landmark", EmitDefaultValue = false)]
|
||||
public string Landmark { get; set; }
|
||||
}
|
||||
|
||||
[DataContract(Namespace = "http://schemas.microsoft.com/search/local/ws/rest/v1")]
|
||||
public class BirdseyeMetadata : ImageryMetadata
|
||||
{
|
||||
[DataMember(Name = "orientation", EmitDefaultValue = false)]
|
||||
public double Orientation { get; set; }
|
||||
|
||||
[DataMember(Name = "tilesX", EmitDefaultValue = false)]
|
||||
public int TilesX { get; set; }
|
||||
|
||||
[DataMember(Name = "tilesY", EmitDefaultValue = false)]
|
||||
public int TilesY { get; set; }
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class BoundingBox
|
||||
{
|
||||
[DataMember(Name = "southLatitude", EmitDefaultValue = false)]
|
||||
public double SouthLatitude { get; set; }
|
||||
|
||||
[DataMember(Name = "westLongitude", EmitDefaultValue = false)]
|
||||
public double WestLongitude { get; set; }
|
||||
|
||||
[DataMember(Name = "northLatitude", EmitDefaultValue = false)]
|
||||
public double NorthLatitude { get; set; }
|
||||
|
||||
[DataMember(Name = "eastLongitude", EmitDefaultValue = false)]
|
||||
public double EastLongitude { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("{0:0.#####},{1:0.#####},{2:0.#####},{3:0.#####}",
|
||||
SouthLatitude,
|
||||
WestLongitude,
|
||||
NorthLatitude,
|
||||
EastLongitude);
|
||||
}
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class Detail
|
||||
{
|
||||
[DataMember(Name = "compassDegrees", EmitDefaultValue = false)]
|
||||
public int CompassDegrees { get; set; }
|
||||
|
||||
[DataMember(Name = "maneuverType", EmitDefaultValue = false)]
|
||||
public string ManeuverType { get; set; }
|
||||
|
||||
[DataMember(Name = "startPathIndices", EmitDefaultValue = false)]
|
||||
public int[] StartPathIndices { get; set; }
|
||||
|
||||
[DataMember(Name = "endPathIndices", EmitDefaultValue = false)]
|
||||
public int[] EndPathIndices { get; set; }
|
||||
|
||||
[DataMember(Name = "roadType", EmitDefaultValue = false)]
|
||||
public string RoadType { get; set; }
|
||||
|
||||
[DataMember(Name = "locationCodes", EmitDefaultValue = false)]
|
||||
public string[] LocationCodes { get; set; }
|
||||
|
||||
[DataMember(Name = "names", EmitDefaultValue = false)]
|
||||
public string[] Names { get; set; }
|
||||
|
||||
[DataMember(Name = "mode", EmitDefaultValue = false)]
|
||||
public string Mode { get; set; }
|
||||
|
||||
[DataMember(Name = "roadShieldRequestParameters", EmitDefaultValue = false)]
|
||||
public RoadShield roadShieldRequestParameters { get; set; }
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class Generalization
|
||||
{
|
||||
[DataMember(Name = "pathIndices", EmitDefaultValue = false)]
|
||||
public int[] PathIndices { get; set; }
|
||||
|
||||
[DataMember(Name = "latLongTolerance", EmitDefaultValue = false)]
|
||||
public double LatLongTolerance { get; set; }
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class Hint
|
||||
{
|
||||
[DataMember(Name = "hintType", EmitDefaultValue = false)]
|
||||
public string HintType { get; set; }
|
||||
|
||||
[DataMember(Name = "text", EmitDefaultValue = false)]
|
||||
public string Text { get; set; }
|
||||
}
|
||||
|
||||
[DataContract(Namespace = "http://schemas.microsoft.com/search/local/ws/rest/v1")]
|
||||
[KnownType(typeof(StaticMapMetadata))]
|
||||
[KnownType(typeof(BirdseyeMetadata))]
|
||||
public class ImageryMetadata : Resource
|
||||
{
|
||||
[DataMember(Name = "imageHeight", EmitDefaultValue = false)]
|
||||
public int ImageHeight { get; set; }
|
||||
|
||||
[DataMember(Name = "imageWidth", EmitDefaultValue = false)]
|
||||
public int ImageWidth { get; set; }
|
||||
|
||||
[DataMember(Name = "imageUrl", EmitDefaultValue = false)]
|
||||
public string ImageUrl { get; set; }
|
||||
|
||||
[DataMember(Name = "imageUrlSubdomains", EmitDefaultValue = false)]
|
||||
public string[] ImageUrlSubdomains { get; set; }
|
||||
|
||||
[DataMember(Name = "vintageEnd", EmitDefaultValue = false)]
|
||||
public string VintageEnd { get; set; }
|
||||
|
||||
[DataMember(Name = "vintageStart", EmitDefaultValue = false)]
|
||||
public string VintageStart { get; set; }
|
||||
|
||||
[DataMember(Name = "zoomMax", EmitDefaultValue = false)]
|
||||
public int ZoomMax { get; set; }
|
||||
|
||||
[DataMember(Name = "zoomMin", EmitDefaultValue = false)]
|
||||
public int ZoomMin { get; set; }
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class Instruction
|
||||
{
|
||||
[DataMember(Name = "maneuverType", EmitDefaultValue = false)]
|
||||
public string ManeuverType { get; set; }
|
||||
|
||||
[DataMember(Name = "text", EmitDefaultValue = false)]
|
||||
public string Text { get; set; }
|
||||
|
||||
[DataMember(Name = "formattedText", EmitDefaultValue = false)]
|
||||
public string FormattedText { get; set; }
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class ItineraryItem
|
||||
{
|
||||
[DataMember(Name = "childItineraryItems", EmitDefaultValue = false)]
|
||||
public ItineraryItem[] ChildItineraryItems { get; set; }
|
||||
|
||||
[DataMember(Name = "compassDirection", EmitDefaultValue = false)]
|
||||
public string CompassDirection { get; set; }
|
||||
|
||||
[DataMember(Name = "details", EmitDefaultValue = false)]
|
||||
public Detail[] Details { get; set; }
|
||||
|
||||
[DataMember(Name = "exit", EmitDefaultValue = false)]
|
||||
public string Exit { get; set; }
|
||||
|
||||
[DataMember(Name = "hints", EmitDefaultValue = false)]
|
||||
public Hint[] Hints { get; set; }
|
||||
|
||||
[DataMember(Name = "iconType", EmitDefaultValue = false)]
|
||||
public string IconType { get; set; }
|
||||
|
||||
[DataMember(Name = "instruction", EmitDefaultValue = false)]
|
||||
public Instruction Instruction { get; set; }
|
||||
|
||||
[DataMember(Name = "maneuverPoint", EmitDefaultValue = false)]
|
||||
public Point ManeuverPoint { get; set; }
|
||||
|
||||
[DataMember(Name = "sideOfStreet", EmitDefaultValue = false)]
|
||||
public string SideOfStreet { get; set; }
|
||||
|
||||
[DataMember(Name = "signs", EmitDefaultValue = false)]
|
||||
public string[] Signs { get; set; }
|
||||
|
||||
[DataMember(Name = "time", EmitDefaultValue = false)]
|
||||
public string Time { get; set; }
|
||||
|
||||
public DateTime TimeUtc
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(Time))
|
||||
{
|
||||
return DateTime.Now;
|
||||
}
|
||||
else
|
||||
{
|
||||
return DateTimeHelper.FromOdataJson(Time);
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
Time = string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
var v = DateTimeHelper.ToOdataJson(value);
|
||||
|
||||
if (v != null)
|
||||
{
|
||||
Time = v;
|
||||
}
|
||||
else
|
||||
{
|
||||
Time = string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[DataMember(Name = "tollZone", EmitDefaultValue = false)]
|
||||
public string TollZone { get; set; }
|
||||
|
||||
[DataMember(Name = "towardsRoadName", EmitDefaultValue = false)]
|
||||
public string TowardsRoadName { get; set; }
|
||||
|
||||
[DataMember(Name = "transitLine", EmitDefaultValue = false)]
|
||||
public TransitLine TransitLine { get; set; }
|
||||
|
||||
[DataMember(Name = "transitStopId", EmitDefaultValue = false)]
|
||||
public int TransitStopId { get; set; }
|
||||
|
||||
[DataMember(Name = "transitTerminus", EmitDefaultValue = false)]
|
||||
public string TransitTerminus { get; set; }
|
||||
|
||||
[DataMember(Name = "travelDistance", EmitDefaultValue = false)]
|
||||
public double TravelDistance { get; set; }
|
||||
|
||||
[DataMember(Name = "travelDuration", EmitDefaultValue = false)]
|
||||
public double TravelDuration { get; set; }
|
||||
|
||||
[DataMember(Name = "travelMode", EmitDefaultValue = false)]
|
||||
public string TravelMode { get; set; }
|
||||
|
||||
[DataMember(Name = "warning", EmitDefaultValue = false)]
|
||||
public Warning[] Warning { get; set; }
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class Line
|
||||
{
|
||||
[DataMember(Name = "type", EmitDefaultValue = false)]
|
||||
public string Type { get; set; }
|
||||
|
||||
[DataMember(Name = "coordinates", EmitDefaultValue = false)]
|
||||
public double[][] Coordinates { get; set; }
|
||||
}
|
||||
|
||||
[DataContract(Namespace = "http://schemas.microsoft.com/search/local/ws/rest/v1")]
|
||||
public class Location : Resource
|
||||
{
|
||||
[DataMember(Name = "name", EmitDefaultValue = false)]
|
||||
public string Name { get; set; }
|
||||
|
||||
[DataMember(Name = "point", EmitDefaultValue = false)]
|
||||
public Point Point { get; set; }
|
||||
|
||||
[DataMember(Name = "entityType", EmitDefaultValue = false)]
|
||||
public string EntityType { get; set; }
|
||||
|
||||
[DataMember(Name = "address", EmitDefaultValue = false)]
|
||||
public DetailedAddress Address { get; set; }
|
||||
|
||||
[DataMember(Name = "confidence", EmitDefaultValue = false)]
|
||||
public string Confidence { get; set; }
|
||||
|
||||
[DataMember(Name = "matchCodes", EmitDefaultValue = false)]
|
||||
public string[] MatchCodes { get; set; }
|
||||
|
||||
[DataMember(Name = "geocodePoints", EmitDefaultValue = false)]
|
||||
public Point[] GeocodePoints { get; set; }
|
||||
|
||||
[DataMember(Name = "queryParseValues", EmitDefaultValue = false)]
|
||||
public QueryParseValue[] QueryParseValues { get; set; }
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class QueryParseValue
|
||||
{
|
||||
[DataMember(Name = "property", EmitDefaultValue = false)]
|
||||
public string Property { get; set; }
|
||||
|
||||
[DataMember(Name = "value", EmitDefaultValue = false)]
|
||||
public string Value { get; set; }
|
||||
}
|
||||
|
||||
[DataContract(Namespace = "http://schemas.microsoft.com/search/local/ws/rest/v1")]
|
||||
public class PushpinMetdata
|
||||
{
|
||||
[DataMember(Name = "anchor", EmitDefaultValue = false)]
|
||||
public Pixel Anchor { get; set; }
|
||||
|
||||
[DataMember(Name = "bottomRightOffset", EmitDefaultValue = false)]
|
||||
public Pixel BottomRightOffset { get; set; }
|
||||
|
||||
[DataMember(Name = "topLeftOffset", EmitDefaultValue = false)]
|
||||
public Pixel TopLeftOffset { get; set; }
|
||||
|
||||
[DataMember(Name = "point", EmitDefaultValue = false)]
|
||||
public Point Point { get; set; }
|
||||
}
|
||||
|
||||
[DataContract(Namespace = "http://schemas.microsoft.com/search/local/ws/rest/v1")]
|
||||
public class Pixel
|
||||
{
|
||||
[DataMember(Name = "x", EmitDefaultValue = false)]
|
||||
public string X { get; set; }
|
||||
|
||||
[DataMember(Name = "y", EmitDefaultValue = false)]
|
||||
public string Y { get; set; }
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class Point : Shape
|
||||
{
|
||||
[DataMember(Name = "type", EmitDefaultValue = false)]
|
||||
public string Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Latitude,Longitude
|
||||
/// </summary>
|
||||
[DataMember(Name = "coordinates", EmitDefaultValue = false)]
|
||||
public double[] Coordinates { get; set; }
|
||||
|
||||
[DataMember(Name = "calculationMethod", EmitDefaultValue = false)]
|
||||
public string CalculationMethod { get; set; }
|
||||
|
||||
[DataMember(Name = "usageTypes", EmitDefaultValue = false)]
|
||||
public string[] UsageTypes { get; set; }
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
[KnownType(typeof(Location))]
|
||||
[KnownType(typeof(Route))]
|
||||
[KnownType(typeof(TrafficIncident))]
|
||||
[KnownType(typeof(ImageryMetadata))]
|
||||
[KnownType(typeof(ElevationData))]
|
||||
[KnownType(typeof(SeaLevelData))]
|
||||
[KnownType(typeof(CompressedPointList))]
|
||||
public class Resource
|
||||
{
|
||||
[DataMember(Name = "bbox", EmitDefaultValue = false)]
|
||||
public double[] BoundingBox { get; set; }
|
||||
|
||||
[DataMember(Name = "__type", EmitDefaultValue = false)]
|
||||
public string Type { get; set; }
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class ResourceSet
|
||||
{
|
||||
[DataMember(Name = "estimatedTotal", EmitDefaultValue = false)]
|
||||
public long EstimatedTotal { get; set; }
|
||||
|
||||
[DataMember(Name = "resources", EmitDefaultValue = false)]
|
||||
public Resource[] Resources { get; set; }
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class Response
|
||||
{
|
||||
[DataMember(Name = "copyright", EmitDefaultValue = false)]
|
||||
public string Copyright { get; set; }
|
||||
|
||||
[DataMember(Name = "brandLogoUri", EmitDefaultValue = false)]
|
||||
public string BrandLogoUri { get; set; }
|
||||
|
||||
[DataMember(Name = "statusCode", EmitDefaultValue = false)]
|
||||
public int StatusCode { get; set; }
|
||||
|
||||
[DataMember(Name = "statusDescription", EmitDefaultValue = false)]
|
||||
public string StatusDescription { get; set; }
|
||||
|
||||
[DataMember(Name = "authenticationResultCode", EmitDefaultValue = false)]
|
||||
public string AuthenticationResultCode { get; set; }
|
||||
|
||||
[DataMember(Name = "errorDetails", EmitDefaultValue = false)]
|
||||
public string[] errorDetails { get; set; }
|
||||
|
||||
[DataMember(Name = "traceId", EmitDefaultValue = false)]
|
||||
public string TraceId { get; set; }
|
||||
|
||||
[DataMember(Name = "resourceSets", EmitDefaultValue = false)]
|
||||
public ResourceSet[] ResourceSets { get; set; }
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class RoadShield
|
||||
{
|
||||
[DataMember(Name = "bucket", EmitDefaultValue = false)]
|
||||
public int Bucket { get; set; }
|
||||
|
||||
[DataMember(Name = "shields", EmitDefaultValue = false)]
|
||||
public Shield[] Shields { get; set; }
|
||||
}
|
||||
|
||||
[DataContract(Namespace = "http://schemas.microsoft.com/search/local/ws/rest/v1")]
|
||||
public class Route : Resource
|
||||
{
|
||||
[DataMember(Name = "id", EmitDefaultValue = false)]
|
||||
public string Id { get; set; }
|
||||
|
||||
[DataMember(Name = "distanceUnit", EmitDefaultValue = false)]
|
||||
public string DistanceUnit { get; set; }
|
||||
|
||||
[DataMember(Name = "durationUnit", EmitDefaultValue = false)]
|
||||
public string DurationUnit { get; set; }
|
||||
|
||||
[DataMember(Name = "travelDistance", EmitDefaultValue = false)]
|
||||
public double TravelDistance { get; set; }
|
||||
|
||||
[DataMember(Name = "travelDuration", EmitDefaultValue = false)]
|
||||
public double TravelDuration { get; set; }
|
||||
|
||||
[DataMember(Name = "travelDurationTraffic", EmitDefaultValue = false)]
|
||||
public double TravelDurationTraffic { get; set; }
|
||||
|
||||
[DataMember(Name = "trafficCongestion", EmitDefaultValue = false)]
|
||||
public string TrafficCongestion { get; set; }
|
||||
|
||||
[DataMember(Name = "trafficDataUsed", EmitDefaultValue = false)]
|
||||
public string TrafficDataUsed { get; set; }
|
||||
|
||||
[DataMember(Name = "routeLegs", EmitDefaultValue = false)]
|
||||
public RouteLeg[] RouteLegs { get; set; }
|
||||
|
||||
[DataMember(Name = "routePath", EmitDefaultValue = false)]
|
||||
public RoutePath RoutePath { get; set; }
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class RouteLeg
|
||||
{
|
||||
[DataMember(Name = "travelDistance", EmitDefaultValue = false)]
|
||||
public double TravelDistance { get; set; }
|
||||
|
||||
[DataMember(Name = "travelDuration", EmitDefaultValue = false)]
|
||||
public double TravelDuration { get; set; }
|
||||
|
||||
[DataMember(Name = "cost", EmitDefaultValue = false)]
|
||||
public double Cost { get; set; }
|
||||
|
||||
[DataMember(Name = "description", EmitDefaultValue = false)]
|
||||
public string Description { get; set; }
|
||||
|
||||
[DataMember(Name = "actualStart", EmitDefaultValue = false)]
|
||||
public Point ActualStart { get; set; }
|
||||
|
||||
[DataMember(Name = "actualEnd", EmitDefaultValue = false)]
|
||||
public Point ActualEnd { get; set; }
|
||||
|
||||
[DataMember(Name = "startLocation", EmitDefaultValue = false)]
|
||||
public Location StartLocation { get; set; }
|
||||
|
||||
[DataMember(Name = "endLocation", EmitDefaultValue = false)]
|
||||
public Location EndLocation { get; set; }
|
||||
|
||||
[DataMember(Name = "itineraryItems", EmitDefaultValue = false)]
|
||||
public ItineraryItem[] ItineraryItems { get; set; }
|
||||
|
||||
[DataMember(Name = "routeRegion", EmitDefaultValue = false)]
|
||||
public string RouteRegion { get; set; }
|
||||
|
||||
[DataMember(Name = "routeSubLegs", EmitDefaultValue = false)]
|
||||
public RouteSubLeg[] RouteSubLegs { get; set; }
|
||||
|
||||
[DataMember(Name = "startTime", EmitDefaultValue = false)]
|
||||
public string StartTime { get; set; }
|
||||
|
||||
public DateTime StartTimeUtc
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(StartTime))
|
||||
{
|
||||
return DateTime.Now;
|
||||
}
|
||||
else
|
||||
{
|
||||
return DateTimeHelper.FromOdataJson(StartTime);
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
StartTime = string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
var v = DateTimeHelper.ToOdataJson(value);
|
||||
|
||||
if (v != null)
|
||||
{
|
||||
StartTime = v;
|
||||
}
|
||||
else
|
||||
{
|
||||
StartTime = string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[DataMember(Name = "endTime", EmitDefaultValue = false)]
|
||||
public string EndTime { get; set; }
|
||||
|
||||
public DateTime EndTimeUtc
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(EndTime))
|
||||
{
|
||||
return DateTime.Now;
|
||||
}
|
||||
else
|
||||
{
|
||||
return DateTimeHelper.FromOdataJson(EndTime);
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
EndTime = string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
var v = DateTimeHelper.ToOdataJson(value);
|
||||
|
||||
if (v != null)
|
||||
{
|
||||
EndTime = v;
|
||||
}
|
||||
else
|
||||
{
|
||||
EndTime = string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: What is the base class?
|
||||
[DataMember(Name = "alternateVias", EmitDefaultValue = false)]
|
||||
public object[] AlternateVias { get; set; }
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class RouteSubLeg
|
||||
{
|
||||
[DataMember(Name = "endWaypoint", EmitDefaultValue = false)]
|
||||
public Waypoint EndWaypoint { get; set; }
|
||||
|
||||
[DataMember(Name = "startWaypoint", EmitDefaultValue = false)]
|
||||
public Waypoint StartWaypoint { get; set; }
|
||||
|
||||
[DataMember(Name = "travelDistance", EmitDefaultValue = false)]
|
||||
public double TravelDistance { get; set; }
|
||||
|
||||
[DataMember(Name = "travelDuration", EmitDefaultValue = false)]
|
||||
public double TravelDuration { get; set; }
|
||||
|
||||
[DataMember(Name = "travelDurationTraffic", EmitDefaultValue = false)]
|
||||
public double TravelDurationTraffic { get; set; }
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class Waypoint : Point
|
||||
{
|
||||
[DataMember(Name = "description", EmitDefaultValue = false)]
|
||||
public string Description { get; set; }
|
||||
|
||||
[DataMember(Name = "isVia", EmitDefaultValue = false)]
|
||||
public bool IsVia { get; set; }
|
||||
|
||||
[DataMember(Name = "locationIdentifier", EmitDefaultValue = false)]
|
||||
public string LocationIdentifier { get; set; }
|
||||
|
||||
[DataMember(Name = "routePathIndex", EmitDefaultValue = false)]
|
||||
public int RoutePathIndex { get; set; }
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class RoutePath
|
||||
{
|
||||
[DataMember(Name = "line", EmitDefaultValue = false)]
|
||||
public Line Line { get; set; }
|
||||
|
||||
[DataMember(Name = "generalizations", EmitDefaultValue = false)]
|
||||
public Generalization[] Generalizations { get; set; }
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
[KnownType(typeof(Point))]
|
||||
public class Shape
|
||||
{
|
||||
[DataMember(Name = "boundingBox", EmitDefaultValue = false)]
|
||||
public double[] BoundingBox { get; set; }
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class Shield
|
||||
{
|
||||
[DataMember(Name = "labels", EmitDefaultValue = false)]
|
||||
public string[] Labels { get; set; }
|
||||
|
||||
[DataMember(Name = "roadShieldType", EmitDefaultValue = false)]
|
||||
public int RoadShieldType { get; set; }
|
||||
}
|
||||
|
||||
[DataContract(Namespace = "http://schemas.microsoft.com/search/local/ws/rest/v1")]
|
||||
public class StaticMapMetadata : ImageryMetadata
|
||||
{
|
||||
[DataMember(Name = "mapCenter", EmitDefaultValue = false)]
|
||||
public Point MapCenter { get; set; }
|
||||
|
||||
[DataMember(Name = "pushpins", EmitDefaultValue = false)]
|
||||
public PushpinMetdata[] Pushpins { get; set; }
|
||||
|
||||
[DataMember(Name = "zoom", EmitDefaultValue = false)]
|
||||
public string Zoom { get; set; }
|
||||
}
|
||||
|
||||
[DataContract(Namespace = "http://schemas.microsoft.com/search/local/ws/rest/v1")]
|
||||
public class TrafficIncident : Resource
|
||||
{
|
||||
[DataMember(Name = "point", EmitDefaultValue = false)]
|
||||
public Point Point { get; set; }
|
||||
|
||||
[DataMember(Name = "congestion", EmitDefaultValue = false)]
|
||||
public string Congestion { get; set; }
|
||||
|
||||
[DataMember(Name = "description", EmitDefaultValue = false)]
|
||||
public string Description { get; set; }
|
||||
|
||||
[DataMember(Name = "detour", EmitDefaultValue = false)]
|
||||
public string Detour { get; set; }
|
||||
|
||||
[DataMember(Name = "start", EmitDefaultValue = false)]
|
||||
public string Start { get; set; }
|
||||
|
||||
public DateTime StartDateTimeUtc
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(Start))
|
||||
{
|
||||
return DateTime.Now;
|
||||
}
|
||||
else
|
||||
{
|
||||
return DateTimeHelper.FromOdataJson(Start);
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
Start = string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
var v = DateTimeHelper.ToOdataJson(value);
|
||||
|
||||
if (v != null)
|
||||
{
|
||||
Start = v;
|
||||
}
|
||||
else
|
||||
{
|
||||
Start = string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[DataMember(Name = "end", EmitDefaultValue = false)]
|
||||
public string End { get; set; }
|
||||
|
||||
public DateTime EndDateTimeUtc
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(End))
|
||||
{
|
||||
return DateTime.Now;
|
||||
}
|
||||
else
|
||||
{
|
||||
return DateTimeHelper.FromOdataJson(End);
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
End = string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
var v = DateTimeHelper.ToOdataJson(value);
|
||||
|
||||
if (v != null)
|
||||
{
|
||||
End = v;
|
||||
}
|
||||
else
|
||||
{
|
||||
End = string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[DataMember(Name = "incidentId", EmitDefaultValue = false)]
|
||||
public long IncidentId { get; set; }
|
||||
|
||||
[DataMember(Name = "lane", EmitDefaultValue = false)]
|
||||
public string Lane { get; set; }
|
||||
|
||||
[DataMember(Name = "lastModified", EmitDefaultValue = false)]
|
||||
public string LastModified { get; set; }
|
||||
|
||||
public DateTime LastModifiedDateTimeUtc
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(LastModified))
|
||||
{
|
||||
return DateTime.Now;
|
||||
}
|
||||
else
|
||||
{
|
||||
return DateTimeHelper.FromOdataJson(LastModified);
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
LastModified = string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
var v = DateTimeHelper.ToOdataJson(value);
|
||||
|
||||
if (v != null)
|
||||
{
|
||||
LastModified = v;
|
||||
}
|
||||
else
|
||||
{
|
||||
LastModified = string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[DataMember(Name = "roadClosed", EmitDefaultValue = false)]
|
||||
public bool RoadClosed { get; set; }
|
||||
|
||||
[DataMember(Name = "severity", EmitDefaultValue = false)]
|
||||
public int Severity { get; set; }
|
||||
|
||||
[DataMember(Name = "toPoint", EmitDefaultValue = false)]
|
||||
public Point ToPoint { get; set; }
|
||||
|
||||
[DataMember(Name = "locationCodes", EmitDefaultValue = false)]
|
||||
public string[] LocationCodes { get; set; }
|
||||
|
||||
[DataMember(Name = "type", EmitDefaultValue = false)]
|
||||
public new int Type { get; set; }
|
||||
|
||||
[DataMember(Name = "verified", EmitDefaultValue = false)]
|
||||
public bool Verified { get; set; }
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class TransitLine
|
||||
{
|
||||
[DataMember(Name = "verboseName", EmitDefaultValue = false)]
|
||||
public string VerboseName { get; set; }
|
||||
|
||||
[DataMember(Name = "abbreviatedName", EmitDefaultValue = false)]
|
||||
public string AbbreviatedName { get; set; }
|
||||
|
||||
[DataMember(Name = "agencyId", EmitDefaultValue = false)]
|
||||
public long AgencyId { get; set; }
|
||||
|
||||
[DataMember(Name = "agencyName", EmitDefaultValue = false)]
|
||||
public string AgencyName { get; set; }
|
||||
|
||||
[DataMember(Name = "lineColor", EmitDefaultValue = false)]
|
||||
public long LineColor { get; set; }
|
||||
|
||||
[DataMember(Name = "lineTextColor", EmitDefaultValue = false)]
|
||||
public long LineTextColor { get; set; }
|
||||
|
||||
[DataMember(Name = "uri", EmitDefaultValue = false)]
|
||||
public string Uri { get; set; }
|
||||
|
||||
[DataMember(Name = "phoneNumber", EmitDefaultValue = false)]
|
||||
public string PhoneNumber { get; set; }
|
||||
|
||||
[DataMember(Name = "providerInfo", EmitDefaultValue = false)]
|
||||
public string ProviderInfo { get; set; }
|
||||
}
|
||||
|
||||
[DataContract]
|
||||
public class Warning
|
||||
{
|
||||
[DataMember(Name = "origin", EmitDefaultValue = false)]
|
||||
public string Origin { get; set; }
|
||||
|
||||
public Coordinate OriginLocation
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(Origin))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
var latLng = Origin.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
double lat, lon;
|
||||
|
||||
if(latLng.Length >= 2 && double.TryParse(latLng[0], out lat) && double.TryParse(latLng[1], out lon))
|
||||
{
|
||||
return new Coordinate(lat, lon);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
Origin = string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
Origin = string.Format("{0},{1}", value.Latitude, value.Longitude);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[DataMember(Name = "severity", EmitDefaultValue = false)]
|
||||
public string Severity { get; set; }
|
||||
|
||||
[DataMember(Name = "text", EmitDefaultValue = false)]
|
||||
public string Text { get; set; }
|
||||
|
||||
[DataMember(Name = "to", EmitDefaultValue = false)]
|
||||
public string To { get; set; }
|
||||
|
||||
public Coordinate ToCoordinate
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(To))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
var latLng = To.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
double lat, lon;
|
||||
|
||||
if (latLng.Length >= 2 && double.TryParse(latLng[0], out lat) && double.TryParse(latLng[1], out lon))
|
||||
{
|
||||
return new Coordinate(lat, lon);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
To = string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
To = string.Format("{0},{1}", value.Latitude, value.Longitude);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[DataMember(Name = "warningType", EmitDefaultValue = false)]
|
||||
public string WarningType { get; set; }
|
||||
}
|
||||
|
||||
[DataContract(Namespace = "http://schemas.microsoft.com/search/local/ws/rest/v1")]
|
||||
public class CompressedPointList : Resource
|
||||
{
|
||||
[DataMember(Name = "value", EmitDefaultValue = false)]
|
||||
public string Value { get; set; }
|
||||
}
|
||||
|
||||
[DataContract(Namespace = "http://schemas.microsoft.com/search/local/ws/rest/v1")]
|
||||
public class ElevationData : Resource
|
||||
{
|
||||
[DataMember(Name = "elevations", EmitDefaultValue = false)]
|
||||
public int[] Elevations { get; set; }
|
||||
|
||||
[DataMember(Name = "zoomLevel", EmitDefaultValue = false)]
|
||||
public int ZoomLevel { get; set; }
|
||||
}
|
||||
|
||||
[DataContract(Namespace = "http://schemas.microsoft.com/search/local/ws/rest/v1")]
|
||||
public class SeaLevelData : Resource
|
||||
{
|
||||
[DataMember(Name = "offsets", EmitDefaultValue = false)]
|
||||
public int[] Offsets { get; set; }
|
||||
|
||||
[DataMember(Name = "zoomLevel", EmitDefaultValue = false)]
|
||||
public int ZoomLevel { get; set; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,268 @@
|
|||
/*
|
||||
* Copyright(c) 2017 Microsoft Corporation. All rights reserved.
|
||||
*
|
||||
* This code is licensed under the MIT License (MIT).
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// A class that defines the options that can to use when calculating a route.
|
||||
/// </summary>
|
||||
public class RouteOptions
|
||||
{
|
||||
#region Private Properties
|
||||
|
||||
private int distanceBeforeFirstTurn = 0, heading = 0, maxSolutions = 1;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
||||
public RouteOptions()
|
||||
{
|
||||
Optimize = RouteOptimizationType.Time;
|
||||
TravelMode = TravelModeType.Driving;
|
||||
TimeType = RouteTimeType.Departure;
|
||||
DateTime = DateTime.Now.AddMinutes(15);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the road types to minimize or avoid when a route is created for the driving travel mode.
|
||||
/// </summary>
|
||||
public List<AvoidType> Avoid { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the distance before the first turn is allowed in the route.
|
||||
/// This option only applies to the driving travel mode.
|
||||
/// An integer distance specified in meters.
|
||||
/// Use this parameter to make sure that the moving vehicle has enough distance to make the first turn.
|
||||
/// </summary>
|
||||
public int DistanceBeforeFirstTurn
|
||||
{
|
||||
get { return distanceBeforeFirstTurn; }
|
||||
set
|
||||
{
|
||||
if (value >= 0)
|
||||
{
|
||||
distanceBeforeFirstTurn = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the initial heading for the route. An integer value between 0 and 359 that represents degrees from
|
||||
/// north where north is 0 degrees and the heading is specified clockwise from north.
|
||||
/// </summary>
|
||||
public int Heading
|
||||
{
|
||||
get { return heading; }
|
||||
set
|
||||
{
|
||||
if (value < 0)
|
||||
{
|
||||
heading = 0;
|
||||
}
|
||||
else if (value > 359)
|
||||
{
|
||||
heading = 359;
|
||||
}
|
||||
else
|
||||
{
|
||||
heading = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specifies what parameters to use to optimize the route.
|
||||
/// </summary>
|
||||
public RouteOptimizationType Optimize { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The mode of travel for the route. Default: Driving.
|
||||
/// </summary>
|
||||
public TravelModeType TravelMode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The dateTime parameter identifies the desired time to be used when calculating a route. This is supported by driving and transit routes.
|
||||
/// When calculating driving routes the route optimization type should be TimeWithTraffic. The route time will be used as the departure time.
|
||||
/// When calculating transit routes timeType can be specified.
|
||||
/// </summary>
|
||||
public DateTime DateTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Specifies how to interpret the date and transit time value that is specified by the dateTime parameter.
|
||||
/// </summary>
|
||||
public RouteTimeType TimeType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Specifies to include or exclude parts of the routes response.
|
||||
/// </summary>
|
||||
public List<RouteAttributeType> RouteAttributes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The units to use for distance.
|
||||
/// </summary>
|
||||
public DistanceUnitType DistanceUnits { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Specifies a series of tolerance values. Each value produces a subset of points that approximates the route
|
||||
/// that is described by the full set of points. This parameter is only valid when the routePathOutput parameter
|
||||
/// is set to Points. You can specify a maximum of seven (7) tolerance values.
|
||||
/// </summary>
|
||||
public List<double> Tolerances { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the maximum number of transit or driving routes to return. An interger between 1 and 3.
|
||||
/// This parameter is available for the Driving and Transit travel modes for routes between two waypoints.
|
||||
/// This parameter does not support routes with more than two waypoints. For driving routes, you must not set
|
||||
/// the avoid and distanceBeforeFirstTurn parameters. The maxSolutions parameter is supported for routes in
|
||||
/// the United States, Canada, Mexico, United Kingdom, Australia, and India.
|
||||
/// </summary>
|
||||
public int MaxSolutions
|
||||
{
|
||||
get { return maxSolutions; }
|
||||
set
|
||||
{
|
||||
if (value < 0)
|
||||
{
|
||||
maxSolutions = 1;
|
||||
}
|
||||
else if (value > 3)
|
||||
{
|
||||
maxSolutions = 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
maxSolutions = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Internal Methods
|
||||
|
||||
internal string GetUrlParam()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
|
||||
if (Optimize != RouteOptimizationType.Time)
|
||||
{
|
||||
sb.AppendFormat("&optmz={0}", Enum.GetName(typeof(RouteOptimizationType), Optimize));
|
||||
}
|
||||
|
||||
if (TravelMode == TravelModeType.Driving && Avoid != null && Avoid.Count > 0)
|
||||
{
|
||||
sb.Append("&avoid=");
|
||||
|
||||
for (var i = 0; i < Avoid.Count; i++)
|
||||
{
|
||||
sb.Append(Enum.GetName(typeof(AvoidType), Avoid[i]));
|
||||
|
||||
if (i < Avoid.Count - 1)
|
||||
{
|
||||
sb.Append(",");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (TravelMode == TravelModeType.Driving && distanceBeforeFirstTurn > 0)
|
||||
{
|
||||
sb.AppendFormat("&dbft={0}", distanceBeforeFirstTurn);
|
||||
}
|
||||
|
||||
if (heading > 0)
|
||||
{
|
||||
sb.AppendFormat("&hd={0}", heading);
|
||||
}
|
||||
|
||||
if (DistanceUnits != DistanceUnitType.KM)
|
||||
{
|
||||
sb.AppendFormat("&du=mi");
|
||||
}
|
||||
|
||||
if (Tolerances != null && Tolerances.Count > 0)
|
||||
{
|
||||
sb.Append("&tl=");
|
||||
|
||||
int cnt = Math.Min(Tolerances.Count, 7);
|
||||
|
||||
for (int i = 0; i < cnt; i++)
|
||||
{
|
||||
sb.AppendFormat("{0:0.######}", Tolerances[i]);
|
||||
|
||||
if (i < Tolerances.Count - 1)
|
||||
{
|
||||
sb.Append(",");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (RouteAttributes != null && RouteAttributes.Count > 0)
|
||||
{
|
||||
sb.Append("&ra=");
|
||||
|
||||
for (var i = 0; i < RouteAttributes.Count; i++)
|
||||
{
|
||||
sb.Append(Enum.GetName(typeof(RouteAttributeType), RouteAttributes[i]));
|
||||
|
||||
if (i < RouteAttributes.Count - 1)
|
||||
{
|
||||
sb.Append(",");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (DateTime != null)
|
||||
{
|
||||
if (TravelMode == TravelModeType.Transit)
|
||||
{
|
||||
sb.AppendFormat(DateTimeFormatInfo.InvariantInfo, "&dt={0:G}", DateTime);
|
||||
sb.AppendFormat("&tt={0}", Enum.GetName(typeof(RouteTimeType), TimeType));
|
||||
}
|
||||
else if (TravelMode == TravelModeType.Driving)
|
||||
{
|
||||
sb.AppendFormat(DateTimeFormatInfo.InvariantInfo, "&dt={0:G}", DateTime);
|
||||
}
|
||||
}
|
||||
|
||||
if (TravelMode != TravelModeType.Walking)
|
||||
{
|
||||
sb.AppendFormat("&maxSolns={0}", maxSolutions);
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* Copyright(c) 2017 Microsoft Corporation. All rights reserved.
|
||||
*
|
||||
* This code is licensed under the MIT License (MIT).
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// A simple address class that can be passed in to queries.
|
||||
/// </summary>
|
||||
public class SimpleAddress
|
||||
{
|
||||
#region Public Properties
|
||||
|
||||
/// <summary>
|
||||
/// The official street line of an address relative to the area, as specified by the Locality, or PostalCode, properties. Typical use of this element would be to provide a street address or any official address.
|
||||
/// </summary>
|
||||
public string AddressLine { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The locality, such as the city or neighborhood, that corresponds to an address.
|
||||
/// </summary>
|
||||
public string Locality { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The subdivision name in the country or region for an address. This element is typically treated as the first order administrative subdivision, but in some cases it is the second, third, or fourth order subdivision in a country, dependency, or region.
|
||||
/// </summary>
|
||||
public string AdminDistrict { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The post code, postal code, or ZIP Code of an address.
|
||||
/// </summary>
|
||||
public string PostalCode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The ISO country code for the country.
|
||||
/// </summary>
|
||||
public string CountryRegion { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* Copyright(c) 2017 Microsoft Corporation. All rights reserved.
|
||||
*
|
||||
* This code is licensed under the MIT License (MIT).
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// A simple waypoint class that can be used to calculate a route.
|
||||
/// </summary>
|
||||
public class SimpleWaypoint
|
||||
{
|
||||
#region Constructor
|
||||
|
||||
/// <summary>
|
||||
/// A waypoint to calculate a route through.
|
||||
/// </summary>
|
||||
public SimpleWaypoint()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A waypoint to calculate a route through.
|
||||
/// </summary>
|
||||
/// <param name="coordinate">Coordinate of the waypoint.</param>
|
||||
public SimpleWaypoint(Coordinate coordinate)
|
||||
{
|
||||
this.Coordinate = coordinate;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A waypoint to calculate a route through.
|
||||
/// </summary>
|
||||
/// <param name="address">Address or location description of waypoint.</param>
|
||||
public SimpleWaypoint(string address)
|
||||
{
|
||||
this.Address = address;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A waypoint to calculate a route through.
|
||||
/// </summary>
|
||||
/// <param name="coordinate">Coordinate of the waypoint.</param>
|
||||
/// <param name="address">Address or location description of waypoint.</param>
|
||||
public SimpleWaypoint(Coordinate coordinate, string address)
|
||||
{
|
||||
this.Coordinate = coordinate;
|
||||
this.Address = address;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
|
||||
/// <summary>
|
||||
/// The coordinate of the waypoint. When specified this will be used instead of the Address value in requests.
|
||||
/// </summary>
|
||||
public Coordinate Coordinate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The address query for the waypoint.
|
||||
/// </summary>
|
||||
public string Address { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// A bool indicating whether the waypoint is a via point.
|
||||
/// </summary>
|
||||
public bool IsViaPoint { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
using System.Resources;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("Bing Maps REST Toolkit")]
|
||||
[assembly: AssemblyDescription("A toolkit that makes it easy to access the Bing Maps REST services from .NET")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Microsoft")]
|
||||
[assembly: AssemblyProduct("BingMapsRESTToolkit")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2017")]
|
||||
[assembly: AssemblyTrademark("Microsoft")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: NeutralResourcesLanguage("en")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright(c) 2017 Microsoft Corporation. All rights reserved.
|
||||
*
|
||||
* This code is licensed under the MIT License (MIT).
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// Abstract class that all Imagery rest requests will derive from.
|
||||
/// </summary>
|
||||
public abstract class BaseImageryRestRequest : BaseRestRequest
|
||||
{
|
||||
}
|
||||
}
|
|
@ -0,0 +1,100 @@
|
|||
/*
|
||||
* Copyright(c) 2017 Microsoft Corporation. All rights reserved.
|
||||
*
|
||||
* This code is licensed under the MIT License (MIT).
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// An abstract class in which all REST service requests derive from.
|
||||
/// </summary>
|
||||
[DataContract]
|
||||
public abstract class BaseRestRequest
|
||||
{
|
||||
public const string baseServiceUrl = "https://dev.virtualearth.net/REST/v1/";
|
||||
|
||||
#region Public Properties
|
||||
|
||||
/// <summary>
|
||||
/// The Bing Maps key for making the request.
|
||||
/// </summary>
|
||||
public string BingMapsKey;
|
||||
|
||||
/// <summary>
|
||||
/// The culture to use for the request.
|
||||
/// </summary>
|
||||
public string Culture;
|
||||
|
||||
/// <summary>
|
||||
/// The geographic region that corresponds to the current viewport.
|
||||
/// </summary>
|
||||
public BoundingBox UserMapView;
|
||||
|
||||
/// <summary>
|
||||
/// The user’s current position.
|
||||
/// </summary>
|
||||
public Coordinate UserLocation;
|
||||
|
||||
/// <summary>
|
||||
/// An Internet Protocol version 4 (IPv4) address.
|
||||
/// </summary>
|
||||
public string UserIp;
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Abstract method which generates the Bing Maps REST request URL.
|
||||
/// </summary>
|
||||
/// <returns>A Bing Maps REST request URL.</returns>
|
||||
public abstract string GetRequestUrl();
|
||||
|
||||
internal string GetBaseRequestUrl()
|
||||
{
|
||||
var url = string.Empty;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(Culture))
|
||||
{
|
||||
url += "&c=" + Culture;
|
||||
}
|
||||
|
||||
if(UserMapView != null){
|
||||
//South Latitude, West Longitude, North Latitude, East Longitude
|
||||
url += string.Format("&umv={0}", UserMapView.ToString());
|
||||
}
|
||||
|
||||
if (UserLocation != null)
|
||||
{
|
||||
url += string.Format("&ul={0:0.#####},{1:0.#####}", UserLocation.Latitude, UserLocation.Longitude);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(UserIp))
|
||||
{
|
||||
url += "&uip=" + UserIp;
|
||||
}
|
||||
|
||||
return url + "&key=" + BingMapsKey + "&clientApi=CSToolkit";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,332 @@
|
|||
/*
|
||||
* Copyright(c) 2017 Microsoft Corporation. All rights reserved.
|
||||
*
|
||||
* This code is licensed under the MIT License (MIT).
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
//http://msdn.microsoft.com/en-us/library/jj158961.aspx
|
||||
|
||||
/// <summary>
|
||||
/// A request for elevation data.
|
||||
/// </summary>
|
||||
public class ElevationRequest : BaseRestRequest
|
||||
{
|
||||
#region Private Properties
|
||||
|
||||
private int row = 2, col = 2, samples = 0;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
|
||||
/// <summary>
|
||||
/// A set of coordinates on the Earth to use in elevation calculations.
|
||||
/// The exact use of these points depends on the type of elevation request.
|
||||
/// Overrides the Bounds value if both are specified.
|
||||
/// The maximum number of points is 1024.
|
||||
/// </summary>
|
||||
public List<Coordinate> Points { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the rectangular area over which to provide elevation values.
|
||||
/// </summary>
|
||||
public BoundingBox Bounds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the number of rows to use to divide the bounding box area into a grid. The rows and columns that define the bounding box each count as two (2) of the rows and columns. Elevation values are returned for all vertices of the grid.
|
||||
/// </summary>
|
||||
public int Row
|
||||
{
|
||||
get { return row; }
|
||||
set
|
||||
{
|
||||
if (value < 2)
|
||||
{
|
||||
row = 2;
|
||||
}
|
||||
else if (value > 512)
|
||||
{
|
||||
row = 512;
|
||||
}
|
||||
else
|
||||
{
|
||||
row = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the number of columns to use to divide the bounding box area into a grid. The rows and columns that define the bounding box each count as two (2) of the rows and columns. Elevation values are returned for all vertices of the grid.
|
||||
/// </summary>
|
||||
public int Col
|
||||
{
|
||||
get { return col; }
|
||||
set
|
||||
{
|
||||
if (value < 2)
|
||||
{
|
||||
col = 2;
|
||||
}else if (value > 512){
|
||||
col = 512;
|
||||
}
|
||||
else
|
||||
{
|
||||
col = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the number of equally-spaced elevation values to provide along a polyline path. Used when Points value is set. Make = 1024
|
||||
/// </summary>
|
||||
public int Samples
|
||||
{
|
||||
get { return samples; }
|
||||
set
|
||||
{
|
||||
if (value < 0)
|
||||
{
|
||||
samples = 0;
|
||||
}
|
||||
else if (value > 1024)
|
||||
{
|
||||
samples = 1024;
|
||||
}
|
||||
else
|
||||
{
|
||||
samples = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specifies which sea level model to use to calculate elevation.
|
||||
/// </summary>
|
||||
public ElevationType Height { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// A boolean indicating if the offset from the geoid should be returned. Requires a list of points to be specified.
|
||||
/// </summary>
|
||||
public bool GetGeoidOffset { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Gets a URL for requesting elevation data for a GET request.
|
||||
/// </summary>
|
||||
/// <returns>Elevation request URL for GET request.</returns>
|
||||
public override string GetRequestUrl()
|
||||
{
|
||||
return GetPostRequestUrl() + "&" + GetPointsAsString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a URL for requesting elevation data for a POST request.
|
||||
/// </summary>
|
||||
/// <returns>Elevation request URL for POST request.</returns>
|
||||
public string GetPostRequestUrl()
|
||||
{
|
||||
//https://dev.virtualearth.net/REST/v1/Elevation/Bounds?bounds=boundingBox&rows=rows&cols=cols&heights=heights&key=BingMapsKey
|
||||
//https://dev.virtualearth.net/REST/v1/Elevation/SeaLevel?points=lat1,long1,lat2,long2,latn,longn&key=BingMapsKey
|
||||
//https://dev.virtualearth.net/REST/v1/Elevation/List?points=lat1,long1,lat2,long2,latn,longn&heights=heights&key=BingMapsKey
|
||||
//https://dev.virtualearth.net/REST/v1/Elevation/Polyline?points=lat1,long1,lat2,long2,latn,longn&heights=heights&samples=samples&key=BingMapsKey
|
||||
|
||||
var sb = new StringBuilder();
|
||||
sb.Append("https://dev.virtualearth.net/REST/v1/Elevation/");
|
||||
|
||||
string seperator = "?";
|
||||
|
||||
if (Points != null && Points.Count > 0)
|
||||
{
|
||||
if (GetGeoidOffset)
|
||||
{
|
||||
//Get elevation geoid offsets
|
||||
sb.Append("SeaLevel");
|
||||
}
|
||||
else if (samples == 0)
|
||||
{
|
||||
//Get elevations for a list of points
|
||||
sb.Append("List");
|
||||
}
|
||||
else
|
||||
{
|
||||
//Get elevations along a Polyline with samples
|
||||
sb.AppendFormat("Polyline?samples={0}", samples);
|
||||
seperator = "&";
|
||||
}
|
||||
}
|
||||
else if (Bounds != null)
|
||||
{
|
||||
if (Row * Col > 1024)
|
||||
{
|
||||
throw new Exception("Row * Col value is greater than 1024.");
|
||||
}
|
||||
|
||||
sb.AppendFormat("Bounds?bounds=boundingBox&rows={0}&cols={1}", row, col);
|
||||
seperator = "&";
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("No Points or Bounds value specified.");
|
||||
}
|
||||
|
||||
if (!GetGeoidOffset && Height == ElevationType.Ellipsoid)
|
||||
{
|
||||
sb.AppendFormat("{0}height=ellipsoid", seperator);
|
||||
}
|
||||
|
||||
sb.AppendFormat("{0}key={1}", seperator, BingMapsKey);
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the Point information as a formated string. Only the first 1024 points will be used.
|
||||
/// </summary>
|
||||
/// <returns>A formatted string of point data.</returns>
|
||||
public string GetPointsAsString()
|
||||
{
|
||||
//points=38.8895,77.0501,38.8877,-77.0472,38.8904,-77.0474,38.8896,77.0351
|
||||
|
||||
var sb = new StringBuilder();
|
||||
sb.Append("points=");
|
||||
|
||||
if (Points != null && Points.Count > 0)
|
||||
{
|
||||
int max = Math.Min(Points.Count, 1024);
|
||||
|
||||
for (var i = 0; i < max; i++)
|
||||
{
|
||||
//Only need 5 decimal places. Any more are insignificant.
|
||||
sb.AppendFormat("{0:0.#####},{1:0.#####}", Points[i].Latitude, Points[i].Longitude);
|
||||
|
||||
if (i < max - 1)
|
||||
{
|
||||
sb.Append(",");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of coordinates that are related to the returned index of the elevation data.
|
||||
/// </summary>
|
||||
/// <returns>A list of coordinates that are related to the index of the returned elevation data.</returns>
|
||||
public List<Coordinate> GetElevationCoordinates()
|
||||
{
|
||||
if (Points != null && Points.Count > 0)
|
||||
{
|
||||
if (GetGeoidOffset || samples == 0)
|
||||
{
|
||||
return Points;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Calculate distance of polyline
|
||||
double totalDistance = 0;
|
||||
for (int i = 0; i < Points.Count - 1; i++)
|
||||
{
|
||||
totalDistance += SpatialTools.HaversineDistance(Points[i], Points[i + 1], DistanceUnitType.KM);
|
||||
}
|
||||
|
||||
double segementLength = totalDistance / samples;
|
||||
|
||||
var coords = new List<Coordinate>(samples);
|
||||
coords.Add(Points[0]);
|
||||
|
||||
int idx = 0;
|
||||
|
||||
//Calculate equally spaced coordinates along polyline
|
||||
for(var s = 0; s < samples; s++)
|
||||
{
|
||||
double dist = 0;
|
||||
double travel = segementLength * s;
|
||||
double dx = travel;
|
||||
|
||||
for (var i = 0; i < Points.Count - 1; i++)
|
||||
{
|
||||
dist += SpatialTools.HaversineDistance(Points[i], Points[i + 1], DistanceUnitType.KM);
|
||||
|
||||
if (dist >= travel)
|
||||
{
|
||||
idx = i;
|
||||
break;
|
||||
}
|
||||
|
||||
dx = travel - dist;
|
||||
}
|
||||
|
||||
if (dx != 0 && idx < Points.Count - 1)
|
||||
{
|
||||
var bearing = SpatialTools.CalculateBearing(Points[idx], Points[idx + 1]);
|
||||
coords.Add(SpatialTools.CalculateCoord(Points[idx], bearing, dx, DistanceUnitType.KM));
|
||||
}
|
||||
}
|
||||
|
||||
return coords;
|
||||
}
|
||||
}
|
||||
else if (Bounds != null)
|
||||
{
|
||||
double dLat = Math.Abs(Bounds.NorthLatitude - Bounds.SouthLatitude) / row;
|
||||
double dLon = Math.Abs(Bounds.WestLongitude - Bounds.EastLongitude) / col;
|
||||
|
||||
double x, y;
|
||||
|
||||
var coords = new Coordinate[row * col];
|
||||
//The elevation values are ordered starting with the southwest corner, and then proceed west to east and south to north.
|
||||
for (int r = 0; r < row; r++)
|
||||
{
|
||||
y = Bounds.SouthLatitude + (dLat * r);
|
||||
|
||||
for (int c = 0; c < col; c++)
|
||||
{
|
||||
x = Bounds.WestLongitude + (dLon * c);
|
||||
|
||||
int idx = r * row + c;
|
||||
|
||||
coords[idx] = new Coordinate()
|
||||
{
|
||||
Latitude = y,
|
||||
Longitude = x
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return new List<Coordinate>(coords);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,150 @@
|
|||
/*
|
||||
* Copyright(c) 2017 Microsoft Corporation. All rights reserved.
|
||||
*
|
||||
* This code is licensed under the MIT License (MIT).
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// Geocodes a query to it's coordinates.
|
||||
/// </summary>
|
||||
public class GeocodeRequest : BaseRestRequest
|
||||
{
|
||||
#region Private Properties
|
||||
|
||||
private int maxResults = 5;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
|
||||
/// <summary>
|
||||
/// A free form string address or Landmark. Overrides the Address values if both are specified.
|
||||
/// </summary>
|
||||
public string Query { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The Address to geocode.
|
||||
/// </summary>
|
||||
public SimpleAddress Address { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the maximum number of locations to return in the response.
|
||||
/// </summary>
|
||||
public int MaxResults
|
||||
{
|
||||
get { return maxResults; }
|
||||
set {
|
||||
if (value > 0 && value <= 20)
|
||||
{
|
||||
maxResults = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When you specified the two-letter ISO country code is included for addresses in the response.
|
||||
/// </summary>
|
||||
public bool IncludeIso2 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Specifies to include the neighborhood in the response when it is available.
|
||||
/// </summary>
|
||||
public bool IncludeNeighborhood { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Gets the request URL. If both a Query and Address are specified the Query value will be used. Throws an exception if a Query or Address value is not specified.
|
||||
/// </summary>
|
||||
/// <returns>Geocode request URL for GET request.</returns>
|
||||
public override string GetRequestUrl()
|
||||
{
|
||||
string url = "https://dev.virtualearth.net/REST/v1/Locations";
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(Query))
|
||||
{
|
||||
url += string.Format("?q={0}", Uri.EscapeDataString(Query));
|
||||
}
|
||||
else if (Address != null)
|
||||
{
|
||||
string seperator = "?";
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(Address.AddressLine))
|
||||
{
|
||||
url += string.Format("{0}addressLine={1}", seperator, Uri.EscapeDataString(Address.AddressLine));
|
||||
seperator = "&";
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(Address.Locality))
|
||||
{
|
||||
url += string.Format("{0}locality={1}", seperator, Uri.EscapeDataString(Address.Locality));
|
||||
seperator = "&";
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(Address.AdminDistrict))
|
||||
{
|
||||
url += string.Format("{0}adminDistrict={1}", seperator, Uri.EscapeDataString(Address.AdminDistrict));
|
||||
seperator = "&";
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(Address.PostalCode))
|
||||
{
|
||||
url += string.Format("{0}postalCode={1}", seperator, Uri.EscapeDataString(Address.PostalCode));
|
||||
seperator = "&";
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(Address.CountryRegion))
|
||||
{
|
||||
url += string.Format("{0}countryRegion={1}", seperator, Uri.EscapeDataString(Address.CountryRegion));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("No Query or Address value specified.");
|
||||
}
|
||||
|
||||
if (IncludeIso2)
|
||||
{
|
||||
url += "&incl=ciso2";
|
||||
}
|
||||
|
||||
if (IncludeNeighborhood)
|
||||
{
|
||||
url += "&inclnb=1";
|
||||
}
|
||||
|
||||
if (maxResults != 5)
|
||||
{
|
||||
url += "&maxResults=" + maxResults;
|
||||
}
|
||||
|
||||
return url + GetBaseRequestUrl();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,184 @@
|
|||
/*
|
||||
* Copyright(c) 2017 Microsoft Corporation. All rights reserved.
|
||||
*
|
||||
* This code is licensed under the MIT License (MIT).
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
//https://msdn.microsoft.com/en-us/library/ff701716.aspx
|
||||
|
||||
/// <summary>
|
||||
/// Requests imagery metadata information from Bing Maps.
|
||||
/// </summary>
|
||||
public class ImageryMetadataRequest : BaseRestRequest
|
||||
{
|
||||
#region Private Properties
|
||||
|
||||
private double orientation = 0;
|
||||
private int zoomLevel = 0;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
|
||||
/// <summary>
|
||||
/// The type of imagery for which you are requesting metadata.
|
||||
/// </summary>
|
||||
public ImageryType ImagerySet { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Required when imagerySet is Birdseye or BirdseyeWithLabels. Optional for other imagery sets. The center point to use for the imagery metadata.
|
||||
/// </summary>
|
||||
public Coordinate CenterPoint { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Get only the basic metadata for an imagery set at a specific location. This URL does not return a map tile URL.
|
||||
/// </summary>
|
||||
public bool GetBasicInfo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// When you specified the two-letter ISO country code is included for addresses in the response.
|
||||
/// </summary>
|
||||
public bool IncludeImageryProviders { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The orientation of the viewport to use for the imagery metadata. This option only applies to Birdseye imagery.
|
||||
/// </summary>
|
||||
public double Orientation
|
||||
{
|
||||
get { return orientation; }
|
||||
set
|
||||
{
|
||||
if (value < 0)
|
||||
{
|
||||
orientation = value % 360 + 360;
|
||||
}
|
||||
else if (value > 360)
|
||||
{
|
||||
orientation = value % 360;
|
||||
}
|
||||
else
|
||||
{
|
||||
orientation = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Required if a centerPoint is specified and imagerySet is set to Road, Aerial or AerialWithLabels The level of zoom to use for the imagery metadata.
|
||||
/// </summary>
|
||||
public int ZoomLevel
|
||||
{
|
||||
get { return zoomLevel; }
|
||||
set
|
||||
{
|
||||
if (value < 1)
|
||||
{
|
||||
zoomLevel = 1;
|
||||
}
|
||||
else if (value > 21)
|
||||
{
|
||||
zoomLevel = 21;
|
||||
}
|
||||
else
|
||||
{
|
||||
zoomLevel = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When set to true tile URL's will use HTTPS.
|
||||
/// </summary>
|
||||
public bool UseHTTPS { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Gets the request URL. Throws an exception if a zoom level is not specified when a centerPoint is specified when ImagerySet is Road, Aerial and AerialWithLabels.
|
||||
/// </summary>
|
||||
/// <returns>Imagery Metadata request URL for GET request.</returns>
|
||||
public override string GetRequestUrl()
|
||||
{
|
||||
string url = "https://dev.virtualearth.net/REST/v1/Imagery/";
|
||||
|
||||
if (GetBasicInfo)
|
||||
{
|
||||
url += "BasicMetadata/";
|
||||
}
|
||||
else
|
||||
{
|
||||
url += "Metadata/";
|
||||
}
|
||||
|
||||
url += Enum.GetName(typeof(ImageryType), ImagerySet);
|
||||
|
||||
if (CenterPoint != null)
|
||||
{
|
||||
url += string.Format("/{0:0.#####},{1:0.#####}?", CenterPoint.Latitude, CenterPoint.Longitude);
|
||||
|
||||
if (ImagerySet == ImageryType.Road || ImagerySet == ImageryType.Aerial || ImagerySet == ImageryType.AerialWithLabels)
|
||||
{
|
||||
if (zoomLevel == 0)
|
||||
{
|
||||
throw new Exception("Zoom Level must be specified when a centerPoint is specified and ImagerySet is Road, Aerial and AerialWithLabels.");
|
||||
}
|
||||
else
|
||||
{
|
||||
url += "zl=" + zoomLevel;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
url += "?";
|
||||
}
|
||||
|
||||
if (orientation != 0)
|
||||
{
|
||||
url += "&dir=" + orientation;
|
||||
}
|
||||
|
||||
if (IncludeImageryProviders)
|
||||
{
|
||||
url += "&incl=ImageryProviders";
|
||||
}
|
||||
|
||||
if (UseHTTPS)
|
||||
{
|
||||
url += "&uriScheme=https";
|
||||
}
|
||||
|
||||
return url + GetBaseRequestUrl();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,339 @@
|
|||
/*
|
||||
* Copyright(c) 2017 Microsoft Corporation. All rights reserved.
|
||||
*
|
||||
* This code is licensed under the MIT License (MIT).
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
//https://msdn.microsoft.com/en-us/library/ff701724.aspx
|
||||
|
||||
/// <summary>
|
||||
/// Requests an image from the REST imagery service.
|
||||
/// </summary>
|
||||
public class ImageryRequest : BaseImageryRestRequest
|
||||
{
|
||||
#region Private Properties
|
||||
|
||||
private int mapWidth = 350;
|
||||
private int mapHeight = 350;
|
||||
private int zoomLevel = 0;
|
||||
|
||||
private const int minMapWidth = 80;
|
||||
private const int minMapHeight = 80;
|
||||
private const int maxMapWidth = 2000;
|
||||
private const int maxMapHeight = 1500;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
|
||||
/// <summary>
|
||||
/// The type of imagery for which you are requesting metadata.
|
||||
/// </summary>
|
||||
public ImageryType ImagerySet { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Required when imagerySet is Birdseye or BirdseyeWithLabels. Optional for other imagery sets. The center point to use for the imagery metadata.
|
||||
/// </summary>
|
||||
public Coordinate CenterPoint { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Specifies whether to change the display of overlapping pushpins so that they display separately on a map.
|
||||
/// </summary>
|
||||
public bool DeclutterPins { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The image format to use for the static map.
|
||||
/// </summary>
|
||||
public ImageFormatType? Format { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Required when a center point or set of route points are not specified. The geographic area to display on the map.
|
||||
/// </summary>
|
||||
public BoundingBox MapArea { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Specifies if the traffic flow layer should be displayed on the map or not. Default is false.
|
||||
/// </summary>
|
||||
public bool ShowTraffic { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The width of the map. Default is 350px.
|
||||
/// </summary>
|
||||
public int MapWidth
|
||||
{
|
||||
get { return mapWidth; }
|
||||
set
|
||||
{
|
||||
if (value < minMapWidth)
|
||||
{
|
||||
mapWidth = minMapWidth;
|
||||
}
|
||||
else if (value > maxMapWidth)
|
||||
{
|
||||
mapWidth = maxMapWidth;
|
||||
}
|
||||
else
|
||||
{
|
||||
mapWidth = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The height of the map. Default is 350px.
|
||||
/// </summary>
|
||||
public int MapHeight
|
||||
{
|
||||
get { return mapHeight; }
|
||||
set
|
||||
{
|
||||
if (value < minMapHeight)
|
||||
{
|
||||
mapHeight = minMapHeight;
|
||||
}
|
||||
else if (value > maxMapHeight)
|
||||
{
|
||||
mapHeight = maxMapHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
mapHeight = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Optional. Specifies whether to return metadata for the static map instead of the image.
|
||||
/// The static map metadata includes the size of the static map and the placement and size
|
||||
/// of the pushpins on the static map.
|
||||
/// </summary>
|
||||
public bool GetMetadata { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// A query string that is used to determine the map location to display.
|
||||
/// </summary>
|
||||
public string Query { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The level of zoom to display.
|
||||
/// </summary>
|
||||
public int ZoomLevel
|
||||
{
|
||||
get { return zoomLevel; }
|
||||
set
|
||||
{
|
||||
if (value < 1)
|
||||
{
|
||||
zoomLevel = 1;
|
||||
}
|
||||
else if (value > 21)
|
||||
{
|
||||
zoomLevel = 21;
|
||||
}
|
||||
else
|
||||
{
|
||||
zoomLevel = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Highlights a polygon for an entity.
|
||||
/// </summary>
|
||||
public bool HighlightEntity { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicates the type of entity that should be highlighted. The entity of this type that
|
||||
/// contains the centerPoint will be highlighted. Supported EntityTypes: CountryRegion, AdminDivision1, or PopulatedPlace.
|
||||
/// </summary>
|
||||
public EntityType? EntityType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// List of pushpins to display on the map.
|
||||
/// </summary>
|
||||
public List<ImageryPushpin> Pushpins { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Specifies two or more locations that define the route and that are in sequential order.
|
||||
/// A route is defined by a set of waypoints and viaWaypoints (intermediate locations that the route must pass through).
|
||||
/// You can have a maximum of 25 waypoints, and a maximum of 10 viaWaypoints between each set of waypoints.
|
||||
/// The start and end points of the route cannot be viaWaypoints.
|
||||
/// </summary>
|
||||
public List<SimpleWaypoint> Waypoints { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Options for calculating route.
|
||||
/// </summary>
|
||||
public RouteOptions RouteOptions { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Gets the request URL. If both a Query and Address are specified the Query value will be used.
|
||||
/// Throws an exception if a Query or Address value is not specified.
|
||||
/// </summary>
|
||||
/// <returns>Geocode request URL for GET request.</returns>
|
||||
public override string GetRequestUrl()
|
||||
{
|
||||
return GetPostRequestUrl() + "&" + GetPushpinsAsString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a URL for requesting imagery data for a POST request.
|
||||
/// </summary>
|
||||
/// <returns>Imagery request URL for POST request.</returns>
|
||||
public string GetPostRequestUrl()
|
||||
{
|
||||
var isQuery = !string.IsNullOrWhiteSpace(Query);
|
||||
var isRoute = (Waypoints != null && Waypoints.Count >= 2);
|
||||
|
||||
var sb = new StringBuilder();
|
||||
sb.Append("https://dev.virtualearth.net/REST/v1/Imagery/Map/");
|
||||
|
||||
sb.Append(Enum.GetName(typeof(ImageryType), ImagerySet));
|
||||
|
||||
if (CenterPoint != null)
|
||||
{
|
||||
sb.AppendFormat("/{0:0.#####},{1:0.#####}/", CenterPoint.Latitude, CenterPoint.Longitude);
|
||||
|
||||
if (zoomLevel != 0)
|
||||
{
|
||||
sb.Append(zoomLevel);
|
||||
}
|
||||
else if (HighlightEntity)
|
||||
{
|
||||
sb.Append(Enum.GetName(typeof(EntityType), EntityType));
|
||||
}
|
||||
else if (ImagerySet == ImageryType.Road || ImagerySet == ImageryType.Aerial || ImagerySet == ImageryType.AerialWithLabels)
|
||||
{
|
||||
throw new Exception("A zoom level or Entity type must be specified when when a center point is specified.");
|
||||
}
|
||||
}
|
||||
else if (isQuery)
|
||||
{
|
||||
sb.AppendFormat("/{0}", Uri.EscapeDataString(Query));
|
||||
}
|
||||
|
||||
if (isRoute)
|
||||
{
|
||||
sb.AppendFormat("/Routes/{0}?", Enum.GetName(typeof(TravelModeType), (RouteOptions != null) ? RouteOptions.TravelMode : TravelModeType.Driving));
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Append("?");
|
||||
}
|
||||
|
||||
sb.AppendFormat("ms={0},{1}", mapWidth, mapHeight);
|
||||
|
||||
if (DeclutterPins)
|
||||
{
|
||||
sb.Append("&dcl=1");
|
||||
}
|
||||
|
||||
if (Format.HasValue)
|
||||
{
|
||||
sb.AppendFormat("&fmt={0}", Enum.GetName(typeof(ImageFormatType), Format.Value));
|
||||
}
|
||||
|
||||
if (MapArea != null && (CenterPoint == null || !isRoute))
|
||||
{
|
||||
sb.AppendFormat("&ma={0}", MapArea.ToString());
|
||||
}
|
||||
|
||||
if (ShowTraffic)
|
||||
{
|
||||
sb.Append("&ml=TrafficFlow");
|
||||
}
|
||||
|
||||
if (GetMetadata)
|
||||
{
|
||||
sb.Append("&mmd=1");
|
||||
}
|
||||
|
||||
if (HighlightEntity)
|
||||
{
|
||||
sb.Append("&he=1");
|
||||
}
|
||||
|
||||
//Routing Parameters
|
||||
|
||||
if (isRoute)
|
||||
{
|
||||
if (Waypoints.Count > 25)
|
||||
{
|
||||
throw new Exception("More than 25 waypoints in route request.");
|
||||
}
|
||||
|
||||
for (int i = 0; i < Waypoints.Count; i++)
|
||||
{
|
||||
|
||||
sb.AppendFormat("&wp.{0}=", i);
|
||||
|
||||
if (Waypoints[i].Coordinate != null)
|
||||
{
|
||||
sb.AppendFormat("{0:0.#####},{1:0.#####}", Waypoints[i].Coordinate.Latitude, Waypoints[i].Coordinate.Longitude);
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.AppendFormat("{0}", Uri.EscapeDataString(Waypoints[i].Address));
|
||||
}
|
||||
}
|
||||
|
||||
if (RouteOptions != null)
|
||||
{
|
||||
sb.Append(RouteOptions.GetUrlParam());
|
||||
}
|
||||
}
|
||||
|
||||
sb.Append(GetBaseRequestUrl());
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the Pushpin information as a formated string.
|
||||
/// </summary>
|
||||
/// <returns>A formatted string of pushpin data.</returns>
|
||||
public string GetPushpinsAsString()
|
||||
{
|
||||
//pp=38.889586530732335,-77.05010175704956;23;LMT&pp=38.88772364638439,-77.0472639799118;7;KMT
|
||||
|
||||
if (Pushpins != null && Pushpins.Count > 0)
|
||||
{
|
||||
var s = String.Join("&", Pushpins);
|
||||
return s;
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* Copyright(c) 2017 Microsoft Corporation. All rights reserved.
|
||||
*
|
||||
* This code is licensed under the MIT License (MIT).
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// Requests a that converts a coordinate into a location such as an address.
|
||||
/// </summary>
|
||||
public class ReverseGeocodeRequest : BaseRestRequest
|
||||
{
|
||||
#region Public Properties
|
||||
|
||||
/// <summary>
|
||||
/// A centeral coordinate to perform the nearby search.
|
||||
/// </summary>
|
||||
public Coordinate Point { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the entity types that you want to return in the response. Only the types you specify will be returned. If the point cannot be mapped to the entity types you specify, no location information is returned in the response.
|
||||
/// </summary>
|
||||
public List<EntityType> IncludeEntityTypes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// When you specified the two-letter ISO country code is included for addresses in the response.
|
||||
/// </summary>
|
||||
public bool IncludeIso2 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Specifies to include the neighborhood in the response when it is available.
|
||||
/// </summary>
|
||||
public bool IncludeNeighborhood { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public override string GetRequestUrl()
|
||||
{
|
||||
string url = string.Format("https://dev.virtualearth.net/REST/v1/Locations/{0:0.#####},{1:0.#####}?",
|
||||
Point.Latitude,
|
||||
Point.Longitude);
|
||||
|
||||
if (IncludeEntityTypes != null && IncludeEntityTypes.Count > 0)
|
||||
{
|
||||
url += "&includeEntityTypes=";
|
||||
for (var i = 0; i < IncludeEntityTypes.Count; i++)
|
||||
{
|
||||
url += Enum.GetName(typeof(EntityType), IncludeEntityTypes[i]);
|
||||
|
||||
if (i < IncludeEntityTypes.Count - 1)
|
||||
{
|
||||
url += ",";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (IncludeIso2)
|
||||
{
|
||||
url += "&incl=ciso2";
|
||||
}
|
||||
|
||||
if (IncludeNeighborhood)
|
||||
{
|
||||
url += "&inclnb=1";
|
||||
}
|
||||
|
||||
return url + GetBaseRequestUrl();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
/*
|
||||
* Copyright(c) 2017 Microsoft Corporation. All rights reserved.
|
||||
*
|
||||
* This code is licensed under the MIT License (MIT).
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// Requests routes from a location to major nearby roads.
|
||||
/// </summary>
|
||||
public class RouteMajorRoadsRequest : BaseRestRequest
|
||||
{
|
||||
#region Public Properties
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the final location for all the routes.
|
||||
/// A destination can be specified as a Point, a landmark, or an address.
|
||||
/// </summary>
|
||||
public SimpleWaypoint Destination { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Specifies to return only starting points for each major route in the response.
|
||||
/// When this option is not specified, detailed directions for each route are returned.
|
||||
/// </summary>
|
||||
public bool ExcludeInstructions { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The units to use for distance.
|
||||
/// </summary>
|
||||
public DistanceUnitType DistanceUnits { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Specifies to include or exclude parts of the routes response.
|
||||
/// </summary>
|
||||
public List<RouteAttributeType> RouteAttributes { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public override string GetRequestUrl()
|
||||
{
|
||||
//https://dev.virtualearth.net/REST/v1/Routes/FromMajorRoads?destination=destination&exclude=routes&rpo=routePathOutput&du=distanceUnit&key=BingMapsKey
|
||||
|
||||
if (Destination == null || (Destination.Coordinate == null && !string.IsNullOrWhiteSpace(Destination.Address)))
|
||||
{
|
||||
throw new Exception("Destination value is invalid.");
|
||||
}
|
||||
|
||||
string url = string.Format("https://dev.virtualearth.net/REST/v1/Routes/FromMajorRoads?destination=");
|
||||
|
||||
if (Destination.Coordinate != null)
|
||||
{
|
||||
url += string.Format("{0:0.#####},{1:0.#####}", Destination.Coordinate.Latitude, Destination.Coordinate.Longitude);
|
||||
}
|
||||
else
|
||||
{
|
||||
url += Uri.EscapeDataString(Destination.Address);
|
||||
}
|
||||
|
||||
if (ExcludeInstructions)
|
||||
{
|
||||
url += "&exclude=routes";
|
||||
}
|
||||
|
||||
if (RouteAttributes != null && RouteAttributes.Count > 0)
|
||||
{
|
||||
url += "&ra=";
|
||||
|
||||
for (var i = 0; i < RouteAttributes.Count; i++)
|
||||
{
|
||||
url += Enum.GetName(typeof(RouteAttributeType), RouteAttributes[i]);
|
||||
|
||||
if (i < RouteAttributes.Count - 1)
|
||||
{
|
||||
url += ",";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (DistanceUnits == DistanceUnitType.KM)
|
||||
{
|
||||
url += "&distanceUnit=mi";
|
||||
}
|
||||
|
||||
return url + GetBaseRequestUrl();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,132 @@
|
|||
/*
|
||||
* Copyright(c) 2017 Microsoft Corporation. All rights reserved.
|
||||
*
|
||||
* This code is licensed under the MIT License (MIT).
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// A request that calculates routes between waypoints.
|
||||
/// </summary>
|
||||
public class RouteRequest : BaseRestRequest
|
||||
{
|
||||
#region Public Properties
|
||||
|
||||
/// <summary>
|
||||
/// Specifies two or more locations that define the route and that are in sequential order.
|
||||
/// A route is defined by a set of waypoints and viaWaypoints (intermediate locations that the route must pass through).
|
||||
/// You can have a maximum of 25 waypoints, and a maximum of 10 viaWaypoints between each set of waypoints.
|
||||
/// The start and end points of the route cannot be viaWaypoints.
|
||||
/// </summary>
|
||||
public List<SimpleWaypoint> Waypoints { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Options to use when calculate route.
|
||||
/// </summary>
|
||||
public RouteOptions RouteOptions { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public override string GetRequestUrl()
|
||||
{
|
||||
//https://dev.virtualearth.net/REST/v1/Routes?wayPoint.1=wayPoint1&viaWaypoint.2=viaWaypoint2&waypoint.3=wayPoint3&wayPoint.n=wayPointn&heading=heading&optimize=optimize&avoid=avoidOptions&distanceBeforeFirstTurn=distanceBeforeFirstTurn&routeAttributes=routeAttributes&maxSolutions=maxSolutions&tolerances=tolerance1,tolerance2,tolerancen&distanceUnit=distanceUnit&mfa=mfa&key=BingMapsKey
|
||||
|
||||
if (Waypoints == null)
|
||||
{
|
||||
throw new Exception("Waypoints not specified.");
|
||||
}
|
||||
else if (Waypoints.Count < 2)
|
||||
{
|
||||
throw new Exception("Not enough Waypoints specified.");
|
||||
}
|
||||
else if (Waypoints[0].IsViaPoint || Waypoints[Waypoints.Count - 1].IsViaPoint)
|
||||
{
|
||||
throw new Exception("Start and end waypoints must not be ViaWaypoints.");
|
||||
}
|
||||
|
||||
var sb = new StringBuilder();
|
||||
|
||||
var TravelMode = (RouteOptions != null) ? RouteOptions.TravelMode : TravelModeType.Driving;
|
||||
|
||||
sb.AppendFormat("https://dev.virtualearth.net/REST/v1/Routes/{0}?", Enum.GetName(typeof(TravelModeType), TravelMode));
|
||||
|
||||
int wayCnt = 0, viaCnt = 0;
|
||||
|
||||
for (int i = 0; i < Waypoints.Count; i++)
|
||||
{
|
||||
if (Waypoints[i].IsViaPoint)
|
||||
{
|
||||
sb.AppendFormat("&vwp.{0}=", i);
|
||||
viaCnt++;
|
||||
|
||||
if (TravelMode == TravelModeType.Transit)
|
||||
{
|
||||
throw new Exception("ViaWaypoints not supported for Transit directions.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.AppendFormat("&wp.{0}=", i);
|
||||
|
||||
if (viaCnt > 10)
|
||||
{
|
||||
throw new Exception("More than 10 viaWaypoints between waypoints.");
|
||||
}
|
||||
|
||||
wayCnt++;
|
||||
viaCnt = 0;
|
||||
}
|
||||
|
||||
if (Waypoints[i].Coordinate != null)
|
||||
{
|
||||
sb.AppendFormat("{0:0.#####},{1:0.#####}", Waypoints[i].Coordinate.Latitude, Waypoints[i].Coordinate.Longitude);
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.AppendFormat("{0}", Uri.EscapeDataString(Waypoints[i].Address));
|
||||
}
|
||||
}
|
||||
|
||||
if (wayCnt > 25)
|
||||
{
|
||||
throw new Exception("More than 25 waypoints in route request.");
|
||||
}
|
||||
|
||||
if (RouteOptions != null)
|
||||
{
|
||||
sb.Append(RouteOptions.GetUrlParam());
|
||||
}
|
||||
|
||||
sb.Append(GetBaseRequestUrl());
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,108 @@
|
|||
/*
|
||||
* Copyright(c) 2017 Microsoft Corporation. All rights reserved.
|
||||
*
|
||||
* This code is licensed under the MIT License (MIT).
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// Requests traffic information.
|
||||
/// </summary>
|
||||
public class TrafficRequest : BaseRestRequest
|
||||
{
|
||||
#region Public Properties
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the area to search for traffic incident information.
|
||||
/// A rectangular area specified as a bounding box.
|
||||
/// The size of the area can be a maximum of 500 km x 500 km.
|
||||
/// </summary>
|
||||
public BoundingBox MapArea { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Specifies whether to include traffic location codes in the response.
|
||||
/// Traffic location codes provide traffic incident information for pre-defined road segments.
|
||||
/// A subscription is typically required to be able to interpret these codes for a geographical area or country.
|
||||
/// Default is false.
|
||||
/// </summary>
|
||||
public bool IncludeLocationCodes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Specifies severity level of traffic incidents to return.
|
||||
/// The default is to return traffic incidents for all severity levels.
|
||||
/// </summary>
|
||||
public List<SeverityType> Severity { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the type of traffic incidents to return.
|
||||
/// </summary>
|
||||
public List<TrafficType> TrafficType { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Gets a URL for requesting traffic data for a GET request.
|
||||
/// </summary>
|
||||
/// <returns>Traffic request URL for GET request.</returns>
|
||||
public override string GetRequestUrl()
|
||||
{
|
||||
//URL Schema:
|
||||
//https://dev.virtualearth.net/REST/v1/Traffic/Incidents/mapArea/includeLocationCodes?severity=severity1,severity2,severityn&type=type1,type2,typen&key=BingMapsKey
|
||||
|
||||
//Examples:
|
||||
//https://dev.virtualearth.net/REST/v1/Traffic/Incidents/37,-105,45,-94?key=YourBingMapsKey
|
||||
//https://dev.virtualearth.net/REST/V1/Traffic/Incidents/37,-105,45,-94/true?t=9,2&s=2,3&o=xml&key=BingMapsKey
|
||||
|
||||
if (MapArea == null)
|
||||
{
|
||||
throw new Exception("MapArea not specified.");
|
||||
}
|
||||
|
||||
string url = string.Format("https://dev.virtualearth.net/REST/V1/Traffic/Incidents/{0:0.#####},{1:0.#####},{2:0.#####},{3:0.#####}{4}",
|
||||
MapArea.SouthLatitude,
|
||||
MapArea.WestLongitude,
|
||||
MapArea.NorthLatitude,
|
||||
MapArea.EastLongitude,
|
||||
(IncludeLocationCodes)? "/true?" : "?");
|
||||
|
||||
if (Severity != null && Severity.Count > 0)
|
||||
{
|
||||
url += "&severity=" + string.Join(",", Severity.Cast<int>().ToArray());
|
||||
}
|
||||
|
||||
if (TrafficType != null && TrafficType.Count > 0)
|
||||
{
|
||||
url += "&type=" + string.Join(",", TrafficType.Cast<int>().ToArray());
|
||||
}
|
||||
|
||||
return url + GetBaseRequestUrl();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,120 @@
|
|||
/*
|
||||
* Copyright(c) 2017 Microsoft Corporation. All rights reserved.
|
||||
*
|
||||
* This code is licensed under the MIT License (MIT).
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||
* so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// A static class that processes requests to the Bing Maps REST services.
|
||||
/// </summary>
|
||||
public static class ServiceManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Processes a REST requests that returns data.
|
||||
/// </summary>
|
||||
/// <param name="request">The REST request to process.</param>
|
||||
/// <returns>The response from the REST service.</returns>
|
||||
public static async Task<Response> GetResponseAsync(BaseRestRequest request)
|
||||
{
|
||||
Stream responseStream = null;
|
||||
if (request is ElevationRequest)
|
||||
{
|
||||
var r = request as ElevationRequest;
|
||||
|
||||
if(r.Points != null && r.Points.Count > 50)
|
||||
{
|
||||
//Make a post request when there are more than 50 points as there is a risk of URL becoming too large for a GET request.
|
||||
responseStream = await ServiceHelper.PostStringAsync(new Uri(r.GetPostRequestUrl()), r.GetPointsAsString(), null);
|
||||
}
|
||||
else
|
||||
{
|
||||
responseStream = await ServiceHelper.GetStreamAsync(new Uri(r.GetRequestUrl()));
|
||||
}
|
||||
}
|
||||
else if (request is ImageryRequest)
|
||||
{
|
||||
var r = request as ImageryRequest;
|
||||
|
||||
r.GetMetadata = true;
|
||||
|
||||
if (r.Pushpins != null && r.Pushpins.Count > 18)
|
||||
{
|
||||
//Make a post request when there are more than 18 pushpins as there is a risk of URL becoming too large for a GET request.
|
||||
responseStream = await ServiceHelper.PostStringAsync(new Uri(r.GetPostRequestUrl()), r.GetPushpinsAsString(), null);
|
||||
}
|
||||
else
|
||||
{
|
||||
responseStream = await ServiceHelper.GetStreamAsync(new Uri(r.GetRequestUrl()));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
responseStream = await ServiceHelper.GetStreamAsync(new Uri(request.GetRequestUrl()));
|
||||
}
|
||||
|
||||
if (responseStream != null)
|
||||
{
|
||||
var ser = new DataContractJsonSerializer(typeof(Response));
|
||||
var r = ser.ReadObject(responseStream) as Response;
|
||||
responseStream.Dispose();
|
||||
return r;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Processes a REST requests that returns an image stream.
|
||||
/// </summary>
|
||||
/// <param name="imageryRequest">The REST request to process.</param>
|
||||
/// <returns>A stream containing an image.</returns>
|
||||
public static async Task<Stream> GetImageAsync(BaseImageryRestRequest imageryRequest)
|
||||
{
|
||||
if (imageryRequest is ImageryRequest)
|
||||
{
|
||||
var r = imageryRequest as ImageryRequest;
|
||||
|
||||
r.GetMetadata = false;
|
||||
|
||||
if (r.Pushpins != null && r.Pushpins.Count > 18)
|
||||
{
|
||||
//Make a post request when there are more than 18 pushpins as there is a risk of URL becoming too large for a GET request.
|
||||
return await ServiceHelper.PostStringAsync(new Uri(r.GetPostRequestUrl()), r.GetPushpinsAsString(), null);
|
||||
}
|
||||
else
|
||||
{
|
||||
return await ServiceHelper.GetStreamAsync(new Uri(r.GetRequestUrl()));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return await ServiceHelper.GetStreamAsync(new Uri(imageryRequest.GetRequestUrl()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче