-->

ArcGIS API - Execute QueryTask unsupported

2019-08-31 00:41发布

问题:

So, I am using the ArcGIS API (javascript) in order to get some information from objects in a featurelayer. The first step here should be detecting which object the user clicked. I am using queries for this. For some reason though, I cannot seem to execute my queries. Every time the execute method is called, the console replies that "Object doesn't support property or method 'execute'". The relevant part of the code is as follows:

thema_4_Verblijf = new FeatureLayer("https://services.arcgisonline.nl/arcgis/rest/services/Basisregistraties/BAG/MapServer/4");
        map_Thema_4.addLayer(thema_4_Verblijf);
        thema_4_Verblijf.on("click", thema_4_Verblijf_Click);
        function thema_4_Verblijf_Click(evt){
            var query = new Query();
            query.returnGeometry = true;
            query.outFields = ["*"];
            query.geometry = evt.mapPoint;
            var queryTask = new QueryTask("https://services.arcgisonline.nl/arcgis/rest/services/Basisregistraties/BAG/MapServer/4");
            queryTask.execute(query,showResults);
        };

        function showResults(featureSet){
            //will show results
        }

At first, I thought this had to do with me not defining the requirements correctly at the start of the script. This cannot be possible though as execute is a method of QueryTask, and 'new QueryTask' itself completes without any errors. Nonetheless, my requirements as defined are:

require([...
    "esri/geometry",
    "esri/tasks/query",
    "esri/tasks/QueryTask",
    "esri/tasks/FeatureSet"
    ],
    function startMap(
    ...
    Query,
    QueryTask,
    ...

Any thoughts on what could be wrong here...?

回答1:

Alright, so this has been answered..

I tried defining querytask with the legacy module and for some reason that worked.

var queryTask = new esri.tasks.QueryTask(...);

I have experienced this before during my current project, somewhere legacy and AMD modules must be mixed up, even though all my requires have been defined using the AMD way.

So yes, this particular question has been fixed (as in: I can continue) but if someone could explain how the two modules can get mixed up, that would be appreciated.