Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <section id="layerswitcher">
  <h1>Layers Groups</h1>
  <label>Group Visible</label>
  <input id="Group" type="checkbox" checked/>

  <section>
    <label>OSM</label>
    <input id="OSM" type="checkbox"/>
  </section>
  
    <section>
    <label>IGNBaseTodo</label>
    <input id="IGNBaseTodo" type="checkbox" checked/>
   </section>
  
  <section>
    <label>LayerGroup inside LayerGroup</label>
    <input id="layerGroupInside" type="checkbox" checked/>
   </section>
  
    <section>
    <label>Municipios</label>
    <input id="municipios" type="checkbox" checked/>
   </section>
</section>

<div id="map"></div>

              
            
!

CSS

              
                html, body, #map { width:100%; height:100%; margin:0; }

#layerswitcher {
  width: 250px;
  height: 200px; 
  position: absolute;
  z-index: 10;
  
  background-color: white;
  padding: 5px;
}


              
            
!

JS

              
                  // Create OSM layer
const osm = new ol.layer.Tile({
  source: new ol.source.OSM(),
  visible: false,
 });

// Create IGN Base Todo layer
const baseIGNTodo = new ol.layer.Tile({
    source: new ol.source.XYZ({
    url: 'https://tms-ign-base.ign.es/1.0.0/IGNBaseTodo/{z}/{x}/{-y}.jpeg'
  })
});

const municipios = new ol.layer.Tile({
  source: new ol.source.TileWMS({
    url: 'http://geostematicos-sigc.juntadeandalucia.es/geoserver/tematicos/wms?',
        params: {
          'LAYERS': 'tematicos:Municipios',
      },
  })
})

const layerGroup = new ol.layer.Group({
  layers: [municipios]
})

// Group layers
const BaseLayerGroup = new ol.layer.Group({
 layers: [osm, baseIGNTodo, layerGroup]
});

// Create map
const map = new ol.Map({
  layers: [BaseLayerGroup],
  target: 'map',
    view: new ol.View({
    center: ol.proj.fromLonLat([0, 0]),
    zoom: 2
  })
});

// Helper function to get element by selector
const $ = (id) => document.querySelector(id);

// Event listeners for checkboxes
const osmInput = $('#OSM');
osmInput.addEventListener('click', () => osm.setVisible(osmInput.checked));

const baseIGNTodoInput = $('#IGNBaseTodo');
baseIGNTodoInput.addEventListener('click', () => baseIGNTodo.setVisible(baseIGNTodoInput.checked));

const layerGroupInsideInput = $('#layerGroupInside');
layerGroupInsideInput.addEventListener('click', () => layerGroup.setVisible(layerGroupInsideInput.checked));

const municipiosInput = $('#municipios');
municipiosInput.addEventListener('click', () => municipios.setVisible(municipiosInput.checked));


const GroupInput = $('#Group');
GroupInput.addEventListener('click', () => {
  const checked = GroupInput.checked;
  BaseLayerGroup.setVisible(GroupInput.checked);
});
              
            
!
999px

Console