Select to view content in your preferred language

ArcGIS API for Javascript 3 QueryTask execute returns no private properties in featureSet.features object

233
1
Jump to solution
02-26-2025 06:54 AM
AndžejMiloš
Emerging Contributor

I have a web application based on ArcGIS API for Javascript 3. In the web application a QueryTask is executed on a MapServer feature layer. The result feature set is used to create a Feature Layer and displayed on the map. Here is a piece of the Javascript source code.

getFeatures: function(layer) {
    let query = new Query();
    query.returnGeometry = true;
    query.outSpatialReference = this.map.spatialReference;
    query.where = this.createWhereQuery();
    query.outFields = ["*"];
    layer.queryTask.execute(query, lang.hitch(this, function (featureSet) {
        if (featureSet.features.length > 0) {
            console.log(featureSet.features);
            let geomType = "esriGeometryPoint";
            let layerDefinition = {
                "geometryType": geomType,
                "fields": [{ name: "OBJECTID", type: "esriFieldTypeOID", alias: "OBJECTID" }]
            }
            let featureCollection = {
                layerDefinition: layerDefinition,
                featureSet: featureSet
            };
            let clusterLayer = new FeatureLayer(featureCollection, {
                outFields: ["*"],
                featureReduction: {
                    type: "cluster"
                }
            });
            this.map.addLayer(clusterLayer);
    }),
    lang.hitch(this, function (error) {
        console.log(error);
        alert("Unable to load points data. Contact server administrator.");
    }));
}

 

Everything worked as excepted when MapServer used data from ESRI File Geodatabase. Recently we created a Postgresql database and published an identical copy of MapServer where data comes from the Postgresql database.

After replacing new MapServer URLs in the web application, I noticed that only single feature is displayed on the map after executing above QueryTask. Nothing, except the URLs, was changed in the Javascript code.

When printing in browser console featureSet.features, I noted that the first feature object looks different than the rest (console print screen below). Private properties are present in the first feature object, and not present in the rest feature objects. I guess this is the reason why only a single feature (the first one) is displayed on the map.

console-print-screen.png

When printing in browser console the same featureSet.features using Mapserver with data from ESRI File Geodatabase, then all feature object look similar to the first one described above, and all features are displayed on the map.

Where is the problem and how to fix it?

0 Kudos
1 Solution

Accepted Solutions
JoelBennett
MVP Regular Contributor

I rarely use 3.x these days, but I remember running into problems where only one feature would show.  In those cases, it was always related to the OBJECTID field - either there wasn't one, or it was configured incorrectly.

It looks like that may be what's going on here.  On line 13, you define the objectID field as "OBJECTID".  However, looking at the attributes, the field name is all lower-case "objectid".  However, field names are case-sensitive.  If you change the definition on line 13 to "objectid", it may solve your problem.

View solution in original post

1 Reply
JoelBennett
MVP Regular Contributor

I rarely use 3.x these days, but I remember running into problems where only one feature would show.  In those cases, it was always related to the OBJECTID field - either there wasn't one, or it was configured incorrectly.

It looks like that may be what's going on here.  On line 13, you define the objectID field as "OBJECTID".  However, looking at the attributes, the field name is all lower-case "objectid".  However, field names are case-sensitive.  If you change the definition on line 13 to "objectid", it may solve your problem.