Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
    <!--
     ArcGIS Maps SDK for JavaScript, https://js.arcgis.com
     For more information about the intro-graphics sample,
     read the original sample description at developers.arcgis.com.
     https://developers.arcgis.com/javascript/latest/sample-code/intro-graphics/
     -->
<title>Intro to graphics | Sample | ArcGIS Maps SDK for JavaScript 4.28</title>

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

    <style>
      html,
      body,
      #viewDiv {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
      }
    </style>

    <script>
        require(["esri/config", "esri/Map", "esri/views/MapView", "esri/layers/FeatureLayer", "esri/widgets/Popup", "esri/widgets/Legend", "esri/widgets/LayerList", "esri/rest/query", "esri/rest/support/Query"], function (esriConfig, Map, MapView, FeatureLayer, Popup, Legend, LayerList, query, Query) {

            // esriConfig.apiKey = "XXXXXXXXX";

            const colors = ["#d92b30", "#3cccb4", "#ffdf3c", "#c27c30", "#f260a1"];

            const commonProperties = {
                type: "simple-marker",
                width: "2px",
                style: "circle"
            };

            const gujarat = {
                ...commonProperties,
                color: colors[0]
            }
            
            const odisha = {
                ...commonProperties,
                color: colors[1]
            }

            const punjab = {
                ...commonProperties,
                color: colors[2]
            }

            const tamilnadu = {
                ...commonProperties,
                color: colors[3]
            }

            const other = {
                ...commonProperties,
                color: colors[4]
            }

            const ptrenderer = {
                type: "unique-value",
                legendOptions:{
                    title: "State Name"
            },
            defaultSymbol: other,
            defaultLabel: "Others",
            field: "state",

            uniqueValueInfos: [
            {
              value: "Gujarat", // code for Gujarat
              symbol: gujarat,
              label: "Gujarat"
            },
            {
              value: "Odisha", // code for Odisha
              symbol: odisha,
              label: "Odisha"
            },
            {
              value: "Punjab", // code for Punjab
              symbol: punjab,
              label: "Punjab"
            },
            {
              value: "Tamil Nadu", // code for Tamil Nadu
              symbol: tamilnadu,
              label: "Tamil Nadu"
            }
          ]

        }

            const params = new Query({
              returnGeometry: true,
              outFields: ["*"]
            });
            
            const map = new Map({
                basemap: "topo-vector"
            });

            const view = new MapView({
                map: map,
                center: [78.9629, 20.5937],
                zoom: 5,
                container: "viewDiv",
                popup: new Popup({
                    defaultPopupTemplateEnabled : true
                }),
            });

            const featureLayer = new FeatureLayer({
                url : "https://services6.arcgis.com/Cj6ppUYzylKGUnEi/arcgis/rest/services/India_Wetlands/FeatureServer",
                renderer: ptrenderer
            });

            view.ui.add("optionsDiv", "bottom-right");
            document.getElementById("doBtn").addEventListener("click", doQuery);
          
          let layerView
            view.whenLayerView(featureLayer).then((lv) =>{
              layerView = lv;
            });

            const attributeName = document.getElementById("attSelect");
            const expressionSign = document.getElementById("signSelect");
            const value = document.getElementById("valSelect");

            function doQuery() {
            // Clear the results from a previous query and close the popup if its open.
            //featureLayer.removeAll();
            if (view.popup.visible) {
            view.closePopup();
            }
            
            params.where = attributeName.value + expressionSign.value + "'" + value.value + "'";

             // executes the query and calls getResults() once the promise is resolved
             // promiseRejected() is called if the promise is rejected
             featureLayer.queryFeatures(params).then(getResults).catch(promiseRejected);
            }

            let highlight;
            function getResults(results){
              
              highlight?.remove();
              highlight = layerView.highlight(results.features);
            }

             // Called each time the promise is rejected
            function promiseRejected(error) {
            console.error("Promise rejected: ", error.message);
             }

            const layerlist = new LayerList({
              view : view
            });
            view.ui.add(layerlist, "top-right")

            view.ui.add(new Legend({ view }), "bottom-left");

            //const featureLayer = new FeatureLayer({
                //url : "https://services6.arcgis.com/Cj6ppUYzylKGUnEi/arcgis/rest/services/India_Wetlands/FeatureServer",
                //renderer: ptrenderer
            //});

            const statesLayer = new FeatureLayer({
                url: "https://livingatlas.esri.in/server1/rest/services/IAB/State/MapServer/0"
            })
            //});   
            map.add(statesLayer,0)
            map.add(featureLayer)
        });
    </script>
  </head>

  <body>
       <div id="viewDiv"></div>
    <div class="esri-widget" id="optionsDiv">
        <h2>Test.</h2>
        <select class="esri-widget" id="attSelect">
          <option value="State">State</option>
        </select>
        <select class="esri-widget" id="signSelect">
          <option value="=">is equal to</option>
        </select>
        <select class="esri-widget" id="valSelect">
          <option value="Gujarat">Gujarat</option>
          <option value="Tamil Nadu"> Tamil Nadu</option>
          <option value="Punjab">Punjab</option>
          <option value="Odisha">Odisha</option>
        </select>
        <br />
        <br />
        <button class="esri-widget" id="doBtn">Do Query</button> <br />
        <p><span id="printResults"></span></p>
      </div>
  </body>
</html>
              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console