Skip to content

Commit

Permalink
filter clusters by country
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiaifrim committed Sep 21, 2020
1 parent 99637ce commit 8c8bdfd
Showing 1 changed file with 32 additions and 12 deletions.
44 changes: 32 additions & 12 deletions src/components/manage/Blocks/DiscodataOpenlayersMapBlock/View.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ const OpenlayersMapView = (props) => {
const [loader, setLoader] = useState(false);
const [mapRendered, setMapRendered] = useState(false);
const [firstFilteringUpdate, setFirstFilteringUpdate] = useState(false);
const regionsSourceWhere = useRef('');
const firstFilteringDone = useRef(false);
const ToggleSidebarControl = useRef(null);
const ViewYourAreaControl = useRef(null);
Expand Down Expand Up @@ -270,6 +271,14 @@ const OpenlayersMapView = (props) => {
useEffect(() => {
if (mapRendered) {
updateFilters();
const baseSql = `(CNTR_CODE LIKE '%:options%')`;
const countries = props.discodata_query.search.siteCountry || [];
regionsSourceWhere.current =
countries.length > 0
? `(${countries
.map((country) => baseSql.replace('options', country))
.join(' OR ')})`
: '';
}
/* eslint-disable-next-line */
}, [
Expand Down Expand Up @@ -313,7 +322,7 @@ const OpenlayersMapView = (props) => {
sql: `(eea_activities LIKE '%:options%')`,
type: 'multiple',
},
// Country / Region / Town
// Country / Region / Provinces
nuts_latest: {
sql: `(nuts_regions LIKE '%:options%')`,
type: 'multiple',
Expand Down Expand Up @@ -824,18 +833,29 @@ const OpenlayersMapView = (props) => {
extent[3] +
',"spatialReference":{"wkid":102100}}',
)}&geometryType=esriGeometryEnvelope&inSR=102100&outFields=*&outSR=102100`;
jsonp(url, null, (error, response) => {
if (error) {
console.log(error.message);
} else {
var features = esrijsonFormat.readFeatures(response, {
featureProjection: projection,
});
if (features.length > 0) {
regionsSource.addFeatures(features);
jsonp(
url,
{
param:
(regionsSourceWhere.current
? qs.stringify({
where: regionsSourceWhere.current,
})
: '') + '&callback',
},
(error, response) => {
if (error) {
console.log(error.message);
} else {
var features = esrijsonFormat.readFeatures(response, {
featureProjection: projection,
});
if (features.length > 0) {
regionsSource.addFeatures(features);
}
}
}
});
},
);
},
strategy: tile(
createXYZ({
Expand Down

0 comments on commit 8c8bdfd

Please sign in to comment.