version 1.0.6 release
Add distance matrix and custom map style support.
This commit is contained in:
Родитель
eaf528749e
Коммит
8b8c7f8ee5
|
@ -1,7 +1,7 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.25420.1
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26430.16
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{EE7ACF1F-56D3-4A01-8262-A49A8B444639}"
|
||||
EndProject
|
||||
|
@ -26,6 +26,17 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Console", "Console", "{8017
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RESTToolkitTestConsoleApp", "Samples\Console\RESTToolkitTestConsoleApp\RESTToolkitTestConsoleApp.csproj", "{3BE4FCCE-768A-4ABE-AF3E-938B5D884AC8}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BingMapsRESTToolkit.Standard", "Source\BingMapsRESTToolkit.Standard\BingMapsRESTToolkit.Standard.csproj", "{F30DC2E6-FE4F-4F0B-BD52-CDA1940CAC4F}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RESTToolkitTestConsoleApp.NetStandard", "Samples\Console\RESTToolkitTestConsoleApp.NetStandard\RESTToolkitTestConsoleApp.NetStandard.csproj", "{1BCB3853-DAFE-4B33-9888-23666A1040B9}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Docs", "Docs", "{5F797BB6-13E8-4A02-BC01-613FC791EB41}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
Docs\API Reference.md = Docs\API Reference.md
|
||||
Docs\Getting Started.md = Docs\Getting Started.md
|
||||
Docs\Readme.md = Docs\Readme.md
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
@ -44,6 +55,14 @@ Global
|
|||
{3BE4FCCE-768A-4ABE-AF3E-938B5D884AC8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{3BE4FCCE-768A-4ABE-AF3E-938B5D884AC8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{3BE4FCCE-768A-4ABE-AF3E-938B5D884AC8}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{F30DC2E6-FE4F-4F0B-BD52-CDA1940CAC4F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F30DC2E6-FE4F-4F0B-BD52-CDA1940CAC4F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F30DC2E6-FE4F-4F0B-BD52-CDA1940CAC4F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F30DC2E6-FE4F-4F0B-BD52-CDA1940CAC4F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{1BCB3853-DAFE-4B33-9888-23666A1040B9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1BCB3853-DAFE-4B33-9888-23666A1040B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1BCB3853-DAFE-4B33-9888-23666A1040B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1BCB3853-DAFE-4B33-9888-23666A1040B9}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -54,5 +73,8 @@ Global
|
|||
{AC15CCAC-63B7-43EB-A1CB-25925F04398B} = {A155C82A-42DC-4206-8DA8-C9C8CC3BFFE2}
|
||||
{80170A9E-5ACF-483A-8A8E-18CA7B0C9A34} = {EE7ACF1F-56D3-4A01-8262-A49A8B444639}
|
||||
{3BE4FCCE-768A-4ABE-AF3E-938B5D884AC8} = {80170A9E-5ACF-483A-8A8E-18CA7B0C9A34}
|
||||
{F30DC2E6-FE4F-4F0B-BD52-CDA1940CAC4F} = {A155C82A-42DC-4206-8DA8-C9C8CC3BFFE2}
|
||||
{1BCB3853-DAFE-4B33-9888-23666A1040B9} = {80170A9E-5ACF-483A-8A8E-18CA7B0C9A34}
|
||||
{5F797BB6-13E8-4A02-BC01-613FC791EB41} = {833D0345-46F0-486E-9BEF-5269405683F8}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<package xmlns="http://schemas.microsoft.com/packaging/2013/01/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>BingMapsRESTToolkit</id>
|
||||
<version>1.0.5</version>
|
||||
<version>1.0.6</version>
|
||||
<title>Bing Maps REST Services Toolkit</title>
|
||||
<authors>Microsoft</authors>
|
||||
<owners>microsoft bingmaps</owners>
|
||||
|
@ -12,6 +12,7 @@
|
|||
<requireLicenseAcceptance>true</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>
|
||||
<releaseNotes>See the changelog here: https://github.com/Microsoft/BingMapsRESTToolkit/blob/master/CHANGELOG.md</releaseNotes>
|
||||
<copyright>© Microsoft Corporation. All rights reserved.</copyright>
|
||||
<tags>Microsoft "Bing Maps" Maps GIS Map Geospatial VB C# .NET REST</tags>
|
||||
<references>
|
||||
|
@ -40,12 +41,15 @@
|
|||
</references>
|
||||
</metadata>
|
||||
<files>
|
||||
<file src="..\Source\bin\Release\BingMapsRESTToolkit.dll" target="lib\dotnet\BingMapsRESTToolkit.dll" />
|
||||
<file src="..\Source\bin\Release\BingMapsRESTToolkit.dll" target="lib\dotnet\BingMapsRESTToolkit.dll" />
|
||||
<file src="..\Source\bin\Release\BingMapsRESTToolkit.pdb" target="lib\dotnet\BingMapsRESTToolkit.pdb" />
|
||||
<file src="..\Source\bin\Release\BingMapsRESTToolkit.XML" target="lib\dotnet\BingMapsRESTToolkit.XML" />
|
||||
<file src="..\Source\bin\Release\BingMapsRESTToolkit.dll" target="lib\net45\BingMapsRESTToolkit.dll" />
|
||||
<file src="..\Source\bin\Release\BingMapsRESTToolkit.pdb" target="lib\net45\BingMapsRESTToolkit.pdb" />
|
||||
<file src="..\Source\bin\Release\BingMapsRESTToolkit.XML" target="lib\net45\BingMapsRESTToolkit.XML" />
|
||||
<file src="..\Source\BingMapsRESTToolkit.Standard\bin\Release\netstandard1.4\BingMapsRESTToolkit.Standard.deps.json" target="lib\netstandard1.4\BingMapsRESTToolkit.Standard.deps.json" />
|
||||
<file src="..\Source\BingMapsRESTToolkit.Standard\bin\Release\netstandard1.4\BingMapsRESTToolkit.Standard.dll" target="lib\netstandard1.4\BingMapsRESTToolkit.Standard.dll" />
|
||||
<file src="..\Source\BingMapsRESTToolkit.Standard\bin\Release\netstandard1.4\BingMapsRESTToolkit.Standard.pdb" target="lib\netstandard1.4\BingMapsRESTToolkit.Standard.pdb" />
|
||||
<file src="..\Source\bin\Release\BingMapsRESTToolkit.dll" target="lib\portable-net45+wp8+win8\BingMapsRESTToolkit.dll" />
|
||||
<file src="..\Source\bin\Release\BingMapsRESTToolkit.pdb" target="lib\portable-net45+wp8+win8\BingMapsRESTToolkit.pdb" />
|
||||
<file src="..\Source\bin\Release\BingMapsRESTToolkit.XML" target="lib\portable-net45+wp8+win8\BingMapsRESTToolkit.XML" />
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
## Version 1.0.6 - Coming soon ##
|
||||
## Version 1.0.6 ##
|
||||
|
||||
* Created a .NET Standard v1.4 assembly.
|
||||
* Add Custom Map Styles support for static images.
|
||||
* Add Distance Matrix API support. Automatically determines is sync or async request is needed and monitors the request till completion. Distance matrix result class contains many help methods to make it easy to integrate into various applicaitons.
|
||||
* Seperate out response classes into individual files for easier management.
|
||||
* Add Execute method to all requests which contains custom business logic for processing each request. No need to use the ServiceManager now.
|
||||
* Add new imagery types; AerialWithLabelsOnDemand, BirdseyeV2, BirdseyeV2WithLabels, CanvasGray, CanvasDark, CanvasLight, and RoadOnDemand.
|
||||
|
||||
## Version 1.0.5 - 3/22/2017 ##
|
||||
|
||||
|
|
|
@ -0,0 +1,690 @@
|
|||
Table of contents
|
||||
=================
|
||||
|
||||
* [ServiceManager Class](#ServiceManager)
|
||||
* [CustomMapStyleManager Class](#CustomMapStyleManager)
|
||||
* [Request Classes](#RequestClasses)
|
||||
- [BaseRestRequest Class](#BaseRestRequest)
|
||||
- [BaseImageryRestRequest Class](#BaseImageryRestRequest)
|
||||
- [DistanceMatrixRequest Class](#DistanceMatrixRequest)
|
||||
- [ElevationRequest Class](#ElevationRequest)
|
||||
- [GeocodeRequest Class](#GeocodeRequest)
|
||||
- [ImageryMetadataRequest Class](#ImageryMetadataRequest)
|
||||
- [ImageryRequest Class](#ImageryRequest)
|
||||
- [ReverseGeocodeRequest Class](#ReverseGeocodeRequest)
|
||||
- [RouteMajorRoadsRequest Class](#RouteMajorRoadsRequest)
|
||||
- [RouteRequest Class](#RouteRequest)
|
||||
- [TrafficRequest Class](#TrafficRequest)
|
||||
* [Common Classes](#CommonClasses)
|
||||
- [BoundingBox Class](#BoundingBox)
|
||||
- [Coordinate Class](#Coordinate)
|
||||
- [ImageryPushpin Class](#ImageryPushpin)
|
||||
- [PointCompression Class](#PointCompression)
|
||||
- [RouteOptions Class](#RouteOptions)
|
||||
- [SimpleAddress Class](#SimpleAddress)
|
||||
- [SimpleWaypoint Class](#SimpleWaypoint)
|
||||
* [Enumerations](#Enumerations)
|
||||
- [AvoidType Enumeration](#AvoidType)
|
||||
- [ConfidenceLevel Enumeration](#ConfidenceLevel)
|
||||
- [DistanceUnitType Enumeration](#DistanceUnitType)
|
||||
- [ElevationType Enumeration](#ElevationType)
|
||||
- [EntityType Enumeration](#EntityType)
|
||||
- [ImageFormatType Enumeration](#ImageFormatType)
|
||||
- [ImageryType Enumeration](#ImageryType)
|
||||
- [RouteAttributeType Enumeration](#RouteAttributeType)
|
||||
- [RouteOptimizationType Enumeration](#RouteOptimizationType)
|
||||
- [RouteTimeType Enumeration](#RouteTimeType)
|
||||
- [SeverityType Enumeration](#SeverityType)
|
||||
- [TrafficType Enumeration](#TrafficType)
|
||||
- [TravelModeType Enumeration](#TravelModeType)
|
||||
* [Enhanced Response Classes](#EnhancedResponseClasses)
|
||||
- [DistanceMatrix Class](#DistanceMatrix)
|
||||
|
||||
This documentation does not include the class definitions for the REST Response. These are documented in the Bing Maps MSDN documentation [here](https://msdn.microsoft.com/en-us/library/ff701707.aspx).
|
||||
|
||||
<a name="ServiceManager"></a> ServiceManager Class
|
||||
==================================================
|
||||
|
||||
This is a static class that is used for processing all requests to the Bing Maps REST Services asynchronously.
|
||||
|
||||
Static Methods
|
||||
--------------
|
||||
|
||||
| Name | Return Type | Description |
|
||||
|------------------------------------------------------|----------------------|----------------------|
|
||||
| GetResponseAsync([BaseRestRequest](#BaseRestRequest) request) | Task<Response> | Processes a REST requests that returns data. |
|
||||
| GetResponseAsync([BaseRestRequest](#BaseRestRequest) request, Action<int> remainingTimeCallback) | Task<Response> | Processes a REST requests that returns data. |
|
||||
| GetImageAsync([BaseImageryRestRequest](#BaseImageryRestRequest) imageryRequest) | Task<Stream> | Processes a REST requests that returns an image stream. |
|
||||
|
||||
<a name="CustomMapStyleManager"></a> CustomMapStyleManager Class
|
||||
==================================================
|
||||
|
||||
A static class to assit with working with Bing Maps Customer Map Styles.
|
||||
|
||||
Static Methods
|
||||
--------------
|
||||
|
||||
| Name | Return Type | Description |
|
||||
|------------------------------------------------------|----------------------|----------------------|
|
||||
| GetRestStyle(string style) | string | Converts a custom JSON map style, into a style using the REST parameter format. If the style is already in the REST parameter formatter, it will be unaltered. |
|
||||
|
||||
|
||||
<a name="RequestClasses"></a> Request Classes
|
||||
===============
|
||||
|
||||
<a name="BaseRestRequest"></a> BaseRestRequest Class
|
||||
---------------------
|
||||
|
||||
An abstract class in which all REST service requests derive from.
|
||||
|
||||
### Methods
|
||||
|
||||
| Name | Return Type | Description |
|
||||
|-----------------|-------------|-----------------------------------------------------------------|
|
||||
| Execute() | Task<Response> | Executes the request. |
|
||||
| Execute(Action<int> remainingTimeCallback) | Task<Response> | Executes the request. |
|
||||
| GetRequestUrl() | string | Abstract method which generates the Bing Maps REST request URL. |
|
||||
|
||||
### Properties
|
||||
|
||||
| Name | Type | Description |
|
||||
|--------------|-------------|-----------------------------------------------------------------|
|
||||
| BingMapsKey | string | The Bing Maps key for making the request. |
|
||||
| Culture | string | The culture to use for the request. |
|
||||
| Domain | string | The domain of the REST service. Default: https://dev.virtualearth.net/REST/v1/ |
|
||||
| UserIp | string | An Internet Protocol version 4 (IPv4) address. |
|
||||
| UserLocation | [Coordinate](#Coordinate) | The user’s current position. |
|
||||
| UserMapView | [BoundingBox](#BoundingBox) | The geographic region that corresponds to the current viewport. |
|
||||
|
||||
<a name="BaseImageryRestRequest"></a> BaseImageryRestRequest Class
|
||||
----------------------------
|
||||
|
||||
Abstract class that all Imagery rest requests will derive from. Inherits from the BaseRestRequest class and currently exposes all the same properties and methods.
|
||||
|
||||
<a name="DistanceMatrixRequest"></a> Distance Matrix Request
|
||||
----------------------
|
||||
|
||||
A request that calculates a distance matrix between origins and destinations. Inherits from the BaseRestRequest class.
|
||||
|
||||
### Methods
|
||||
|
||||
| Name | Return Type | Description |
|
||||
|---------------------------|------------------------|----------------|
|
||||
| Execute() | Task<Response> | Executes the request. |
|
||||
| Execute(Action<int> remainingTimeCallback) | Task<Response> | Executes the request. |
|
||||
| GeocodeWaypoints() | Task | Geocodes the origins and destinations. |
|
||||
| GetEuclideanDistanceMatrix() | Task<[DistanceMatrix](#DistanceMatrix)> | Calculates a Distance Matrix for the origins and destinations based on the euclidean distance (straight line/as the crow flies). This calculation only uses; Origins, Destinations, and Distance Units properties from the request and only calculates travel distance. |
|
||||
| GetNumberOfCoordinatePairs() | int | Returns the number of coordinate pairs that would be in the resulting matrix based on the number of origins and destinations in the request. |
|
||||
| GetPostRequestBody() | string | Returns a JSON string object representing the request. |
|
||||
| GetRequestUrl() | string | Gets the request URL to perform a query for a distance matrix when using POST. |
|
||||
|
||||
### Properties
|
||||
|
||||
| Name | Type | Description |
|
||||
|------------|-------------|
|
||||
| origins | List<[SimpleWaypoint](#SimpleWaypoint)> |**Required**. List of origins. |
|
||||
| destinations | List<[SimpleWaypoint](#SimpleWaypoint)> | **Required**. List of destinations. |
|
||||
| TravelMode | [TravelModeType](#TravelModeType) | **Required**. Specifies the mode of transportation to use when calculating the distance matrix. |
|
||||
| StartTime | DateTime | **Optional for Driving**. Specifies the start or departure time of the matrix to calculate and uses predictive traffic data. |
|
||||
| endTime | DateTime | **Optional for Driving**. If specified, a matrix based on traffic data with contain a histogram of travel times and distances for the specified resolution intervals (default is 15 minutes) between the start and end times. A start time must be specified for the request to be valid and the total time between start and end cannot be greater than 24 hours. |
|
||||
| resolution | int | **Optional for Driving**. The number of intervals to calculate a histogram of data for each cell where a single interval is a quarter of an hour. Can be one of the following values:<br/><br/> • **1** - 15 minutes<br/> • **2** - 30 minutes<br/> • **3** - 45 minutes<br/> • **4** - an hour<br/><br/>If start time is specified and `resolution` is not, it will default to an interval of 1 (15 minutes).<br/><br/>**Example**: resolution=2 |
|
||||
| distanceUnit | [DistanceUnitType](#DistanceUnitType) | **Optional.** The units to use for distances in the response. |
|
||||
| timeUnit | [TimeUnitType](#TimeUnitType) | **Optional.** The units to use for time durations in the response. |
|
||||
|
||||
<a name="ElevationRequest"></a> ElevationRequest Class
|
||||
----------------------
|
||||
|
||||
A request for elevation data. Inherits from the BaseRestRequest class.
|
||||
|
||||
### Methods
|
||||
|
||||
| Name | Return Type | Description |
|
||||
|---------------------------|------------------------|----------------|
|
||||
| Execute() | Task<Response> | Executes the request. |
|
||||
| Execute(Action<int> remainingTimeCallback) | Task<Response> | Executes the request. |
|
||||
| GetElevationCoordinates() | List<[Coordinate](#Coordinate)> | Gets a list of coordinates that are related to the returned index of the elevation data. |
|
||||
| GetPointsAsString() | string | Returns the Point information as a formatted string. Only the first 1024 points will be used. Example: `points=38.8895,77.0501,38.8877,-77.0472,38.8904,-77.0474,38.8896,77.0351` |
|
||||
| GetPostRequestUrl() | string | Gets a URL for requesting elevation data for a POST request. |
|
||||
| GetRequestUrl() | string | Gets a URL for requesting elevation data for a GET request. |
|
||||
|
||||
### Properties
|
||||
|
||||
| Name | Type | Description |
|
||||
|----------------|------------------------|---------------------------------|
|
||||
| Bounds | [BoundingBox](#BoundingBox) | Specifies the rectangular area over which to provide elevation values. |
|
||||
| Col | int | 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. |
|
||||
| GetGeoidOffset | bool | A boolean indicating if the offset from the geoid should be returned. Requires a list of points to be specified. |
|
||||
| Height | [ElevationType](#ElevationType) | Specifies which sea level model to use to calculate elevation. |
|
||||
| Points | List<[Coordinate](#Coordinate)> | 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. |
|
||||
| Row | int | 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. |
|
||||
| Samples | int | Specifies the number of equally-spaced elevation values to provide along a polyline path. Used when Points value is set. Make = 1024 |
|
||||
| Bounds | [BoundingBox](#BoundingBox) | Specifies the rectangular area over which to provide elevation values. |
|
||||
|
||||
<a name="GeocodeRequest"></a> GeocodeRequest Class
|
||||
--------------------
|
||||
|
||||
Geocodes a query to its coordinates. Inherits from the BaseRestRequest class.
|
||||
|
||||
### Methods
|
||||
|
||||
| Name | Return Type | Description |
|
||||
|-----------------|-------------|-------------------|
|
||||
| Execute() | Task<Response> | Executes the request. |
|
||||
| Execute(Action<int> remainingTimeCallback) | Task<Response> | Executes the request. |
|
||||
| GetRequestUrl() | string | 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. |
|
||||
|
||||
### Properties
|
||||
|
||||
| Name | Type | Description |
|
||||
|---------------------|---------------|---------------------|
|
||||
| Address | [SimpleAddress](#SimpleAddress) | The Address to geocode. |
|
||||
| IncludeIso2 | bool | When you specified the two-letter ISO country code is included for addresses in the response. |
|
||||
| IncludeNeighborhood | bool | Specifies to include the neighborhood in the response when it is available. |
|
||||
| MaxResults | int | Specifies the maximum number of locations to return in the response. |
|
||||
| Query | string | A free form string address or Landmark. Overrides the Address values if both are specified. |
|
||||
|
||||
<a name="ImageryMetadataRequest"></a> ImageryMetadataRequest Class
|
||||
----------------------------
|
||||
|
||||
Requests imagery metadata information from Bing Maps. Inherits from the BaseRestRequest class.
|
||||
|
||||
### Methods
|
||||
|
||||
| Name | Return Type | Description |
|
||||
|-----------------|-------------|--------------------------------------------|
|
||||
| Execute() | Task<Response> | Executes the request. |
|
||||
| Execute(Action<int> remainingTimeCallback) | Task<Response> | Executes the request. |
|
||||
| GetRequestUrl() | string | 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. |
|
||||
|
||||
### Properties
|
||||
|
||||
| Name | Type | Description |
|
||||
|-------------------------|-------------|---------------------------------|
|
||||
| CenterPoint | [Coordinate](#Coordinate) | Required when imagerySet is Birdseye or BirdseyeWithLabels. Optional for other imagery sets. The center point to use for the imagery metadata. |
|
||||
| GetBasicInfo | bool | Get only the basic metadata for an imagery set at a specific location. This URL does not return a map tile URL. |
|
||||
| ImagerySet | [ImageryType](#ImageryType) | The type of imagery for which you are requesting metadata. |
|
||||
| IncludeImageryProviders | bool | When you specified the two-letter ISO country code is included for addresses in the response. |
|
||||
| Orientation | double | The orientation of the viewport to use for the imagery metadata. This option only applies to Birdseye imagery. |
|
||||
| UseHTTPS | bool | When set to true tile URL's will use HTTPS. |
|
||||
| ZoomLevel | int | 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. |
|
||||
|
||||
<a name="ImageryRequest"></a> ImageryRequest Class
|
||||
====================
|
||||
|
||||
Requests an image from the REST imagery service. Inherits from the BaseImageryRestRequest class.
|
||||
|
||||
### Methods
|
||||
|
||||
| Name | Return Type | Description |
|
||||
|-----------------------|-------------|----------------------------|
|
||||
| Execute() | Task<Response> | Executes the request. |
|
||||
| Execute(Action<int> remainingTimeCallback) | Task<Response> | Executes the request. |
|
||||
| GetPostRequestUrl() | string | Gets a URL for requesting imagery data for a POST request. |
|
||||
| GetPushpinsAsString() | string | Returns the Pushpin information as a formatted string. |
|
||||
| GetRequestUrl() | string | 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. |
|
||||
|
||||
### Properties
|
||||
|
||||
| Name | Type | Description |
|
||||
|-----------------|----------------------------|----------------|
|
||||
| CenterPoint | [Coordinate](#Coordinate) | Required when imagerySet is Birdseye or BirdseyeWithLabels. Optional for other imagery sets. The center point to use for the imagery metadata. |
|
||||
| DeclutterPins | bool | Specifies whether to change the display of overlapping pushpins so that they display separately on a map. |
|
||||
| EntityType | [EntityType](#EntityType) | 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. |
|
||||
| Format | [ImageFormatType](#ImageFormatType) | The image format to use for the static map. |
|
||||
| GetMetadata | bool | 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. |
|
||||
| HighlightEntity | bool | Highlights a polygon for an entity. |
|
||||
| ImagerySet | [ImageryType](#ImageryType) | The type of imagery for which you are requesting metadata. |
|
||||
| MapArea | [BoundingBox](#BoundingBox) | Required when a center point or set of route points are not specified. The geographic area to display on the map. |
|
||||
| MapHeight | int | The height of the map. Default is **350px**. |
|
||||
| MapWidth | int | The width of the map. Default is **350px**. |
|
||||
| Pushpins | List<[ImageryPushpin](#ImageryPushpin)> | List of pushpins to display on the map. |
|
||||
| Query | string | A query string that is used to determine the map location to display. |
|
||||
| RouteOptions | [RouteOptions](#RouteOptions) | Options for calculating route. |
|
||||
| ShowTraffic | bool | Specifies if the traffic flow layer should be displayed on the map or not. Default is **false**. |
|
||||
| Style | string | The custom map style to apply to the image. |
|
||||
| Waypoints | List<[SimpleWaypoint](#SimpleWaypoint)> | 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. |
|
||||
| ZoomLevel | int | The level of zoom to display. |
|
||||
|
||||
<a name="ReverseGeocodeRequest"></a> ReverseGeocodeRequest Class
|
||||
---------------------------
|
||||
|
||||
Requests a that converts a coordinate into a location such as an address. Inherits from the BaseRestRequest class.
|
||||
|
||||
### Methods
|
||||
|
||||
| Name | Return Type | Description |
|
||||
|-----------------|-------------|----------------------------------------------------------|
|
||||
| Execute() | Task<Response> | Executes the request. |
|
||||
| Execute(Action<int> remainingTimeCallback) | Task<Response> | Executes the request. |
|
||||
| GetRequestUrl() | string | Gets the request URL to perform a reverse geocode query. |
|
||||
|
||||
### Properties
|
||||
|
||||
| Name | Type | Description |
|
||||
|---------------------|------------------------|----------------|
|
||||
| IncludeEntityTypes | List<[EntityType](#EntityType)> | 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. |
|
||||
| IncludeIso2 | bool | When you specified the two-letter ISO country code is included for addresses in the response. |
|
||||
| IncludeNeighborhood | bool | Specifies to include the neighborhood in the response when it is available. |
|
||||
| Point | [Coordinate](#Coordinate) | A central coordinate to perform the nearby search. |
|
||||
|
||||
<a name="RouteMajorRoadsRequest"></a> RouteMajorRoadsRequest Class
|
||||
----------------------------
|
||||
|
||||
Requests routes from a location to major nearby roads. Inherits from the BaseRestRequest class.
|
||||
|
||||
### Methods
|
||||
|
||||
| Name | Return Type | Description |
|
||||
|-----------------|-------------|------------------------------------------------|
|
||||
| Execute() | Task<Response> | Executes the request. |
|
||||
| Execute(Action<int> remainingTimeCallback) | Task<Response> | Executes the request. |
|
||||
| GetRequestUrl() | string | Gets the request URL to perform a query for routes using major roads. |
|
||||
|
||||
### Properties
|
||||
|
||||
| Name | Type | Description |
|
||||
|---------------------|--------------------------------|---------------|
|
||||
| Destination | [SimpleWaypoint](#SimpleWaypoint) | Specifies the final location for all the routes. A destination can be specified as a Point, a landmark, or an address. |
|
||||
| DistanceUnits | [DistanceUnitType](#DistanceUnitType) | The units to use for distance. |
|
||||
| ExcludeInstructions | bool | 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. |
|
||||
| RouteAttributes | List<[RouteAttributeType](#RouteAttributeType)> | Specifies to include or exclude parts of the routes response. |
|
||||
|
||||
<a name="RouteRequest"></a> RouteRequest Class
|
||||
------------------
|
||||
|
||||
A request that calculates routes between waypoints. Inherits from the BaseRestRequest class.
|
||||
|
||||
### Methods
|
||||
|
||||
| Name | Return Type | Description |
|
||||
|-----------------|-------------|---------------------------------------------------------------|
|
||||
| Execute() | Task<Response> | Executes the request. |
|
||||
| Execute(Action<int> remainingTimeCallback) | Task<Response> | Executes the request. |
|
||||
| GetRequestUrl() | string | Gets the request URL to perform a query for route directions. |
|
||||
|
||||
### Properties
|
||||
|
||||
| Name | Type | Description |
|
||||
|--------------|----------------------------|-------------------|
|
||||
| RouteOptions | [RouteOptions](#RouteOptions) | Options to use when calculate route. |
|
||||
| Waypoints | List<[SimpleWaypoint](#SimpleWaypoint)> | 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. |
|
||||
|
||||
<a name="TrafficRequest"></a> TrafficRequest Class
|
||||
--------------------
|
||||
|
||||
Requests traffic information. Inherits from the BaseRestRequest class.
|
||||
|
||||
### Methods
|
||||
|
||||
| Name | Return Type | Description |
|
||||
|-----------------|-------------|-----------------------------------------------------------|
|
||||
| Execute() | Task<Response> | Executes the request. |
|
||||
| Execute(Action<int> remainingTimeCallback) | Task<Response> | Executes the request. |
|
||||
| GetRequestUrl() | string | Gets a URL for requesting traffic data for a GET request. |
|
||||
|
||||
### Properties
|
||||
|
||||
| Name | Type | Description |
|
||||
|----------------------|--------------------------|----------------|
|
||||
| IncludeLocationCodes | bool | 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**. |
|
||||
| MapArea | [BoundingBox](#BoundingBox) | 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. |
|
||||
| Severity | List<SeverityType> | Specifies severity level of traffic incidents to return. The default is to return traffic incidents for all severity levels. |
|
||||
| TrafficType | List<TrafficType> | Specifies the type of traffic incidents to return. |
|
||||
|
||||
<a name="CommonClasses"></a> Common Classes
|
||||
==============
|
||||
|
||||
<a name="BoundingBox"></a> BoundingBox Class
|
||||
-----------------
|
||||
|
||||
### Methods
|
||||
|
||||
| Name | Return Type | Description |
|
||||
|------------|-------------|-------------|
|
||||
| ToString() | string | Returns a string in the format `SouthLatitude,WestLongitude,NorthLatitude,EastLongitude` |
|
||||
|
||||
### Properties
|
||||
|
||||
| Name | Type | Description |
|
||||
|---------------|--------|-------------|
|
||||
| EastLongitude | double | The eastern most longitude value. |
|
||||
| NorthLatitude | double | The northern most latitude value. |
|
||||
| SouthLatitude | double | The southern most latitude value. |
|
||||
| WestLongitude | double | The western most longitude value. |
|
||||
|
||||
<a name="Coordinate"></a> Coordinate Class
|
||||
----------------
|
||||
|
||||
A class that defines location coordinate value.
|
||||
|
||||
### Constructor
|
||||
|
||||
> Coordinate()
|
||||
|
||||
> Coordinate(double latitude, double longitude)
|
||||
|
||||
### Properties
|
||||
|
||||
| Name | Type | Description |
|
||||
|-----------|--------|-----------------------|
|
||||
| Latitude | double | Latitude coordinate. |
|
||||
| Longitude | double | Longitude coordinate. |
|
||||
|
||||
<a name="ImageryPushpin"></a> ImageryPushpin Class
|
||||
--------------------
|
||||
|
||||
Pushpin defination for Bing Maps REST imagery service as documented [here](https://msdn.microsoft.com/en-us/library/ff701719.aspx)
|
||||
|
||||
### Methods
|
||||
|
||||
| Name | Return Type | Description |
|
||||
|------------|-------------|------------------------------------------------------------------------------------------------------|
|
||||
| ToString() | string | Returns a string version of the pushpin in the format `pushpin=latitude,longitude;iconStyle;label` |
|
||||
|
||||
### Properties
|
||||
|
||||
| Name | Type | Description |
|
||||
|-----------|------------|----------------------------------------|
|
||||
| IconStyle | int | The icon style to use for the pushpin. |
|
||||
| Label | string | Label to display on top of pushpin. |
|
||||
| Location | [Coordinate](#Coordinate) | Coordinate to display pushpin. |
|
||||
|
||||
<a name="PointCompression"></a> PointCompression Class
|
||||
----------------------
|
||||
|
||||
This is a static class that exposes a compression algorithm to 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 and 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/jj158958.aspx)
|
||||
|
||||
[http://msdn.microsoft.com/en-us/library/dn306801.aspx](http://msdn.microsoft.com/en-us/library/dn306801.aspx)
|
||||
|
||||
### Static Methods
|
||||
|
||||
| Name | Return Type | Description |
|
||||
|-----------------------------------------------------------------|-------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| Encode(List<[Coordinate](#Coordinate)> points) | string | Compresses a list of coordinates into a string. Based on: [http://msdn.microsoft.com/en-us/library/jj158958.aspx](http://msdn.microsoft.com/en-us/library/jj158958.aspx) |
|
||||
| TryDecode(string value, out List<[Coordinate](#Coordinate)> parsedValue) | bool | Decodes a collection of coordinates from a compressed string. Returns a boolean indicating if the algorithm was able to decode the compressed coordinates or not. Based on: [http://msdn.microsoft.com/en-us/library/dn306801.aspx](http://msdn.microsoft.com/en-us/library/dn306801.aspx) |
|
||||
|
||||
<a name="RouteOptions"></a> RouteOptions Class
|
||||
------------------
|
||||
|
||||
A class that defines the options that can to use when calculating a route.
|
||||
|
||||
### Properties
|
||||
|
||||
| Name | Type | Description |
|
||||
|-------------------------|--------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| Avoid | List<[AvoidType](#AvoidType)> | Specifies the road types to minimize or avoid when a route is created for the driving travel mode. |
|
||||
| DateTime | DateTime | 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. |
|
||||
| DistanceBeforeFirstTurn | int | 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. |
|
||||
| DistanceUnits | [DistanceUnitType](#DistanceUnitType) | The units to use for distance. |
|
||||
| Heading | int | 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. |
|
||||
| MaxSolutions | int | 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. |
|
||||
| Optimize | [RouteOptimizationType](#RouteOptimizationType) | Specifies what parameters to use to optimize the route. |
|
||||
| RouteAttributes | List<[RouteAttributeType](#RouteAttributeType)> | Specifies to include or exclude parts of the routes response. |
|
||||
| TimeType | [RouteTimeType](#RouteTimeType) | Specifies how to interpret the date and transit time value that is specified by the dateTime parameter. |
|
||||
| Tolerances | List<double> | 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. |
|
||||
| TravelMode | [TravelModeType](#TravelModeType) | The mode of travel for the route. Default: Driving. |
|
||||
|
||||
<a name="SimpleAddress"></a> SimpleAddress Class
|
||||
-------------------
|
||||
|
||||
A simple address class that can be passed in to queries.
|
||||
|
||||
### Properties
|
||||
|
||||
| Name | Type | Description |
|
||||
|---------------|--------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| AddressLine | string | 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. |
|
||||
| AdminDistrict | string | 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. |
|
||||
| CountryRegion | string | The ISO country code for the country. |
|
||||
| Locality | string | The locality, such as the city or neighborhood, that corresponds to an address. |
|
||||
| PostalCode | string | The post code, postal code, or ZIP Code of an address. |
|
||||
|
||||
<a name="SimpleWaypoint"></a> SimpleWaypoint Class
|
||||
--------------------
|
||||
|
||||
A simple waypoint class that can be used to calculate a route.
|
||||
|
||||
### Constructor
|
||||
|
||||
> SimpleWaypoint()
|
||||
|
||||
> SimpleWaypoint([Coordinate](#Coordinate) coordinate)
|
||||
|
||||
> SimpleWaypoint(string address)
|
||||
|
||||
> SimpleWaypoint([Coordinate](#Coordinate) coordinate, string address)
|
||||
|
||||
> SimpleWaypoint(double latitude, double longitude)
|
||||
|
||||
### Properties
|
||||
|
||||
| Name | Type | Description |
|
||||
|------------|------------|------------------------------------------------------------------------------------------------------------|
|
||||
| Address | string | The address query for the waypoint. |
|
||||
| Coordinate | [Coordinate](#Coordinate) | The coordinate of the waypoint. When specified this will be used instead of the Address value in requests. |
|
||||
| IsViaPoint | bool | A bool indicating whether the waypoint is a via point. |
|
||||
|
||||
<a name="Enumerations"></a> Enumerations
|
||||
============
|
||||
|
||||
<a name="AvoidType"></a> AvoidType Enumeration
|
||||
---------------------
|
||||
|
||||
Specifies the road types to minimize or avoid when the route is created for the driving travel mode.
|
||||
|
||||
| Name | Description |
|
||||
|------------------|----------------------------------------------------------------|
|
||||
| Highways | Avoids the use of highways in the route. |
|
||||
| MinimizeHighways | Minimizes (tries to avoid) the use of highways in the route. |
|
||||
| MinimizeTolls | Minimizes (tries to avoid) the use of toll roads in the route. |
|
||||
| Tolls | Avoids the use of toll roads in the route. |
|
||||
|
||||
<a name="ConfidenceLevel"></a> ConfidenceLevel Enumeration
|
||||
---------------------------
|
||||
|
||||
The level of confidence that the geocoded location result is a match.
|
||||
|
||||
| Name | Description |
|
||||
|---------|--------------------------|
|
||||
| High | High confidence match. |
|
||||
| Low | Low confidence match. |
|
||||
| Medium | Medium confidence match. |
|
||||
| None | No confidence level set. |
|
||||
|
||||
<a name="DistanceUnitType"></a> DistanceUnitType Enumeration
|
||||
----------------------------
|
||||
|
||||
Units of measurements for distances.
|
||||
|
||||
| Name | Description |
|
||||
|-------|--------------------------|
|
||||
| Kilometers | Distances in Kilometers. |
|
||||
| Miles | Distances in Miles. |
|
||||
|
||||
<a name="ElevationType"></a> ElevationType Enumeration
|
||||
-------------------------
|
||||
|
||||
Relative elevation type.
|
||||
|
||||
| Name | Description |
|
||||
|------------|-----------------------------------|
|
||||
| Ellipsoid | Ellipsoid Earth model (WGS84). |
|
||||
| Sealevel | Geoid Earth model (EGM2008 2.5’). |
|
||||
|
||||
<a name="EntityType"></a> EntityType Enumeration
|
||||
----------------------
|
||||
|
||||
Types of location based entities.
|
||||
|
||||
| Name | Description |
|
||||
|-----------------|----------------------------------------------------------------------------------------------------|
|
||||
| Address | A street address or RoadBlock. |
|
||||
| AdminDivision1 | First administrative level within the country/region level, such as a state or a province. |
|
||||
| AdminDivision2 | Second administrative level within the country/region level, such as a county. |
|
||||
| CountryRegion | Country or region |
|
||||
| Neighborhood | A section of a populated place that is typically well-known, but often with indistinct boundaries. |
|
||||
| PopulatedPlace | A concentrated area of human settlement, such as a city, town or village. |
|
||||
| Postcode1 | The smallest post code category, such as a zip code. |
|
||||
|
||||
<a name="ImageFormatType"></a> ImageFormatType Enumeration
|
||||
---------------------------
|
||||
|
||||
Imagery format types.
|
||||
|
||||
| Name | Description |
|
||||
|-------|----------------------------------------------------------------------------------------------|
|
||||
| GIF | GIF image format. |
|
||||
| JPEG | JPEG image format. JPEG format is the default for Road, Aerial and AerialWithLabels imagery. |
|
||||
| PNG | PNG image format. PNG is the default format for CollinsBart and OrdnanceSurvey imagery. |
|
||||
|
||||
<a name="ImageryType"></a> ImageryType Enumeration
|
||||
-----------------------
|
||||
|
||||
Types of map imagery.
|
||||
|
||||
| Name | Description |
|
||||
|---------------------|-----------------------------------------|
|
||||
| Aerial | Aerial imagery. |
|
||||
| AerialWithLabels | Aerial imagery with a road overlay. |
|
||||
| AerialWithLabelsOnDemand | Aerial imagery with on-demand road overlay. |
|
||||
| Birdseye | Bird’s eye (oblique-angle) imagery |
|
||||
| BirdseyeWithLabels | Bird’s eye imagery with a road overlay. |
|
||||
| BirdseyeV2 | The second generation Bird’s eye (oblique-angle) imagery. |
|
||||
| BirdseyeV2WithLabels | The second generation Bird’s eye (oblique-angle) imagerywith a road overlay. |
|
||||
| CanvasDark | A dark version of the road maps. |
|
||||
| CanvasGray | A grayscale version of the road maps. |
|
||||
| CanvasLight | A lighter version of the road maps which also has some of the details such as hill shading disabled. |
|
||||
| OrdnanceSurvey | Ordnance Survey imagery. |
|
||||
| Road | Roads without additional imagery. |
|
||||
| RoadOnDemand | Roads without additional imagery. Uses dynamic tile service. |
|
||||
|
||||
<a name="RouteAttributeType"></a> RouteAttributeType Enumeration
|
||||
------------------------------
|
||||
|
||||
The type of route attributes to include in a route response.
|
||||
|
||||
| Name | Description |
|
||||
|---------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| All | Used to specify the following attributes as a group: excluteItinerary, routePath, and transitStops. |
|
||||
| ExcludeItinerary | 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. |
|
||||
| RoutePath | Include a set of point (latitude and longitude) values that describe the route’s path in the response. |
|
||||
| RouteSummariesOnly | Include only travel time and distance for the route, and does not provide other information. |
|
||||
| TransitStops | Include information about transit stops for transit routes. |
|
||||
|
||||
<a name="RouteOptimizationType"></a> RouteOptimizationType Enumeration
|
||||
---------------------------------
|
||||
|
||||
Specifies what parameters to use to optimize the route on the map.
|
||||
|
||||
| Name | Description |
|
||||
|-------------------|----------------------|
|
||||
| Distance | Optimizes route for shortest distance. |
|
||||
| Time | Optimizes route for shortest travel time. |
|
||||
| TimeAvoidClosure | The route is calculated to minimize the time and avoid road closures. Traffic information is not used in the calculation. |
|
||||
| TimeWithTraffic | Optimizes route for shortest travel time with respect to current traffic conditions. |
|
||||
|
||||
<a name="RouteTimeType"></a> RouteTimeType Enumeration
|
||||
-------------------------
|
||||
|
||||
Specifies how to interpret the date and transit time value that is specified by the dateTime parameter.
|
||||
|
||||
| Name | Description |
|
||||
|----------------|--------------------|
|
||||
| Arrival | The dateTime parameter contains the desired arrival time for a transit request. |
|
||||
| Departure | The dateTime parameter contains the desired departure time for a transit request. |
|
||||
| LastAvailable | The dateTime parameter contains the latest departure time available for a transit request. |
|
||||
|
||||
<a name="SeverityType"></a> SeverityType Enumeration
|
||||
------------------------
|
||||
|
||||
Specifies the severity level of a traffic incident.
|
||||
|
||||
| Name | Description |
|
||||
|------------|----------------------|
|
||||
| LowImpact | Low impact severity. |
|
||||
| Minor | Minor severity. |
|
||||
| Moderate | Moderate severity. |
|
||||
| Serious | Serious severity. |
|
||||
|
||||
<a name="TimeUnitType"></a> TimeUnitType Enumeration
|
||||
-----------------------
|
||||
|
||||
Represents the units in which time is measured.
|
||||
|
||||
| Name | Description |
|
||||
|------------------|---------------------------------|
|
||||
| Minutes | Time is in minutes. |
|
||||
| Seconds | Time is in seconds. |
|
||||
|
||||
<a name="TrafficType"></a> TrafficType Enumeration
|
||||
-----------------------
|
||||
|
||||
Specifies the type of a traffic incident.
|
||||
|
||||
| Name | Description |
|
||||
|------------------|---------------------------------|
|
||||
| Accident | Accident incident type. |
|
||||
| Congestion | Congestion incident type. |
|
||||
| DisabledVehicle | Disabled vehicle incident type. |
|
||||
| MassTransit | Mass transit incident type. |
|
||||
| Miscellaneous | Miscellaneous incident type. |
|
||||
| OtherNews | Other news incident type. |
|
||||
| PlannedEvent | Planned event incident type. |
|
||||
| RoadHazard | Road hazard incident type. |
|
||||
| Construction | Construction incident type. |
|
||||
| Alert | Alert incident type. |
|
||||
| Weather | Weather incident type. |
|
||||
|
||||
<a name="TravelModeType"></a> TravelModeType Enumeration
|
||||
--------------------------
|
||||
|
||||
The mode of travel for the route.
|
||||
|
||||
| Name | Description |
|
||||
|----------|---------------|
|
||||
| Driving | Driving mode. |
|
||||
| Walking | Walking mode. |
|
||||
| Transit | Transit mode. |
|
||||
|
||||
<a name="EnhancedResponseClasses"></a> Enhanced Response Classes
|
||||
================================================================
|
||||
|
||||
These are response classes that have been extended extensively to make them easier to use.
|
||||
|
||||
<a name="DistanceMatrix"><a/> DistanceMatrix Class
|
||||
--------------------------------------------------
|
||||
|
||||
### Methods
|
||||
|
||||
An indexing system has been added to the DistanceMatrix class to make it easy to retrieve cells by origin and destination index.
|
||||
|
||||
| Name | Return Type | Description |
|
||||
|-----------------|-------------|----------------------------------------------------------|
|
||||
| GetCell(int originIdx, int destinationIdx) | DistanceMatrixCell | Retrives the distance matrix cell for a specified origin-destination pair. Returns -1 if a cell can not be found in the results or had an error in calculation. |
|
||||
| GetCell(int originIdx, int destinationIdx, DateTime timeInterval) | DistanceMatrixCell | Retrives the distance matrix cell for a specified origin-destination pair and time interval. Returns -1 if a cell can not be found in the results or had an error in calculation. |
|
||||
| GetCell(int originIdx, int destinationIdx, int timeIntervalIdx) | DistanceMatrixCell | Retrives the distance matrix cell for a specified origin-destination pair and time interval. Returns -1 if a cell can not be found in the results or had an error in calculation. |
|
||||
| GetCells(int originIdx, int destinationIdx) | DistanceMatrixCell[] | Gets all cells for the specified origin and destination index, ordered by time (ascending). |
|
||||
| GetDistance(int originIdx, int destinationIdx) | double | Retrives the travel distance for a specified origin-destination pair. Returns -1 if a cell can not be found in the results or had an error in calculation. |
|
||||
| GetDistance(int originIdx, int destinationIdx, DateTime timeInterval) | double | Retrives the travel distance for a specified origin-destination pair and time interval. Returns -1 if a cell can not be found in the results or had an error in calculation. |
|
||||
| GetDistance(int originIdx, int destinationIdx, int timeIntervalIdx) | double | Retrives the travel distance for a specified origin-destination pair and time interval. Returns -1 if a cell can not be found in the results or had an error in calculation. |
|
||||
| GetDistances(int originIdx, int destinationIdx) | double[] | Gets all travel distances for the specified origin and destination index, ordered by time (ascending). |
|
||||
| GetTime(int originIdx, int destinationIdx) | double | Retrives the travel time for a specified origin-destination pair. Returns -1 if a cell can not be found in the results or had an error in calculation. |
|
||||
| GetTime(int originIdx, int destinationIdx, DateTime timeInterval) | double | Retrieves the travel time for a specified origin-destination pair and time interval. Returns -1 if a cell can not be found in the results or had an error in calculation. |
|
||||
| GetTime(int originIdx, int destinationIdx, int timeIntervalIdx) | double | Retrieves the travel time for a specified origin-destination pair and time interval. Returns -1 if a cell can not be found in the results or had an error in calculation. |
|
||||
| GetTimes(int originIdx, int destinationIdx) | double[] | Gets all travel times for the specified origin and destination index, ordered by time (ascending). |
|
||||
|
||||
|
||||
|
||||
### Properties
|
||||
|
||||
| Name | Type | Description |
|
||||
|---------------------|------------------------|----------------|
|
||||
| Destinations | [SimpleWaypoint](#SimpleWaypoint)\[\] | The array of destinations that were used to calculate the distance matrix. |
|
||||
| ErrorMessage| string | Details of an error that may have occurred when processing the request. |
|
||||
| Origins | [SimpleWaypoint](#SimpleWaypoint)\[\] | The array of destinations that were used to calculate the distance matrix. |
|
||||
| Result | DistanceMatrixCell\[\] | Array of distance matrix cell results containing information for each coordinate pair and time interval. |
|
||||
| TimeIntervals | List<DateTime> | A list of time intervals in which the distance matrix calculated for. |
|
|
@ -0,0 +1,195 @@
|
|||
* [Creating a Bing Maps key](#CreatingABingMapsKey)
|
||||
* [Running the Samples](#RunningTheSamples)
|
||||
* [Adding the Bing Maps REST Toolkit to your project](#AddingToolkitToProject)
|
||||
* [How to make a Request to the REST services](#HowToMakeARequest)
|
||||
|
||||
The Bing Maps REST services allow you to query the raw data that powers Bing Maps. The Bing Maps REST Services Toolkit provides an easy to use .NET wrapper around these services. To keep things easy the request and response classes in this library are aligned with the structure of the [documented Bing Maps REST Services API](https://msdn.microsoft.com/en-us/library/ff701713.aspx).
|
||||
|
||||
<a name="CreatingABingMapsKey"></a> Creating a Bing Maps key
|
||||
------------------------
|
||||
|
||||
To use Bing Maps in your own application you will need a Bing Maps key. All Bing Maps map controls and services use a Bing Maps key for authentication. You can get a Bing Maps key in two ways:
|
||||
|
||||
**Through the Bing Maps Portal**
|
||||
|
||||
The [Bing Maps Account Center](http://www.bingmapsportal.com/) is the main portal where Bing Maps accounts can be managed and monitored. This is recommended if you are a Microsoft Volume license customer.
|
||||
|
||||
- Go to <a href="https://www.bingmapsportal.com/" class="uri" class="uri">https://www.bingmapsportal.com/</a>
|
||||
|
||||
- Press the sign in button and follow the steps to sign up.
|
||||
|
||||
- Once logged in go to My Account -> My Keys
|
||||
|
||||
- Press the button to create a new key.
|
||||
|
||||
- Add an application name and optionally a URL. It doesn’t matter what this is, it’s for your own information to help remember what the key is for. Set the key type to Basic, and the application type to public website. This will give you 125,000 transactions a year for free.
|
||||
|
||||
- Now that you have a key, it can be used to access all the Bing Maps map controls and services.
|
||||
|
||||
**Through the Azure Marketplace**
|
||||
|
||||
If you are an Azure user, you can create a Bing Maps key through the [Azure marketplace](https://azure.microsoft.com/en-us/marketplace/partners/bingmaps/mapapis/). Going through the Azure Marketplace provides a bit more flexibility for licensing as you would license Bing Maps from month to month, rather than being locked into a 1 year+ contract. Additionally, smaller volumes of transactions can be purchased through the Azure marketplace than through Volume licensing. However, if your application does any of the following, you will want to create a Bing Maps account through the Bing Maps account center.
|
||||
|
||||
- Your application will generate more than 500,000 transactions a month or you expect it to exceed this amount at some point. The Azure marketplace is limited to licensing this many transactions.
|
||||
|
||||
- Your application will be used for used with real-time GPS positioned assets such as truck or personnel. This requires a Bing Maps account created through the Bing Maps account center.
|
||||
|
||||
- If you want detailed usage reports. Currently the reporting functionality in the Azure marketplace is limited.
|
||||
|
||||
To find out about licensing options and learn about Bing Maps controls, please visit [www.microsoft.com/maps](http://www.microsoft.com/maps).
|
||||
|
||||
<a name="RunningTheSamples"></a> Running the Samples
|
||||
-------------------
|
||||
|
||||
Download the complete project including the samples and the source code for the Ring Maps REST toolkit. All of the samples require a Bing Maps key to work. To add your Bing Maps key to the sample, open the **App.config** file of the sample and add it to the **BingMapsKey** property. This property likely has a placeholder value of **YOUR\_BING\_MAPS\_KEY**. Once this is done, simply run the sample in debug or release mode.
|
||||
|
||||
<a name="AddingToolkitToProject"></a> Adding the Bing Maps REST Toolkit to your project
|
||||
-------------------------------------------------
|
||||
|
||||
There are two options for adding the Bing Maps REST toolkit to your project.
|
||||
|
||||
**Use the NuGet Package**
|
||||
|
||||
The Bing Maps REST Services Toolkit is available as a [NuGet package](https://www.nuget.org/packages/BingMapsRESTToolkit). If using Visual Studio, open the **NuGet Package Manager**, select the **Browse** tab and search for "Bing Maps REST". This will reduce the list of results enough to find the "BingMapsRESTToolkit" package. If you want to verify you have the correct package, the listed owner of the package is bingmaps and the author is Microsoft.
|
||||
|
||||
Alternatively, if you are using the nuget command line:
|
||||
|
||||
> PM> Install-Package BingMapsRESTToolkit
|
||||
|
||||
**Download the Source Code**
|
||||
|
||||
Download the source code and add the BingMapsRESTToolkit project to your solution. Once this is done you can a reference to it from your main project.
|
||||
|
||||
<a name="HowToMakeARequest"></a> How to make a Request to the REST services
|
||||
------------------------------------------
|
||||
|
||||
| Update |
|
||||
|--------|
|
||||
| All requests classes now have an **Execute** method which can be used instead of the **ServiceManager** for all requests that return a response object to make things even easier. For requests that return and image stream, continue to use the **ServiceManager**. |
|
||||
|
||||
The Bing Maps REST Toolkit has two key components, a service manager and a set of request classes. The [ServiceManager](https://github.com/Microsoft/BingMapsRESTToolkit/blob/master/Docs/API%20Reference.md#ServiceManager) is a static class that makes it easy to asynchronously process any Bing Maps REST request which inherits from the [BaseRestReuqest](https://github.com/Microsoft/BingMapsRESTToolkit/blob/master/Docs/API%20Reference.md#BaseRestRequest) class. Here is a list of the different requests classes available:
|
||||
|
||||
- [DistanceMatrixRequest Class](https://github.com/Microsoft/BingMapsRESTToolkit/blob/master/Docs/API%20Reference.md#DistanceMatrixRequest)
|
||||
|
||||
- [ElevationRequest Class](https://github.com/Microsoft/BingMapsRESTToolkit/blob/master/Docs/API%20Reference.md#ElevationRequest)
|
||||
|
||||
- [GeocodeRequest Class](https://github.com/Microsoft/BingMapsRESTToolkit/blob/master/Docs/API%20Reference.md#GeocodeRequest)
|
||||
|
||||
- [ImageryMetadataRequest Class](https://github.com/Microsoft/BingMapsRESTToolkit/blob/master/Docs/API%20Reference.md#ImageryMetadataRequest)
|
||||
|
||||
- [ImageryRequest Class](https://github.com/Microsoft/BingMapsRESTToolkit/blob/master/Docs/API%20Reference.md#ImageryRequest)
|
||||
|
||||
- [ReverseGeocodeRequest Class](https://github.com/Microsoft/BingMapsRESTToolkit/blob/master/Docs/API%20Reference.md#ReverseGeocodeRequest)
|
||||
|
||||
- [RouteMajorRoadsRequest Class](https://github.com/Microsoft/BingMapsRESTToolkit/blob/master/Docs/API%20Reference.md#RouteMajorRoadsRequest)
|
||||
|
||||
- [RouteRequest Class](https://github.com/Microsoft/BingMapsRESTToolkit/blob/master/Docs/API%20Reference.md#RouteRequest)
|
||||
|
||||
- [TrafficRequest Class](https://github.com/Microsoft/BingMapsRESTToolkit/blob/master/Docs/API%20Reference.md#TrafficRequest)
|
||||
|
||||
The **ServiceManager** class has two static methods; **GetResponseAsync** and **GetImageAsync**. The **GetResponseAsync** method will return a Response object from the Bing Maps REST services which aligns with the documented Response object. The **GetImageAsync** method will return a stream containing the image data.
|
||||
|
||||
**Requesting a Response object**
|
||||
|
||||
The following is an example of how to make a geocode request and get the response from the Bing Maps REST services.
|
||||
|
||||
```
|
||||
//Create a request.
|
||||
var request = new GeocodeRequest()
|
||||
{
|
||||
Query = "New York, NY",
|
||||
IncludeIso2 = true,
|
||||
IncludeNeighborhood = true,
|
||||
MaxResults = 25,
|
||||
BingMapsKey = "YOUR_BING_MAPS_KEY"
|
||||
};
|
||||
|
||||
//Process the request by using the ServiceManager.
|
||||
var response = await request.Execute(request);
|
||||
|
||||
if(response != null &&
|
||||
response.ResourceSets != null &&
|
||||
response.ResourceSets.Length > 0 &&
|
||||
response.ResourceSets[0].Resources != null &&
|
||||
response.ResourceSets[0].Resources.Length > 0)
|
||||
{
|
||||
var result = response.ResourceSets[0].Resources[0] as BingMapsRESTToolkit.Location;
|
||||
|
||||
//Do something with the result.
|
||||
}
|
||||
```
|
||||
|
||||
Here is the same code sample using the **ServiceManager**.
|
||||
|
||||
```
|
||||
//Create a request.
|
||||
var request = new GeocodeRequest()
|
||||
{
|
||||
Query = "New York, NY",
|
||||
IncludeIso2 = true,
|
||||
IncludeNeighborhood = true,
|
||||
MaxResults = 25,
|
||||
BingMapsKey = "YOUR_BING_MAPS_KEY"
|
||||
};
|
||||
|
||||
//Process the request by using the ServiceManager.
|
||||
var response = await ServiceManager.GetResponseAsync(request);
|
||||
|
||||
if(response != null &&
|
||||
response.ResourceSets != null &&
|
||||
response.ResourceSets.Length > 0 &&
|
||||
response.ResourceSets[0].Resources != null &&
|
||||
response.ResourceSets[0].Resources.Length > 0)
|
||||
{
|
||||
var result = response.ResourceSets[0].Resources[0] as BingMapsRESTToolkit.Location;
|
||||
|
||||
//Do something with the result.
|
||||
}
|
||||
```
|
||||
|
||||
**Requesting an Image Result**
|
||||
|
||||
The following is an example of how to request a map image from the Bing Maps REST services to retrieve the image stream.
|
||||
|
||||
```
|
||||
//Create an image request.
|
||||
var request = 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 = "YOUR_BING_MAPS_KEY"
|
||||
};
|
||||
|
||||
//Process the request by using the ServiceManager.
|
||||
using (var imageStream = await ServiceManager.GetImageAsync(request))
|
||||
{
|
||||
//Do something with the image stream.
|
||||
|
||||
//Here is how to display the image in an Image tag in a WPF app.
|
||||
var bitmapImage = new BitmapImage();
|
||||
bitmapImage.BeginInit();
|
||||
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
|
||||
bitmapImage.StreamSource = imageStream;
|
||||
bitmapImage.EndInit();
|
||||
MyImage.Source = bitmapImage;
|
||||
}
|
||||
```
|
|
@ -0,0 +1,4 @@
|
|||
Welcome to the Bing Maps REST Services Toolkit documentation!
|
||||
|
||||
* [Getting Started](Getting%20Started.md)
|
||||
* [API Reference](API%20Reference.md)
|
|
@ -1,11 +1,11 @@
|
|||
![Bing Maps Logo](https://github.com/Microsoft/Bing-Maps-V8-TypeScript-Definitions/blob/master/images/BingMapsLogoTeal.png)
|
||||
|
||||
[![NuGet](https://img.shields.io/badge/NuGet-1.0.5-blue.svg)](https://www.nuget.org/packages/BingMapsRESTToolkit)
|
||||
[![NuGet](https://img.shields.io/badge/NuGet-1.0.6-blue.svg)](https://www.nuget.org/packages/BingMapsRESTToolkit)
|
||||
[![license](https://img.shields.io/badge/license-MIT-yellow.svg)](https://github.com/Microsoft/BingMapsRESTToolkit/blob/master/LICENSE.md)
|
||||
|
||||
# Bing Maps REST Toolkit for .NET #
|
||||
|
||||
This is a portable .NET class library which provides a set of tools that make it easy to access the Bing Maps REST services in .NET based apps. Take a look at the [Getting Started documentation](https://github.com/Microsoft/BingMapsRESTToolkit/wiki/Getting-Started).
|
||||
This is a portable .NET class library which provides a set of tools that make it easy to access the Bing Maps REST services in .NET based apps. Take a look at the [Getting Started documentation](https://github.com/Microsoft/BingMapsRESTToolkit/blob/master/Docs/Getting%20Started.md).
|
||||
|
||||
## Features ##
|
||||
|
||||
|
@ -13,6 +13,7 @@ This is a portable .NET class library which provides a set of tools that make it
|
|||
* Implements the documented [best practices for Bing Maps](https://msdn.microsoft.com/en-us/library/dn894107.aspx). For example, it automatically encodes query parameters. A commonly overlooked stepped which greatly reduces the chances of invalid queries being sent to the service.
|
||||
* Handles errors and rate limiting by catching exception and returning response with error message.
|
||||
* Automatically determines when a POST request should be made instead of a GET request.
|
||||
* Fast indexed lookups of Distance Matrix results.
|
||||
|
||||
## NuGet Package ##
|
||||
|
||||
|
@ -25,6 +26,7 @@ Alternatively, if you are using the nuget command line:
|
|||
## Supported Platforms ##
|
||||
|
||||
* .NET Framework 4.5+
|
||||
* .NET Standard 1.4+
|
||||
* Universal Windows Platform (UWP)
|
||||
* Windows 10
|
||||
* Windows 8.1
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
using BingMapsRESTToolkit;
|
||||
using System;
|
||||
|
||||
namespace RESTToolkitTestConsoleApp.NetStandard
|
||||
{
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
var r = ServiceManager.GetResponseAsync(new GeocodeRequest()
|
||||
{
|
||||
BingMapsKey = System.Configuration.ConfigurationManager.AppSettings.Get("BingMapsKey"),
|
||||
Query = "Seattle"
|
||||
}).GetAwaiter().GetResult();
|
||||
|
||||
if (r != null && r.ResourceSets != null &&
|
||||
r.ResourceSets.Length > 0 &&
|
||||
r.ResourceSets[0].Resources != null &&
|
||||
r.ResourceSets[0].Resources.Length > 0)
|
||||
{
|
||||
for (var i = 0; i < r.ResourceSets[0].Resources.Length; i++)
|
||||
{
|
||||
Console.WriteLine((r.ResourceSets[0].Resources[i] as Location).Name);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("No results found.");
|
||||
}
|
||||
|
||||
Console.ReadLine();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
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("RESTToolkitTestConsoleApp.NetStandard")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("RESTToolkitTestConsoleApp.NetStandard")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2017")]
|
||||
[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)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("1bcb3853-dafe-4b33-9888-23666a1040b9")]
|
||||
|
||||
// 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,65 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" 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>{1BCB3853-DAFE-4B33-9888-23666A1040B9}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RootNamespace>RESTToolkitTestConsoleApp.NetStandard</RootNamespace>
|
||||
<AssemblyName>RESTToolkitTestConsoleApp.NetStandard</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
<TargetFrameworkProfile />
|
||||
</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.Core" />
|
||||
<Reference Include="System.Runtime.Serialization" />
|
||||
<Reference Include="System.Runtime.Serialization.Primitives, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\..\packages\System.Runtime.Serialization.Primitives.4.1.1\lib\net46\System.Runtime.Serialization.Primitives.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\Source\BingMapsRESTToolkit.Standard\BingMapsRESTToolkit.Standard.csproj">
|
||||
<Project>{f30dc2e6-fe4f-4f0b-bd52-cda1940cac4f}</Project>
|
||||
<Name>BingMapsRESTToolkit.Standard</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="System.Runtime.Serialization.Primitives" version="4.1.1" targetFramework="net462" />
|
||||
</packages>
|
|
@ -2,7 +2,7 @@
|
|||
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">
|
||||
Title="Bing Maps REST Service Toolkit Test app" Height="600" Width="900">
|
||||
|
||||
<Window.Resources>
|
||||
<Style TargetType="Button">
|
||||
|
@ -12,41 +12,46 @@
|
|||
</Window.Resources>
|
||||
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="200"/>
|
||||
<ColumnDefinition/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="130"/>
|
||||
<RowDefinition Height="70"/>
|
||||
<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"/>
|
||||
<Button Content="Geospatial Endpoint" Click="GeospatialEndpointBtn_Clicked"/>
|
||||
<ScrollViewer Grid.RowSpan="2" VerticalScrollBarVisibility="Auto">
|
||||
<StackPanel>
|
||||
<Button Content="Geocode" Click="GeocodeBtn_Clicked" Height="30"/>
|
||||
<Button Content="Reverse Geocode" Click="ReverseGeocodeBtn_Clicked" Height="30"/>
|
||||
<Button Content="Elevation" Click="ElevationBtn_Clicked" Height="30"/>
|
||||
<Button Content="Route" Click="RouteBtn_Clicked" Height="30"/>
|
||||
<Button Content="Transit Route" Click="TransitRouteBtn_Clicked" Height="30"/>
|
||||
<Button Content="Traffic" Click="TrafficBtn_Clicked" Height="30"/>
|
||||
<Button Content="Imagery Metadata" Click="ImageMetadataBtn_Clicked" Height="30"/>
|
||||
<Button Content="Static Image" Click="StaticImageBtn_Clicked" Height="30"/>
|
||||
<Button Content="Static Image Metadata" Click="StaticImageMetadataBtn_Clicked" Height="30"/>
|
||||
<Button Content="Geospatial Endpoint" Click="GeospatialEndpointBtn_Clicked" Height="30"/>
|
||||
<Button Content="Distance Matrix" Click="DistanceMatrixBtn_Clicked" Height="30"/>
|
||||
<Button Content="Distance Matrix Histogram" Click="DistanceMatrixHistogramBtn_Clicked" Height="30"/>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
|
||||
<StackPanel Grid.RowSpan="2" Grid.Column="1">
|
||||
<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"/>
|
||||
|
||||
<TextBox Name="RequestUrlTbx" Height="25" Margin="10,0"/>
|
||||
</StackPanel>
|
||||
|
||||
<TabControl Grid.Row="1">
|
||||
<TabControl Grid.Row="1" Grid.Column="1">
|
||||
<TabItem Name="ResponseTab" Header="Response">
|
||||
<TreeView Name="ResultTreeView" BorderThickness="0">
|
||||
<TreeView.Resources>
|
||||
|
@ -69,7 +74,12 @@
|
|||
</TabItem>
|
||||
</TabControl>
|
||||
|
||||
<StackPanel Grid.Row="1" Orientation="Horizontal" Height="35" HorizontalAlignment="Right" VerticalAlignment="Top">
|
||||
<Grid Name="RequestProgressBar" Width="300" Height="35" Grid.Row="1" Grid.Column="1" Visibility="Collapsed">
|
||||
<ProgressBar IsIndeterminate="True" />
|
||||
<TextBlock Name="RequestProgressBarText" HorizontalAlignment="Center" VerticalAlignment="Center">Processing...</TextBlock>
|
||||
</Grid>
|
||||
|
||||
<StackPanel Grid.Row="1" Grid.Column="1" Orientation="Horizontal" Height="35" HorizontalAlignment="Right" VerticalAlignment="Top">
|
||||
<Button Content="Expand All" Click="ExpandTree_Clicked"/>
|
||||
<Button Content="Collapse" Click="CollapseTree_Clicked"/>
|
||||
</StackPanel>
|
||||
|
|
|
@ -28,8 +28,9 @@ using System.Collections.Generic;
|
|||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Animation;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Threading;
|
||||
|
||||
namespace RESTToolkitTestApp
|
||||
{
|
||||
|
@ -39,6 +40,9 @@ namespace RESTToolkitTestApp
|
|||
|
||||
private string BingMapsKey = System.Configuration.ConfigurationManager.AppSettings.Get("BingMapsKey");
|
||||
|
||||
private DispatcherTimer _timer;
|
||||
private TimeSpan _time;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructor
|
||||
|
@ -46,6 +50,21 @@ namespace RESTToolkitTestApp
|
|||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_timer = new DispatcherTimer(new TimeSpan(0, 0, 1), DispatcherPriority.Normal, delegate
|
||||
{
|
||||
if (_time != null)
|
||||
{
|
||||
RequestProgressBarText.Text = string.Format("Time remaining: {0}", _time);
|
||||
|
||||
if (_time == TimeSpan.Zero)
|
||||
{
|
||||
_timer.Stop();
|
||||
}
|
||||
|
||||
_time = _time.Add(TimeSpan.FromSeconds(-1));
|
||||
}
|
||||
}, Application.Current.Dispatcher);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -370,6 +389,59 @@ namespace RESTToolkitTestApp
|
|||
ProcessRequest(r);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Demostrates how to make a Distance Matrix Request.
|
||||
/// </summary>
|
||||
private async void DistanceMatrixBtn_Clicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var r = new DistanceMatrixRequest()
|
||||
{
|
||||
Origins = new List<SimpleWaypoint>()
|
||||
{
|
||||
new SimpleWaypoint(47.6044, -122.3345),
|
||||
new SimpleWaypoint(47.6731, -122.1185),
|
||||
new SimpleWaypoint(47.6149, -122.1936)
|
||||
},
|
||||
Destinations = new List<SimpleWaypoint>()
|
||||
{
|
||||
new SimpleWaypoint(45.5347, -122.6231),
|
||||
new SimpleWaypoint(47.4747, -122.2057)
|
||||
},
|
||||
BingMapsKey = BingMapsKey,
|
||||
TimeUnits = TimeUnitType.Minutes,
|
||||
DistanceUnits = DistanceUnitType.Miles
|
||||
};
|
||||
|
||||
ProcessRequest(r);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Demostrates how to make a Distance Matrix Histogram Request.
|
||||
/// </summary>
|
||||
private void DistanceMatrixHistogramBtn_Clicked(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var r = new DistanceMatrixRequest()
|
||||
{
|
||||
Origins = new List<SimpleWaypoint>()
|
||||
{
|
||||
new SimpleWaypoint(47.6044, -122.3345),
|
||||
new SimpleWaypoint(47.6731, -122.1185),
|
||||
new SimpleWaypoint(47.6149, -122.1936)
|
||||
},
|
||||
Destinations = new List<SimpleWaypoint>()
|
||||
{
|
||||
new SimpleWaypoint(45.5347, -122.6231),
|
||||
new SimpleWaypoint(47.4747, -122.2057)
|
||||
},
|
||||
BingMapsKey = BingMapsKey,
|
||||
StartTime = DateTime.Now,
|
||||
EndTime = DateTime.Now.AddHours(8),
|
||||
Resolution = 4
|
||||
};
|
||||
|
||||
ProcessRequest(r);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
@ -378,15 +450,27 @@ namespace RESTToolkitTestApp
|
|||
{
|
||||
try
|
||||
{
|
||||
ProcessingTimeTbx.Text = "";
|
||||
RequestProgressBar.Visibility = Visibility.Visible;
|
||||
RequestProgressBarText.Text = string.Empty;
|
||||
|
||||
ResultTreeView.ItemsSource = null;
|
||||
|
||||
RequestUrlTbx.Text = request.GetRequestUrl();
|
||||
|
||||
var start = DateTime.Now;
|
||||
|
||||
//Process the request by using the ServiceManager.
|
||||
var response = await ServiceManager.GetResponseAsync(request);
|
||||
//Execute the request.
|
||||
var response = await request.Execute((remainingTime) =>
|
||||
{
|
||||
if (remainingTime > -1)
|
||||
{
|
||||
_time = TimeSpan.FromSeconds(remainingTime);
|
||||
|
||||
RequestProgressBarText.Text = string.Format("Time remaining {0} ", _time);
|
||||
|
||||
_timer.Start();
|
||||
}
|
||||
});
|
||||
|
||||
var end = DateTime.Now;
|
||||
|
||||
|
@ -394,8 +478,10 @@ namespace RESTToolkitTestApp
|
|||
|
||||
ProcessingTimeTbx.Text = string.Format(CultureInfo.InvariantCulture, "{0:0} ms", processingTime.TotalMilliseconds);
|
||||
|
||||
List<ObjectNode> nodes = new List<ObjectNode>();
|
||||
nodes.Add(new ObjectNode("result", response));
|
||||
var nodes = new List<ObjectNode>()
|
||||
{
|
||||
new ObjectNode("result", response)
|
||||
};
|
||||
ResultTreeView.ItemsSource = nodes;
|
||||
|
||||
ResponseTab.IsSelected = true;
|
||||
|
@ -404,12 +490,18 @@ namespace RESTToolkitTestApp
|
|||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
|
||||
_timer.Stop();
|
||||
RequestProgressBar.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
|
||||
private async void ProcessImageRequest(BaseImageryRestRequest imageRequest)
|
||||
{
|
||||
try
|
||||
{
|
||||
RequestProgressBar.Visibility = Visibility.Visible;
|
||||
RequestProgressBarText.Text = string.Empty;
|
||||
|
||||
RequestUrlTbx.Text = imageRequest.GetRequestUrl();
|
||||
|
||||
//Process the request by using the ServiceManager.
|
||||
|
@ -429,6 +521,8 @@ namespace RESTToolkitTestApp
|
|||
{
|
||||
MessageBox.Show(ex.Message);
|
||||
}
|
||||
|
||||
RequestProgressBar.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
|
||||
private void ExpandTree_Clicked(object sender, RoutedEventArgs e)
|
||||
|
|
|
@ -186,9 +186,9 @@ namespace RESTToolkitTestApp
|
|||
{
|
||||
if (p.PropertyType.IsPublic)
|
||||
{
|
||||
if (p.PropertyType.IsClass || p.PropertyType.IsArray)
|
||||
if (p.PropertyType.IsClass || p.PropertyType.IsArray || p.PropertyType.FullName.StartsWith("System.Collections.Generic.List"))
|
||||
{
|
||||
if (p.PropertyType.IsArray)
|
||||
if (p.PropertyType.IsArray || p.PropertyType.FullName.StartsWith("System.Collections.Generic.List"))
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
|
@ -0,0 +1,122 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard1.4</TargetFramework>
|
||||
<Version>1.0.6</Version>
|
||||
<Authors>Microsoft</Authors>
|
||||
<Company>Microsoft</Company>
|
||||
<Description>A toolkit that makes it easy to access the Bing Maps REST services from .NET</Description>
|
||||
<Copyright>Microsoft 2017</Copyright>
|
||||
<PackageLicenseUrl>https://github.com/Microsoft/BingMapsRESTToolkit/blob/master/LICENSE.md</PackageLicenseUrl>
|
||||
<PackageProjectUrl>https://github.com/Microsoft/BingMapsRESTToolkit</PackageProjectUrl>
|
||||
<PackageIconUrl>https://www.bing.com/sa/simg/bing_p_rr_teal_min.ico</PackageIconUrl>
|
||||
<PackageTags>Microsoft "Bing Maps" Maps GIS Map Geospatial VB C# .NET REST</PackageTags>
|
||||
<PackageReleaseNotes>See the changelog here: https://github.com/Microsoft/BingMapsRESTToolkit/blob/master/CHANGELOG.md</PackageReleaseNotes>
|
||||
<PackageId>BingMapsRESTToolkit</PackageId>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\CustomMapStyleManager.cs" Link="CustomMapStyleManager.cs" />
|
||||
<Compile Include="..\Enums\AvoidType.cs" Link="Enums\AvoidType.cs" />
|
||||
<Compile Include="..\Enums\ConfidenceLevel.cs" Link="Enums\ConfidenceLevel.cs" />
|
||||
<Compile Include="..\Enums\DistanceUnitType.cs" Link="Enums\DistanceUnitType.cs" />
|
||||
<Compile Include="..\Enums\ElevationType.cs" Link="Enums\ElevationType.cs" />
|
||||
<Compile Include="..\Enums\EntityType.cs" Link="Enums\EntityType.cs" />
|
||||
<Compile Include="..\Enums\ImageFormatType.cs" Link="Enums\ImageFormatType.cs" />
|
||||
<Compile Include="..\Enums\ImageResolutionType.cs" Link="Enums\ImageResolutionType.cs" />
|
||||
<Compile Include="..\Enums\ImageryType.cs" Link="Enums\ImageryType.cs" />
|
||||
<Compile Include="..\Enums\ManeuverType.cs" Link="Enums\ManeuverType.cs" />
|
||||
<Compile Include="..\Enums\RouteAttributeType.cs" Link="Enums\RouteAttributeType.cs" />
|
||||
<Compile Include="..\Enums\RouteOptimizationType.cs" Link="Enums\RouteOptimizationType.cs" />
|
||||
<Compile Include="..\Enums\RouteTimeType.cs" Link="Enums\RouteTimeType.cs" />
|
||||
<Compile Include="..\Enums\SeverityType.cs" Link="Enums\SeverityType.cs" />
|
||||
<Compile Include="..\Enums\TimeUnitType.cs" Link="Enums\TimeUnitType.cs" />
|
||||
<Compile Include="..\Enums\TrafficType.cs" Link="Enums\TrafficType.cs" />
|
||||
<Compile Include="..\Enums\TravelModeType.cs" Link="Enums\TravelModeType.cs" />
|
||||
<Compile Include="..\Enums\WarningType.cs" Link="Enums\WarningType.cs" />
|
||||
<Compile Include="..\Internal\DateTimeHelper.cs" Link="Internal\DateTimeHelper.cs" />
|
||||
<Compile Include="..\Internal\EnumHelper.cs" Link="Internal\EnumHelper.cs" />
|
||||
<Compile Include="..\Internal\ServiceHelper.cs" Link="Internal\ServiceHelper.cs" />
|
||||
<Compile Include="..\Internal\SpatialTools.cs" Link="Internal\SpatialTools.cs" />
|
||||
<Compile Include="..\Models\BoundingBox.cs" Link="Models\BoundingBox.cs" />
|
||||
<Compile Include="..\Models\Coordinate.cs" Link="Models\Coordinate.cs" />
|
||||
<Compile Include="..\Models\CustomMapStyles\BorderedMapElementStyle.cs" Link="Models\CustomMapStyles\BorderedMapElementStyle.cs" />
|
||||
<Compile Include="..\Models\CustomMapStyles\CustomMapStyle.cs" Link="Models\CustomMapStyles\CustomMapStyle.cs" />
|
||||
<Compile Include="..\Models\CustomMapStyles\MapElements.cs" Link="Models\CustomMapStyles\MapElements.cs" />
|
||||
<Compile Include="..\Models\CustomMapStyles\MapElementStyle.cs" Link="Models\CustomMapStyles\MapElementStyle.cs" />
|
||||
<Compile Include="..\Models\CustomMapStyles\SettingsStyle.cs" Link="Models\CustomMapStyles\SettingsStyle.cs" />
|
||||
<Compile Include="..\Models\ImageryPushpin.cs" Link="Models\ImageryPushpin.cs" />
|
||||
<Compile Include="..\Models\PointCompression.cs" Link="Models\PointCompression.cs" />
|
||||
<Compile Include="..\Models\ResponseModels\Address.cs" Link="Models\ResponseModels\Address.cs" />
|
||||
<Compile Include="..\Models\ResponseModels\BirdseyeMetadata.cs" Link="Models\ResponseModels\BirdseyeMetadata.cs" />
|
||||
<Compile Include="..\Models\ResponseModels\CompressedPointList.cs" Link="Models\ResponseModels\CompressedPointList.cs" />
|
||||
<Compile Include="..\Models\ResponseModels\CoverageArea.cs" Link="Models\ResponseModels\CoverageArea.cs" />
|
||||
<Compile Include="..\Models\ResponseModels\Detail.cs" Link="Models\ResponseModels\Detail.cs" />
|
||||
<Compile Include="..\Models\ResponseModels\DistanceMatrix.cs" Link="Models\ResponseModels\DistanceMatrix.cs" />
|
||||
<Compile Include="..\Models\ResponseModels\DistanceMatrixAsyncStatus.cs" Link="Models\ResponseModels\DistanceMatrixAsyncStatus.cs" />
|
||||
<Compile Include="..\Models\ResponseModels\DistanceMatrixCell.cs" Link="Models\ResponseModels\DistanceMatrixCell.cs" />
|
||||
<Compile Include="..\Models\ResponseModels\ElevationData.cs" Link="Models\ResponseModels\ElevationData.cs" />
|
||||
<Compile Include="..\Models\ResponseModels\Generalization.cs" Link="Models\ResponseModels\Generalization.cs" />
|
||||
<Compile Include="..\Models\ResponseModels\GeospatialEndpointResponse.cs" Link="Models\ResponseModels\GeospatialEndpointResponse.cs" />
|
||||
<Compile Include="..\Models\ResponseModels\GeospatialService.cs" Link="Models\ResponseModels\GeospatialService.cs" />
|
||||
<Compile Include="..\Models\ResponseModels\Hint.cs" Link="Models\ResponseModels\Hint.cs" />
|
||||
<Compile Include="..\Models\ResponseModels\ImageryMetadata.cs" Link="Models\ResponseModels\ImageryMetadata.cs" />
|
||||
<Compile Include="..\Models\ResponseModels\ImageryProvider.cs" Link="Models\ResponseModels\ImageryProvider.cs" />
|
||||
<Compile Include="..\Models\ResponseModels\Instruction.cs" Link="Models\ResponseModels\Instruction.cs" />
|
||||
<Compile Include="..\Models\ResponseModels\ItineraryItem.cs" Link="Models\ResponseModels\ItineraryItem.cs" />
|
||||
<Compile Include="..\Models\ResponseModels\Line.cs" Link="Models\ResponseModels\Line.cs" />
|
||||
<Compile Include="..\Models\ResponseModels\Location.cs" Link="Models\ResponseModels\Location.cs" />
|
||||
<Compile Include="..\Models\ResponseModels\Pixel.cs" Link="Models\ResponseModels\Pixel.cs" />
|
||||
<Compile Include="..\Models\ResponseModels\Point.cs" Link="Models\ResponseModels\Point.cs" />
|
||||
<Compile Include="..\Models\ResponseModels\PushpinMetdata.cs" Link="Models\ResponseModels\PushpinMetdata.cs" />
|
||||
<Compile Include="..\Models\ResponseModels\QueryParseValue.cs" Link="Models\ResponseModels\QueryParseValue.cs" />
|
||||
<Compile Include="..\Models\ResponseModels\Resource.cs" Link="Models\ResponseModels\Resource.cs" />
|
||||
<Compile Include="..\Models\ResponseModels\ResourceSet.cs" Link="Models\ResponseModels\ResourceSet.cs" />
|
||||
<Compile Include="..\Models\ResponseModels\Response.cs" Link="Models\ResponseModels\Response.cs" />
|
||||
<Compile Include="..\Models\ResponseModels\RoadShield.cs" Link="Models\ResponseModels\RoadShield.cs" />
|
||||
<Compile Include="..\Models\ResponseModels\Route.cs" Link="Models\ResponseModels\Route.cs" />
|
||||
<Compile Include="..\Models\ResponseModels\RouteLeg.cs" Link="Models\ResponseModels\RouteLeg.cs" />
|
||||
<Compile Include="..\Models\ResponseModels\RoutePath.cs" Link="Models\ResponseModels\RoutePath.cs" />
|
||||
<Compile Include="..\Models\ResponseModels\RouteSubLeg.cs" Link="Models\ResponseModels\RouteSubLeg.cs" />
|
||||
<Compile Include="..\Models\ResponseModels\SeaLevelData.cs" Link="Models\ResponseModels\SeaLevelData.cs" />
|
||||
<Compile Include="..\Models\ResponseModels\Shape.cs" Link="Models\ResponseModels\Shape.cs" />
|
||||
<Compile Include="..\Models\ResponseModels\Shield.cs" Link="Models\ResponseModels\Shield.cs" />
|
||||
<Compile Include="..\Models\ResponseModels\StaticMapMetadata.cs" Link="Models\ResponseModels\StaticMapMetadata.cs" />
|
||||
<Compile Include="..\Models\ResponseModels\TrafficIncident.cs" Link="Models\ResponseModels\TrafficIncident.cs" />
|
||||
<Compile Include="..\Models\ResponseModels\TransitLine.cs" Link="Models\ResponseModels\TransitLine.cs" />
|
||||
<Compile Include="..\Models\ResponseModels\Warning.cs" Link="Models\ResponseModels\Warning.cs" />
|
||||
<Compile Include="..\Models\ResponseModels\Waypoint.cs" Link="Models\ResponseModels\Waypoint.cs" />
|
||||
<Compile Include="..\Models\RouteOptions.cs" Link="Models\RouteOptions.cs" />
|
||||
<Compile Include="..\Models\SimpleAddress.cs" Link="Models\SimpleAddress.cs" />
|
||||
<Compile Include="..\Models\SimpleWaypoint.cs" Link="Models\SimpleWaypoint.cs" />
|
||||
<Compile Include="..\Requests\BaseImageryRestRequest.cs" Link="Requests\BaseImageryRestRequest.cs" />
|
||||
<Compile Include="..\Requests\BaseRestRequest.cs" Link="Requests\BaseRestRequest.cs" />
|
||||
<Compile Include="..\Requests\DistanceMatrixRequest.cs" Link="Requests\DistanceMatrixRequest.cs" />
|
||||
<Compile Include="..\Requests\ElevationRequest.cs" Link="Requests\ElevationRequest.cs" />
|
||||
<Compile Include="..\Requests\GeocodeRequest.cs" Link="Requests\GeocodeRequest.cs" />
|
||||
<Compile Include="..\Requests\GeospatialEndpointRequest.cs" Link="Requests\GeospatialEndpointRequest.cs" />
|
||||
<Compile Include="..\Requests\ImageryMetadataRequest.cs" Link="Requests\ImageryMetadataRequest.cs" />
|
||||
<Compile Include="..\Requests\ImageryRequest.cs" Link="Requests\ImageryRequest.cs" />
|
||||
<Compile Include="..\Requests\ReverseGeocodeRequest.cs" Link="Requests\ReverseGeocodeRequest.cs" />
|
||||
<Compile Include="..\Requests\RouteMajorRoadsRequest.cs" Link="Requests\RouteMajorRoadsRequest.cs" />
|
||||
<Compile Include="..\Requests\RouteRequest.cs" Link="Requests\RouteRequest.cs" />
|
||||
<Compile Include="..\Requests\TrafficRequest.cs" Link="Requests\TrafficRequest.cs" />
|
||||
<Compile Include="..\ServiceManager.cs" Link="ServiceManager.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Enums\" />
|
||||
<Folder Include="Models\CustomMapStyles\" />
|
||||
<Folder Include="Models\ResponseModels\" />
|
||||
<Folder Include="Internal\" />
|
||||
<Folder Include="Requests\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="System.Net.Requests" Version="4.3.0" />
|
||||
<PackageReference Include="System.Runtime.Serialization.Json" Version="4.0.3" />
|
||||
<PackageReference Include="System.Runtime.Serialization.Primitives" Version="4.1.1" />
|
||||
<PackageReference Include="System.Threading.Tasks.Parallel" Version="4.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -48,11 +48,13 @@
|
|||
<Compile Include="Enums\RouteAttributeType.cs" />
|
||||
<Compile Include="Enums\RouteOptimizationType.cs" />
|
||||
<Compile Include="Enums\RouteTimeType.cs" />
|
||||
<Compile Include="Enums\TimeUnitType.cs" />
|
||||
<Compile Include="Enums\TravelModeType.cs" />
|
||||
<Compile Include="Enums\SeverityType.cs" />
|
||||
<Compile Include="Enums\TrafficType.cs" />
|
||||
<Compile Include="Enums\WarningType.cs" />
|
||||
<Compile Include="Internal\DateTimeHelper.cs" />
|
||||
<Compile Include="Internal\EnumHelper.cs" />
|
||||
<Compile Include="Models\BoundingBox.cs" />
|
||||
<Compile Include="CustomMapStyleManager.cs" />
|
||||
<Compile Include="Models\CustomMapStyles\CustomMapStyle.cs" />
|
||||
|
@ -65,6 +67,9 @@
|
|||
<Compile Include="Models\ResponseModels\CompressedPointList.cs" />
|
||||
<Compile Include="Models\ResponseModels\CoverageArea.cs" />
|
||||
<Compile Include="Models\ResponseModels\Detail.cs" />
|
||||
<Compile Include="Models\ResponseModels\DistanceMatrix.cs" />
|
||||
<Compile Include="Models\ResponseModels\DistanceMatrixCell.cs" />
|
||||
<Compile Include="Models\ResponseModels\DistanceMatrixAsyncStatus.cs" />
|
||||
<Compile Include="Models\ResponseModels\ElevationData.cs" />
|
||||
<Compile Include="Models\ResponseModels\Generalization.cs" />
|
||||
<Compile Include="Models\ResponseModels\GeospatialEndpointResponse.cs" />
|
||||
|
@ -98,6 +103,7 @@
|
|||
<Compile Include="Models\ResponseModels\Warning.cs" />
|
||||
<Compile Include="Models\ResponseModels\Waypoint.cs" />
|
||||
<Compile Include="Models\RouteOptions.cs" />
|
||||
<Compile Include="Requests\DistanceMatrixRequest.cs" />
|
||||
<Compile Include="Requests\GeospatialEndpointRequest.cs" />
|
||||
<Compile Include="Requests\ImageryMetadataRequest.cs" />
|
||||
<Compile Include="Requests\ImageryRequest.cs" />
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
using BingMapsRESTToolkit.Models.CustomMapStyles;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
|
@ -33,16 +32,16 @@ using System.Text.RegularExpressions;
|
|||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// Custom Map style object
|
||||
/// A static class to assit with working with Bing Maps Customer Map Styles.
|
||||
/// </summary>
|
||||
public class CustomMapStyleManager
|
||||
{
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Gets the
|
||||
/// Converts a custom JSON map style, into a style using the REST parameter format. If the style is already in the REST parameter formatter, it will be unaltered.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <returns>A style in the REST parameter formatter</returns>
|
||||
public static string GetRestStyle(string style)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(style) && style.Contains("{"))
|
||||
|
|
|
@ -32,7 +32,7 @@ namespace BingMapsRESTToolkit
|
|||
/// <summary>
|
||||
/// Distances in Kilometers.
|
||||
/// </summary>
|
||||
KM,
|
||||
Kilometers,
|
||||
|
||||
/// <summary>
|
||||
/// Distances in Miles
|
||||
|
|
|
@ -39,6 +39,11 @@ namespace BingMapsRESTToolkit
|
|||
/// </summary>
|
||||
AerialWithLabels,
|
||||
|
||||
/// <summary>
|
||||
/// Aerial imagery with on-demand road overlay.
|
||||
/// </summary>
|
||||
AerialWithLabelsOnDemand,
|
||||
|
||||
/// <summary>
|
||||
/// Bird’s eye (oblique-angle) imagery
|
||||
/// </summary>
|
||||
|
@ -49,6 +54,16 @@ namespace BingMapsRESTToolkit
|
|||
/// </summary>
|
||||
BirdseyeWithLabels,
|
||||
|
||||
/// <summary>
|
||||
/// The second generation Bird’s eye (oblique-angle) imagery.
|
||||
/// </summary>
|
||||
BirdseyeV2,
|
||||
|
||||
/// <summary>
|
||||
/// The second generation Bird’s eye (oblique-angle) imagerywith a road overlay.
|
||||
/// </summary>
|
||||
BirdseyeV2WithLabels,
|
||||
|
||||
/// <summary>
|
||||
/// A dark version of the road maps.
|
||||
/// </summary>
|
||||
|
@ -77,11 +92,6 @@ namespace BingMapsRESTToolkit
|
|||
/// <summary>
|
||||
/// Ordnance Survey imagery.
|
||||
/// </summary>
|
||||
OrdnanceSurvey,
|
||||
|
||||
/// <summary>
|
||||
/// Collins Bart imagery
|
||||
/// </summary>
|
||||
CollinsBart
|
||||
OrdnanceSurvey
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
/// <summary>
|
||||
|
|
|
@ -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>
|
||||
/// Represents the units in which time is measured.
|
||||
/// </summary>
|
||||
public enum TimeUnitType
|
||||
{
|
||||
/// <summary>
|
||||
/// Time is in seconds.
|
||||
/// </summary>
|
||||
Seconds,
|
||||
|
||||
/// <summary>
|
||||
/// Time is in minutes.
|
||||
/// </summary>
|
||||
Minutes
|
||||
}
|
||||
}
|
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* 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>
|
||||
/// Helper class for converting enums between their string versions.
|
||||
/// </summary>
|
||||
internal static class EnumHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts distance unit type to a string.
|
||||
/// </summary>
|
||||
/// <param name="dut">Distance unit to convert.</param>
|
||||
/// <returns>A string version of the distance unit.</returns>
|
||||
public static string DistanceUnitTypeToString(DistanceUnitType dut)
|
||||
{
|
||||
if(dut == DistanceUnitType.Miles)
|
||||
{
|
||||
return "miles";
|
||||
}
|
||||
|
||||
return "kilometers";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a string into a DistanceUnitType.
|
||||
/// </summary>
|
||||
/// <param name="dut">A string to convert.</param>
|
||||
/// <returns>A distance unit type.</returns>
|
||||
public static DistanceUnitType DistanceUnitStringToEnum(string dut)
|
||||
{
|
||||
switch (dut.ToLowerInvariant())
|
||||
{
|
||||
case "miles":
|
||||
case "mile":
|
||||
case "mi":
|
||||
case "imperial":
|
||||
return DistanceUnitType.Miles;
|
||||
case "kilometers":
|
||||
case "kiloemeter":
|
||||
case "km":
|
||||
case "kilometres":
|
||||
case "kilometre":
|
||||
case "metric":
|
||||
default:
|
||||
return DistanceUnitType.Kilometers;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts time unit type to a string.
|
||||
/// </summary>
|
||||
/// <param name="tut">Time unit to convert.</param>
|
||||
/// <returns>A string version of the time unit.</returns>
|
||||
public static string TimeUnitTypeToString(TimeUnitType tut)
|
||||
{
|
||||
if (tut == TimeUnitType.Minutes)
|
||||
{
|
||||
return "minutes";
|
||||
}
|
||||
|
||||
return "seconds";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a string into a TimeUnitType.
|
||||
/// </summary>
|
||||
/// <param name="tut">A string to convert.</param>
|
||||
/// <returns>A time unit type.</returns>
|
||||
public static TimeUnitType TimeUnitStringToEnum(string tut)
|
||||
{
|
||||
switch (tut.ToLowerInvariant())
|
||||
{
|
||||
case "minutes":
|
||||
case "min":
|
||||
case "mins":
|
||||
case "m":
|
||||
return TimeUnitType.Minutes;
|
||||
case "seconds":
|
||||
case "second":
|
||||
case "secs":
|
||||
case "sec":
|
||||
case "s":
|
||||
default:
|
||||
return TimeUnitType.Seconds;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -25,6 +25,7 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Runtime.Serialization.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
|
@ -207,6 +208,23 @@ namespace BingMapsRESTToolkit
|
|||
return tcs.Task;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deserializes a response stream into a Response object.
|
||||
/// </summary>
|
||||
/// <param name="responseStream">The response stream to deserialize.</param>
|
||||
/// <returns>A Response object.</returns>
|
||||
public static T DeserializeStream<T>(Stream responseStream) where T : class
|
||||
{
|
||||
if (responseStream != null)
|
||||
{
|
||||
var ser = new DataContractJsonSerializer(typeof(T));
|
||||
var r = ser.ReadObject(responseStream) as T;
|
||||
return r;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
|
|
@ -74,7 +74,7 @@ namespace BingMapsRESTToolkit
|
|||
{
|
||||
case DistanceUnitType.Miles:
|
||||
return EarthRadius.Miles;
|
||||
case DistanceUnitType.KM:
|
||||
case DistanceUnitType.Kilometers:
|
||||
default:
|
||||
return EarthRadius.KM;
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ namespace BingMapsRESTToolkit
|
|||
/// <summary>
|
||||
/// Latitude coordinate.
|
||||
/// </summary>
|
||||
[DataMember(Name = "lat", EmitDefaultValue = false)]
|
||||
[DataMember(Name = "latitude")]
|
||||
public double Latitude
|
||||
{
|
||||
get
|
||||
|
@ -87,7 +87,7 @@ namespace BingMapsRESTToolkit
|
|||
/// <summary>
|
||||
/// Longitude coordinate.
|
||||
/// </summary>
|
||||
[DataMember(Name = "lon", EmitDefaultValue = false)]
|
||||
[DataMember(Name = "longitude")]
|
||||
public double Longitude
|
||||
{
|
||||
get
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace BingMapsRESTToolkit.Models.CustomMapStyles
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// The style options that can be appliction to bordered map elements.
|
||||
|
|
|
@ -24,8 +24,8 @@
|
|||
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace BingMapsRESTToolkit.Models.CustomMapStyles
|
||||
{
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// Defines a custom map style.
|
||||
/// </summary>
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace BingMapsRESTToolkit.Models.CustomMapStyles
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// The styles options that can be applied to map elements.
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace BingMapsRESTToolkit.Models.CustomMapStyles
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// Map Elements which can be styled.
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace BingMapsRESTToolkit.Models.CustomMapStyles
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// Global style settings
|
||||
|
|
|
@ -0,0 +1,466 @@
|
|||
/*
|
||||
* 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.Runtime.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// A Distance Matrix response object which is returned when geocoding or reverse geocoding.
|
||||
/// </summary>
|
||||
[DataContract(Namespace = "http://schemas.microsoft.com/search/local/ws/rest/v1")]
|
||||
public class DistanceMatrix : Resource
|
||||
{
|
||||
#region Private Properties
|
||||
|
||||
/// <summary>
|
||||
/// Array of distance matrix cell results containing information for each coordinate pair and time interval.
|
||||
/// </summary>
|
||||
private DistanceMatrixCell[] results = null;
|
||||
|
||||
/// <summary>
|
||||
/// An indexer for the results to allow for fast lookups. Format is [origins][destinations][time intervals].
|
||||
/// </summary>
|
||||
private int[][][] cellIndex = null;
|
||||
|
||||
/// <summary>
|
||||
/// The number of origins that were specified in the request.
|
||||
/// </summary>
|
||||
private int numOrigins = 0;
|
||||
|
||||
/// <summary>
|
||||
/// The number of destinations that were specified in the request. If none were specified, the number of origins is used.
|
||||
/// </summary>
|
||||
private int numDestinations = 0;
|
||||
|
||||
/// <summary>
|
||||
/// The number of time intervals in which distance matrix cells where calculated for.
|
||||
/// </summary>
|
||||
private int numTimeIntervals = 0;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
|
||||
/// <summary>
|
||||
/// The array of destinations that were used to calculate the distance matrix.
|
||||
/// </summary>
|
||||
[DataMember(Name = "destinations", EmitDefaultValue = false)]
|
||||
public SimpleWaypoint[] Destinations { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The array of origins that were used to calculate the distance matrix.
|
||||
/// </summary>
|
||||
[DataMember(Name = "origins", EmitDefaultValue = false)]
|
||||
public SimpleWaypoint[] Origins { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Details of an error that may have occurred when processing the request.
|
||||
/// </summary>
|
||||
[DataMember(Name = "errorMessage", EmitDefaultValue = false)]
|
||||
public string ErrorMessage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Array of distance matrix cell results containing information for each coordinate pair and time interval.
|
||||
/// </summary>
|
||||
[DataMember(Name = "results", EmitDefaultValue = false)]
|
||||
public DistanceMatrixCell[] Results
|
||||
{
|
||||
get
|
||||
{
|
||||
return results;
|
||||
}
|
||||
set
|
||||
{
|
||||
results = value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Additional properties extracted from request and results
|
||||
|
||||
/// <summary>
|
||||
/// A list of time intervals in which the distance matrix calculated for.
|
||||
/// </summary>
|
||||
public List<DateTime> TimeIntervals { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Retrives the distance matrix cell for a specified origin-destination pair.
|
||||
/// Returns -1 if a cell can not be found in the results or had an error in calculation.
|
||||
/// </summary>
|
||||
/// <param name="originIdx">The index of the origin in the requests origins array.</param>
|
||||
/// <param name="destinationIdx">The index of the destination in the requests destinations array.</param>
|
||||
/// <returns>The distance matrix cell for a specified origin-destination pair.</returns>
|
||||
public DistanceMatrixCell GetCell(int originIdx, int destinationIdx)
|
||||
{
|
||||
return GetCell(originIdx, destinationIdx, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrives the distance matrix cell for a specified origin-destination pair and time interval.
|
||||
/// Returns -1 if a cell can not be found in the results or had an error in calculation.
|
||||
/// </summary>
|
||||
/// <param name="originIdx">The index of the origin in the requests origins array.</param>
|
||||
/// <param name="destinationIdx">The index of the destination in the requests destinations array.</param>
|
||||
/// <param name="timeInterval">The time interval to retrieve the distance matrix cell for.</param>
|
||||
/// <returns>The distance matrix cell for a specified origin-destination pair and time interval.</returns>
|
||||
public DistanceMatrixCell GetCell(int originIdx, int destinationIdx, DateTime timeInterval)
|
||||
{
|
||||
if (TimeIntervals != null && TimeIntervals.Contains(timeInterval))
|
||||
{
|
||||
return GetCell(originIdx, destinationIdx, TimeIntervals.IndexOf(timeInterval));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrives the distance matrix cell for a specified origin-destination pair and time interval.
|
||||
/// Returns -1 if a cell can not be found in the results or had an error in calculation.
|
||||
/// </summary>
|
||||
/// <param name="originIdx">The index of the origin in the requests origins array.</param>
|
||||
/// <param name="destinationIdx">The index of the destination in the requests destinations array.</param>
|
||||
/// <param name="timeIntervalIdx">The time interval to retrieve the distance matrix cell for.</param>
|
||||
/// <returns>The distance matrix cell for a specified origin-destination pair and time interval.</returns>
|
||||
public DistanceMatrixCell GetCell(int originIdx, int destinationIdx, int timeIntervalIdx)
|
||||
{
|
||||
if(cellIndex == null)
|
||||
{
|
||||
GenerateIndex();
|
||||
}
|
||||
|
||||
if (cellIndex != null && originIdx >= 0 && destinationIdx >= 0 && timeIntervalIdx >= 0 && cellIndex.Length > 0
|
||||
&& originIdx < numOrigins && destinationIdx < numDestinations && timeIntervalIdx < numTimeIntervals)
|
||||
{
|
||||
var idx = cellIndex[originIdx][destinationIdx][timeIntervalIdx];
|
||||
if (idx > -1)
|
||||
{
|
||||
return results[idx];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all cells for the specified origin and destination index, ordered by time (ascending).
|
||||
/// </summary>
|
||||
/// <param name="originIdx">The index of the origin in the requests origins array.</param>
|
||||
/// <param name="destinationIdx">The index of the destination in the requests destinations array.</param>
|
||||
/// <returns>All cells for the specified origin and destination index, ordered by time.</returns>
|
||||
public DistanceMatrixCell[] GetCells(int originIdx, int destinationIdx)
|
||||
{
|
||||
if (cellIndex == null)
|
||||
{
|
||||
GenerateIndex();
|
||||
}
|
||||
|
||||
if (cellIndex != null && originIdx >= 0 && destinationIdx >= 0 && cellIndex.Length > 0
|
||||
&& originIdx < numOrigins && destinationIdx < numDestinations)
|
||||
{
|
||||
var indices = cellIndex[originIdx][destinationIdx];
|
||||
if (indices != null && indices.Length > 0)
|
||||
{
|
||||
var cells = new List<DistanceMatrixCell>(indices.Length);
|
||||
|
||||
for (int i = 0; i < indices.Length; i++)
|
||||
{
|
||||
cells.Add(results[indices[i]]);
|
||||
}
|
||||
|
||||
//Sort the cells by time.
|
||||
cells = cells.OrderBy(x => x.DepartureTimeUtc).ToList();
|
||||
|
||||
return cells.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrives the travel distance for a specified origin-destination pair.
|
||||
/// Returns -1 if a cell can not be found in the results or had an error in calculation.
|
||||
/// </summary>
|
||||
/// <param name="originIdx">The index of the origin in the requests origins array.</param>
|
||||
/// <param name="destinationIdx">The index of the destination in the requests destinations array.</param>
|
||||
/// <returns>The travel distance for a specified origin-destination pair.</returns>
|
||||
public double GetDistance(int originIdx, int destinationIdx)
|
||||
{
|
||||
return GetDistance(originIdx, destinationIdx, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrives the travel distance for a specified origin-destination pair and time interval.
|
||||
/// Returns -1 if a cell can not be found in the results or had an error in calculation.
|
||||
/// </summary>
|
||||
/// <param name="originIdx">The index of the origin in the requests origins array.</param>
|
||||
/// <param name="destinationIdx">The index of the destination in the requests destinations array.</param>
|
||||
/// <param name="timeInterval">The time interval to retrieve the travel distance for.</param>
|
||||
/// <returns>The travel distance for a specified origin-destination pair and time interval.</returns>
|
||||
public double GetDistance(int originIdx, int destinationIdx, DateTime timeInterval)
|
||||
{
|
||||
if (TimeIntervals != null && TimeIntervals.Contains(timeInterval))
|
||||
{
|
||||
return GetDistance(originIdx, destinationIdx, TimeIntervals.IndexOf(timeInterval));
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrives the travel distance for a specified origin-destination pair and time interval.
|
||||
/// Returns -1 if a cell can not be found in the results or had an error in calculation.
|
||||
/// </summary>
|
||||
/// <param name="originIdx">The index of the origin in the requests origins array.</param>
|
||||
/// <param name="destinationIdx">The index of the destination in the requests destinations array.</param>
|
||||
/// <param name="timeIntervalIdx">The time interval to retrieve the travel distance for.</param>
|
||||
/// <returns>The travel distance for a specified origin-destination pair and time interval.</returns>
|
||||
public double GetDistance(int originIdx, int destinationIdx, int timeIntervalIdx)
|
||||
{
|
||||
var c = GetCell(originIdx, destinationIdx, timeIntervalIdx);
|
||||
|
||||
if (c != null)
|
||||
{
|
||||
return c.TravelDistance;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all travel distances for the specified origin and destination index, ordered by time (ascending).
|
||||
/// </summary>
|
||||
/// <param name="originIdx">The index of the origin in the requests origins array.</param>
|
||||
/// <param name="destinationIdx">The index of the destination in the requests destinations array.</param>
|
||||
/// <returns>All travel distances for the specified origin and destination index, ordered by time.</returns>
|
||||
public double[] GetDistances(int originIdx, int destinationIdx)
|
||||
{
|
||||
var cells = GetCells(originIdx, destinationIdx);
|
||||
|
||||
if (cells != null)
|
||||
{
|
||||
var distances = new double[cells.Length];
|
||||
|
||||
for (int i = 0; i < cells.Length; i++)
|
||||
{
|
||||
distances[i] = cells[i].TravelDistance;
|
||||
}
|
||||
|
||||
return distances;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrives the travel time for a specified origin-destination pair.
|
||||
/// Returns -1 if a cell can not be found in the results or had an error in calculation.
|
||||
/// </summary>
|
||||
/// <param name="originIdx">The index of the origin in the requests origins array.</param>
|
||||
/// <param name="destinationIdx">The index of the destination in the requests destinations array.</param>
|
||||
/// <returns>The travel time for a specified origin-destination pair.</returns>
|
||||
public double GetTime(int originIdx, int destinationIdx)
|
||||
{
|
||||
return GetTime(originIdx, destinationIdx, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the travel time for a specified origin-destination pair and time interval.
|
||||
/// Returns -1 if a cell can not be found in the results or had an error in calculation.
|
||||
/// </summary>
|
||||
/// <param name="originIdx">The index of the origin in the requests origins array.</param>
|
||||
/// <param name="destinationIdx">The index of the destination in the requests destinations array.</param>
|
||||
/// <param name="timeInterval">The time interval to retrieve the travel time for.</param>
|
||||
/// <returns>The travel time for a specified origin-destination pair and time interval.</returns>
|
||||
public double GetTime(int originIdx, int destinationIdx, DateTime timeInterval)
|
||||
{
|
||||
if (TimeIntervals != null && TimeIntervals.Contains(timeInterval))
|
||||
{
|
||||
return GetTime(originIdx, destinationIdx, TimeIntervals.IndexOf(timeInterval));
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the travel time for a specified origin-destination pair and time interval.
|
||||
/// Returns -1 if a cell can not be found in the results or had an error in calculation.
|
||||
/// </summary>
|
||||
/// <param name="originIdx">The index of the origin in the requests origins array.</param>
|
||||
/// <param name="destinationIdx">The index of the destination in the requests destinations array.</param>
|
||||
/// <param name="timeIntervalIdx">The index of the time interval.</param>
|
||||
/// <returns>The travel time for a specified origin-destination pair and time interval.</returns>
|
||||
public double GetTime(int originIdx, int destinationIdx, int timeIntervalIdx)
|
||||
{
|
||||
var c = GetCell(originIdx, destinationIdx, timeIntervalIdx);
|
||||
|
||||
if (c != null)
|
||||
{
|
||||
return c.TravelDuration;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all travel times for the specified origin and destination index, ordered by time (ascending).
|
||||
/// </summary>
|
||||
/// <param name="originIdx">The index of the origin in the requests origins array.</param>
|
||||
/// <param name="destinationIdx">The index of the destination in the requests destinations array.</param>
|
||||
/// <returns>All travel times for the specified origin and destination index, ordered by time.</returns>
|
||||
public double[] GetTimes(int originIdx, int destinationIdx)
|
||||
{
|
||||
var cells = GetCells(originIdx, destinationIdx);
|
||||
|
||||
if (cells != null)
|
||||
{
|
||||
var times = new double[cells.Length];
|
||||
|
||||
for (int i = 0; i < cells.Length; i++)
|
||||
{
|
||||
times[i] = cells[i].TravelDuration;
|
||||
}
|
||||
|
||||
return times;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
/// <summary>
|
||||
/// Loops through results and generates an result index based on the origin, destination and time interval indices.
|
||||
/// </summary>
|
||||
private void GenerateIndex()
|
||||
{
|
||||
if (results == null)
|
||||
{
|
||||
cellIndex = null;
|
||||
return;
|
||||
}
|
||||
|
||||
//Scan results and capture time intervals, origin and destination sizes.
|
||||
numOrigins = -1;
|
||||
numDestinations = -1;
|
||||
TimeIntervals = new List<DateTime>();
|
||||
|
||||
foreach (var c in results)
|
||||
{
|
||||
if(c.OriginIndex > numOrigins)
|
||||
{
|
||||
numOrigins = c.OriginIndex;
|
||||
}
|
||||
|
||||
if (c.DestinationIndex > numDestinations)
|
||||
{
|
||||
numDestinations = c.DestinationIndex;
|
||||
}
|
||||
|
||||
var date = c.DepartureTimeUtc;
|
||||
|
||||
if (date != null && date.HasValue && !TimeIntervals.Contains(date.Value))
|
||||
{
|
||||
TimeIntervals.Add(date.Value);
|
||||
}
|
||||
}
|
||||
|
||||
numOrigins++;
|
||||
numDestinations++;
|
||||
|
||||
if (TimeIntervals.Count == 0)
|
||||
{
|
||||
TimeIntervals.Add(DateTime.Now);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Sort the time intervals.
|
||||
TimeIntervals.Sort();
|
||||
}
|
||||
|
||||
if (numDestinations == 0 && numOrigins > 0)
|
||||
{
|
||||
numDestinations = numOrigins;
|
||||
}
|
||||
|
||||
if (numOrigins > 0 && numDestinations > 0)
|
||||
{
|
||||
numTimeIntervals = TimeIntervals.Count;
|
||||
|
||||
//Initialize cell indexer
|
||||
cellIndex = new int[numOrigins][][];
|
||||
|
||||
Parallel.For(0, numOrigins, o =>
|
||||
{
|
||||
cellIndex[o] = new int[numDestinations][];
|
||||
|
||||
for (int d = 0; d < numDestinations; d++)
|
||||
{
|
||||
cellIndex[o][d] = new int[numTimeIntervals];
|
||||
|
||||
for (int t = 0; t < numTimeIntervals; t++)
|
||||
{
|
||||
cellIndex[o][d][t] = -1;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//Loop through results and generate index.
|
||||
if (numTimeIntervals == 1)
|
||||
{
|
||||
Parallel.For(0, results.Length, i =>
|
||||
{
|
||||
var cell = results[i];
|
||||
cellIndex[cell.OriginIndex][cell.DestinationIndex][0] = i;
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
Parallel.For(0, results.Length, i =>
|
||||
{
|
||||
var cell = results[i];
|
||||
if (cell.DepartureTimeUtc != null && cell.DepartureTimeUtc.HasValue && !TimeIntervals.Contains(cell.DepartureTimeUtc.Value))
|
||||
{
|
||||
cellIndex[cell.OriginIndex][cell.DestinationIndex][TimeIntervals.IndexOf(cell.DepartureTimeUtc.Value)] = i;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
* 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.Runtime.Serialization;
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// The status of an asynchronous distance matrix request.
|
||||
/// </summary>
|
||||
[DataContract(Namespace = "http://schemas.microsoft.com/search/local/ws/rest/v1")]
|
||||
public class DistanceMatrixAsyncStatus : Resource
|
||||
{
|
||||
#region Public Properties
|
||||
|
||||
/// <summary>
|
||||
/// Specifies if the request is accepted. A request will not be accepted if it is not valid, is not within the
|
||||
/// coordinate pair limits, or if a coordinate in origins or destinations has no coverage.
|
||||
/// </summary>
|
||||
[DataMember(Name = "isAccepted", EmitDefaultValue = false)]
|
||||
public bool IsAccepted { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Specifies if the request has completed.
|
||||
/// </summary>
|
||||
[DataMember(Name = "isCompleted", EmitDefaultValue = false)]
|
||||
public bool IsCompleted { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// A unique identifier for an asynchronous request. This can be used to retrieve the results of an asynchronous request when it has completed.
|
||||
/// </summary>
|
||||
[DataMember(Name = "requestId", EmitDefaultValue = false)]
|
||||
public string RequestId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Details of an error that may have occurred when processing the request.
|
||||
/// </summary>
|
||||
[DataMember(Name = "errorMessage", EmitDefaultValue = false)]
|
||||
public string ErrorMessage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// An estimated number of seconds to wait before calling back for results when making an asynchronous request.
|
||||
/// </summary>
|
||||
[DataMember(Name = "callbackInSeconds", EmitDefaultValue = false)]
|
||||
public int CallbackInSeconds { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The callback URL to use to check the status of the request.
|
||||
/// </summary>
|
||||
[DataMember(Name = "callbackUrl", EmitDefaultValue = false)]
|
||||
public string CallbackUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The URL where the results can be downloaded from. The result is a DistanceMatrix object in JSON form.
|
||||
/// </summary>
|
||||
[DataMember(Name = "resultUrl", EmitDefaultValue = false)]
|
||||
public string ResultUrl { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -0,0 +1,122 @@
|
|||
/*
|
||||
* 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 Distance Matrix response object which is returned when geocoding or reverse geocoding.
|
||||
/// </summary>
|
||||
[DataContract]
|
||||
public class DistanceMatrixCell
|
||||
{
|
||||
#region Public Properties
|
||||
|
||||
/// <summary>
|
||||
/// The index of the origin in the provided origins array used to calculate this cell.
|
||||
/// </summary>
|
||||
[DataMember(Name = "originIndex", EmitDefaultValue = false)]
|
||||
public int OriginIndex { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The index of the destination in the provided destinations array used to calculate this cell.
|
||||
/// </summary>
|
||||
[DataMember(Name = "destinationIndex", EmitDefaultValue = false)]
|
||||
public int DestinationIndex { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The physical distance covered to complete a route between the origin and destination.
|
||||
/// </summary>
|
||||
[DataMember(Name = "travelDistance", EmitDefaultValue = false)]
|
||||
public double TravelDistance { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The time that it takes, in minutes, to travel a corresponding TravelDistance.
|
||||
/// </summary>
|
||||
[DataMember(Name = "travelDuration", EmitDefaultValue = false)]
|
||||
public double TravelDuration { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The departure time in which this cell was calculated for. Only returned when a startTime is specified.
|
||||
/// When an endTime is specified in the request several cells will be returned for the same origin and destination pairs,
|
||||
/// each having a different departure time for each time interval in the generated histogram request. This string is in ISO 8601 date format.
|
||||
/// </summary>
|
||||
[DataMember(Name = "departureTime", EmitDefaultValue = false)]
|
||||
public string DepartureTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The departure time in which this cell was calculated for. Only returned when a startTime is specified.
|
||||
/// When an endTime is specified in the request several cells will be returned for the same origin and destination pairs,
|
||||
/// each having a different departure time for each time interval in the generated histogram request.
|
||||
/// </summary>
|
||||
public DateTime? DepartureTimeUtc
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(DepartureTime))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
DateTime dt;
|
||||
|
||||
if(DateTime.TryParse(DepartureTime, out dt))
|
||||
{
|
||||
return dt;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value == null)
|
||||
{
|
||||
DepartureTime = string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (value.HasValue)
|
||||
{
|
||||
DepartureTime = value.Value.ToString("O");
|
||||
}
|
||||
else {
|
||||
DepartureTime = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A boolean indicating if an error occurred when calculating this cell.
|
||||
/// </summary>
|
||||
[DataMember(Name = "hasError", EmitDefaultValue = false)]
|
||||
public bool HasError { get; set; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -27,7 +27,7 @@ using System.Runtime.Serialization;
|
|||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// A Location response object which is reutrned when geocoding or reverse geocoding.
|
||||
/// A Location response object which is returned when geocoding or reverse geocoding.
|
||||
/// </summary>
|
||||
[DataContract(Namespace = "http://schemas.microsoft.com/search/local/ws/rest/v1")]
|
||||
public class Location : Resource
|
||||
|
|
|
@ -38,6 +38,8 @@ namespace BingMapsRESTToolkit
|
|||
[KnownType(typeof(SeaLevelData))]
|
||||
[KnownType(typeof(CompressedPointList))]
|
||||
[KnownType(typeof(GeospatialEndpointResponse))]
|
||||
[KnownType(typeof(DistanceMatrix))]
|
||||
[KnownType(typeof(DistanceMatrixAsyncStatus))]
|
||||
public class Resource
|
||||
{
|
||||
/// <summary>
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
|
@ -42,13 +43,46 @@ namespace BingMapsRESTToolkit
|
|||
/// The unit used for distance.
|
||||
/// </summary>
|
||||
[DataMember(Name = "distanceUnit", EmitDefaultValue = false)]
|
||||
public string DistanceUnit { get; set; }
|
||||
public string DistanceUnit
|
||||
{
|
||||
get
|
||||
{
|
||||
return EnumHelper.DistanceUnitTypeToString(DistanceUnitType);
|
||||
}
|
||||
set
|
||||
{
|
||||
DistanceUnitType = EnumHelper.DistanceUnitStringToEnum(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The unit used for distance as an Enum.
|
||||
/// </summary>
|
||||
public DistanceUnitType DistanceUnitType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The unit used for time of travel.
|
||||
/// </summary>
|
||||
[DataMember(Name = "durationUnit", EmitDefaultValue = false)]
|
||||
public string DurationUnit { get; set; }
|
||||
public string DurationUnit
|
||||
{
|
||||
get
|
||||
{
|
||||
return EnumHelper.TimeUnitTypeToString(TimeUnitType);
|
||||
}
|
||||
set
|
||||
{
|
||||
TimeUnitType = EnumHelper.TimeUnitStringToEnum(value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The unit used for time as an Enum.
|
||||
/// </summary>
|
||||
public TimeUnitType TimeUnitType { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// The physical distance covered by the entire route. This value is not supported for the Transit travel mode.
|
||||
|
|
|
@ -91,10 +91,6 @@ namespace BingMapsRESTToolkit
|
|||
[DataMember(Name = "itineraryItems", EmitDefaultValue = false)]
|
||||
public ItineraryItem[] ItineraryItems { get; set; }
|
||||
|
||||
//TODO: What is this?
|
||||
[DataMember(Name = "routeRegion", EmitDefaultValue = false)]
|
||||
public string RouteRegion { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Information about a segments of the route leg defined by the route leg waypoints and any intermediate via-waypoints.
|
||||
/// For example, if the route leg has two via-waypoints in addition to start and end waypoints, there would be three (3) route sub-legs.
|
||||
|
@ -189,9 +185,5 @@ namespace BingMapsRESTToolkit
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: What is the base class?
|
||||
[DataMember(Name = "alternateVias", EmitDefaultValue = false)]
|
||||
public object[] AlternateVias { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,9 @@ namespace BingMapsRESTToolkit
|
|||
[DataMember(Name = "isVia", EmitDefaultValue = false)]
|
||||
public bool IsVia { get; set; }
|
||||
|
||||
//TODO: What is this?
|
||||
/// <summary>
|
||||
/// A unique identifier for the location.
|
||||
/// </summary>
|
||||
[DataMember(Name = "locationIdentifier", EmitDefaultValue = false)]
|
||||
public string LocationIdentifier { get; set; }
|
||||
|
||||
|
|
|
@ -105,12 +105,12 @@ namespace BingMapsRESTToolkit
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specifies what parameters to use to optimize the route.
|
||||
/// Specifies what parameters to use to optimize the route. Default: Time
|
||||
/// </summary>
|
||||
public RouteOptimizationType Optimize { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The mode of travel for the route. Default: Driving.
|
||||
/// The mode of travel for the route. Default: Driving
|
||||
/// </summary>
|
||||
public TravelModeType TravelMode { get; set; }
|
||||
|
||||
|
@ -208,7 +208,7 @@ namespace BingMapsRESTToolkit
|
|||
sb.AppendFormat("&hd={0}", heading);
|
||||
}
|
||||
|
||||
if (DistanceUnits != DistanceUnitType.KM)
|
||||
if (DistanceUnits != DistanceUnitType.Kilometers)
|
||||
{
|
||||
sb.AppendFormat("&du=mi");
|
||||
}
|
||||
|
|
|
@ -22,11 +22,16 @@
|
|||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// A simple waypoint class that can be used to calculate a route.
|
||||
/// </summary>
|
||||
[DataContract]
|
||||
public class SimpleWaypoint
|
||||
{
|
||||
#region Constructor
|
||||
|
@ -67,15 +72,94 @@ namespace BingMapsRESTToolkit
|
|||
this.Address = address;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A waypoint to calculate a route through.
|
||||
/// </summary>
|
||||
/// <param name="latitude">The latitude coordinate.</param>
|
||||
/// <param name="longitude">The longitude coordinate.</param>
|
||||
public SimpleWaypoint(double latitude, double longitude)
|
||||
{
|
||||
this.Coordinate = new Coordinate(latitude, longitude);
|
||||
}
|
||||
|
||||
#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>
|
||||
/// A serializable Latitude property.
|
||||
/// </summary>
|
||||
[DataMember(Name = "latitude")]
|
||||
internal double? Latitude
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Coordinate != null)
|
||||
{
|
||||
return Coordinate.Latitude;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value.HasValue)
|
||||
{
|
||||
if (Coordinate == null)
|
||||
{
|
||||
Coordinate = new Coordinate(value.Value, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
Coordinate.Latitude = value.Value;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Coordinate = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A serializable longitude property.
|
||||
/// </summary>
|
||||
[DataMember(Name = "longitude")]
|
||||
internal double? Longitude
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Coordinate != null)
|
||||
{
|
||||
return Coordinate.Longitude;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value.HasValue)
|
||||
{
|
||||
if (Coordinate == null)
|
||||
{
|
||||
Coordinate = new Coordinate(0, value.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
Coordinate.Longitude = value.Value;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Coordinate = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The address query for the waypoint.
|
||||
/// </summary>
|
||||
|
@ -87,5 +171,80 @@ namespace BingMapsRESTToolkit
|
|||
public bool IsViaPoint { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Static Methods
|
||||
|
||||
/// <summary>
|
||||
/// Tries to geocode a simple waypoint.
|
||||
/// </summary>
|
||||
/// <param name="waypoint">The simple waypoint to geocode.</param>
|
||||
/// <param name="baseRequest">A base request that has the information need to perform a geocode, primarily a Bing Maps key.</param>
|
||||
/// <returns>A Task in which the simple waypoint will be geocoded.</returns>
|
||||
internal static Task TryGeocode(SimpleWaypoint waypoint, BaseRestRequest baseRequest)
|
||||
{
|
||||
return new Task(async () =>
|
||||
{
|
||||
if (waypoint != null && waypoint.Coordinate == null && !string.IsNullOrEmpty(waypoint.Address))
|
||||
{
|
||||
var request = new GeocodeRequest()
|
||||
{
|
||||
Query = waypoint.Address,
|
||||
MaxResults = 1,
|
||||
BingMapsKey = baseRequest.BingMapsKey,
|
||||
Culture = baseRequest.Culture,
|
||||
Domain = baseRequest.Domain,
|
||||
UserIp = baseRequest.UserIp,
|
||||
UserLocation = baseRequest.UserLocation,
|
||||
UserMapView = baseRequest.UserMapView,
|
||||
UserRegion = baseRequest.UserRegion
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
var r = await ServiceManager.GetResponseAsync(request);
|
||||
|
||||
if (r != null && r.ResourceSets != null &&
|
||||
r.ResourceSets.Length > 0 &&
|
||||
r.ResourceSets[0].Resources != null &&
|
||||
r.ResourceSets[0].Resources.Length > 0)
|
||||
{
|
||||
var l = r.ResourceSets[0].Resources[0] as Location;
|
||||
|
||||
waypoint.Coordinate = new Coordinate(l.Point.Coordinates[0], l.Point.Coordinates[1]);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
//Do nothing.
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to geocode a list of simple waypoints.
|
||||
/// </summary>
|
||||
/// <param name="waypoints">A list of simple waypoints to geocode.</param>
|
||||
/// <param name="baseRequest">A base request that has the information need to perform a geocode, primarily a Bing Maps key.</param>
|
||||
/// <returns>A Task in which a list of simple waypoints will be geocoded.</returns>
|
||||
internal static async Task GeocodeWaypoints(List<SimpleWaypoint> waypoints, BaseRestRequest baseRequest)
|
||||
{
|
||||
var geocodeTasks = new List<Task>();
|
||||
|
||||
foreach (var wp in waypoints)
|
||||
{
|
||||
if (wp != null && wp.Coordinate == null && !string.IsNullOrEmpty(wp.Address))
|
||||
{
|
||||
geocodeTasks.Add(TryGeocode(wp, baseRequest));
|
||||
}
|
||||
}
|
||||
|
||||
if (geocodeTasks.Count > 0)
|
||||
{
|
||||
await Task.WhenAll(geocodeTasks);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,5 +26,5 @@ using System.Runtime.InteropServices;
|
|||
// 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.5.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.5.0")]
|
||||
[assembly: AssemblyVersion("1.0.6.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.6.0")]
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
|
@ -87,12 +88,44 @@ namespace BingMapsRESTToolkit
|
|||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <summary>
|
||||
/// Abstract method which generates the Bing Maps REST request URL.
|
||||
/// </summary>
|
||||
/// <returns>A Bing Maps REST request URL.</returns>
|
||||
public abstract string GetRequestUrl();
|
||||
|
||||
/// <summary>
|
||||
/// Executes the request.
|
||||
/// </summary>
|
||||
/// <returns>A response containing the requested data.</returns>
|
||||
public virtual async Task<Response> Execute()
|
||||
{
|
||||
return await this.Execute(null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes the request.
|
||||
/// </summary>
|
||||
/// <param name="remainingTimeCallback">A callback function in which the estimated remaining time is sent.</param>
|
||||
/// <returns>A response containing the requested data.</returns>
|
||||
public virtual async Task<Response> Execute(Action<int> remainingTimeCallback)
|
||||
{
|
||||
Response r = null;
|
||||
|
||||
using (var responseStream = await ServiceHelper.GetStreamAsync(new Uri(GetRequestUrl())))
|
||||
{
|
||||
r = ServiceHelper.DeserializeStream<Response>(responseStream);
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the base request URL.
|
||||
/// </summary>
|
||||
/// <returns>The base request URL.</returns>
|
||||
internal string GetBaseRequestUrl()
|
||||
{
|
||||
var url = string.Empty;
|
||||
|
@ -119,5 +152,7 @@ namespace BingMapsRESTToolkit
|
|||
|
||||
return url + "&key=" + BingMapsKey + "&clientApi=CSToolkit";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,626 @@
|
|||
/*
|
||||
* 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.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
/// <summary>
|
||||
/// A request that calculates a distance matrix between origins and destinations.
|
||||
/// </summary>
|
||||
[DataContract]
|
||||
public class DistanceMatrixRequest : BaseRestRequest
|
||||
{
|
||||
#region Private Properties
|
||||
|
||||
/// <summary>
|
||||
/// The maximum number of coordinate pairs that can be in a standar distance matrix request.
|
||||
/// </summary>
|
||||
private const int MaxCoordinatePairs = 625;
|
||||
|
||||
/// <summary>
|
||||
/// The maximum number of coordinate pairs that can be in an Async request for a distance matrix histogram.
|
||||
/// </summary>
|
||||
private const int MaxAsyncCoordinatePairsHistogram = 100;
|
||||
|
||||
/// <summary>
|
||||
/// The maximum number of hours between the start and end time when calculating a distance matrix histogram.
|
||||
/// </summary>
|
||||
private const double MaxTimeSpanHours = 24;
|
||||
|
||||
/// <summary>
|
||||
/// The maximium number of times the retry the status check if it fails. This will allow for possible connection issues.
|
||||
/// </summary>
|
||||
private const int MaxStatusCheckRetries = 3;
|
||||
|
||||
/// <summary>
|
||||
/// Number of seconds to delay a retry of a status check.
|
||||
/// </summary>
|
||||
private const int StatusCheckRetryDelay = 10;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructure
|
||||
|
||||
/// <summary>
|
||||
/// A request that calculates a distance matrix between origins and destinations.
|
||||
/// </summary>
|
||||
public DistanceMatrixRequest() : base()
|
||||
{
|
||||
TravelMode = TravelModeType.Driving;
|
||||
DistanceUnits = DistanceUnitType.Kilometers;
|
||||
TimeUnits = TimeUnitType.Seconds;
|
||||
Resolution = 1;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
|
||||
/// <summary>
|
||||
/// Required. List of origins described as coordinate pairs with latitudes and longitudes.
|
||||
/// </summary>
|
||||
public List<SimpleWaypoint> Origins { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// List of destinations described as coordinate pairs with latitudes and longitudes.
|
||||
/// </summary>
|
||||
public List<SimpleWaypoint> Destinations { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Specifies the mode of transportation to use when calculating the distance matrix. Can be one of the following values: driving [default], walking, transit.
|
||||
/// </summary>
|
||||
public TravelModeType TravelMode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Optional for Driving. Specifies the start or departure time of the matrix to calculate and uses traffic data in calculations.
|
||||
/// This option is only supported when the mode is set to driving.
|
||||
/// </summary>
|
||||
public DateTime? StartTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Optional for Driving. If specified, a matrix based on traffic data with contain a histogram of travel times and distances for
|
||||
/// the specified resolution (default is 15 minutes) between the start and end times. A start time must be specified for the request to be valid.
|
||||
/// This option is only supported when the mode is set to driving.
|
||||
/// </summary>
|
||||
public DateTime? EndTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The number of intervals to calculate a histogram of data for each cell for where a single interval is a quarter
|
||||
/// of an hour, 2 intervals would be 30 minutes, 3 intervals would be 45 minutes, 4 intervals would be for an hour.
|
||||
/// If start time is specified and resolution is not, it will default to an interval of 1 (15 minutes).
|
||||
/// </summary>
|
||||
public int Resolution { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The units to use for distance. Default: Kilometers.
|
||||
/// </summary>
|
||||
public DistanceUnitType DistanceUnits { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The units to use for time. Default: Seconds.
|
||||
/// </summary>
|
||||
public TimeUnitType TimeUnits { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Executes the request.
|
||||
/// </summary>
|
||||
/// <returns>A response containing the requested distance matrix.</returns>
|
||||
public override async Task<Response> Execute() {
|
||||
return await this.Execute(null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes the request.
|
||||
/// </summary>
|
||||
/// <param name="remainingTimeCallback">A callback function in which the estimated remaining time is sent.</param>
|
||||
/// <returns>A response containing the requested distance matrix.</returns>
|
||||
public override async Task<Response> Execute(Action<int> remainingTimeCallback)
|
||||
{
|
||||
//Make sure all origins and destinations are geocoded.
|
||||
await GeocodeWaypoints();
|
||||
|
||||
var requestUrl = GetRequestUrl();
|
||||
var requestBody = GetPostRequestBody();
|
||||
|
||||
Response response = null;
|
||||
|
||||
using (var responseStream = await ServiceHelper.PostStringAsync(new Uri(requestUrl), requestBody, "application/json"))
|
||||
{
|
||||
response = ServiceHelper.DeserializeStream<Response>(responseStream);
|
||||
}
|
||||
|
||||
if(response != null && response.ErrorDetails != null && response.ErrorDetails.Length > 0)
|
||||
{
|
||||
throw new Exception("Error: " + response.ErrorDetails[0]);
|
||||
}
|
||||
|
||||
if (response != null && response.ResourceSets != null && response.ResourceSets.Length > 0 && response.ResourceSets[0].Resources != null && response.ResourceSets[0].Resources.Length > 0)
|
||||
{
|
||||
if (response.ResourceSets[0].Resources[0] is DistanceMatrixAsyncStatus && !string.IsNullOrEmpty((response.ResourceSets[0].Resources[0] as DistanceMatrixAsyncStatus).RequestId))
|
||||
{
|
||||
var status = response.ResourceSets[0].Resources[0] as DistanceMatrixAsyncStatus;
|
||||
var statusUrl = new Uri(status.CallbackUrl);
|
||||
//var statusUrl = new Uri(this.Domain + "Routes/DistanceMatrixAsyncCallback?requestId=" + status.RequestId + "&key=" + this.BingMapsKey);
|
||||
|
||||
if (status.CallbackInSeconds > 0 || !status.IsCompleted || string.IsNullOrEmpty(status.ResultUrl))
|
||||
{
|
||||
remainingTimeCallback?.Invoke(status.CallbackInSeconds);
|
||||
|
||||
//Wait remaining seconds.
|
||||
await Task.Delay(TimeSpan.FromSeconds(status.CallbackInSeconds));
|
||||
|
||||
status = await MonitorAsyncStatus(statusUrl, 0, remainingTimeCallback);
|
||||
}
|
||||
|
||||
if (status != null)
|
||||
{
|
||||
if (status.IsCompleted && !string.IsNullOrEmpty(status.ResultUrl))
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var resultStream = await ServiceHelper.GetStreamAsync(new Uri(status.ResultUrl)))
|
||||
{
|
||||
DistanceMatrix dm = ServiceHelper.DeserializeStream<DistanceMatrix>(resultStream);
|
||||
|
||||
response.ResourceSets[0].Resources[0] = dm;
|
||||
|
||||
//TODO: Overwrite origins/destinations for now as we have added support for geocoding in this library, but this is not yet supported by the Distance Matirx API.
|
||||
dm.Origins = this.Origins.ToArray();
|
||||
dm.Destinations = this.Destinations.ToArray();
|
||||
}
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
response.ResourceSets[0].Resources[0] = new DistanceMatrix()
|
||||
{
|
||||
ErrorMessage = "There was an issue downloading and serializing the results. Results Download URL: " + status.ResultUrl
|
||||
};
|
||||
}
|
||||
}
|
||||
else if (!status.IsAccepted)
|
||||
{
|
||||
response.ResourceSets[0].Resources[0] = new DistanceMatrix()
|
||||
{
|
||||
ErrorMessage = "The request was not accepted."
|
||||
};
|
||||
}
|
||||
else if (!string.IsNullOrEmpty(status.ErrorMessage))
|
||||
{
|
||||
response.ResourceSets[0].Resources[0] = new DistanceMatrix()
|
||||
{
|
||||
ErrorMessage = status.ErrorMessage
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
else if (response.ResourceSets[0].Resources[0] is DistanceMatrix && (response.ResourceSets[0].Resources[0] as DistanceMatrix).Results != null)
|
||||
{
|
||||
DistanceMatrix dm = response.ResourceSets[0].Resources[0] as DistanceMatrix;
|
||||
|
||||
//TODO: Overwrite origins/destinations for now as we have added support for geocoding in this library, but this is not yet supported by the Distance Matirx API.
|
||||
dm.Origins = this.Origins.ToArray();
|
||||
dm.Destinations = this.Destinations.ToArray();
|
||||
|
||||
if (dm.Results != null) {
|
||||
return response;
|
||||
}
|
||||
else if(!string.IsNullOrEmpty(dm.ErrorMessage))
|
||||
{
|
||||
var msg = "Error: " + (response.ResourceSets[0].Resources[0] as DistanceMatrix).ErrorMessage;
|
||||
throw new Exception(msg);
|
||||
}
|
||||
}
|
||||
else if (response.ResourceSets[0].Resources[0] is DistanceMatrixAsyncStatus && !string.IsNullOrEmpty((response.ResourceSets[0].Resources[0] as DistanceMatrixAsyncStatus).ErrorMessage))
|
||||
{
|
||||
var msg = "Error: " + (response.ResourceSets[0].Resources[0] as DistanceMatrixAsyncStatus).ErrorMessage;
|
||||
throw new Exception(msg);
|
||||
}
|
||||
else if (response.ResourceSets[0].Resources[0] is DistanceMatrix && !string.IsNullOrEmpty((response.ResourceSets[0].Resources[0] as DistanceMatrix).ErrorMessage))
|
||||
{
|
||||
var msg = "Error: " + (response.ResourceSets[0].Resources[0] as DistanceMatrix).ErrorMessage;
|
||||
throw new Exception(msg);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Geocodes the origins and destinations.
|
||||
/// </summary>
|
||||
/// <returns>A task for geocoding the origins and destinations.</returns>
|
||||
public async Task GeocodeWaypoints()
|
||||
{
|
||||
//Ensure all the origins are geocoded.
|
||||
if (Origins != null)
|
||||
{
|
||||
await SimpleWaypoint.GeocodeWaypoints(Origins, this);
|
||||
}
|
||||
|
||||
//Ensure all the destinations are geocoded.
|
||||
if (Destinations != null)
|
||||
{
|
||||
await SimpleWaypoint.GeocodeWaypoints(Destinations, this);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calculates a Distance Matrix for the origins and destinations based on the euclidean distance (straight line/as the crow flies). This calculation only uses; Origins, Destinations, and Distance Units properties from the request and only calculates travel distance.
|
||||
/// </summary>
|
||||
/// <returns>A Distance Matrix for the origins and destinations based on the euclidean distance (straight line/as the crow flies).</returns>
|
||||
public async Task<DistanceMatrix> GetEuclideanDistanceMatrix()
|
||||
{
|
||||
if(this.Origins != null && this.Origins.Count > 0)
|
||||
//Make sure all origins and destinations are geocoded.
|
||||
await GeocodeWaypoints();
|
||||
|
||||
var dm = new DistanceMatrix()
|
||||
{
|
||||
Origins = this.Origins.ToArray()
|
||||
};
|
||||
|
||||
int cnt = 0;
|
||||
|
||||
if (this.Destinations == null || this.Destinations.Count == 0)
|
||||
{
|
||||
dm.Destinations = this.Origins.ToArray();
|
||||
dm.Results = new DistanceMatrixCell[this.Origins.Count * this.Origins.Count];
|
||||
|
||||
for (var i = 0; i < Origins.Count; i++)
|
||||
{
|
||||
for (var j = 0; j < Origins.Count; j++)
|
||||
{
|
||||
dm.Results[cnt] = new DistanceMatrixCell()
|
||||
{
|
||||
OriginIndex = i,
|
||||
DestinationIndex = j,
|
||||
TravelDistance = SpatialTools.HaversineDistance(Origins[i].Coordinate, Origins[j].Coordinate, DistanceUnits)
|
||||
};
|
||||
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dm.Destinations = this.Destinations.ToArray();
|
||||
dm.Results = new DistanceMatrixCell[this.Origins.Count * this.Destinations.Count];
|
||||
|
||||
for (var i = 0; i < Origins.Count; i++)
|
||||
{
|
||||
for (var j = 0; j < Destinations.Count; j++)
|
||||
{
|
||||
dm.Results[cnt] = new DistanceMatrixCell()
|
||||
{
|
||||
OriginIndex = i,
|
||||
DestinationIndex = j,
|
||||
TravelDistance = SpatialTools.HaversineDistance(Origins[i].Coordinate, Destinations[j].Coordinate, DistanceUnits)
|
||||
};
|
||||
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return dm;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the number of coordinate pairs that would be in the resulting matrix based on the number of origins and destinations in the request.
|
||||
/// </summary>
|
||||
/// <returns>The number of coordinate pairs that would be in the resulting matrix based on the number of origins and destinations in the request.</returns>
|
||||
public int GetNumberOfCoordinatePairs()
|
||||
{
|
||||
int numCoordPairs = Origins.Count;
|
||||
|
||||
if (Destinations != null)
|
||||
{
|
||||
numCoordPairs *= Destinations.Count;
|
||||
}
|
||||
else
|
||||
{
|
||||
numCoordPairs *= Origins.Count;
|
||||
}
|
||||
|
||||
return numCoordPairs;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the request URL to perform a query for a distance matrix when using POST.
|
||||
/// </summary>
|
||||
/// <returns>A request URL to perform a query for a distance matrix when using POST.</returns>
|
||||
public override string GetRequestUrl()
|
||||
{
|
||||
//Matrix when using POST
|
||||
//https://dev.virtualearth.net/REST/v1/Routes/DistanceMatrix?key=BingMapsKey
|
||||
|
||||
ValidateLocations(Origins, "Origin");
|
||||
|
||||
if (Destinations != null)
|
||||
{
|
||||
ValidateLocations(Destinations, "Destination");
|
||||
}
|
||||
|
||||
bool isAsyncRequest = false;
|
||||
|
||||
int numCoordPairs = GetNumberOfCoordinatePairs();
|
||||
|
||||
if (numCoordPairs > MaxCoordinatePairs)
|
||||
{
|
||||
throw new Exception("The number of Origins and Destinations provided would result in a matrix that has more than 625 coordinate pairs.");
|
||||
}
|
||||
|
||||
if (StartTime.HasValue)
|
||||
{
|
||||
if(TravelMode != TravelModeType.Driving)
|
||||
{
|
||||
throw new Exception("Start time parameter can only be used with the driving travel mode.");
|
||||
}
|
||||
|
||||
//Since start time is specified, an asynchronous request will be made which allows up to 100 coordinate pairs in the matrix (coordinate pairs).
|
||||
if (numCoordPairs > MaxAsyncCoordinatePairsHistogram)
|
||||
{
|
||||
throw new Exception("The number of Origins and Destinations provided would result in a matrix that has more than 100 coordinate pairs which is the limit when a histogram is requested.");
|
||||
}
|
||||
|
||||
isAsyncRequest = true;
|
||||
}
|
||||
|
||||
if (EndTime.HasValue)
|
||||
{
|
||||
if(!StartTime.HasValue)
|
||||
{
|
||||
throw new Exception("End time specified without a corresponding stat time.");
|
||||
}
|
||||
|
||||
var timeSpan = EndTime.Value.Subtract(StartTime.Value);
|
||||
|
||||
if(timeSpan.TotalHours > MaxTimeSpanHours)
|
||||
{
|
||||
throw new Exception("The time span between start and end time is more than 24 hours.");
|
||||
}
|
||||
|
||||
if(Resolution < 0 || Resolution > 4)
|
||||
{
|
||||
throw new Exception("Invalid resolution specified. Should be 1, 2, 3, or 4.");
|
||||
}
|
||||
}
|
||||
|
||||
return this.Domain + "Routes/DistanceMatrix" + ((isAsyncRequest)? "Async?" : "" + "?") + GetBaseRequestUrl();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a JSON string object representing the request.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string GetPostRequestBody()
|
||||
{
|
||||
//Build the JSON object using string builder as faster than JSON serializer.
|
||||
|
||||
var sb = new StringBuilder();
|
||||
|
||||
sb.Append("{\"origins\":[");
|
||||
|
||||
foreach (var o in Origins)
|
||||
{
|
||||
sb.AppendFormat("{{\"latitude\":{0:0.#####},\"longitude\":{1:0.#####}}},", o.Latitude, o.Longitude);
|
||||
}
|
||||
|
||||
//Remove trailing comma.
|
||||
sb.Length--;
|
||||
|
||||
sb.Append("]");
|
||||
|
||||
if (Destinations != null && Destinations.Count > 0)
|
||||
{
|
||||
sb.Append(",\"destinations\":[");
|
||||
|
||||
foreach (var d in Destinations)
|
||||
{
|
||||
sb.AppendFormat("{{\"latitude\":{0:0.#####},\"longitude\":{1:0.#####}}},", d.Latitude, d.Longitude);
|
||||
}
|
||||
|
||||
//Remove trailing comma.
|
||||
sb.Length--;
|
||||
|
||||
sb.Append("]");
|
||||
}
|
||||
|
||||
string mode;
|
||||
|
||||
switch (TravelMode)
|
||||
{
|
||||
case TravelModeType.Transit:
|
||||
mode = "transit";
|
||||
break;
|
||||
case TravelModeType.Walking:
|
||||
mode = "walking";
|
||||
break;
|
||||
case TravelModeType.Driving:
|
||||
default:
|
||||
mode = "driving";
|
||||
break;
|
||||
}
|
||||
|
||||
sb.AppendFormat(",\"travelMode\":\"{0}\"", mode);
|
||||
|
||||
if (StartTime.HasValue)
|
||||
{
|
||||
sb.AppendFormat(DateTimeFormatInfo.InvariantInfo, ",\"startTime\":\"{0:O}\"", StartTime.Value);
|
||||
|
||||
if (EndTime.HasValue)
|
||||
{
|
||||
sb.AppendFormat(DateTimeFormatInfo.InvariantInfo, ",\"endTime\":\"{0:O}\"", EndTime.Value);
|
||||
sb.AppendFormat(",\"resolution\":{0}", Resolution);
|
||||
}
|
||||
}
|
||||
|
||||
string tu;
|
||||
|
||||
switch (TimeUnits)
|
||||
{
|
||||
case TimeUnitType.Minutes:
|
||||
tu = "minutes";
|
||||
break;
|
||||
case TimeUnitType.Seconds:
|
||||
default:
|
||||
tu = "seconds";
|
||||
break;
|
||||
}
|
||||
|
||||
sb.AppendFormat(",\"timeUnit\":\"{0}\"", tu);
|
||||
|
||||
string du;
|
||||
|
||||
switch (DistanceUnits)
|
||||
{
|
||||
case DistanceUnitType.Miles:
|
||||
du = "mile";
|
||||
break;
|
||||
case DistanceUnitType.Kilometers:
|
||||
default:
|
||||
du = "kilometer";
|
||||
break;
|
||||
}
|
||||
|
||||
sb.AppendFormat(",\"distanceUnit\":\"{0}\"}}", du);
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
/// <summary>
|
||||
/// Varifies that an array of locations are valid and geocoded.
|
||||
/// </summary>
|
||||
/// <param name="locations">The array of locations to validate.</param>
|
||||
/// <param name="name">The name of the locations array.</param>
|
||||
private void ValidateLocations(List<SimpleWaypoint> locations, string name)
|
||||
{
|
||||
if (locations == null)
|
||||
{
|
||||
throw new Exception(name + "s not specified.");
|
||||
}
|
||||
else if (locations.Count < 1)
|
||||
{
|
||||
throw new Exception("Not enough " + name + "s specified.");
|
||||
}
|
||||
|
||||
//Verify all waypoints are geocoded.
|
||||
for (int i = 0; i < locations.Count; i++)
|
||||
{
|
||||
if (locations[i] == null) {
|
||||
throw new Exception(name + " " + i + " is null.");
|
||||
}
|
||||
else if(locations[i].Coordinate == null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(locations[i].Address))
|
||||
{
|
||||
throw new Exception(name + " " + i + " has no location information.");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception(name + " " + i + " not geocoded. Address: " + locations[i].Address);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Monitors the status of an async distance matrix request.
|
||||
/// </summary>
|
||||
/// <param name="statusUrl">The status URL for the async request.</param>
|
||||
/// <param name="failedTries">The number of times the status check has failed consecutively.</param>
|
||||
/// <param name="remainingTimeCallback">A callback function in whichthe estimated remaining time is sent.</param>
|
||||
/// <returns>The final async status when the request completed, had an error, or was not accepted.</returns>
|
||||
private async Task<DistanceMatrixAsyncStatus> MonitorAsyncStatus(Uri statusUrl, int failedTries, Action<int> remainingTimeCallback)
|
||||
{
|
||||
DistanceMatrixAsyncStatus status = null;
|
||||
|
||||
try
|
||||
{
|
||||
using (var rs = await ServiceHelper.GetStreamAsync(statusUrl))
|
||||
{
|
||||
var r = ServiceHelper.DeserializeStream<Response>(rs);
|
||||
|
||||
if (r != null)
|
||||
{
|
||||
if(r.ErrorDetails != null && r.ErrorDetails.Length > 0)
|
||||
{
|
||||
throw new Exception(r.ErrorDetails[0]);
|
||||
}
|
||||
else if (r.ResourceSets != null && r.ResourceSets.Length > 0 && r.ResourceSets[0].Resources != null && r.ResourceSets[0].Resources.Length > 0 && r.ResourceSets[0].Resources[0] is DistanceMatrixAsyncStatus)
|
||||
{
|
||||
status = r.ResourceSets[0].Resources[0] as DistanceMatrixAsyncStatus;
|
||||
|
||||
if (status.CallbackInSeconds > 0)
|
||||
{
|
||||
remainingTimeCallback?.Invoke(status.CallbackInSeconds);
|
||||
|
||||
//Wait remaining seconds.
|
||||
await Task.Delay(TimeSpan.FromSeconds(status.CallbackInSeconds));
|
||||
return await MonitorAsyncStatus(statusUrl, 0, remainingTimeCallback);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//Check to see how many times the status check has failed consecutively.
|
||||
if (failedTries < MaxStatusCheckRetries)
|
||||
{
|
||||
//Wait some time and try again.
|
||||
await Task.Delay(TimeSpan.FromSeconds(StatusCheckRetryDelay));
|
||||
return await MonitorAsyncStatus(statusUrl, failedTries + 1, remainingTimeCallback);
|
||||
}
|
||||
else
|
||||
{
|
||||
status.ErrorMessage = "Failed to get status, and exceeded the maximium of " + MaxStatusCheckRetries + " retries. Error message: " + ex.Message;
|
||||
status.CallbackInSeconds = -1;
|
||||
status.IsCompleted = false;
|
||||
}
|
||||
}
|
||||
|
||||
//Should only get here is the request has completed, was not accepted or there was an error.
|
||||
return status;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
|
@ -25,7 +25,9 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
|
@ -138,6 +140,44 @@ namespace BingMapsRESTToolkit
|
|||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Executes the request.
|
||||
/// </summary>
|
||||
/// <returns>A response containing the requested data.</returns>
|
||||
public override async Task<Response> Execute()
|
||||
{
|
||||
return await this.Execute(null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes the request.
|
||||
/// </summary>
|
||||
/// <param name="remainingTimeCallback">A callback function in which the estimated remaining time is sent.</param>
|
||||
/// <returns>A response containing the requested data.</returns>
|
||||
public override async Task<Response> Execute(Action<int> remainingTimeCallback)
|
||||
{
|
||||
Stream responseStream = null;
|
||||
|
||||
if (Points != null && 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(GetPostRequestUrl()), GetPointsAsString(), null);
|
||||
}
|
||||
else
|
||||
{
|
||||
responseStream = await ServiceHelper.GetStreamAsync(new Uri(GetRequestUrl()));
|
||||
}
|
||||
|
||||
if (responseStream != null)
|
||||
{
|
||||
var r = ServiceHelper.DeserializeStream<Response>(responseStream);
|
||||
responseStream.Dispose();
|
||||
return r;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a URL for requesting elevation data for a GET request.
|
||||
/// </summary>
|
||||
|
@ -255,7 +295,7 @@ namespace BingMapsRESTToolkit
|
|||
double totalDistance = 0;
|
||||
for (int i = 0; i < Points.Count - 1; i++)
|
||||
{
|
||||
totalDistance += SpatialTools.HaversineDistance(Points[i], Points[i + 1], DistanceUnitType.KM);
|
||||
totalDistance += SpatialTools.HaversineDistance(Points[i], Points[i + 1], DistanceUnitType.Kilometers);
|
||||
}
|
||||
|
||||
double segementLength = totalDistance / samples;
|
||||
|
@ -274,7 +314,7 @@ namespace BingMapsRESTToolkit
|
|||
|
||||
for (var i = 0; i < Points.Count - 1; i++)
|
||||
{
|
||||
dist += SpatialTools.HaversineDistance(Points[i], Points[i + 1], DistanceUnitType.KM);
|
||||
dist += SpatialTools.HaversineDistance(Points[i], Points[i + 1], DistanceUnitType.Kilometers);
|
||||
|
||||
if (dist >= travel)
|
||||
{
|
||||
|
@ -288,7 +328,7 @@ namespace BingMapsRESTToolkit
|
|||
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));
|
||||
coords.Add(SpatialTools.CalculateCoord(Points[idx], bearing, dx, DistanceUnitType.Kilometers));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -145,11 +145,13 @@ namespace BingMapsRESTToolkit
|
|||
{
|
||||
url += string.Format(CultureInfo.InvariantCulture, "/{0:0.#####},{1:0.#####}?", CenterPoint.Latitude, CenterPoint.Longitude);
|
||||
|
||||
if (ImagerySet == ImageryType.Road || ImagerySet == ImageryType.Aerial || ImagerySet == ImageryType.AerialWithLabels)
|
||||
if (ImagerySet == ImageryType.Road || ImagerySet == ImageryType.Aerial || ImagerySet == ImageryType.AerialWithLabels ||
|
||||
ImagerySet == ImageryType.RoadOnDemand || ImagerySet == ImageryType.AerialWithLabelsOnDemand || ImagerySet == ImageryType.CanvasDark ||
|
||||
ImagerySet == ImageryType.CanvasGray || ImagerySet == ImageryType.CanvasLight)
|
||||
{
|
||||
if (zoomLevel == 0)
|
||||
{
|
||||
throw new Exception("Zoom Level must be specified when a centerPoint is specified and ImagerySet is Road, Aerial and AerialWithLabels.");
|
||||
throw new Exception("Zoom Level must be specified when a centerPoint is specified and ImagerySet is Road, Aerial, AerialWithLabels, or any variation of these (Canvas/OnDemand).");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -25,7 +25,9 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
{
|
||||
|
@ -205,6 +207,47 @@ namespace BingMapsRESTToolkit
|
|||
|
||||
#region Public Methods
|
||||
|
||||
/// <summary>
|
||||
/// Executes the request.
|
||||
/// </summary>
|
||||
/// <returns>A response containing the requested data.</returns>
|
||||
public override async Task<Response> Execute()
|
||||
{
|
||||
return await this.Execute(null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Executes the request.
|
||||
/// </summary>
|
||||
/// <param name="remainingTimeCallback">A callback function in which the estimated remaining time is sent.</param>
|
||||
/// <returns>A response containing the requested data.</returns>
|
||||
public override async Task<Response> Execute(Action<int> remainingTimeCallback)
|
||||
{
|
||||
Stream responseStream = null;
|
||||
|
||||
GetMetadata = true;
|
||||
|
||||
if (Pushpins != null && 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(GetPostRequestUrl()), GetPushpinsAsString(), null);
|
||||
}
|
||||
else
|
||||
{
|
||||
responseStream = await ServiceHelper.GetStreamAsync(new Uri(GetRequestUrl()));
|
||||
}
|
||||
|
||||
if (responseStream != null)
|
||||
{
|
||||
var r = ServiceHelper.DeserializeStream<Response>(responseStream);
|
||||
responseStream.Dispose();
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <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.
|
||||
|
@ -228,23 +271,25 @@ namespace BingMapsRESTToolkit
|
|||
sb.Append("Imagery/Map/");
|
||||
|
||||
sb.Append(Enum.GetName(typeof(ImageryType), ImagerySet));
|
||||
|
||||
|
||||
if (CenterPoint != null)
|
||||
{
|
||||
sb.AppendFormat(CultureInfo.InvariantCulture, "/{0:0.#####},{1:0.#####}/", CenterPoint.Latitude, CenterPoint.Longitude);
|
||||
sb.AppendFormat(CultureInfo.InvariantCulture, "/{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.");
|
||||
}
|
||||
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 ||
|
||||
ImagerySet == ImageryType.RoadOnDemand || ImagerySet == ImageryType.AerialWithLabelsOnDemand || ImagerySet == ImageryType.CanvasDark ||
|
||||
ImagerySet == ImageryType.CanvasGray || ImagerySet == ImageryType.CanvasLight)
|
||||
{
|
||||
throw new Exception("Zoom Level must be specified when a centerPoint is specified and ImagerySet is Road, Aerial, AerialWithLabels, or any variation of these (Canvas/OnDemand).");
|
||||
}
|
||||
}
|
||||
else if (isQuery)
|
||||
{
|
||||
|
|
|
@ -105,7 +105,7 @@ namespace BingMapsRESTToolkit
|
|||
}
|
||||
}
|
||||
|
||||
if (DistanceUnits != DistanceUnitType.KM)
|
||||
if (DistanceUnits != DistanceUnitType.Kilometers)
|
||||
{
|
||||
url += "&du=mi";
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BingMapsRESTToolkit
|
||||
|
@ -41,51 +40,18 @@ namespace BingMapsRESTToolkit
|
|||
/// <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;
|
||||
return await request.Execute(null);
|
||||
}
|
||||
|
||||
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 data.
|
||||
/// </summary>
|
||||
/// <param name="request">The REST request to process.</param>
|
||||
/// <param name="remainingTimeCallback">A callback function in which the estimated remaining time is sent.</param>
|
||||
/// <returns>The response from the REST service.</returns>
|
||||
public static async Task<Response> GetResponseAsync(BaseRestRequest request, Action<int> remainingTimeCallback)
|
||||
{
|
||||
return await request.Execute(remainingTimeCallback);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
Загрузка…
Ссылка в новой задаче