* Return some parsed values in DMS formats that @mapbox/sexagesimal can't parse, see iD#10066 * Note that `@mapbox/sexagesimal` returns [lat,lon], so this code does too. * @param {string} q - string to attempt to parse * @return {Array ?} The location formatted as `[lat,lon]
(q)
| 812 | * @return {Array<Number>?} The location formatted as `[lat,lon]`, or `null` it can't be parsed |
| 813 | */ |
| 814 | dmsMatcher(q) { |
| 815 | let match; |
| 816 | |
| 817 | // DD MM SS , DD MM SS ex: 35 11 10.1 , 136 49 53.8 |
| 818 | const DMS_DMS = /^\s*(-?)\s*(\d+)\s+(\d+)\s+(\d+\.?\d*)\s*\,\s*(-?)\s*(\d+)\s+(\d+)\s+(\d+\.?\d*)\s*$/; |
| 819 | match = q.match(DMS_DMS); |
| 820 | if (match) { |
| 821 | let lat = (+match[2]) + (+match[3]) / 60 + (+match[4]) / 3600; |
| 822 | let lon = (+match[6]) + (+match[7]) / 60 + (+match[8]) / 3600; |
| 823 | if (match[1] === '-') lat *= -1; |
| 824 | if (match[5] === '-') lon *= -1; |
| 825 | return [lat, lon]; |
| 826 | } |
| 827 | |
| 828 | // DD MM , DD MM ex: 35 11 10.1 , 136 49 53.8 |
| 829 | const DM_DM = /^\s*(-?)\s*(\d+)\s+(\d+\.?\d*)\s*\,\s*(-?)\s*(\d+)\s+(\d+\.?\d*)\s*$/; |
| 830 | match = q.match(DM_DM); |
| 831 | if (match) { |
| 832 | let lat = +match[2] + (+match[3]) / 60; |
| 833 | let lon = +match[5] + (+match[6]) / 60; |
| 834 | if (match[1] === '-') lat *= -1; |
| 835 | if (match[4] === '-') lon *= -1; |
| 836 | return [lat, lon]; |
| 837 | } |
| 838 | |
| 839 | return null; |
| 840 | } |
| 841 | |
| 842 | |
| 843 | /** |
no test coverage detected