1.0.18 • Published 1 year ago

@riaskov/metro-ru v1.0.18

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Metro RU

Module type: MinChrome Module type: MinNode Module type: CJS+ESM Module type: target-ES2016

Russian Cities metro (subway) stations data with methods for calculating a distance between given coordinate and station (using Haversine formula):

  • Moscow Metro
  • Saint Petersburg Metro
  • Kazan Metro
  • Ekaterinburg Metro
  • in progress Nizhny Novgorod Metro
  • in progress Novosibirsk Metro
  • in progress Samara Metro

TODO

  • add English translation of stations names
  • add an address of each station
  • automatically push browser minified version to CDN
  • create super-minimal (<10 KBytes; now it's 40 KBytes) version for browser
  • add mocha/chai tests

API

Data structures

Available cities:

enum City {
    Moscow = "Moscow",
    SaintPetersburg = "SaintPetersburg",
    Ekaterinburg = "Ekaterinburg",
    Kazan = "Kazan"
}

Metro station description:

interface MetroStation {
    name: string
    nameTranslit: string
    lat: number
    lon: number
    lineColor: string
    lineName: string
    lineNameTranslit: string
    order: number
}
FieldTypeDescription
namestringRussian name of station
nameTranslitstringTransliterated name of station
latnumberLatitude of your coordinate
lonnumberLongitude of your coordinate
lineColorstringColor of the line in #HEX
lineNamestringRussian name of the line
lineNameTranslitstringTransliterated name of the line
ordernumberOrder of the station in the line (from 0 - the Northern station)

Functions

Getting the closest station by city and coordinate (Lat+Lon)

function getClosestStation(
    city: City,
    lat: number,
    lon: number,
): [MetroStation, number] | null

Params:

ParamTypeDescription
cityCityName of the city in Russian
latnumberLatitude of your coordinate
lonnumberLongitude of your coordinate

Returns the closest station (MetroStation-part) with distance in meters (number-part) from the given coordinate. Returns null if you pass an incorrect city name.

Example:

import { City, getClosestStation } from "@riaskov/metro-ru"

console.log(getClosestStation(City.Moscow, 55.640918, 37.754337))
[
  {
      name: 'Алма-Атинская',
      nameTranslit: 'Alma-Atinskaya',
      lat: 55.63349,
      lon: 37.765678, 
      lineColor: '#4FB04F',
      lineName: 'Замоскворецкая',
      lineNameTranslit: 'Zamoskvoretskaya',
      order: 21
  },
  1090
]

Getting the N closest stations by city and coordinate (Lat+Lon)

import { City, getClosestStations } from "@riaskov/metro-ru"

function getClosestStations(
    city: City,
    lat: number,
    lon: number,
    n: number,
): [MetroStation, number][] | null

Params:

ParamTypeDescription
cityCityName of the city in Russian
latnumberLatitude of your coordinate
lonnumberLongitude of your coordinate

Returns an array of N closest stations (MetroStation-part) with distances in meters (number-part) (array of tuples like [MetroStation, number]). Returns null if you pass an incorrect city name.

Example:

import { getClosestStations } from '@riaskov/metro-ru'

console.log(getClosestStations(City.Moscow, 55.640918, 37.754337, 2))
[
  [
    {
      name: 'Алма-Атинская',
      nameTranslit: 'Alma-Atinskaya', 
      lat: 55.63349,
      lon: 37.765678,
      lineColor: '#4FB04F',
      lineName: 'Замоскворецкая',
      lineNameTranslit: 'Zamoskvoretskaya',
      order: 21
    },
    1090
  ],
  [
    {
      name: 'Марьино',
      nameTranslit: 'Marino',
      lat: 55.649158,
      lon: 37.743844,
      lineColor: '#BED12C',
      lineName: 'Люблинско-Дмитровская',
      lineNameTranslit: 'Lyublinsko-Dmitrovskaya',
      order: 16
    },
    1128
  ]
]

License

MIT (see the LICENSE file).

Acknowledgements

This project uses Open Data files provided data.mos.ru (Creative Commons Attribution 3.0)

1.0.18

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago