Skip to content

Remove the use of document.querySelector to a more local search using 'this' #1368

Open
@AliyanH

Description

Hello, document.querySelector returns the first element in the document matching the specified selector. This can cause an issue when the web page has multiple Leaflet maps in the page (as the first map will always be selected even when called from the second map).

Similarly, document.querySelector does not search inside of a ShadowRoot which can cause an issue when the leaflet map is inside of one, and create an error (which is the case for me).

I believe the use of document.querySelector can be changed to do a more local search for the map, which can always return the right element. For ex, the following code (which is causing an error for me) can be change from this:

document.querySelector('.leaflet-marker-pane').appendChild(el);

To this:
this._map._container.querySelector('.leaflet-marker-pane').appendChild(el);

Please let me know what you think, Thanks.

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions