
OpenLayers 2.10 Beginner's Guide Create, optimize, and deploy stunning cross-browser web maps with the OpenLayers JavaScript web-mapping library Erik Hazzard BIRMINGHAM - MUMBAI OpenLayers 2.10 Beginner's Guide Copyright © 2011 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: March 2011 Production Reference: 1110311 Published by Packt Publishing Ltd. 32 Lincoln Road Olton Birmingham, B27 6PA, UK. ISBN 978-1-849514-12-5 www.packtpub.com Cover Image by Jose Argudo ([email protected]) Credits Author Editorial Team Leader Erik Hazzard Aanchal Kumar Reviewers Project Team Leader Xurxo Méndez Pérez Priya Mukherji Alan Palazzolo Project Coordinator Ian Turton Jovita Pinto Couzic Mikael Proofreader Acquisition Editor Steve Maguire Usha Iyer Graphics Development Editor Nilesh Mohite Maitreya Bhakal Production Coordinator Technical Editors Adline Swetha Jesuthas Pallavi Kachare Cover Work Indexers Adline Swetha Jesuthas Hemangini Bari Rekha Nair About the Author Erik Hazzard is a web developer—designer, Open Source advocate, and VI user. He loves to learn, teach, and occasionally blogs on his website at http://vasir.net/. As a professional web developer of five years, Erik specializes in Python and JavaScript, using open source software whenever possible. When he's not developing web applications, he's often developing or designing video games. He works at FREAC (Florida Resources and Environmental Analysis Center), a great place with great people that does all kinds of GIS and web development work. I'd like to thank the developers of OpenLayers, who continually do a fantastic job of developing the best web-mapping framework. I'd like to also thank my friends and mentors Ian Johnson and David Arthur for giving me the confidence and support I needed to get into web development. I'd like to thank Georgianna Strode and Stephen Hodge for their guidance, advice, and providing me with the opportunity to become a better web developer. I could not have written this book without the help of the great team at Packt; I hope every author can be as lucky as me to have such an excellent group of people to work with. I'd like to thank my parents for their never ending support. Lastly, I'd like to thank my love, Alisen, for her understanding and taking the time to help me make sure that the book is as easy to read as possible. About the Reviewers Xurxo Méndez Pérez was born in 1983 in Ourense, a little town in the south of Galicia, Spain. He lived there until he started the study for a degree in IT in the University of A Coruña, which finalized in 2008. For the last two years he has been working, at the Computer Architecture Group of the University of A Coruña developing GIS applications (making intensive use of many OGC standards) like Sitegal and SIUXFor (web GIS based applications to manage land properties and promote their good uses in the Galician region), MeteoSIX (a GIS system that provides access to geolocated observed and forecasted meteorological data in Galicia) and others. He also has large experience (3+ years) as a developer of mobile applications, having played first with JavaME, but nowadays he specializes in Google Android, with more than a dozen developed applications, some of them combining concepts like GIS and geolocation, real time responsiveness, and multiuser needs. Alan Palazzolo has been building web applications big and small for over five years, most of which have been with the open source, content management system Drupal, and along the way has picked up some experience in data visualization and mapping. He is a strong believer and advocate for the open source methodology in software and in life. He was involved in starting a Free Geek chapter in the Twin Cities, and constantly tries to use technology, and specifically the Internet, to enhance the lives of those that are less fortunate than most. Ian Turton is a geography researcher at the Pennsylvania State University. He became a geographer by accident nearly 20 years ago and hasn't managed to escape yet. During that period he was a co-founder of the GeoTools open source Java toolkit that is now used as the basis of many geographic open source projects. He continues to serve on the Project Steering Committee for the project as well as committing new code and patches. He has also taught the very popular course "Open Web Mapping" using open standards and open source programs at the Pennsylvania State University and the University of Leeds. www.PacktPub.com Support files, eBooks, discount offers, and more You might want to visit www.PacktPub.com for support files and downloads related to your book. Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details. At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks. http://PacktLib.PacktPub.com Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can access, read and search across Packt's entire library of books. Why Subscribe? Fully searchable across every book published by Packt Copy and paste, print and bookmark content On demand and accessible via web browser Free Access for Packt account holders If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access. Table of Contents Preface 1 Chapter 1: Getting Started with OpenLayers 7 What is OpenLayers? 8 Why use OpenLayers? 8 What, technically, is OpenLayers? 8 Client side 8 Library 9 Anatomy of a web-mapping application 9 Web map client 10 Web map server 10 Relation to Google / Yahoo! / and other mapping APIs 11 Layers in OpenLayers 11 What is a Layer? 12 The OpenLayers website 12 Time for action – downloading OpenLayers 13 Making our first map 15 Time for action – creating your first map 15 How the code works 17 Understanding the code—Line by line 18 JavaScript object notation 21 Behind the scenes—Object Oriented Programming (OOP) 24 Interaction happens with objects 25 MadLibs 25 Time for Action – play MadLibs 25 Programming with OOP 26 Subclasses 26 Now what? 27 API docs 28 Table of Contents Where to go for help 28 This book's website 28 Mailing lists 28 IRC 29 OpenLayers source code repository 29 Summary 30 Chapter 2: Squashing Bugs With Firebug 31 What is Firebug? 32 Setting up Firebug 32 Time for Action – downloading Firebug 32 Firebug controls 34 Panels 34 Console panel 35 HTML panel 35 CSS panel 37 Script panel 37 DOM panel 38 Net panel 38 Panel conclusion 41 Using the Console panel 42 Time for Action – executing code in the Console 42 Time for Action – creating object literals 43 Object literals 44 Time for Action – interacting with a map 45 API documentation 47 Summary 47 Chapter 3: The 'Layers' in OpenLayers 49 What's a layer? 50 Layers in OpenLayers 50 Base layer 51 Overlay layers 51 Time for Action – creating a map with multiple layers 51 Creating layer objects 54 Layer.WMS class 55 WMS layer parameters: 55 Parameters versus arguments 57 Time for Action – configuring the options parameter 58 Configuring layer options 61 wms_state_lines layer options 61 Scale dependency 61 wms_layer_labels layer options 62 The visibility property 62 [ ii ] Table of Contents The opacity property 62 Map tiles 62 Many images make up a map 63 Available layer properties 65 Data types 66 OpenLayers.Layer class properties 66 Modifying layer properties 71 The OpenLayers.Layer class 71 Subclasses 71 Layer Class—Sub and super classes 72 Other layer types 72 Layer.ArcGIS93Rest 72 Layer.ArcIMS 73 Layer.Google 73 Time for Action – creating a Google Maps layer 73 Layer.Grid 75 Layer.Image 76 Time for Action – using the image layer 76 Image layer parameters 77 Layer.MapGuide 78 Layer.TileCache 79 Layer.Vector 79 Layer.VirtualEarth 79 Layer.WFS 80 Layer.WMS 80 Layer.Yahoo 80 Accessing layer objects 80 Time for Action – accessing map.layers 80 Time for Action – accessing layer objects in Firebug 82 Accessing layer properties 82 map.layers 82 Storing references to layer objects 83 Layer class methods 85 Time for Action – defining a global layer object variable 85 Layer class method definitions 86 Summary 88 Chapter 4: Wrapping Our Heads Around Projections 89 Map projections 90 Why on earth are Projections used? 90 Projection characteristics 90 Area 90 [ iii ] Table
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages372 Page
-
File Size-