Added Geospatial Endpoint service support.
Fixed distance unit bug in RouteMajorRoadsRequest.
This commit is contained in:
Ricky Brundritt 2017-03-22 18:00:13 -07:00
Родитель 87bff8a3cd
Коммит 870e6120c5
10 изменённых файлов: 216 добавлений и 16 удалений

Просмотреть файл

@ -7,7 +7,7 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope
## How to contribute ##
There are a couple of ways you can contribute to this repo:
* **Ideas, feature requests and bugs**: We are open to all ideas and we want to get rid of bugs! Use the [Issues section](https://github.com/Microsoft/Bing-Maps-V8-TypeScript-Definitions/issues) to either report a new issue, provide your ideas or contribute to existing threads
* **Ideas, feature requests and bugs**: We are open to all ideas and we want to get rid of bugs! Use the [Issues section](https://github.com/Microsoft/BingMapsRESTToolkit/issues) to either report a new issue, provide your ideas or contribute to existing threads
* **Documentation**: Found a typo or strangely worded sentences? Submit a PR!
**Note:** If the issue you are experiencing is with the Bing Maps SDK itself, please report in the [MSDN forums](https://social.msdn.microsoft.com/Forums/en-US/home?forum=bingmapsajax&filter=alltypes&sort=lastpostdesc), or if you license Bing Maps, contact the [Bing Maps Enterprise support team](https://www.microsoft.com/maps/support.aspx).

Просмотреть файл

@ -31,6 +31,7 @@
<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"/>
</StackPanel>
<Grid Margin="5,10,5,5">

Просмотреть файл

@ -57,7 +57,7 @@ namespace RESTToolkitTestApp
{
var r = new GeocodeRequest()
{
Query = "New York, NY",
Query = "66-46 74th St, Middle Village, NY 11379",
IncludeIso2 = true,
IncludeNeighborhood = true,
MaxResults = 25,
@ -297,6 +297,23 @@ namespace RESTToolkitTestApp
ProcessImageRequest(r);
}
/// <summary>
/// Demostrates how to make a Geospatial Endpoint Request.
/// </summary>
private void GeospatialEndpointBtn_Clicked(object sender, RoutedEventArgs e)
{
var r = new GeospatialEndpointRequest()
{
//Language = "zh-CN",
Culture = "zh-CN",
UserRegion = "CN",
UserLocation = new Coordinate(40, 116),
BingMapsKey = BingMapsKey
};
ProcessRequest(r);
}
#endregion
#region Private Methods

Просмотреть файл

@ -53,6 +53,7 @@
<Compile Include="Models\BoundingBox.cs" />
<Compile Include="Models\ImageryPushpin.cs" />
<Compile Include="Models\RouteOptions.cs" />
<Compile Include="Requests\GeospatialEndpointRequest.cs" />
<Compile Include="Requests\ImageryMetadataRequest.cs" />
<Compile Include="Requests\ImageryRequest.cs" />
<Compile Include="Models\PointCompression.cs" />
@ -76,7 +77,6 @@
<Compile Include="Requests\ReverseGeocodeRequest.cs" />
<Compile Include="Requests\TrafficRequest.cs" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

Просмотреть файл

@ -23,6 +23,7 @@
*/
using System;
using System.Globalization;
using System.Runtime.Serialization;
namespace BingMapsRESTToolkit
@ -103,6 +104,11 @@ namespace BingMapsRESTToolkit
}
}
public override string ToString()
{
return string.Format(CultureInfo.InvariantCulture, "{0:0.#####},{1:0.#####}", Latitude, Longitude);
}
#endregion
}
}

Просмотреть файл

@ -391,6 +391,15 @@ namespace BingMapsRESTToolkit
[DataMember(Name = "usageTypes", EmitDefaultValue = false)]
public string[] UsageTypes { get; set; }
public Coordinate GetCoordinate()
{
if (Coordinates.Length >= 2) {
return new Coordinate(Coordinates[0], Coordinates[1]);
}
return null;
}
}
[DataContract]
@ -401,6 +410,7 @@ namespace BingMapsRESTToolkit
[KnownType(typeof(ElevationData))]
[KnownType(typeof(SeaLevelData))]
[KnownType(typeof(CompressedPointList))]
[KnownType(typeof(GeospatialEndpointResponse))]
public class Resource
{
/// <summary>
@ -986,4 +996,73 @@ namespace BingMapsRESTToolkit
[DataMember(Name = "zoomLevel", EmitDefaultValue = false)]
public int ZoomLevel { get; set; }
}
/// <summary>
/// This response specifies:
/// - Whether this is a politically disputed area, such as an area claimed by more than one country.
/// - Whether services are available in the users region.
/// - A list of available geospatial services including endpoints and language support for each service.
/// </summary>
[DataContract(Namespace = "http://schemas.microsoft.com/search/local/ws/rest/v1")]
public class GeospatialEndpointResponse : Resource
{
/// <summary>
/// Specifies if this area in the request is claimed by more than one country.
/// </summary>
[DataMember(Name = "isDisputedArea", EmitDefaultValue = false)]
public bool IsDisputedArea { get; set; }
/// <summary>
/// Specifies if Geospatial Platform services are available in the country or region. Microsoft does not support services in embargoed areas.
/// </summary>
[DataMember(Name = "isSupported", EmitDefaultValue = false)]
public bool IsSupported { get; set; }
/// <summary>
/// The country or region that was used to determine service support. If you specified a User Location in
/// the request that is in a non-disputed country or region, this country or region is returned in the response.
/// </summary>
[DataMember(Name = "ur", EmitDefaultValue = false)]
public string UserRegion { get; set; }
/// <summary>
/// Information for each geospatial service that is available in the country or region and language specified in the request.
/// </summary>
[DataMember(Name = "services", EmitDefaultValue = false)]
public GeospatialService[] Services { get; set; }
}
/// <summary>
/// Information for a geospatial service that is available in the country or region and language specified in the request.
/// </summary>
[DataContract]
public class GeospatialService
{
/// <summary>
/// The URL service endpoint to use in this region. Note that to use the service, you must typically add parameters specific to
/// the service. These parameters are not described in this documentation.
/// </summary>
[DataMember(Name = "endpoint", EmitDefaultValue = false)]
public string Endpoint { get; set; }
/// <summary>
/// Set to true if the service supports the language in the request for the region. If the language is supported, then the
/// service endpoint will return responses using this language. If it is not supported, then the service will use the fallback language.
/// </summary>
[DataMember(Name = "fallbackLanguage", EmitDefaultValue = false)]
public string FallbackLanguage { get; set; }
/// <summary>
/// Specifies the secondary or fallback language in this region or country. If the requested language is not supported
/// and a fallback language is not available, United States English (en-us) is used.
/// </summary>
[DataMember(Name = "languageSupported", EmitDefaultValue = false)]
public bool LanguageSupported { get; set; }
/// <summary>
/// An abbreviated name for the service.
/// </summary>
[DataMember(Name = "serviceName", EmitDefaultValue = false)]
public string ServiceName { get; set; }
}
}

Просмотреть файл

@ -22,9 +22,7 @@
* THE SOFTWARE.
*/
using System;
using System.Runtime.Serialization;
using System.Globalization;
namespace BingMapsRESTToolkit
{
@ -39,27 +37,32 @@ namespace BingMapsRESTToolkit
/// <summary>
/// The Bing Maps key for making the request.
/// </summary>
public string BingMapsKey;
public string BingMapsKey { get; set; }
/// <summary>
/// The culture to use for the request.
/// The culture to use for the request. An IETF language code, that includes the language and region code subtags, such as en-us or zh-hans.
/// </summary>
public string Culture;
public string Culture { get; set; }
/// <summary>
/// The geographic region that corresponds to the current viewport.
/// </summary>
public BoundingBox UserMapView;
public BoundingBox UserMapView { get; set; }
/// <summary>
/// The users current position.
/// </summary>
public Coordinate UserLocation;
public Coordinate UserLocation { get; set; }
/// <summary>
/// An ISO 3166-1 alpha-2 region code, such as US, IN, and CN.
/// </summary>
public string UserRegion { get; set; }
/// <summary>
/// An Internet Protocol version 4 (IPv4) address.
/// </summary>
public string UserIp;
public string UserIp { get; set; }
#endregion
@ -85,7 +88,7 @@ namespace BingMapsRESTToolkit
if (UserLocation != null)
{
url += string.Format(CultureInfo.InvariantCulture, "&ul={0:0.#####},{1:0.#####}", UserLocation.Latitude, UserLocation.Longitude);
url += string.Format("&ul={0}", UserLocation);
}
if (!string.IsNullOrWhiteSpace(UserIp))

Просмотреть файл

@ -0,0 +1,94 @@
/*
* Copyright(c) 2017 Microsoft Corporation. All rights reserved.
*
* This code is licensed under the MIT License (MIT).
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do
* so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
using System;
namespace BingMapsRESTToolkit
{
/// <summary>
/// The Geospatial Endpoint Service is a REST service that provides information about Geospatial Platform services
/// for the language and geographical region you specify. The service information includes available service endpoints
/// and language support for these endpoints. Disputed geographical areas and embargoed countries or regions that
/// do not have any service support are also identified.
/// https://msdn.microsoft.com/en-us/library/dn948525.aspx
/// </summary>
public class GeospatialEndpointRequest : BaseRestRequest
{
#region Public Properties
/// <summary>
/// When set to true the returned service URL's will use HTTPS.
/// </summary>
public bool UseHTTPS { get; set; }
#endregion
#region Public Methods
/// <summary>
/// Gets the request URL. If both a Query and Address are specified, the Query value will be used. Throws an exception if a Query or Address value is not specified.
/// </summary>
/// <returns>Geocode request URL for GET request.</returns>
public override string GetRequestUrl()
{
string url = "https://dev.virtualearth.net/REST/v1/GeospatialEndpoint";
if (!string.IsNullOrWhiteSpace(Culture))
{
url += string.Format("/{0}", Culture);
}
else
{
throw new Exception("Invalid Language value specified.");
}
if (!string.IsNullOrWhiteSpace(UserRegion))
{
url += string.Format("/{0}", UserRegion);
}
else
{
throw new Exception("Invalid UserRegion value specified.");
}
if(UserLocation != null)
{
url += string.Format("/{0}", UserLocation);
}
if (UseHTTPS)
{
url += "?uriScheme=http";
}
else
{
url += "?";
}
return url + GetBaseRequestUrl();
}
#endregion
}
}

Просмотреть файл

@ -105,9 +105,9 @@ namespace BingMapsRESTToolkit
}
}
if (DistanceUnits == DistanceUnitType.KM)
if (DistanceUnits != DistanceUnitType.KM)
{
url += "&distanceUnit=mi";
url += "&du=mi";
}
return url + GetBaseRequestUrl();

Просмотреть файл

@ -79,10 +79,10 @@ namespace BingMapsRESTToolkit
if (responseStream != null)
{
var ser = new DataContractJsonSerializer(typeof(Response));
var ser = new DataContractJsonSerializer(typeof(Response));
var r = ser.ReadObject(responseStream) as Response;
responseStream.Dispose();
return r;
return r;
}
return null;