mapbox / mapbox-gl-directions

Directions plugin for mapbox-gl-js using Mapbox Directions API.
https://mapbox.com/mapbox-gl-js/example/mapbox-gl-directions/
ISC License
235 stars 124 forks source link

TypeScript Definitions #265

Open alexsantos-eth opened 3 years ago

alexsantos-eth commented 3 years ago

I dont found any typescript definition file for ApiResponse here. maybe like this?

interface MapBoxDirections {
    code: string
    uuid: string
    waypoints: {
        distance: number
        name: string
        location: number[]
    }[]
    routes: {
        distance: number
        duration: number
        geometry: {
            coordinates: number[][]
            type: string
        }
        legs: {
            admins: {
                iso_3166_1: string
                iso_3166_1_alpha3: string
            }[]
            distance: number
            duration: number
            steps: []
            summary: string
            weight: number
        }[]
        weight: number
        weight_name: string
    }[]
}
tobijafischer commented 6 months ago

Thanks for sharing. I still couldn't find any types, so here's the slightly more up-to-date version of your type that I'm using. The only difference really is that there is a new property legs.via_waypoints and that I have changed the location properties to [number, number] as coordinates are always returned in this format.

export interface MapboxDirections {
  code: string
  uuid: string
  waypoints: {
    distance: number
    name: string
    location: [number, number]
  }[]
  routes: {
    distance: number
    duration: number
    geometry: {
      coordinates: [number, number][]
      type: string
    }
    legs: {
      via_waypoints: [],
      admins: {
        iso_3166_1: string
        iso_3166_1_alpha3: string
      }[]
      distance: number
      duration: number
      steps: []
      summary: string
      weight: number
    }[]
    weight: number
    weight_name: string
  }[]
}

P.S. Note that legs.via_waypoints and legs.steps must be typed separately if these features are to be used.