Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
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
AU$36.99 AU$53.99
Paperback
AU$67.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $24.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
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 : 9781849514125
Category :
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $24.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

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

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.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
$199.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 AU$5 each
Feature tick icon Exclusive print discounts
$279.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 AU$5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total AU$ 211.97
OpenLayers 2.10 Beginner's Guide
AU$67.99
OpenLayers Cookbook
AU$67.99
GeoServer Beginner's Guide
AU$75.99
Total AU$ 211.97 Stars icon

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

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.