DSContEd / IntroWebDevelopment

At the end of the course, students will be able to plan, design, and implement a web site using current standards and best practices.
1 stars 1 forks source link

Why is it called "filtered" geoJSON (variable filteredGEOJSON in Map Viewer) ? #18

Open TonyGoodDay2 opened 7 years ago

jjsahn commented 7 years ago

/Filtering Selection/ filteredGEOJSON = geoDataFile.features; if (primaryEntity != "PSNUPrioritization" && primaryEntity != "IsDreams") {

    var maxValueTextBox = d3.select('input[id="maxIndValue"]').property("value");
    var minValueTextBox = d3.select('input[id="minIndValue"]').property("value");

    if (minValueTextBox != 0) { //Added if Statment to keep all Countries
        filteredGEOJSON = filterGeoJSON(geoDataFile.features, primaryEntity, minValueTextBox, "ge");
    }

    if (maxValueTextBox != 0) {
        filteredGEOJSON = filterGeoJSON(filteredGEOJSON, primaryEntity, maxValueTextBox, "le");
    }

}
/*Now Filter Prioritization*/
var PSNUtoFilterOut = returnArrayUnchecked('PSNUCheckbox');
for (var i = 0; i < PSNUtoFilterOut.length; i++) {
    filteredGEOJSON = filterGeoJSON(filteredGEOJSON, 'PSNUPrioritization', PSNUtoFilterOut[i], "ne");
}
cmitchell74 commented 7 years ago

/Filtering Selection/ filteredGEOJSON = geoDataFile.features; if (primaryEntity != "PSNUPrioritization" && primaryEntity != "IsDreams") {

    var maxValueTextBox = d3.select('input[id="maxIndValue"]').property("value");
    var minValueTextBox = d3.select('input[id="minIndValue"]').property("value");

    if (minValueTextBox != 0) { //Added if Statment to keep all Countries
        filteredGEOJSON = filterGeoJSON(geoDataFile.features, primaryEntity, minValueTextBox, "ge");
    }

    if (maxValueTextBox != 0) {
        filteredGEOJSON = filterGeoJSON(filteredGEOJSON, primaryEntity, maxValueTextBox, "le");
    }

}
jjsahn commented 7 years ago

//Filter Data Function function filterGeoJSON(json, propertiesKey, value, operator) { / Operator "eq" equals "lt" less than "le" less than or equal "gt" greater than "ge" greather than or equal "ne" not equal /

var result = [];
var i = 0;

if (operator === "lt") {
    for (var filteredIndex in json) {
        if (json[filteredIndex].properties[

                propertiesKey] < value) {

            result[i] = json[filteredIndex];
            i++;
        }
    }

} else if (operator === "gt") {
    for (var filteredIndex in json) {
        if (json[filteredIndex].properties[

                propertiesKey] > value) {

            result[i] = json[filteredIndex];
            i++;
        }
    }

} else if (operator === "eq") {
    for (var filteredIndex in json) {
        if (json[filteredIndex].properties[

                propertiesKey] === value) {

            result[i] = json[filteredIndex];
            i++;
        }
    }

} else if (operator === "ne") {
    for (var filteredIndex in json) {
        if (json[filteredIndex].properties[
                propertiesKey] != value) {
            result[i] = json[filteredIndex];
            i++;
        }
    }

} else if (operator === "le") {
    for (var filteredIndex in json) {
        if (json[filteredIndex].properties[
                propertiesKey] <= value) {
            result[i] = json[filteredIndex];
            i++;
        }
    }

} else if (operator === "ge") {
    for (var filteredIndex in json) {
        if (json[filteredIndex].properties[
                propertiesKey] >= value) {
            result[i] = json[filteredIndex];
            i++;
        }
    }
}
return result;

}

TonyGoodDay2 commented 7 years ago

So the next logical question is ..what is the function "filterGEOJSON()"?

cmitchell74 commented 7 years ago

//Filter Data Function function filterGeoJSON(json, propertiesKey, value, operator) { / Operator "eq" equals "lt" less than "le" less than or equal "gt" greater than "ge" greather than or equal "ne" not equal /

var result = [];
var i = 0;

if (operator === "lt") {
    for (var filteredIndex in json) {
        if (json[filteredIndex].properties[

                propertiesKey] < value) {

            result[i] = json[filteredIndex];
            i++;
        }
    }

} else if (operator === "gt") {
    for (var filteredIndex in json) {
        if (json[filteredIndex].properties[

                propertiesKey] > value) {

            result[i] = json[filteredIndex];
            i++;
        }
    }

} else if (operator === "eq") {
    for (var filteredIndex in json) {
        if (json[filteredIndex].properties[

                propertiesKey] === value) {

            result[i] = json[filteredIndex];
            i++;
        }
    }

} else if (operator === "ne") {
    for (var filteredIndex in json) {
        if (json[filteredIndex].properties[
                propertiesKey] != value) {
            result[i] = json[filteredIndex];
            i++;
        }
    }

} else if (operator === "le") {
    for (var filteredIndex in json) {
        if (json[filteredIndex].properties[
                propertiesKey] <= value) {
            result[i] = json[filteredIndex];
            i++;
        }
    }

} else if (operator === "ge") {
    for (var filteredIndex in json) {
        if (json[filteredIndex].properties[
                propertiesKey] >= value) {
            result[i] = json[filteredIndex];
            i++;
        }
    }
}
return result;

}