TransWikia.com

Publish a feature service from a shapefile in ArcGIS Online using JavaScript

Geographic Information Systems Asked by Shalinee Mishra on February 22, 2021

I have created a custom HTML page for data extract analysis using ArcGIS API, the API save the shapefile in zip format by default in my ArcGIS portal, so I just want to publish the shapefile(.zip) as a hosted feature layer using JavaScript.

One Answer

To my knowledge you cannot publish a shapefile directly to AGOL via the ArcGIS JavaScript API (at least not with the Version 4.x JS API). If you still want to use JavaScript to accomplish this, you likely want to use the ArcGIS REST API. Specifically a combo of the Upload and the Publish Item endpoints.

Then you can just use whatever JS HTTP client (or just plain JS fetch) to make a POST request to each endpoint with the required request body params as outlined in the above links.

At a high level the workflow would be:

  • Use the Upload endpoint to store the shapefile in AGOL (may not be necessary since you stated you already have a method for uploading)
  • Get the itemID from the response (or by some other means)
  • Use the item ID along with publish params to publish to AGOL
  • Obtain the feature service URL from the response and pass on to the next step in your business logic
  • (Optional): Use Delete to do some cleanup of the original shapefile (or take this to some offline scheduled process)

The tough part will be handling the async nature of all of this as, if this routine is to be used in a client facing application, it will keep the user sitting for a while. If performance isn't an issue, just await each request and run synchronously. Else, you may want to run that routine in a web worker or something to free up the UI.

Answered by Chaz on February 22, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP