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 > JS > afterLoad (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 (){
var mapsvg = this;
var acfToMapsvgStatuses = {
// first number is the ACF field value, second number is MapSVG status
"1": 1,
"2": 2,
"3": 3
};
mapsvg.regionsRepository.events.on("loaded", function() {
mapsvg.regionsRepository.getLoaded().forEach( function(region){
if(region.post && region.post.acf){
var status = acfToMapsvgStatuses[region.post.acf.statusFieldName];
if(typeof status !== "undefined"){
mapsvg.getRegion(region.id).setStatus(status)
}
}
});
});
}