Esri Arc Online使用API​​将过滤结果看到一个简单的网页

时间:2017-06-02 08:31:02

标签: api gis arcgis esri

我需要创建一个简单的网页,我可以在其中看到网上过滤器的结果,而不是每天创建过滤器。这样,当我登录arc gis时,结果将每天自动刷新。

我听说有一个API,我的想法是否可行?

1 个答案:

答案 0 :(得分:1)

假设您要过滤FeatureLayer - 原始问题不明确,但FeatureLayer似乎合乎逻辑 - 您应该设置definitionExpression属性,如{{3}中所述}。

以下是一个例子:

<!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>