-1

I need to create a simple webpage where I can see the result of filters in arc online into it instead of creating the filter each day. By that, the results will be refreshed automatically each day when I log in into arc gis.

I heard that there is an API, is my idea is feasible ?

Ahmad Ali
  • 61
  • 5
  • 1
    It isn't clear what you mean by "filters" in ArcGIS Online (a definition query on a layer?), or "result" (subet of points? report of tabular data? something else?). Please clarify what your ultimate goal is. – Erica Jun 02 '17 at 12:02
  • 1
    A definition query on a layer – Ahmad Ali Jun 02 '17 at 17:29
  • Is it possible ? – Ahmad Ali Jun 02 '17 at 17:30
  • So you want an independent webpage that does a definition query and determines how many features are returned, correct? – Erica Jun 02 '17 at 18:31
  • 1
    I think this question would be more on-topic at the [gis.se] Stack Exchange where there are many Q&As on Arc**GIS** Online – PolyGeo Jun 03 '17 at 01:26
  • 1
    This is the correct place for the question since it is a development question. Non-dev GIS questions go in the GIS Stack Exchange. – Gary Sheppard Jun 05 '17 at 12:07

1 Answers1

1

Assuming you want to filter a FeatureLayer--the original question is unclear, but FeatureLayer seems logical--you should set the definitionExpression property, as described in the FeatureLayer documentation.

Here's an example:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
  <title>FeatureLayer - 4.3</title>

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

  <style>
    html,
    body,
    #viewDiv {
      padding: 0;
      margin: 0;
      height: 100%;
      width: 100%;
    }
    #filterDiv {
      position: absolute;
      top: 12px;
      right: 12px;
      padding: 12px;
      background-color: rgba(0, 0, 0, 0.5);
      color: white;
    }
  </style>

  <script>
    require([
        "esri/Map",
        "esri/views/MapView",
        "esri/layers/FeatureLayer",
        "dojo/dom",
        "dojo/on",
        "dojo/domReady!"
      ],
      function(
        Map,
        MapView,
        FeatureLayer,
        dom,
        on
      ) {

        var map = new Map({
          basemap: "hybrid"
        });

        var view = new MapView({
          container: "viewDiv",
          map: map,

          extent: {
            xmin: -9177811,
            ymin: 4247000,
            xmax: -9176791,
            ymax: 4247784,
            spatialReference: 102100
          }
        });

        var featureLayer = new FeatureLayer({
          url: "https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Landscape_Trees/FeatureServer/0",
          definitionExpression: "Sci_Name = 'Ulmus pumila'"
        });

        map.add(featureLayer);

        view.then(function() {
          on(dom.byId("filterInput"), "change", updateFilter);

          function updateFilter(ev) {
            featureLayer.definitionExpression = ev.target.checked ?
                "Sci_Name = 'Ulmus pumila'" :
                undefined;
          }
        });

      });
  </script>
</head>

<body>
  <div id="viewDiv"></div>
  <div id="filterDiv">
    <label>Filter
      <input id="filterInput" type="checkbox" checked="yes">
    </label>
  </div>
</body>

</html>
Gary Sheppard
  • 4,764
  • 3
  • 25
  • 35