ArcGIS API for JavaScript——获取FeatureLayer的属性值

论坛 期权论坛     
匿名小用户   2019-10-20 22:55   3166   0
<!-- 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">&lt;!DOCTYPE html&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-title">html</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-title">head</span>&gt;</span>
    <span class="hljs-tag">&lt;<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>&gt;</span>
    <span class="hljs-tag">&lt;<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>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">title</span>&gt;</span>Create Map and add a dynamic layer<span class="hljs-tag">&lt;/<span class="hljs-title">title</span>&gt;</span>
    <span class="hljs-comment">&lt;!--使用的是本机离线API--&gt;</span>
    <span class="hljs-tag">&lt;<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>/&gt;</span>
    <span class="hljs-tag">&lt;<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> /&gt;</span>
    <span class="hljs-tag">&lt;<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>&gt;</span><span class="javascript"></span><span class="hljs-tag">&lt;/<span class="hljs-title">script</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-title">style</span>&gt;</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">&lt;/<span class="hljs-title">style</span>&gt;</span>

    <span class="hljs-tag">&lt;<span class="hljs-title">script</span>&gt;</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">/****************************************************************
        
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:50
帖子:1079
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP