Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
OpenLayers 2.10 Beginner's Guide
OpenLayers 2.10 Beginner's Guide

OpenLayers 2.10 Beginner's Guide: Create, optimize, and deploy stunning cross-browser web maps with the OpenLayers JavaScript web mapping library

eBook
€8.99 €28.99
Paperback
€37.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

OpenLayers 2.10 Beginner's Guide

Chapter 2. Squashing Bugs With Firebug

OpenLayers is, at a fundamental level, not doing anything that is conceptually too hard to grasp. It gets map images from a server, and puts them together. From a technical level, however, there is a lot of work going on, and it might seem magical how it all works together so well.

Fortunately, there are many tools to dispel any potential magical thinking we might have and show us how OpenLayers is working behind the scenes. Firebug, a free and open source plugin for Firefox, is one such great tool. Speeding up development time, viewing network communication, and squashing bugs are just a few things that Firebug, and other web development tools, do that make them hard to live without.

To really use OpenLayers effectively and to its full potential, we need to understand how it works. In this chapter, we'll try our best to do just that, by using web development tools to examine OpenLayers' inner workings. By doing so, we'll accomplish two things. First...

What is Firebug?


Firebug is a free, open source addon for Firefox. If you do not have Firefox, I recommend downloading it (it is also free and open source). However, other modern and standards based browsers, such as Google's Chrome, Apple's Safari, and Opera, also work well and have great built in developer tools.

Firebug, and other web development tools, makes the web development process much easier and quicker. What do I mean by this? With these tools, we can change anything on our site, on the fly, without editing or saving any files. We can type in JavaScript code with a command line interface and execute it immediately. We can view all the requests that our web page sends to servers, along with the server's reply. For example, if our map isn't able to get back map images from the server, we could examine the requests our page is making and find out if we have any typos or haven't set up our map layer properly.

Using these tools makes it a lot easier to develop not only an OpenLayers...

Setting up Firebug


Since Firebug is an extension of Firefox, you'll need to first install Firefox. You can download it for free at http://getfirefox.com. After that, Firebug can be freely downloaded at http://getfirebug.com. When you click on the link to download Firebug, Firefox will prompt you with a message asking if you wish to install the plugin. After installing, all you have to do is restart Firefox and you'll be good to go.

Time for Action – downloading Firebug


If you do not already have an up to date version of Firefox installed, please do so now. After you have installed Firefox, set up Firebug by following these steps:

  1. Go to http://getfirebug.com.

  2. Click on the Install Firebug for Firefox button. Once you click this, you should see a message similar to this:

  3. Click Install, wait for it to finish installing, and then restart Firefox.

  4. Now that Firebug is installed, you should see a Firebug icon on the bottom right side of your screen.

    .

What Just Happened?

When Firebug is not enabled, the Firebug Icon is gray. When it is in enabled, it has an orange color—this is just a quick way for you to tell if Firebug is enabled or not for the current page you're on.

When you click on the Firebug icon (near the bottom right of your browser's window), Firebug will open and you can start using it. But before we start, let's take a look at what Firebug looks like after initially installing it and clicking on the Firebug icon:

The...

Firebug controls


Firebug icon: The Firebug icon on the top left contains various commands and options related to Firebug when you click on it.

Page Inspector icon: This icon, a cursor inside a rectangle, is the HTML Inspector. When you click on it, your mouse cursor will identify HTML elements on the web page. So, when you mouse over anything on a website, the element will be outlined in blue and the HTML panel will open up and show you the element your mouse is over.

Panels

The next set of controls is called panels; each panel provides a different type of function. The panels act like tabs (the two terms can be used interchangeably), but Firebug refers to them as 'panels' in the documentation. Let's go over each panel, since they are, essentially, what makes up Firebug.

Console panel

Firebug's Console panel is where we'll spend most of our time. It acts as a powerful JavaScript command line, or interpreter, which means we can type in JavaScript code and execute it right away—no need to...

Panel conclusion


Each panel serves a certain purpose and all of Firebug's panels are extremely useful, but throughout the book we will be mainly focusing on the following panels:

  • Console panel (Command Line JavaScript)

  • HTML panel

  • Net panel

These three panels will be used the most throughout the book. We'll occasionally come back to the other panels, but we won't spend a whole lot of time with them. However, before we conclude this chapter, let's get a bit more familiar with the Console panel, since we'll be making heavy use of it in the coming chapters.

Using the Console panel


We talked a bit about what the console panel is—essentially, a JavaScript command line. We can execute any JavaScript code we want, and interact with any page element. There are two primary components to the Console panel—the console log area and the input area.

The console log area will display information about any errors, along with displaying any code that is entered. The input area allows us to either enter a single line of code or, by clicking on the red arrow on the right side of the input box, multiple lines of code.

Before we start using the console with our maps, let's get familiar with the console by executing some JavaScript code.

Time for Action – executing code in the Console


We're going to do some basic JavaScript coding via the Firebug console; specifically, just calling a built in alert() function to display an alert.

  1. Open up Firefox. It doesn't matter at this point what website (if any) that you go to, since we will be writing a stand alone code.

  2. Open up Firebug by clicking on the Firebug icon. Go to the Console panel. If it is not enabled, enable it.

  3. Now, at the bottom of your screen you'll see an area where you can enter code, designated by >>>. Clicking anywhere after that will allow you to enter the code.

  4. Type in the following code, and then hit Enter.

    alert('Narwhals like bacon');
  5. You should see an alert box pop up with the text Narhwals like bacon (or whatever string you passed into the alert function). After the code is executed, it will appear in the log above the input line.

What Just Happened?

We just executed some JavaScript code without having to edit and save any files. Although we did a simple...

Time for Action – creating object literals


We're going to introduce object literals and get acclimated with how to manipulate them now, so we can better work with OpenLayers code.

  1. Open up Firefox and Firebug's Console panel (enabling it if it disabled)—again, it doesn't matter right now what page you're on.

  2. Click on the red arrow on the bottom right, above the Firebug icon. This will open up a side panel where we can type in multiple lines of code. The code will not be executed when we press Enter, like in single line mode. Instead, we can execute the code by either pressing Ctrl + Enter or clicking Run.

  3. Type in the following code, and then execute it by pressing Ctrl+Enter or clicking Run.

    var my_parameters = {'answer': 42, 'question': null};
    console.log(my_parameters);
  4. The above code should display, in the console log area, something similar to Object { answer=42 }. Click on it, and the DOM panel will open, showing you all the information about the object you just created.

  5. Click on the Console...

Time for Action – interacting with a map


We'll use the map we created in Chapter 1 to do this example, interacting with our OpenLayers map by calling various functions of the map.

  1. Open up the map from Chapter 1 in Firefox. Enable Firebug and the Console panel. If you would like, you can take a look at the Net panel and view the network activity to see the requests your page is making.

  2. Go to the Console panel, input and then execute the following code:

    console.log(map);
  3. You should see the map object information come up in the console log. Click on it, and take a moment to look over the various attributes it has. Near the bottom, you can see a list of all the functions that belong to it (which are also referred to as methods).

    Take note of the function names, as we'll be using them.

  4. Go back to the Console panel, type in and execute the following code:

    map.zoomIn();
    map.getExtent();
  5. Take note of the extent. Clear out the code you typed in, then type in the following and execute it:

    map.zoomToMaxExtent...

Summary


In this chapter, we learned more about how OpenLayers works. We learned how to set up and use Firebug and other Web Development tools.

We then took a look at the panels that Firebug provides and what they are used for. Finally, we spent time with the Console panel—something you'll be making extensive use of throughout this book (and when you're developing your own web maps).

This chapter aimed to provide some foundational knowledge of web development tools for getting into both OpenLayers and general web development. Web development tools, like Firebug, are one of the biggest assets in our toolkit. They speed up development time, help us identify bugs, interact with our code better, and much more.

Note

Firebug and such tools can also degrade performance if you are just browsing the web, so it is probably best to leave them disabled unless you're using them.

For the code exercises in the following chapters, it will be very beneficial if you use Firebug to first test the code, to see what...

Left arrow icon Right arrow icon

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Mar 18, 2011
Length: 372 pages
Edition :
Language : English
ISBN-13 : 9781849514132
Category :
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Mar 18, 2011
Length: 372 pages
Edition :
Language : English
ISBN-13 : 9781849514132
Category :
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 117.97
OpenLayers 2.10 Beginner's Guide
€37.99
OpenLayers Cookbook
€37.99
GeoServer Beginner's Guide
€41.99
Total 117.97 Stars icon
Banner background image

Table of Contents

11 Chapters
Getting Started with OpenLayers Chevron down icon Chevron up icon
Squashing Bugs With Firebug Chevron down icon Chevron up icon
The 'Layers' in OpenLayers Chevron down icon Chevron up icon
Wrapping Our Heads Around Projections Chevron down icon Chevron up icon
Interacting with Third Party APIs Chevron down icon Chevron up icon
Taking Control of Controls Chevron down icon Chevron up icon
Styling Controls Chevron down icon Chevron up icon
Charting the Map Class Chevron down icon Chevron up icon
Using Vector Layers Chevron down icon Chevron up icon
Vector Layer Style Guide Chevron down icon Chevron up icon
Making Web Map Apps Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.2
(9 Ratings)
5 star 55.6%
4 star 11.1%
3 star 33.3%
2 star 0%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




R. L. Hore Jun 15, 2012
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I needed to get up to speed on Open Layers quickly and this is the book that did it. Nice and easy to read with plenty of examples.
Amazon Verified review Amazon
中山修 Apr 19, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
サンプルが多くOpenLayersのすばらしさを把握することができました。
Amazon Verified review Amazon
Bette Lamore Sep 10, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Everything I expected.
Amazon Verified review Amazon
Courtney McNealy Jun 17, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book was a great way to get started using OpenLayers. It has chapters that cover how to set up a basic map using Google, Yahoo, Bing, or OpenStreetMap, how to add controls and use layers, and would be useful even for someone who does not know javascript, html, or css.EDIT: My initial review criticized this book's lack of useful information for making markers, etc, but really this was a misunderstanding of OpenLayers on my part. This book has in-depth information about how to build "features" on vector layers, which are many times more powerful than "markers". There is also lots of information and reference material in this book about events and event listeners, which is sometimes hard to find in the online documentation.I have increased my rating of this book to 5 stars because of how useful it has been to me. I started building a map using this book when I knew nothing about OpenLayers, and have advanced to making custom controls, complex events, and advanced styling based on the information in this book!
Amazon Verified review Amazon
poncho Apr 14, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
英語は、まったくといえるほど駄目なので、購入をためらっていたがOpenLayersを体系的に記述した日本語情報がなかったので購入した。独学の私に、基本を体系的に習得できる貴重なものだった。
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.