<!-- flowchart 箭头图标 勿删 -->
<svg style="display: none;">
<path d="M5,0 0,2.5 5,5z" id="raphael-marker-block" stroke-linecap="round" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"></path>
</svg>
<h2 id="arcgis-api-for-javascript获取featurelayer的属性值">ArcGIS API for JavaScript——获取FeatureLayer的属性值</h2>
<p>当我们将一个图层发布为服务后,在JS代码中想取到图层里面的数据该怎么做呢?在下面的例子中将演示当鼠标点击图层点时弹出图层属性的过程。 <br>
一、测试数据 <br>
<img alt="这里写图片描述" src="https://201907.oss-cn-shanghai.aliyuncs.com/cs/5606289-a8410cc5536a645fa9d2f3349b8e350f" title=""> <br>
二、发布服务 <br>
<img alt="这里写图片描述" src="https://201907.oss-cn-shanghai.aliyuncs.com/cs/5606289-09841a9aa429b9041274a645adbf659e" title=""> <br>
三、引用服务 <br>
引用服务的代码如下:</p>
<pre class="blockcode"><code class="hljs xml"><span class="hljs-doctype"><!DOCTYPE html></span>
<span class="hljs-tag"><<span class="hljs-title">html</span>></span>
<span class="hljs-tag"><<span class="hljs-title">head</span>></span>
<span class="hljs-tag"><<span class="hljs-title">meta</span> <span class="hljs-attribute">http-equiv</span>=<span class="hljs-value">"Content-Type"</span> <span class="hljs-attribute">content</span>=<span class="hljs-value">"text/html; charset=utf-8"</span>></span>
<span class="hljs-tag"><<span class="hljs-title">meta</span> <span class="hljs-attribute">name</span>=<span class="hljs-value">"viewport"</span> <span class="hljs-attribute">content</span>=<span class="hljs-value">"initial-scale=1, maximum-scale=1,user-scalable=no"</span>></span>
<span class="hljs-tag"><<span class="hljs-title">title</span>></span>Create Map and add a dynamic layer<span class="hljs-tag"></<span class="hljs-title">title</span>></span>
<span class="hljs-comment"><!--使用的是本机离线API--></span>
<span class="hljs-tag"><<span class="hljs-title">link</span> <span class="hljs-attribute">rel</span>=<span class="hljs-value">"stylesheet"</span> <span class="hljs-attribute">type</span>=<span class="hljs-value">"text/css"</span> <span class="hljs-attribute">href</span>=<span class="hljs-value">"http://localhost/arcgis_js_api/library/3.18/3.18/dijit/themes/claro/claro.css"</span>/></span>
<span class="hljs-tag"><<span class="hljs-title">link</span> <span class="hljs-attribute">rel</span>=<span class="hljs-value">"stylesheet"</span> <span class="hljs-attribute">type</span>=<span class="hljs-value">"text/css"</span> <span class="hljs-attribute">href</span>=<span class="hljs-value">"http://localhost/arcgis_js_api/library/3.18/3.18/esri/css/esri.css"</span> /></span>
<span class="hljs-tag"><<span class="hljs-title">script</span> <span class="hljs-attribute">src</span>=<span class="hljs-value">"http://localhost/arcgis_js_api/library/3.18/3.18/init.js"</span> <span class="hljs-attribute">djConfig</span>=<span class="hljs-value">"parseOnLoad:true"</span>></span><span class="javascript"></span><span class="hljs-tag"></<span class="hljs-title">script</span>></span>
<span class="hljs-tag"><<span class="hljs-title">style</span>></span><span class="css">
<span class="hljs-tag">html</span>, <span class="hljs-tag">body</span>, <span class="hljs-id">#map</span> <span class="hljs-rules">{
<span class="hljs-rule"><span class="hljs-attribute">padding</span>:<span class="hljs-value"> <span class="hljs-number">0</span></span></span>;
<span class="hljs-rule"><span class="hljs-attribute">margin</span>:<span class="hljs-value"> <span class="hljs-number">0</span></span></span>;
<span class="hljs-rule"><span class="hljs-attribute">height</span>:<span class="hljs-value"> <span class="hljs-number">100</span>%</span></span>;
<span class="hljs-rule"><span class="hljs-attribute">width</span>:<span class="hljs-value"> <span class="hljs-number">100</span>%</span></span>;
<span class="hljs-rule">}</span></span>
</span><span class="hljs-tag"></<span class="hljs-title">style</span>></span>
<span class="hljs-tag"><<span class="hljs-title">script</span>></span><span class="javascript">
<span class="hljs-built_in">require</span>([
<span class="hljs-string">"esri/map"</span>,
<span class="hljs-string">"esri/layers/FeatureLayer"</span>,
<span class="hljs-string">"esri/layers/LabelClass"</span>,
<span class="hljs-string">"dojo/_base/Color"</span>,
<span class="hljs-string">"esri/symbols/Font"</span>,
<span class="hljs-string">"esri/symbols/TextSymbol"</span>,
<span class="hljs-string">"dojo/domReady!"</span>
],
<span class="hljs-function"><span class="hljs-keyword">function</span><span class="hljs-params">(
Map,
FeatureLayer,
LabelClass,Color,Font,TextSymbol
)</span> {</span>
<span class="hljs-keyword">var</span> map = <span class="hljs-keyword">new</span> Map(<span class="hljs-string">"map"</span>,{
showLabels : <span class="hljs-literal">true</span>
});
<span class="hljs-comment">/****************************************************************
|
|