Fixed spatial issues with finding map cuts data.
This commit is contained in:
@@ -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 => {
|
||||
|
||||
Reference in New Issue
Block a user