mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-17 08:42:21 +00:00
Knip, configured with the application, package exports, scripts, QA harnesses, workers, tools and tests as entry points, reports exports that no module imports. Each was checked by hand against string-based and namespace imports. - Symbols that are still used inside their own module lose only the `export` keyword (176 constants and helpers). - Unused re-exports are removed from barrel modules (flight, military, vessel, CCTV, directions, transit history, local ADS-B and street-level policy modules). - Declarations that nothing uses at all are deleted, among them AIS_WATCHDOG_STATUSES, applyFilter, isRadioCountryCode, compactText, DENSITY_STOPS, the unused CCTV endpoint constants, and the SDR band constants. - Default exports that nothing imports are removed. The ones in src/data/earthquakes.js, src/data/telegeographySubmarineCables.js, src/data/wind.js and src/data/bhoteKoshiLocator.js each constructed a layer instance at import time that nothing used; those instances are no longer created. Every export of a package.json entry stays, as does TOMTOM_CREDIT, which the traffic layer reads from the credits namespace it is given.
80 lines
2.1 KiB
JavaScript
80 lines
2.1 KiB
JavaScript
export function featureReference(feature) {
|
|
const geometry = feature?.geometry;
|
|
if (!geometry) return null;
|
|
|
|
const props = feature?.properties || {};
|
|
const propertyCoords = coordsFromProperty(props.coordinates);
|
|
if (propertyCoords) {
|
|
return {
|
|
lon: propertyCoords[0],
|
|
lat: propertyCoords[1],
|
|
};
|
|
}
|
|
|
|
if (geometry.type === 'Point') {
|
|
const coords = coordsFromPoint(geometry.coordinates);
|
|
if (!coords) return null;
|
|
return { lon: coords[0], lat: coords[1] };
|
|
}
|
|
|
|
const coords = [];
|
|
collectLonLat(geometry.coordinates, coords);
|
|
if (!coords.length) return null;
|
|
|
|
let lonSum = 0;
|
|
let latSum = 0;
|
|
for (const [lon, lat] of coords) {
|
|
lonSum += lon;
|
|
latSum += lat;
|
|
}
|
|
return {
|
|
lon: lonSum / coords.length,
|
|
lat: latSum / coords.length,
|
|
};
|
|
}
|
|
|
|
function coordsFromProperty(value) {
|
|
if (!Array.isArray(value) || value.length < 2) return null;
|
|
const lon = Number(value[0]);
|
|
const lat = Number(value[1]);
|
|
if (!Number.isFinite(lon) || !Number.isFinite(lat)) return null;
|
|
return [lon, lat];
|
|
}
|
|
|
|
function coordsFromPoint(value) {
|
|
if (!Array.isArray(value) || value.length < 2) return null;
|
|
const lon = Number(value[0]);
|
|
const lat = Number(value[1]);
|
|
if (!Number.isFinite(lon) || !Number.isFinite(lat)) return null;
|
|
return [lon, lat];
|
|
}
|
|
|
|
function collectLonLat(value, out) {
|
|
if (!Array.isArray(value)) return;
|
|
if (typeof value[0] === 'number' && typeof value[1] === 'number') {
|
|
const lon = Number(value[0]);
|
|
const lat = Number(value[1]);
|
|
if (Number.isFinite(lon) && Number.isFinite(lat)) {
|
|
out.push([lon, lat]);
|
|
}
|
|
return;
|
|
}
|
|
for (const child of value) collectLonLat(child, out);
|
|
}
|
|
|
|
export function featureLabel(feature) {
|
|
const props = feature?.properties || {};
|
|
return String(props.name || props.id || feature?.id || '').trim();
|
|
}
|
|
|
|
export function normalizeFeatures(json, kind) {
|
|
const features = Array.isArray(json?.features) ? json.features : [];
|
|
return features.map((feature, index) => {
|
|
const id = feature?.properties?.id || feature?.id || `${kind}-${index}`;
|
|
return {
|
|
...feature,
|
|
id: String(id),
|
|
};
|
|
});
|
|
}
|