MCPcopy Create free account
hub / github.com/Maps4HTML/MapML.js / _firstCoordinate

Function _firstCoordinate

src/mapml/handlers/QueryHandler.js:24–43  ·  view source on GitHub ↗
(json)

Source from the content-addressed store, hash-verified

22// Extract the first [x, y] coordinate pair from a GeoJSON object,
23// drilling into FeatureCollection → Feature → Geometry → coordinates.
24function _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
45export var QueryHandler = Handler.extend({
46 addHooks: function () {

Callers 1

_hasProjectedCoordinatesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected