function drawTerrain(map, selectedPlotID = null) {
    // Unique to threshold page, no changes are made on the panel hero
    let threshold_Form = document.getElementById('threshold_form');
    if (threshold_Form != null)  {
        threshold_bool = true;
    }

    // Get fields from database
    fetch('../api/v1.0/polygons')
        .then(function (response) {
            // Error checking
            if (response.ok) {
                return response.json();
            } else {
                alert('Something went wrong fetching!');
            }
        })
        .then(function (plotJson) {
            // Create new bounds object
            let bounds = new google.maps.LatLngBounds();
            plotJson.forEach((plot) => {
                // Default polygon configuration
                let polygon = new google.maps.Polygon({
                    paths: JSON.parse(plot.plotPath),
                    strokeColor: '#fc852f',
                    strokeOpacity: 0.8,
                    strokeWeight: 2.25,
                    fillColor: '#fc852f',
                    fillOpacity: 0.3,
                    map: map
                });

                // Draw the selected polygon in blue
                if (selectedPlotID !== null) {
                    if (plot.id == selectedPlotID) {
                        polygon.strokeColor = '#2fbffc';
                        polygon.fillColor = '#2fbffc';
                    };
                }

                // Extend the bounds to fit, based on the given vertices
                polygon.getPath().getArray().forEach(function (vertex) {
                    bounds.extend(vertex);
                });

                polygon.addListener('click', function () {
                    // Open Threshold
                    if (threshold_Form) {
                        charge_thresholds_values(`${plot.id}`);
                    } 

                    else {
                        // Update helper text
                        let actionDescription = document.getElementById("actionText");
                        actionDescription.innerHTML = '<span class="lang" id="select_2">Seleccione una sonda o campo</span>';
                        centerPlot(`${plot.id}`);
                        // Resfresh translation
                        prepareTranslation();
                    }
                });
            });
        });
}
// It draws all fields (polygons) in orange, and the selected field in blue

It draws all fields (polygons) in orange, and the selected field in blue
It draws all fields ( polygons ) in orange and the selected field in blue
function drawTerrain(map, selectedPlotID = null) {
    let threshold_Form = document.getElementById('threshold_form');
    if (threshold_Form != null)  {
        threshold_bool = true;
    }
    fetch('../api/v1.0/polygons')
        .then(function (response) {
            if (response.ok) {
                return response.json();
            } else {
                alert('Something went wrong fetching!');
            }
        })
        .then(function (plotJson) {
            let bounds = new google.maps.LatLngBounds();
            plotJson.forEach((plot) => {
                let polygon = new google.maps.Polygon({
                    paths: JSON.parse(plot.plotPath),
                    strokeColor: '#fc852f',
                    strokeOpacity: 0.8,
                    strokeWeight: 2.25,
                    fillColor: '#fc852f',
                    fillOpacity: 0.3,
                    map: map
                });
                if (selectedPlotID !== null) {
                    if (plot.id == selectedPlotID) {
                        polygon.strokeColor = '#2fbffc';
                        polygon.fillColor = '#2fbffc';
                    };
                }
                polygon.getPath().getArray().forEach(function (vertex) {
                    bounds.extend(vertex);
                });
                polygon.addListener('click', function () {
                    if (threshold_Form) {
                        charge_thresholds_values(`${plot.id}`);
                    } 
                    else {
                        let actionDescription = document.getElementById("actionText");
                        actionDescription.innerHTML = '<span class="lang" id="select_2">Seleccione una sonda o campo</span>';
                        centerPlot(`${plot.id}`);
                        prepareTranslation();
                    }
                });
            });
        });
}
function drawTerrain ( map , selectedPlotID = null ) { let threshold_Form = document . getElementById ( 'threshold_form' ) ; if ( threshold_Form != null ) { threshold_bool = true ; } fetch ( '../api/v1.0/polygons' ) . then ( function ( response ) { if ( response . ok ) { return response . json ( ) ; } else { alert ( 'Something went wrong fetching!' ) ; } } ) . then ( function ( plotJson ) { let bounds = new google . maps . LatLngBounds ( ) ; plotJson . forEach ( ( plot ) => { let polygon = new google . maps . Polygon ( { paths : JSON . parse ( plot . plotPath ) , strokeColor : '#fc852f' , strokeOpacity : 0.8 , strokeWeight : 2.25 , fillColor : '#fc852f' , fillOpacity : 0.3 , map : map } ) ; if ( selectedPlotID !== null ) { if ( plot . id == selectedPlotID ) { polygon . strokeColor = '#2fbffc' ; polygon . fillColor = '#2fbffc' ; } ; } polygon . getPath ( ) . getArray ( ) . forEach ( function ( vertex ) { bounds . extend ( vertex ) ; } ) ; polygon . addListener ( 'click' , function ( ) { if ( threshold_Form ) { charge_thresholds_values ( ` ${ plot . id } ` ) ; } else { let actionDescription = document . getElementById ( "actionText" ) ; actionDescription . innerHTML = '<span class="lang" id="select_2">Seleccione una sonda o campo</span>' ; centerPlot ( ` ${ plot . id } ` ) ; prepareTranslation ( ) ; } } ) ; } ) ; } ) ; }
It draws all fields (polygons) in orange, and the selected field in blue
It draws all fields ( polygons ) in orange and the selected field in blue
// Unique to threshold page, no changes are made on the panel hero
 // Get fields from database
 // Error checking
 // Create new bounds object
 // Default polygon configuration
 // Draw the selected polygon in blue
 // Extend the bounds to fit, based on the given vertices
 // Open Threshold
 // Update helper text
 // Resfresh translation
