(json)
| 22 | // Extract the first [x, y] coordinate pair from a GeoJSON object, |
| 23 | // drilling into FeatureCollection → Feature → Geometry → coordinates. |
| 24 | function _firstCoordinate(json) { |
| 25 | if (!json) return null; |
| 26 | let type = json.type && json.type.toUpperCase(); |
| 27 | if (type === 'FEATURECOLLECTION') { |
| 28 | if (json.features && json.features.length > 0) |
| 29 | return _firstCoordinate(json.features[0]); |
| 30 | } else if (type === 'FEATURE') { |
| 31 | return _firstCoordinate(json.geometry); |
| 32 | } else if (json.coordinates) { |
| 33 | // Unwrap nested arrays until we reach a [number, number] pair |
| 34 | let coords = json.coordinates; |
| 35 | while (Array.isArray(coords) && Array.isArray(coords[0])) { |
| 36 | coords = coords[0]; |
| 37 | } |
| 38 | if (coords.length >= 2 && typeof coords[0] === 'number') return coords; |
| 39 | } else if (type === 'GEOMETRYCOLLECTION' && json.geometries) { |
| 40 | if (json.geometries.length > 0) return _firstCoordinate(json.geometries[0]); |
| 41 | } |
| 42 | return null; |
| 43 | } |
| 44 | |
| 45 | export var QueryHandler = Handler.extend({ |
| 46 | addHooks: function () { |
no outgoing calls
no test coverage detected