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 – using different projection codes


Let's create a basic map using a different projection. Using the usual code from Chapter 1, Getting Started with OpenLayers, recreate your map object the following way. We'll be specifying the projection property, along with the center and zoom properties. The projection we will use is EPSG:4326, a projection used for world data. Usually, when you don't specify a projection, the default projection in OpenLayers is EPSG:3857 (historically, called EPSG:900913), used by Google Maps and other third-party APIs such as Bing Maps or OpenStreetMap.

  1. Declare a new layer:

    var blueMarbleLayer = new ol.layer.Tile({ 
      source: new ol.source.TileWMS({
        url: 'http://maps.boundlessgeo.com/geowebcache/service/wms', 
        params: {
          'TILED' : true,
          'VERSION': '1.1.1',
          'LAYERS': 'bluemarble',
          'FORMAT': 'image/jpeg'
        }
      })
    });
  2. Then, declare a new view:

    var view = new ol.view({
      projection: 'EPSG:4326',
      center: [-1.81185, 52.44314...