Display attribute value from arcgis layer to html

2019-09-20 08:39发布

问题:

I want to display attribute value from arcgis layer to html input textbox using javascript

Can anyone help me on this issue?
Best Regards.

回答1:

Just click on a tree, it will fill the inputText on the top right corner

<link rel="stylesheet" type="text/css" href="https://js.arcgis.com/3.19/esri/css/esri.css">
<style>
  html, body, #mapDiv {
    height: 100%;
    padding: 0;
    margin: 0;
  }
  #inputAttribute {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 300px;
  }
</style>

<script>var dojoConfig = { parseOnLoad:true };</script>
<script src="https://js.arcgis.com/3.19compact/"></script>
<script>
  require(["esri/map", "esri/layers/FeatureLayer", "dojo/on", "dojo/dom", "dojo/domReady!"], function(Map, FeatureLayer, On, Dom) {
    var node = Dom.byId('inputAttribute');
    var map = new Map("mapDiv", {
      center: [-122.41, 37.78],
      zoom: 17,
      basemap: "topo"
    });
    var featureLayer = new FeatureLayer("https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Street_Trees/FeatureServer/0",{
      outFields: ["qSpecies"]
    });
    map.addLayer(featureLayer);
    On(featureLayer, 'click', function (e) {
      node.value = e.graphic.attributes.qSpecies;
    });
  });
</script>
<div id="mapDiv"></div>
<input type="text" name="attribut" id="inputAttribute">