FeatureLayer parameter outSR syntax

1029
2
Jump to solution
09-29-2020 09:20 AM
WillHughes
New Contributor III

See Esri sample below. I am trying to output the geometries in lat/long 4326. Can someone check the syntax?

Basic Querying in FeatureLayer | ArcGIS API for JavaScript 4.16 

See line 160. 

outSR: "{wkid:4326}",

The output spatial reference is not going into the request.

<html>
  <head>
    <meta charset="utf-8" />
    <meta
      name="viewport"
      content="initial-scale=1,maximum-scale=1,user-scalable=no"
    />
    <!--
  ArcGIS API for JavaScript, https://js.arcgis.com
  For more information about the featurelayer-query-basic sample, read the original sample description at developers.arcgis.com.
  https://developers.arcgis.com/javascript/latest/sample-code/featurelayer-query-basic/index.html
  -->
<title>
      Basic Querying in FeatureLayer | Sample | ArcGIS API for JavaScript 4.16
    </title>

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

    <style>
      html,
      body,
      #viewDiv {
        height: 100%;
        width: 100%;
        margin: 0;
        padding: 0;
      }
      #optionsDiv {
        background-color: white;
        color: black;
        padding: 6px;
        max-width: 400px;
      }
    </style>
    <script>
      require([
        "esri/Map",
        "esri/Graphic",
        "esri/views/MapView",
        "esri/layers/FeatureLayer",
        "esri/widgets/Legend"
      ], function (Map, Graphic, MapView, FeatureLayer, Legend) {
        // Crime in SF
        var layer = new FeatureLayer({
          // autocasts as new PortalItem()
          portalItem: {
            id: "234d2e3f6f554e0e84757662469c26d3"
          },
          outFields: ["*"]
        });

        var map = new Map({
          basemap: "gray-vector",
          layers: [layer]
        });

        var view = new MapView({
          container: "viewDiv",
          map: map,
          popup: {
            autoOpenEnabled: false,
            dockEnabled: true,
            dockOptions: {
              // dock popup at bottom-right side of view
              buttonEnabled: false,
              breakpoint: false,
              position: "bottom-right"
            }
          }
        });

        var legend = new Legend({
          view: view,
          layerInfos: [
            {
              layer: layer
            }
          ]
        });

        view.ui.add(legend, "bottom-left");
        view.ui.add("optionsDiv", "top-right");

        // additional query fields initially set to null for basic query
        var distance = null;
        var units = null;
        var sr = null;

        //create graphic for mouse point click
        var pointGraphic = new Graphic({
          symbol: {
            type: "simple-marker", // autocasts as new SimpleMarkerSymbol()
            color: [0, 0, 139],
            outline: {
              color: [255, 255, 255],
              width: 1.5
            }
          }
        });

        // Create graphic for distance buffer
        var bufferGraphic = new Graphic({
          symbol: {
            type: "simple-fill", // autocasts as new SimpleFillSymbol()
            color: [173, 216, 230, 0.2],
            outline: {
              // autocasts as new SimpleLineSymbol()
              color: [255, 255, 255],
              width: 1
            }
          }
        });

        // when query type changes, set appropriate values
        var queryOpts = document.getElementById("query-type");

        queryOpts.addEventListener("change", function () {
          switch (queryOpts.value) {
            // values set for distance query
            case "distance":
              distance = 0.5;
              units = "miles";
              break;
            default:
              // Default set to basic query
              distance = null;
              units = null;
              
          }
        });
        layer.load().then(function () {
          // Set the view extent to the data extent
          view.extent = layer.fullExtent;
          layer.popupTemplate = layer.createPopupTemplate();
        });

        view.on("click", function (event) {
          view.graphics.remove(pointGraphic);
          if (view.graphics.includes(bufferGraphic)) {
            view.graphics.remove(bufferGraphic);
          }
          queryFeatures(event);
        });

        function queryFeatures(screenPoint) {
          const point = view.toMap(screenPoint);
          layer
            .queryFeatures({
              geometry: point,
              // distance and units will be null if basic query selected
              distance: distance,
              units: units,
              spatialRelationship: "intersects",
              returnGeometry: true,
              returnQueryGeometry: true,
              outSR: "{wkid:4326}",
              outFields: ["*"]
            })
            .then(function (featureSet) {
              // set graphic location to mouse pointer and add to mapview
              pointGraphic.geometry = point;
              view.graphics.add(pointGraphic);
              // open popup of query result
              view.popup.open({
                location: point,
                features: featureSet.features,
                featureMenuOpen: true
              });
              if (featureSet.queryGeometry) {
                bufferGraphic.geometry = featureSet.queryGeometry;
                view.graphics.add(bufferGraphic);
              }
            });
        }
      });
    </script>
  </head>
  <body>
    <div id="viewDiv"></div>
    <div id="optionsDiv" class="esri-widget">
      <p>
        Select a query type and click a point on the map to view the results.
      </p>
      <select id="query-type" class="esri-widget">
        <option value="basic">Basic Query</option>
        <option value="distance">Query By Distance</option>
      </select>
    </div>
  </body>
</html>
Tags (3)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Will,

  There is no such property as "outSR" on the query class. You need to use the outSpatialReference property.

View solution in original post

2 Replies
RobertScheitlin__GISP
MVP Emeritus

Will,

  There is no such property as "outSR" on the query class. You need to use the outSpatialReference property.

WillHughes
New Contributor III

outSpatialReference: "4326",        This syntax worked. Thanks!

0 Kudos