How to merge ArcGIS feature layers and display as one layer on client side

4061
16
10-16-2019 10:51 AM
HanlunSong
New Contributor II

I am working on a project that utilizes ArcGIS JS API to display maps using the approach of Portal Item layers. (https://developers.arcgis.com/javascript/latest/sample-code/layers-portal/index.html) Now we have a request to merge these layers (either on the client side or some other approaches) and display as one layer. And so far I haven't found a way to do it with ArcGIS JS API. I have considered switching the entire client-side JS library to something like esri-leaflet, and raised a question at their repository. Then the closest answer/approach I get so far is to subscribe to ArcGIS Enterprise and use dynamicmaplayer to achieve this. My question: Is there any way to achieve this (pulling multiple Portal item layers and merge & display as one layer) just with ArcGIS JS API? Or in general - What are the possible/recommended approaches to achieve this, no matter client side or not? If we can rebuild the entire app to achieve this, what is the recommended approach?

Tags (2)
0 Kudos
16 Replies
EvelynHernandez
Occasional Contributor III

I dont think so because u are still going to have the overlaping on the layers.

How i told u, the best way to do that is choosing with layer, index what u want to put first and what do u want to put behind.

0 Kudos
ReneRubalcava
Frequent Contributor

There is no simple solution for what you are tying to do, not really. You basically need to do a client side join of two different datasets. Without building a server side solution, you may able to do something like this on the client, but first a warning. It's hacky, with no guarantees.

Here are the steps.

  1. Load all target layers
  2. Query for all features with geometries from target layers
    1. If you hit an exceedsTransferLimit on your query, you'll need to paginate the queries
  3. Use the fields or a single feature from each layer to create your fieldInfos for popups
  4. Create a FeatureLayer using this information
  5. Use all the results of your queried features as the source of the FeatureLayer
  6. Tada

And same rules for FeatureLayers apply, must all be same geometry type, if layers have different schemas for fields, you'll have empty fields in popups.

If doing this dynamically in an app, just remove the old merged featurelayer and create a new one.

Did I mention this is completely untested?

HanlunSong
New Contributor II

Haha, thank you very much. It is very informative nonetheless.

You mentioned server side solution - could you talk more about that too?

Also, what if I switch the entire client side to something like esri-leaflet? Can I only query data from those layers (do I need ArcGIS Enterprise to query data only from layers?) and render them with leaflet?

0 Kudos
ReneRubalcava
Frequent Contributor

It's no easier with esri-leaflet, probably even more work.

A server side solution would be to use a server object extension with Enterprise. I did this years ago to do something similar when I needed to add related data to the results of my feature requests. This does require having an Enterprise license and enough .NET or Java know how to build the extension.

HanlunSong
New Contributor II

Thank you. I think I should explore the server side option too. I do know .Net and some Java but not sure if it will be enough. I notice you are author of two ArcGIS books. May I ask if you could recommend some good resources other the ESRI documentation to get started on this?

0 Kudos
ReneRubalcava
Frequent Contributor

That's a tough one. I don't think I've seen non-esri blog posts on SOE's, but there are videos from previous dev summits.

Here is the latest.

Extending ArcGIS Enterprise - YouTube 

Here are some Java templates

GitHub - Esri/server-extension-java: Template for creating Server Object Extensions (SOEs) and Serve... 

and .NET templates

GitHub - Esri/server-extension-dotnet: Server extensions allow developers to change and extend the c... 

Like I said, it's been a few years since I've done this, but I do remember the hardest part being debugging the services, which was basically looking at the error logs in the enterprise admin pages, but maybe this has been improved.

Thanks!

0 Kudos
HanlunSong
New Contributor II

Oh I see, thanks.

In that case, if I manually merge the layers into one layer beforehand (as a result, the merged layer will have many fields, how do I display polygon color based on a new field which is dynamically created to store sum of two or more fields? It does not have to be strictly creating a new field on the fly. The end goal is to display color based on the sum of multiple fields (i.e. heat map).

Update: I am able to achieve the above using Arcade Expression and Renderers. 

0 Kudos