Book Image

OpenLayers 3: Beginner's Guide

By : Thomas Gratier, Paul Spencer, Erik Hazzard
Book Image

OpenLayers 3: Beginner's Guide

By: Thomas Gratier, Paul Spencer, Erik Hazzard

Overview of this book

<p>This book is a practical, hands-on guide that provides you with all the information you need to get started with mapping using the OpenLayers 3 library.</p> <p>The book starts off by showing you how to create a simple map. Through the course of the book, we will review each component needed to make a map in OpenLayers 3, and you will end up with a full-fledged web map application. You will learn the key role of each OpenLayers 3 component in making a map, and important mapping principles such as projections and layers. You will create your own data files and connect to backend servers for mapping. A key part of this book will also be dedicated to building a mapping application for mobile devices and its specific components.</p>
Table of Contents (22 chapters)
OpenLayers 3 Beginner's Guide
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Time for action – determining coordinates


Let's take a look at a couple of examples on coordinates from our previous maps:

  1. Open up the final example from Chapter 1, Getting Started with OpenLayers. Pan around the map in any direction. Then, in Chrome Developer Tools, type the following:

    map.getView().getCenter();

    Depending on where you have panned, your output should read something like the following:

    [9397474.0038099,3595597.9798909]
    
  2. Now, open up the example from the beginning of this chapter. Pan around, and then in Chrome Developer Tools, type:

    map.getView().getCenter();

    You should see something like the following:

    [-72.8125, 19.6875]
    
  3. Reuse this last array to change the representation of your degrees values. For calculation, we always use dd (decimal degrees) but some people such as sailors will prefer the DMS (Degrees, Minutes, Seconds) notation:

    ol.coordinate.toStringHDMS([-72.8125, 19.6875]);

What just happened?

We just took a look at the longitude and latitude values for the center of the...