Search code examples
arcgis-js-api

Instantiate FeatureLayer without using require statement ArcGIS javascript api 4.x


Using ArcGIS javascript api 4.x, what is the correct way to instantiate a FeatureLayer without using the require statement? For example, If I want to create a query object, I can instantiate it using the require statement as follows:

require([
"esri/tasks/support/Query"
],
function (Query) {
var query = new Query();
});

But I can also instantiate it without the require statement as follows:

var query = myLayer.createQuery();

Now if I want to instantiate a FeatureLayer using the require statement I can do so as follows:

require([
"esri/layers/FeatureLayer"
],
function (FeatureLayer) {
var myLayer = new FeatureLayer();
});

Now the question is, how can I instantiate a FeatureLayer without the require statement?

Thank you.

SOLUTION

Solution provided by cabesuon. Using the query object instead of a featurelayer resolved the issue. I am able to reuse the query object with no need to instantiate.

More info

esri-rest-query


Solution

  • You can not do that, you need to import FeatureLayer to use it.

    The case you mention with Query is different. In it, FeatureLayer is importing Query "for you" and offer a way for using it. It works as a proxy for creating Query objects.

    If, just as an example, Map had a method for creating FeatureLayer objects, then you could avoid the import sentence.

    Now, FeatureLayer offers a method to create a Query object because is handy, this method preset properties related to the service witch in other way you will have to do it yourself.