Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!DOCTYPE html>
<html>

<head>
    <link rel="icon" href="https://webapp.willcountyillinois.com/gisweb/images/WillCountyGreen_CustomLogo_small.png">
    <meta charset="utf-8" />
    <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
    <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
    <title>Green Guide</title>

    <link rel="stylesheet" href="https://js.arcgis.com/4.15/esri/themes/light/main.css" />
    <script src="https://js.arcgis.com/4.16/"></script>
    <link rel="stylesheet" href="green.css">
    <script src="config.js"></script>

</head>


<body>
    <div id="viewDiv">

        <div id="sidebar" class="esri-widget">
            <div id="text">
                <h1>Green Guide</h1>
            </div>
        </div>
    </div>
    <div id="filterDiv">
        <div class="drop-downs">
            <div class="oneline">Search by Item:</div>
            <select id="keyword" class="oneline"></select>
            <div class="oneline">Search by Category:</div>
            <select id="category" class="oneline"></select>
            <div>
                <input id="ResidentialRB" name="resorbus" type="radio" value="Residential" checked="checked"><label for="ResidentialRB">Residential</label>
                <input id="BusinessRB" name="resorbus" type="radio" value="Business"><label for="BusinessRB">Business</label>
            </div>
            <button id="filterBtn">Search</button>
        </div>
    </div>
    <div>Updating...</div>
    <div id="searchParentDiv">
    </div>
    <div id="loadingDiv" class="loading">Updating...</div>
</body>

</html>
              
            
!

CSS

              
                html,
body,
#viewDiv {
    height: 100%;
    width: 100%;
    margin: 0;
}

.visible {
    display: block !important;
}

.loading {
    position: absolute;
    top: 100px;
    left: 100px;
    background-color: black;
    color: white;
    display: none;
    padding: 8px;
}

.esri-view-width-less-than-xlarge .esri-zoom .esri-widget--button {
    display: none;
}

#viewDiv {
    position: absolute;
    height: calc(100% - 67px);
    top: 67px;
}

#filterDiv {
    font: 16px Nunito;
    position: relative;
    background-color: white;
    color: black;
    padding: 6px;
    top: 0;
    background: #d4e1c0;
    border-bottom: 0px dotted #91dca1;
    bottom: 0;
    width: unset;
}

#category,
#keyword {
    font: 12px Nunito;
    margin-top: 8px;
    margin-bottom: 8px;
    display: inline-block;
}

.drop-downs {
    width: 100%;
}

.oneline {
    display: inline-block;
    margin-right: 6px;
}

#filterBtn {
    position: relative;
    float: right;
    bottom: 20px;
    width: 50px;
    font: bold 12px Nunito;
    color: #fff;
    background-color: rgb(9, 134, 65);
    border: 1px solid #1c9c52;
    text-decoration: none;
    cursor: pointer;
    padding: 2px 4px;
}

    #filterBtn:hover {
        background-color: rgb(45, 147, 239);
        border: 1px solid #0ab0ed;
    }

.docking-control {
    position: absolute;
    z-index: 10;
    top: 50%;
    left: 50%;
    width: 250px;
    height: 80px;
    padding: 10px;
    box-sizing: border-box;
    margin: -40px 0 0 -125px;
    background-color: #232324;
    color: #323232;
    text-align: center;
    -webkit-box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

    .docking-control label {
        display: inline-block;
        font-weight: bold;
        margin: 0 0 10px 0;
        padding: 0;
        font-size: 16px;
    }

.esri-feature h1 {
    font-size: 29px;
}

#sidebar {
    z-index: 99;
    position: absolute;
    top: 0;
    right: 0;
    height: 100%;
    background: rgba(228, 246, 232, 0.8);
    text-align: center;
    width: 380px;
    font: Nunito;
    font-size: 14px;
    padding: 6px;
    font-size: initial;
    background-image: url('https://webapp.willcountyillinois.com/gisweb/images/WillCountyGreen_CustomLogo_large.png');
    background-repeat: no-repeat;
    background-position: bottom;
}

.esri-feature h1 {
    font-size: 29px;
    color: rgb(8, 126, 63)
}

.esri-widget {
    color: #323232;
    font-size: 14px;
    font-family: Nunito;
    line-height: 1.3em;
}

#text {
    color: white;
    padding: 3%;
}

.esri-search {
    border: none;
    margin-top: 15px;
    float: left;
}



/*this section is for i-pads*/
@media (max-width: 960px) {

    #viewDiv {
        height: 100%;
        width: 100%;
        margin: 0;
    }

    .visible {
        display: block !important;
    }

    .loading {
        position: absolute;
        top: 100px;
        left: 100px;
        background-color: black;
        color: white;
        display: none;
        padding: 8px;
    }

    .esri-ui { /*set screen width here*/
        width: 76%;
    }

    #filterDiv {
        height: auto;
        font: 15px Nunito
    }

    #filterBtn {
        position: relative;
        float: right;
        bottom: 20px;
        width: 50px;
        font: bold 12px Nunito;
        color: #fff;
        background-color: rgb(9, 134, 65);
        border: 1px solid #1c9c52;
        text-decoration: none;
        cursor: pointer;
        padding: 2px 4px;
    }

    .esri-search {
        border: none;
        left: 1px;
        float: left !important;
        margin-top: 70px !important;
        width: 200px;
    }

    #sidebar {
        z-index: 99;
        position: absolute;
        top: 70px;
        right: 0;
        height: 90%;
        background: rgba(228, 246, 232, 0.8);
        text-align: center;
        width: 180px;
        font: Nunito;
        padding: 6px;
        font-size: initial;
        background-image: url('https://webapp.willcountyillinois.com/gisweb/images/WillCountyGreen_CustomLogo_medium.png');
        background-repeat: no-repeat;
        background-position: bottom;
    }

    .esri-feature h1 {
        font-size: 19px;
        color: rgb(8, 126, 63)
    }

    .esri-widget {
        color: #323232;
        font-size: 14px;
        font-family: Nunito;
        line-height: 1.3em;
    }

    #text {
        color: white;
        padding: 3%;
    }
}

/*this section is for mobile devices*/
@media (max-width: 460px) {

    #viewDiv {
        height: 100%;
        width: 100%;
        margin: 0;
    }

    .visible {
        display: block !important;
    }

    .loading {
        position: absolute;
        top: 100px;
        left: 100px;
        background-color: black;
        color: white;
        display: none;
        padding: 8px;
    }

    .esri-ui { /*set screen width here*/
        width: 60%;
    }

    #filterDiv {
        height: auto;
        font: 14px Nunito
    }

    #filterBtn {
        position: relative;
        float: right;
        bottom: 20px;
        width: 50px;
        font: bold 12px Nunito;
        color: #fff;
        background-color: rgb(9, 134, 65);
        border: 1px solid #1c9c52;
        text-decoration: none;
        cursor: pointer;
        padding: 2px 4px;
    }

    .esri-search {
        border: none;
        left: 1px;
        float: left !important;
        margin-top: 70px !important;
        width: 200px;
    }

    #sidebar {
        z-index: 99;
        padding: 4px;
        height: 84%;
        top: 100px;
        background: rgba(228, 246, 232, 0.8);
        text-align: center;
        font: bold 12px Nunito;
        width: 157px;
        background-image: url('https://webapp.willcountyillinois.com/gisweb/images/WillCountyGreen_CustomLogo_medium.png');
        background-repeat: no-repeat;
        background-position: bottom;
    }

    .esri-feature h1 {
        font-size: 15px;
        color: rgb(8, 126, 63)
    }

    .esri-widget {
        color: #323232;
        font-size: 14px;
        font-family: Nunito;
        line-height: 1.3em;
    }

    #text {
        color: white;
        padding: 3%;
    }
}

              
            
!

JS

              
                // JavaScript source code
require([
    "esri/Map",
    "esri/views/MapView",
    "esri/layers/FeatureLayer",
    "esri/layers/GraphicsLayer",
    "esri/widgets/Search",
    "esri/widgets/Home",
    "esri/widgets/Feature",
    "dojo/dom-class",
    "dojo/domReady!"

], function (Map, MapView, FeatureLayer, GraphicsLayer, Search, Home, Feature, domClass) {
    var catTypeSelect = document.getElementById("category");
    var keyTypeSelect = document.getElementById("keyword");
    var filterButton = document.getElementById("filterBtn");
    var resRb = document.getElementById("ResidentialRB");
    var busRb = document.getElementById("BusinessRB");

    //***popups***
    //popup template for table
    var template = {
        //autocasts the new template
        title: "<font size='2.75px'><b>{USER_Name}</b>",
        content: [
            {
                //set content elements in the order to display
                type: "fields",
                fieldInfos: [
                    {
                        fieldName: "USER_Addre",
                        label: "Address",
                        visible: true
                    },
                    {
                        fieldName: "USER_City",
                        label: "City",
                        visible: true
                    },
                    {
                        fieldName: "USER_Zip",
                        label: "Zip Code",
                        visible: true
                    },
                    {
                        fieldName: "USER_Phone",
                        label: " Phone",
                        visible: true
                    },
                    {
                        fieldName: "USER_Link",
                        label: "Website",
                        visible: true
                    },
                    {
                        fieldName: "USER_Notes",
                        label: "Extra Notes",
                        visible: true
                    }
                ]
            }
        ]
    };

    //popup template for description
    var template2 = {
        //autocasts the new template
        content: [
            {
                //set a descriptive text element
                type: "text", // TextContentElement
                text: "<font color='#323232'><b>{Description}</b>"
            },
        ]
    };

    // Recycle Layer
    var recycleLayer = new FeatureLayer({
        portalItem: {
            // autocasts as new PortalItem()
            id: "b5665da3feab4b6091914cbfe4ab028f"
        },
        popupTemplate: template,
        outFields: ["*"],
        visible: false
    });

    // GraphicsLayer for displaying results
    var resultsLayer = new GraphicsLayer();
    //Set map view
    var map = new Map({
        basemap: "gray-vector",
        layers: [recycleLayer, resultsLayer]
    });

    var view = new MapView({
        container: "viewDiv",
        map: map,
        center: [-88.2, 41.8],
        zoom: 8.7,
        padding: {
            right: 380
        },

        //popup
        popup: {}
    });

    //PopupTemplates
    view.when().then(function () {
        // Create a default graphic for when the application starts
        const graphic = {
            popupTemplate: {
                content: "To change search from Item to Category, make sure Search by Item dropdown is set to 'Select One'. <br> <br>Businesses should note that they will find more appropriate listings if they check Business under the search box."
            }
        };

        // Provide a graphic to a new instance of a Feature widget
        const feature = new Feature({
            container: "sidebar",
            graphic: graphic,
            map: view.map,
            spatialReference: view.spatialReference
        });

        view.whenLayerView(recycleLayer).then(function (layerView) {
            let highlight;
            // listen for the pointer-move event on the View
            view.on("click", function (event) {
                // Perform a hitTest on the View
                view.hitTest(event).then(function (event) {
                    // Make sure graphic has a popupTemplate
                    let results = event.results.filter(function (result) {
                        return result.graphic.layer.popupTemplate;
                    });
                    let result = results[0];
                    highlight && highlight.remove();
                    
                    // Update the graphic of the Feature widget
                    // on pointer-move with the result
                    if (result) {
                        feature.graphic = result.graphic.clone(); //clone it to avoid mutation
                        feature.graphic.popupTemplate = template2; // template2 for feature widget
                        highlight = layerView.highlight(result.graphic);
                    } else {
                        feature.graphic = graphic;
                    }
                });
            });
        });
    });


    //home widget
    var homeBtn = new Home({
        view: view
    });
    view.ui.add(homeBtn, "bottom-left");

    //search widget
    const searchWidget = new Search({
        view: view
    });
    //Adds the search widget below other elements in
    //the top left corner of the view
    view.ui.add(searchWidget, {
        position: "bottom-left",
        index: 2
    });

    // query all features from the recycle layer
    view
        .when(function () {
            return recycleLayer.when(function () {
                var query = recycleLayer.createQuery();
                return recycleLayer.queryFeatures(query);
            });
        })
        .then(getValues)
        .then(getUniqueValues)
        .then(addToSelect);


    // query the layer based on the selected Category
    catTypeSelect.addEventListener("change", function () {
        var sqlExp = "";
        if (catTypeSelect.selectedIndex > 0) {
            sqlExp +=
                "Category LIKE '%" +
                catTypeSelect.options[catTypeSelect.selectedIndex].value +
                "%'";
        }
        var query = recycleLayer.createQuery();
        query.where = sqlExp;
        recycleLayer.queryFeatures(query)
            .then(getValues2)
            .then(getUniqueValues2)
            .then(addToSelect2);

        setDefinitionExpression();
    });

    keyTypeSelect.addEventListener("change", setDefinitionExpression);

    // return an array of all the values in the
    // Category and item_keyword fields of the Recycle layer
    function getValues(response) {
        var features = response.features;
        var values = features.map(function (feature) {
            return {
                Category: feature.attributes.Category,
                item_keyword: feature.attributes.item_keyword
            };
        });
        return values;
    }

    function getValues2(response) {
        var features = response.features;
        var values = features.map(function (feature) {
            return feature.attributes.item_keyword;
        });
        return values;
    }

    // return an array of unique values in
    // the item_keyword and Category fields of the Recycle layer
    function getUniqueValues(values) {
        var uniqueKeyValues = [];
        var uniqueCatValues = [];

        values.forEach(function (item, i) {
            var keyVal = item.item_keyword.split(";");
            var catVal = item.Category.split(";");
            catVal.map(function (val1) {
                if (
                    (uniqueCatValues.length < 1 ||
                        uniqueCatValues.indexOf(val1) === -1) &&
                    val1 !== ""
                ) {
                    uniqueCatValues.push(val1);
                }
            });
            keyVal.map(function (val2) {
                if (
                    (uniqueKeyValues.length < 1 ||
                        uniqueKeyValues.indexOf(val2) === -1) &&
                    val2 !== ""
                ) {
                    uniqueKeyValues.push(val2);
                }
            });
        });
        return {
            uKeyVals: uniqueKeyValues,
            uCatVals: uniqueCatValues
        };
    }

    function getUniqueValues2(values) {
        var uniqueKeyValues = [];

        values.forEach(function (item, i) {
            var keyVal = item.split(";");
            keyVal.map(function (val2) {
                if (
                    (uniqueKeyValues.length < 1 ||
                        uniqueKeyValues.indexOf(val2) === -1) &&
                    val2 !== ""
                ) {
                    uniqueKeyValues.push(val2);
                }
            });
        });
        return uniqueKeyValues;
    }

    // Add the unique values to the recycle type
    // select element. This will allow the user
    // to filter categories by type.
    function addToSelect(values) {
        var dOpt = document.createElement("option");
        dOpt.value = "";
        dOpt.selected = true;
        dOpt.text = "Select one";
        catTypeSelect.add(dOpt);
        values.uCatVals.sort();
        values.uCatVals.forEach(function (value) {
            var option = document.createElement("option");
            option.text = value;
            catTypeSelect.add(option);
        });

        var dOpt2 = document.createElement("option");
        dOpt2.value = "";
        dOpt2.disabled = true;
        dOpt2.selected = true;
        dOpt2.text = "Select one";
        keyTypeSelect.add(dOpt2);
        values.uKeyVals.sort();
        values.uKeyVals.forEach(function (value) {
            var option = document.createElement("option");
            option.text = value;
            keyTypeSelect.add(option);
        });

        return setDefinitionExpression();
    }
    // re-query the layer based on the selected Category and re-populate the keyword select
    function addToSelect2(values) {
        while (keyTypeSelect.options.length > 0) {
            keyTypeSelect.remove(0)
        }
        var dOpt2 = document.createElement("option");
        dOpt2.value = "";
        dOpt2.disabled = true;
        dOpt2.selected = true;
        dOpt2.text = "Select one";
        keyTypeSelect.add(dOpt2);
        values.sort();
        values.forEach(function (value)
        {
            var option = document.createElement("option");
            option.text = value;
            keyTypeSelect.add(option);
        });
        
        return true;
    }

    // set the definition expression on the recycle
    // layer to reflect the selection of the user
        function setDefinitionExpression() {
        domClass.add('loadingDiv', 'visible'); //add loadingDiv
        var sqlExp = "";
        if (catTypeSelect.selectedIndex > 0) {
            sqlExp +=
                "Category LIKE '%" +
                catTypeSelect.options[catTypeSelect.selectedIndex].value +
                "%'";
        }
        if (keyTypeSelect.selectedIndex > 0) {
            if (sqlExp === "") {
                sqlExp +=
                    "item_keyword LIKE '%" +
                    keyTypeSelect.options[keyTypeSelect.selectedIndex].value +
                    "%'";
            } else {
                sqlExp +=
                    " AND item_keyword LIKE '%" +
                    keyTypeSelect.options[keyTypeSelect.selectedIndex].value +
                    "%'";
            }
        }
        if (resRb.checked) {
            if (sqlExp !== "") {
                sqlExp += " AND USER_IsRes = 'TRUE'";
            }
        } else {
            if (sqlExp !== "") {
                sqlExp += " AND USER_IsBus = 'TRUE'";
            }
        }
        console.info(sqlExp);
        recycleLayer.definitionExpression = sqlExp;

        if (!recycleLayer.visible) {
            recycleLayer.visible = true;
        }
        
        return queryForGeometries();
    }

    // Get all the geometries of the recycle layer
    // the createQuery() method creates a query
    // object that respects the definitionExpression
    // of the layer
    function queryForGeometries() {
        console.log("Running query");
        var rQuery = recycleLayer.createQuery();

        return recycleLayer.queryFeatures(rQuery).then(function (response) {
            rGeometries = response.features.map(function (feature) {
                return feature.geometry;
            });
            domClass.remove('loadingDiv', 'visible'); //remove loadingDiv
            return rGeometries;
        });
    }

    filterButton.addEventListener("click", function () {
        setDefinitionExpression();
    });
});

              
            
!
999px

Console