O'Reilly logo

OpenLayers 2.10 by Erik Hazzard

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How the code works

Now, let's take a look at the code—line by line. Before we do that, let's include a quick reference to the line numbers at which the requirements from the previous section occur at. These are the core things that you need to do to have a functioning map.

Note

We'll denote line numbers with brackets—[x], where x is the line number.

  1. Including the OpenLayers library files:
    Line [6]
      <script type='text/javascript' src='OpenLayers.js'></script>
  2. Creating an HTML element for our map:
    Lines [30] and [31]
      <div id='map_element' style='width: 500px; height: 500px'>
    </div>
  3. Creating a map object from the Map class:
    Line [12]
      map = new OpenLayers.Map('map_element', { });
  4. Creating a layer object from a Layer class:
    Lines [13] to [18] var wms_layer = ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required