typescriptarcgis-js-api

EsriJS: CustomLayerView doesn't requestRender


I am currently writing a custom Layer and a custom LayerView in Typescript using https://developers.arcgis.com/javascript/latest/sample-code/custom-lv-masking/ as a guide.

To use proper Typescript Classes I have split the example code into a class CustomLayer and CustomLayerView2D and extended BaseLayerView2D. In the handler function I have the following code

    const projectionPromise = projection.load();
    const layer = this.layer as CustomLayer;

    if (!layer.geometry) {
      this.projectedGeometry = null;
      this.needsImageUpdate = true;
      this.requestRender();
      return;
    }

    if (geometry !== oldGeometry) {
      projectionPromise.then(() => {
        this.projectedGeometry = projection.project(
          layer.geometry,
          layer.tileInfo.spatialReference,
          projection.getTransformation(layer.geometry.spatialReference, layer.tileInfo.spatialReference)
        );
        this.needsImageUpdate = true;
        this.requestRender();
      });
    } else {
      this.needsImageUpdate = true;
      this.requestRender();
    }

Every time I call this.requestRender() I get the error that in BaseLayerView2D display is not set.

So I tried to call super.initialize() to set display but then I get the error that in BaseLayerView2D container is not set. How can I set container or what am I doing wrong?


Solution

  • It turns out that trying to force the Esri example into TypeScript classes caused the error. Exporting the example as a lambda function (abridged from the original example) worked.