how to custom request method and params for GeoJSONLayer

830
5
10-29-2021 04:50 AM
zkf
by
New Contributor II

we can only use method of get and a url to get GeoJSON data for GeoJSONLayer,

It's too inflexible.

if params is too long,

there will be problems.

 i want to load a GeoJSONLayer by GeoJSON data by other custom request ,

how i can i do?

or how  can i custom request method and params by official method?

0 Kudos
5 Replies
UndralBatsukh
Esri Regular Contributor

Hi there,

At version 4.22, GeoJSONLayer will support customParameters property where you can set your custom query parameters. GeoJSONLayer will also be a refreshable layer. For example, you can change the customParameters of your GeoJSONLayer at runtime and call refresh method. This will update the layer's data at runtime. You can test this using our next build.

This codepen app shows customParameters and refresh in action. The JS API 4.22 version will be released end of December 2021.

Hope this helps,

-Undral

zkf
by
New Contributor II

thank you for your anwser.The browser has a limit on the length of the url,if params too long,GET method will be error.What should I do?

0 Kudos
UndralBatsukh
Esri Regular Contributor

Hi there, 

 

The esriRequest automatically switches to POST if URL is too long. The maxUrlLength controls when requests switch to POST. So you don't have to anything. 🙂

Hope this helps,

-Undral 

zkf
by
New Contributor II

Sorry I didn't read the document carefully enough .Is there a way to specify the request method? 

0 Kudos
UndralBatsukh
Esri Regular Contributor

You don't have to do anything. The GeoJSONLayer uses esriRequet to fetch the data. If your url query params are more 2000 characters, the esriRequest switches to post automatically. So the GeoJSONLayer will fetch the data no matter how long the url is.

0 Kudos