Select to view content in your preferred language

Using CDFs, can a single Data Provider return several layers?

119
1
Friday
Francisco_R
Esri Contributor

Hi,

I have read through the docs and the Samples Github repo, but I have not yet found clarity regarding multi-layer CDFs.

At developer stage the console is pretty clear regarding the routes:

debug: ROUTE | [GET, POST] | /test-layers/rest/services/FeatureServer
debug: ROUTE | [GET, POST] | /test-layers/rest/services/FeatureServer/layers
debug: ROUTE | [GET, POST] | /test-layers/rest/services/FeatureServer/:layer([0-9]+)
debug: ROUTE | [GET, POST] | /test-layers/rest/services/FeatureServer/:layer([0-9]+)/info
debug: ROUTE | [GET, POST] | /test-layers/rest/services/FeatureServer/:layer([0-9]+)/query
debug: ROUTE | [GET, POST] | /test-layers/rest/services/FeatureServer/*


However all the examples are singled-layer.

 

Is it possible to publish a custom data provider based service that exposes 2 or more layers?

If so, could a sample be added to the Github repo or shared here? 

0 Kudos
1 Reply
John_Hash
Esri Contributor

Hello. Thank you for the question.
Yes, it is possible to support multiple layers in your custom data provider. We generally advise to keep the provider logic limited to one layer per service to keep provider complexity to a minimum and performance maximized, but there are some recognized cases where multiple layers may be warranted. There are plans to add more documentation and samples around multiple layers in the future, but I can show you how to accomplish this now. Here is some pseudocode for the basics on how it works. In summary, you capture whether the request is a layer-level or service-level request. For the service-level request, return the three properties shown below: `layers`, `tables`, and `metadata`.

  async getData(req) {
    const layer = req.params.layer;
    let response;

    switch (layer) {
      case '0':
        response = this.getLayer0Data();
        break;

      case '1':
        response = this.getLayer1Data();
        break;

      default:
        response = this.getServiceLevelData();
        break;
    }
    return response;
  }

  async getLayer0Data() {
    // layer 0 logic  
    return {
      ...geojson,
      metadata: metadata
    };
  };

  getLayer1Data() {
    // layer 1 logic
    return {
      ...geojson,
      metadata: metadata
    };
  }

  getServiceLevelData() {
    return {
      layers: [this.getLayer0Data(), this.getLayer1Data()],
      tables: [],
      metadata: {
        // metadata
      }
    }
  }
}




0 Kudos