Select to view content in your preferred language

custom featurelayer pagination load

1379
1
08-12-2016 12:17 AM
yanli
by
Emerging Contributor

I find featurelayer with arcgis for js 4.0  can load large data form server with "pagination",  like this "Axis politics ".

so  I  try to Realization it  without the pagination,my code i

var queryTask = new QueryTask({
    url: "http://*******/arcgis/rest/services/Test/MapServer/1"
});
var time = 0;

function querydata() {

    for (var i = 0; i < 8; i++) {

        var query = new Query();
        query.returnGeometry = true;
        //query.outFields = ["OBJECTID", "RELHEI", "name"];
        query.outFields = ["*"];
        var start = 0 + i * 1000
        var end = start + 1000
        query.where = "OBJECTID > " + start + " AND OBJECTID < " + end;

        queryTask.execute(query)
            .then(function (results) {
                time++;
                var l = results.features;

                if (time == 8) {

                    myMap.add(querylayer);
                }
                collection.addMany(results.features);
                querylayer.source = collection;

            })
            .otherwise(function (error) {
                console.log(error);
            })

    }

}

I load the 8000 polygon. I find it slow, the featurelayer render all the geometry once ,it  not render 8 times.how to realize render the featurelayer one by one?????

0 Kudos
1 Reply
FC_Basson
MVP Regular Contributor

You could add all the result features in a bigger array and then add them all at once:

var queryTask = new QueryTask({
    url: "http://*******/arcgis/rest/services/Test/MapServer/1"
});
var time = 0;


function querydata() {
    var allFeatures = []; // array for all resulting features
    for (var i = 0; i < 8; i++) {
        var query = new Query();
        query.returnGeometry = true;
        //query.outFields = ["OBJECTID", "RELHEI", "name"]; 
        query.outFields = ["*"];
        var start = 0 + i * 1000
        var end = start + 1000
        query.where = "OBJECTID > " + start + " AND OBJECTID < " + end;


        queryTask.execute(query)
            .then(function(results) {
                time++;
                var l = results.features;
                //collection.addMany(results.features);
                allFeatures.push(results.features);
                if (i == 8) {
                    // add when final result set has been retrieved
                    collection.addMany(allFeatures);
                    querylayer.source = collection;
                    myMap.add(querylayer);
                }


            })
            .otherwise(function(error) {
                console.log(error);
            })
    }
}
0 Kudos