Esri InfoWindow没有显示返回的结果

时间:2014-12-12 11:24:28

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

我在尝试检索数据并使用ArcGIS将它们显示在infoWindow时遇到了一些问题。这是我的javascript:

var map;
require(["esri/map","esri/dijit/Scalebar","esri/layers/FeatureLayer", "esri/dijit/Legend", 
     "dojo/_base/array", "dojo/parser", 
     "dijit/layout/BorderContainer", "dijit/layout/ContentPane", 
     "dijit/layout/AccordionContainer","esri/InfoTemplate","dojo/dom-construct","dojo/domReady!"], 
     function(Map,Scalebar, FeatureLayer, Legend, arrayUtils, parser, InfoTemplate,domConstruct){
    parser.parse();
    map=new Map("map", {
    center:[-56.049, 38.485],
    zoom:3,
    basemap: "topo"});

// Show legend
map.on("layers-add-result", function(evt){
var layerInfo = arrayUtils.map(evt.layers, function(layer, index){
    return {layer:layer.layer, title:layer.layer.name};
});

if(layerInfo.length >0){
    var legendDijit = new Legend({
    map:map,
    layerInfos: layerInfo}, "legendDiv");
    legendDijit.startup();
}
});

var legendFeature = new 
     FeatureLayer("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3", { 
     mode: FeatureLayer.MODE_ONDEMAND, 
     outFields:["*"] 
     });

// Show infoWindow 
var content = "<b>State</b>: ${STATE_NAME}";
var infoTemplate = new InfoTemplate("${STATE_NAME}", content);
            featureLayer = new FeatureLayer("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3",
            {
                mode: FeatureLayer.MODE_ONDEMAND,
                infoTemplate: infoTemplate,
                outFields: ["*"]
            });
map.addLayers([featureLayer]);

// Show scalebar
var scalebar = new Scalebar({
    map:map,
    scalebarUnit: "dual",
    attachTo:"bottom-left"});
});

传说和比例尺没有问题。但是,当我点击某个区域时,它确实弹出了一个infoWindow,但没有结果。我想知道为什么它不起作用。

提前致谢。

1 个答案:

答案 0 :(得分:0)

您需要的AMD模块的顺序必须与您获得的构造函数的顺序相对应。在您的情况下,InfoTemplate对应于&#34; dijit / layout / BorderContainer&#34;:

  require(["esri/map", "esri/dijit/Scalebar", "esri/layers/FeatureLayer", "esri/dijit/Legend",
         "dojo/_base/array", "dojo/parser",
         "dijit/layout/BorderContainer", "dijit/layout/ContentPane",
         "dijit/layout/AccordionContainer", "esri/InfoTemplate", "dojo/dom-construct", "dojo/domReady!"],
         function (Map, Scalebar, FeatureLayer, Legend, arrayUtils, parser, InfoTemplate, domConstruct) {...

这将有效:

   require(["esri/map", "esri/dijit/Scalebar", "esri/layers/FeatureLayer", "esri/dijit/Legend",
         "dojo/_base/array", "dojo/parser",
         "dijit/layout/BorderContainer", "dijit/layout/ContentPane",
         "dijit/layout/AccordionContainer", "esri/InfoTemplate", "dojo/dom-construct", "dojo/domReady!"],
         function (Map, Scalebar, FeatureLayer, Legend, arrayUtils, parser, BorderContainer, ContentPane, AccordionContainer,  InfoTemplate, domConstruct) {...