Fixed spatial issues with finding map cuts data.

This commit is contained in:
2025-09-10 20:57:07 -06:00
parent ebf9ff23ab
commit 006cbcf9c3
5 changed files with 48 additions and 129 deletions

View File

@@ -35,10 +35,18 @@ function isPointInPolygon(lat, lng, polygon) {
*/
function isLocationInCut(location, cutGeoJson) {
// Handle different possible field names for coordinates
const lat = location.latitude || location.Latitude || location.lat;
const lng = location.longitude || location.Longitude || location.lng || location.lon;
const latRaw = location.latitude || location.Latitude || location.lat;
const lngRaw = location.longitude || location.Longitude || location.lng || location.lon;
if (!lat || !lng || !cutGeoJson) {
if (!latRaw || !lngRaw || !cutGeoJson) {
return false;
}
// Parse coordinates as floats since they might be strings
const lat = parseFloat(latRaw);
const lng = parseFloat(lngRaw);
if (isNaN(lat) || isNaN(lng)) {
return false;
}
@@ -72,14 +80,20 @@ function filterLocationsInCut(locations, cut, filters = {}) {
const geojsonData = cut.geojson || cut.Geojson || cut.GeoJSON || cut['GeoJSON Data'] || cut.geojson_data;
if (!geojsonData) {
console.log('No geojson data found for cut:', cut.name || cut.Name || 'Unknown');
return [];
}
// Debug: Log total locations being tested
console.log(`Testing ${locations.length} locations against cut boundaries`);
// First filter by geographic boundaries
let filteredLocations = locations.filter(location =>
isLocationInCut(location, geojsonData)
);
console.log(`Filtered ${locations.length} total locations down to ${filteredLocations.length} locations within cut bounds`);
// Apply additional filters
if (filters.support_level) {
filteredLocations = filteredLocations.filter(location => {