Set region status by a value of a custom ACF field
If your posts have a custom field created using the ACF plugin, and you want to use that field to set region statuses in MapSVG, add the following code to MapSVG > Menu > JavaScript > Map > afterLoadRegions (replace the existing code):
For example, if you have an ACF field named statusFieldName that needs to correspond to the MapSVG status field, modify statusFieldName
to match your field name and adjust the values in the acfToMapsvgStatuses
object to align with your data.
function (event){
const { map } = event
const acfToMapsvgStatuses = {
// first number is the ACF field value, second number is MapSVG status
"1": 1,
"2": 2,
"3": 3
};
map.regionsRepository.getLoaded().forEach( function(region){
if(region.post && region.post.acf){
var status = acfToMapsvgStatuses[region.post.acf.statusFieldName];
if(typeof status !== "undefined"){
const region = map.getRegion(region.id)
if(region){
region.setStatus(status)
}
}
}
});
}