diff --git a/api/src/paths/public/search.test.ts b/api/src/paths/public/search.test.ts index 463061e7..7264eaa4 100644 --- a/api/src/paths/public/search.test.ts +++ b/api/src/paths/public/search.test.ts @@ -81,6 +81,7 @@ describe('search', () => { number_sites: 1, size_ha: 100, state_code: 1, + maskedLocation: false, geometry: '{"type":"Point","coordinates":[50.7,60.9]}' } ]; @@ -109,6 +110,7 @@ describe('search', () => { number_sites: searchList[0].number_sites, size_ha: searchList[0].size_ha, state_code: searchList[0].state_code, + maskedLocation: searchList[0].maskedLocation, geometry: [ { type: 'Point', diff --git a/api/src/paths/public/search.ts b/api/src/paths/public/search.ts index df5a23fe..937be911 100644 --- a/api/src/paths/public/search.ts +++ b/api/src/paths/public/search.ts @@ -59,7 +59,8 @@ export function getSearchResults(): RequestHandler { p.state_code, psc.number_sites, psc.size_ha, - public.ST_asGeoJSON(psc.geography) as geometry + public.ST_asGeoJSON(psc.geography) as geometry, + psc.geojson#>>'{}' as geojson FROM project p LEFT JOIN diff --git a/api/src/paths/search.test.ts b/api/src/paths/search.test.ts index 07e3a18c..549bb5d7 100644 --- a/api/src/paths/search.test.ts +++ b/api/src/paths/search.test.ts @@ -107,6 +107,7 @@ describe('search', () => { number_sites: 1, size_ha: 100, state_code: 1, + maskedLocation: false, geometry: '{"type":"Point","coordinates":[50.7,60.9]}' } ]; @@ -133,6 +134,7 @@ describe('search', () => { number_sites: searchList[0].number_sites, size_ha: searchList[0].size_ha, state_code: searchList[0].state_code, + maskedLocation: searchList[0].maskedLocation, geometry: [ { type: 'Point', diff --git a/api/src/paths/search.ts b/api/src/paths/search.ts index da9c8508..c0f86050 100644 --- a/api/src/paths/search.ts +++ b/api/src/paths/search.ts @@ -140,16 +140,35 @@ const _maskGateKeeper = (originalFeatureArray: string, originalGeoJSON: string) units: 'meters', properties: feature.properties }); - featureArray.coordinates[index] = mask.geometry.coordinates; + featureArray.coordinates[index] = mask.geometry.coordinates[0]; } }); } catch (error) { console.log('error', error); + throw error; } return featureArray; }; +/** + * Check if there are any masked locations in the geojson. + * @param geojsonString + * @returns {boolean} + */ +const _findMaskedLocations = (geojsonString: string) => { + let maskedLocations = false; + try { + const geojson = JSON.parse(geojsonString); + if (geojson && geojson.some((feature: any) => feature.properties.maskedLocation)) { + maskedLocations = true; + } + } catch (error) { + console.log('error', error); + throw error; + } + return maskedLocations; +}; /** * Extract an array of search result data from DB query. * @@ -167,6 +186,7 @@ export function _extractResults(rows: any[]): any[] { rows.forEach((row) => { // Protected shapes must have their geometry masked here const features = _maskGateKeeper(row.geometry, row.geojson); + const maskedLocations = _findMaskedLocations(row.geojson || '{[]}'); const result: any = { id: row.id, @@ -175,7 +195,8 @@ export function _extractResults(rows: any[]): any[] { state_code: row.state_code, number_sites: row.number_sites, size_ha: row.size_ha, - geometry: [features] + geometry: [features], + maskedLocation: maskedLocations }; searchResults.push(result); diff --git a/app/src/components/map/MapContainer.tsx b/app/src/components/map/MapContainer.tsx index 689d737c..0fd79536 100644 --- a/app/src/components/map/MapContainer.tsx +++ b/app/src/components/map/MapContainer.tsx @@ -416,7 +416,8 @@ const convertToCentroidGeoJSON = (features: any) => { is_project: f.is_project, state_code: f.state_code, number_sites: f.number_sites, - size_ha: f.size_ha + size_ha: f.size_ha, + maskedLocation: f.maskedLocation } }; }) @@ -1057,6 +1058,7 @@ const initializeMap = ( const numberSites = prop.number_sites; const sizeHa = prop.size_ha; const stateCode = prop.state_code; + const maskedLocation = prop.maskedLocation; let thumbnail = ''; try { @@ -1083,6 +1085,7 @@ const initializeMap = ( number_sites={numberSites} size_ha={sizeHa} state_code={stateCode} + maskedLocation={maskedLocation} thumbnail={thumbnail} maskDisclaimer={true} /> @@ -1110,6 +1113,7 @@ const initializeMap = ( const numberSites = prop.number_sites; const sizeHa = prop.size_ha; const stateCode = prop.state_code; + const maskedLocation = prop.maskedLocation; let thumbnail = ''; try { @@ -1133,6 +1137,7 @@ const initializeMap = ( state_code={stateCode} thumbnail={thumbnail} maskDisclaimer={true} + maskedLocation={maskedLocation} /> ); diff --git a/app/src/components/map/components/Popup.tsx b/app/src/components/map/components/Popup.tsx index 438d370d..9a3cb5e7 100644 --- a/app/src/components/map/components/Popup.tsx +++ b/app/src/components/map/components/Popup.tsx @@ -110,11 +110,6 @@ const MapPopup = (props: any) => { {maskedLocation && (