Ad

How To Switch Layers Using Checkbox In Openlayers 3

- 1 answer

I'm trying to switch layers using a checkbox, but the switch from "baselayer" to "topo" doesn't work. Please help:

<body>
    <div id="mapa"></div>
    <nav id="layers">
        <ul>
            <li><input type="radio" name="layer" value="baseLayer" checked>ORTO</li>
            <li><input type="radio" name="layer" value="topo"> TOPO</li>
            <li><input type="radio" name="layer" value="untiled"> Warstwa</li>
        </ul>
    </nav>
</body>

A Fiddle is also available.

Ad

Answer

Your fiddle will not work for varius reasons.

  1. You do not include jquery but you use it within your code

  2. source: new ol.source.ToPo doesnt exist. It is unknow for openlayers. Maybe it is just a typo. But I have changed it to ol.source.TileWMS.

Here is your fiddle reconstructed. It takes some time to load the images, but this has to do with your server.

Also consider to upgrade to the latest ol3 version. 3.7.0 is too old!

Ad
source: stackoverflow.com
Ad