Unable to extend FeatureLayer at 4.16

1103
3
07-29-2020 11:28 AM
ToddAtkins
Occasional Contributor

At 4.16, extending the FeatureLayer no longer works. We have a feature layer where we set the source property in the constructor to generate some graphics on the client side. For this layer in particular, we extended FeatureLayer to add a few helper methods that lets us talk to our internal API.

At 4.15, this worked as expected, however at 4.16, we now get an error: "Feature layer must be created with either a url or a source". Inspecting the output, the source property is undefined so at some point along the line the constructor is failing if the class extended.

Codepen Example: https://codepen.io/tatkins/pen/JjGQYqp 

Just swap from 4.16 to 4.15 in the api url and the layer will work.

For example:

class ExtendedLayer extends FeatureLayer {
  constructor(props) {
    super(props);
  }
}

const layer = new ExtendedLayer({...})

At 4.16 this will fail but will work correctly at 4.15.

Any insight is appreciated.

Tags (2)
0 Kudos
3 Replies
YannCabon
Esri Contributor

I'm sorry your are running into this. API Classes moved away from `dojo/_base/declare` and internals have changed. We never supported extending classes using native ES classes, and it worked by chance. We might support it at some point, after more refactoring, but it's not immediate work.

See Implementing Accessor | ArcGIS API for JavaScript 4.16 

const ExtendedFeatureLayer = FeatureLayer.createSubclass({
  additionalMethod() {

  }
})

You can make it work with ES classes, but this is not supported and will likely change in the future

class ExtendedLayer extends FeatureLayer {
  constructor(props) {
    super(props);
    this.postscript();
  }
}
0 Kudos
ToddAtkins
Occasional Contributor

Ah, I didn't know that about the ES classes and the Esri API.

I'm having a look at the Accessor stuff in there but haven't had a lot of success yet. Maybe because I'm using esri-loader in this project (it's a create-react-app project). I'll fiddle with it some more and see if I can get it to work this way, otherwise I can refactor the code and workaround it.

Thanks again for your help.

0 Kudos
Maka
by
New Contributor

(Edit)

0 Kudos