使用ArcGIS的Javascript:InfoWindow不显示字段中的值

时间:2018-06-14 11:00:21

标签: javascript arcgis esri arcgis-js-api esri-javascript-api

我有一个特定国家/地区的功能层位于显示世界上所有国家/地区的另一个功能层之上。

如果您点击这些特定国家/地区,则会弹出一个信息窗口。信息窗口应显示国家/地区的名称。但它没有。

popup content missing

代码如下。这有什么问题?

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
    <title>Feature Layer Only Map</title>
    <link rel="stylesheet" href="https://js.arcgis.com/3.24/esri/css/esri.css">
    <style>
      html, body, #map {
        height: 100%;
        width: 100%;
        margin: 0;
        padding: 0;
      }
    </style>
    <script src="https://js.arcgis.com/3.24/"></script>
    <script>
      require([
        "dojo/dom-construct",
        "esri/map",
     "esri/InfoTemplate",
        "esri/layers/FeatureLayer",
        "esri/geometry/Extent",
        "dojo/domReady!"
      ], function(
          domConstruct,
          Map,
      InfoTemplate,
          FeatureLayer,
           Extent

        ) {
          var bounds = new Extent({
            "xmin":-20037509,
            "ymin":-8283276,
            "xmax":20037509,
            "ymax":17929239,
            "spatialReference":{"wkid":102100}
          });

          var map = new Map("map", {
            extent: bounds
          });

          var url = "https://services8.arcgis.com/qruYQAspohLtOguC/ArcGIS/rest/services/englishspeakingcountries/FeatureServer/0";

          var template = new InfoTemplate("Country", "${ADMIN}");

          var fl = new FeatureLayer(url, {
            id: "englishspeakingcountries_0",
            infoTemplate: template
          });

          map.addLayer(fl);

      var url_2 = "https://services.arcgis.com/P3ePLMYs2RVChkJx/arcgis/rest/services/World_Countries/FeatureServer/0"

      var fl2 = new FeatureLayer(url_2);
      map.addLayer(fl2, 0);
        }
      );
    </script>
  </head>
  <body>
    <div id="map"></div>
  </body>
</html>

1 个答案:

答案 0 :(得分:1)

使用Chrome开发者工具中的“网络”标签,我发现对要素服务的查询仅返回每个要素的ObjectId字段和几何图形。使用outFields属性来解决此问题:

var fl = new FeatureLayer(url, {
  id: "englishspeakingcountries_0", 
  outFields: "*",
  infoTemplate: template
});

Australia popup