2

I'm publishing services to ArcGIS server and I want to test them out in a simple HTML web map. I would like to create a pop-up window to test if the attributes are coming through. Since I will be doing this with many feature services I don't want to make a static info template. Here is the code I am using:

var infoWindow = new InfoWindowLite(null, domConstruct.create("div", null, null, map.root));
        infoWindow.startup();
        map.setInfoWindow(infoWindow);
        map.infoWindow.resize(200, 75);

        //adds information about Alameda County
       var template = new InfoTemplate();
        template.setTitle("<b>${STATE_NAME} - ${STATE_ABBR}</b>");
        template.setContent("${STATE_NAME} is in the ${SUB_REGION} sub region.");

        //adds the border around each of the states
        var featureLayer = new FeatureLayer("https://sampleserver6.arcgisonline.com/arcgis/rest/services/Census/MapServer/3", {
          mode: FeatureLayer.MODE_ONDEMAND,
          infoTemplate:template,
          outFields: ["STATE_NAME" , "SUB_REGION", "STATE_ABBR"]
        });
        map.addLayer(featureLayer);

Where it says "template.setTitle" and "template.setContent" as well as "outFields" is there a way to use a generic index like the first three fields for each feature class?

  • 2
    Generally the wildcard character "*" is used to return all fields. Try outFields: ["*"] – landocalrissian Jun 21 at 15:56
0
  1. Which version of arcgis-js-api are you using? In v4 there's no infoTemplate, so I guess v3. If you can, you might wanna consider using arcgis api v4.
  2. The default popup contains all the fields, you can map the layer fields into an array if you want to use indices and not names. Example:
    var field_names = layer.fields.map(function(item) { return item['alias']; });
  3. You can create a function for the popup creation and in it use the fields indices I've created a CodePen example that uses indices and not fields names based on arcgis api example

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.