-
-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6316 from hotosm/feature/6303-restrict-live-monit…
…oring-on-expert-mode Feature/6303 restrict live monitoring on expert mode
- Loading branch information
Showing
4 changed files
with
139 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { MAPBOX_TOKEN, UNDERPASS_URL } from '.'; | ||
|
||
export const underpassConfig = { | ||
API_URL: UNDERPASS_URL, | ||
MAPBOX_TOKEN, | ||
// set default sources of Tasking Manager | ||
sources: { | ||
osm: { | ||
type: 'raster', | ||
tiles: ['https://a.tile.openstreetmap.org/{z}/{x}/{y}.png'], | ||
tileSize: 256, | ||
attribution: '© OpenStreetMap Contributors', | ||
maxzoom: 19, | ||
}, | ||
Bing: { | ||
type: 'raster', | ||
tiles: ['https://ecn.t3.tiles.virtualearth.net/tiles/a{quadkey}.jpeg?g=1'], | ||
tileSize: 256, | ||
attribution: '© OpenStreetMap Contributors', | ||
maxzoom: 18, | ||
}, | ||
Mapbox: { | ||
type: 'raster', | ||
tiles: [ | ||
`https://api.mapbox.com/styles/v1/mapbox/satellite-v9/tiles/{z}/{x}/{y}?access_token=${MAPBOX_TOKEN}`, | ||
], | ||
tileSize: 512, | ||
attribution: '© OpenStreetMap Contributors © Mapbox', | ||
maxzoom: 19, | ||
}, | ||
EsriWorldImagery: { | ||
type: 'raster', | ||
tiles: [ | ||
'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}', | ||
], | ||
tileSize: 256, | ||
attribution: '© OpenStreetMap Contributors © ESRI', | ||
maxzoom: 18, | ||
}, | ||
}, | ||
}; | ||
|
||
export const availableImageryOptions = [ | ||
{ label: 'OSM', value: 'osm' }, | ||
{ label: 'Bing', value: 'Bing' }, | ||
{ label: 'Mapbox Satellite', value: 'Mapbox' }, | ||
{ label: 'ESRI World Imagery', value: 'EsriWorldImagery' }, | ||
]; | ||
|
||
export const statusList = { | ||
ALL: '', | ||
UNSQUARED: 'badgeom', | ||
OVERLAPPING: 'overlapping', | ||
BADVALUE: 'badvalue', | ||
}; | ||
|
||
export const mappingTypesTags = { | ||
ROADS: 'highway', | ||
BUILDINGS: 'building', | ||
WATERWAYS: 'waterway', | ||
}; | ||
|
||
export const mappingTypesFeatureTypes = { | ||
ROADS: 'line', | ||
BUILDINGS: 'polygon', | ||
WATERWAYS: 'line', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { useState, useEffect } from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import { useParams } from 'react-router-dom'; | ||
|
||
import { useProjectQuery } from '../api/projects'; | ||
import { useAvailableCountriesQuery } from '../api/projects'; | ||
|
||
/** | ||
* A React custom hook that checks if a project can view live monitoring feature | ||
* | ||
* Returns null if the status is unknown, else returns boolean | ||
* | ||
*/ | ||
export default function useHasLiveMonitoringFeature() { | ||
const { id: projectId } = useParams(); | ||
const userDetails = useSelector((state) => state.auth.userDetails); | ||
const [hasLiveMonitoringFeature, setHasLiveMonitoringFeature] = useState(null); | ||
|
||
const { data: project } = useProjectQuery(projectId); | ||
const { data: availableCountries } = useAvailableCountriesQuery(); | ||
|
||
useEffect(() => { | ||
if (!availableCountries || !project || !userDetails) return; | ||
|
||
// set hasLiveMonitoringFeature to false if project is not published | ||
// or expert mode is not enabled | ||
if (project.data.status !== 'PUBLISHED' || !userDetails.isExpert) { | ||
setHasLiveMonitoringFeature(false); | ||
return; | ||
} | ||
|
||
// check if the project has live monitoring feature enabled | ||
// based on the country list provided by available.json | ||
const isLiveMonitoringAvailableInCountry = project.data.countryTag.some((country) => | ||
availableCountries.countries.some((item) => country.toLowerCase() === item.toLowerCase()), | ||
); | ||
|
||
setHasLiveMonitoringFeature(isLiveMonitoringAvailableInCountry); | ||
}, [availableCountries, project, userDetails]); | ||
|
||
return hasLiveMonitoringFeature; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters