Skip to content
Advertisement

Multiple tile issue google maps API v3 JS

I have a map where user from an admin panel can add many tiled layers to the map. Those layers will be added to the map in the form of loop. The user can switch the layer on and off based on their selection.

After adding the layers via the loop when I select the first layer the second layer renders but if I don’t add the layers via the loop but add them separately the layer selection works fine.

Here is my code

JavaScript

Advertisement

Answer

To make your loop work (with modern browsers), use the let keyword to define the path:

JavaScript

watercolor layer:

watercolor layer

toner layer:

toner layer

working live example

complete code:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement