I agree that this appears to be the correct way (and time) to access the map. I am adding my layer to the map before I try to call getMap(). While I was trying to understand what was going wrong I would write out the event object to the console from the load event. It would show in the debug window that _map was set but when I tried to access it with something like getMap() it was always null. That to me looks like an odd timing issue so I tired the following.
export class MyDynamicMapServiceLayer extends ArcGISDynamicMapServiceLayer {
constructor(url: string, options? ArcGISDynamicMapServiceLayerOptions) {
super(url, options);
this.on('load', (event) => {
setTimeout(() => {
console.log(super.getMap());
}, 0);
});
}
}
It might be strange to use a setTimeout this way, especially since the wait time is 0 milliseconds, but this appears to let the layer finish initializing and set the _map variable, which I think is what getMap() returns. Oddly enough this worked.