//-----------------------------------------------------------------------
//
// Copyright (c) 2016 Mapbox. All rights reserved.
//
//-----------------------------------------------------------------------
namespace Mapbox.Geocoding
{
using System;
using System.Collections.Generic;
using Mapbox.Platform;
/// Base geocode class.
/// Type of Query field (either string or LatLng).
public abstract class GeocodeResource : Resource
{
/// A List of all possible geocoding feature types.
public static readonly List FeatureTypes = new List
{
"country", "region", "postcode", "place", "locality", "neighborhood", "address", "poi"
};
private readonly string apiEndpoint = "geocoding/v5/";
private readonly string mode = "mapbox.places/";
// Optional
private string[] types;
/// Gets or sets the query.
public abstract T Query { get; set; }
/// Gets the API endpoint as a partial URL path.
public override string ApiEndpoint {
get {
return this.apiEndpoint;
}
}
/// Gets the mode.
public string Mode {
get {
return this.mode;
}
}
/// Gets or sets which feature types to return results for.
public string[] Types {
get {
return this.types;
}
set {
if (value == null)
{
this.types = value;
return;
}
for (int i = 0; i < value.Length; i++)
{
// Validate provided types
if (!FeatureTypes.Contains(value[i]))
{
throw new Exception("Invalid type. Must be \"country\", \"region\", \"postcode\", \"place\", \"locality\", \"neighborhood\", \"address\", or \"poi\".");
}
}
this.types = value;
}
}
}
}