Can't access tooltip _container variable in tooltip object in leaflet

Viewed 10

I am trying to have access to the tooltip container dom element.

I added an init hook on each tooltip element which adds them to an array, and then I have an init hook on the map to loop each tooltip.

When console log my tooltip, I can see in the console there the object has a _container property that contains the dom element I want. However when I try to read it directly, for example by logging it to the console, it returns undefined. Is there a way I can access that property?

Here is an example of the code I am using:

var tooltipArray = [];

L.Map.addInitHook(function () {
    this.on('zoomend', function() {
        tooltipArray.forEach(function (tooltip) {
            console.log(tooltip);
            console.log(tooltip._container);
        })
     });
});
L.Tooltip.addInitHook(function () {
    tooltipArray.push(this);
});

This is the result in the console

As you can see from the capture, the first console.log shows the tooltip object, and the the second one returns undefined.

0 Answers
Related