Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying OpenLayers 2.10 Beginner's Guide
  • Table Of Contents Toc
  • Feedback & Rating feedback
OpenLayers 2.10 Beginner's Guide

OpenLayers 2.10 Beginner's Guide

4.2 (9)
close
close
OpenLayers 2.10 Beginner's Guide

OpenLayers 2.10 Beginner's Guide

4.2 (9)

Overview of this book

Table of Contents (18 chapters)
close
close
OpenLayers 2.10
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Time for Action – styling the LayerSwitcher control


Let's take a look now at how to style the LayerSwitcher control. Unlike the previous example, we'll place this control in a div element outside the map.

  1. Start a new page. We'll link to an external CSS file that will override the base LayerSwitcher control style, like in the previous example. Include a <link> tag that references a file called ex3_layerswitcher_style.css, which we'll create soon.

  2. Next, we'll need to create a div element that will house our control. Create a div tag after the map_element div:

    <div id='layer_switcher_control'></div>
  3. Now, in your JavaScript code, create the map and WMS layer object as normal. Add a LayerSwitcher control, and pass in the layer_switcher_control element as the div property:

    map.addControl(new OpenLayers.Control.LayerSwitcher({
      div: document.getElementById('layer_switcher_control')
    }));
  4. Now, if you open up the map you should see the map with the layer switcher control beneath it:

  5. By...

Unlock full access

Continue reading for free

A Packt free trial gives you instant online access to our library of over 7000 practical eBooks and videos, constantly updated with the latest in tech
bookmark search playlist font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY