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 custom projection with WMS sources


In this part, we will see how to display the WMS image coming from the authority responsible for geology maps in France, the BRGM (equivalent to USGS to simplify):

  1. Let's copy the usual template into the sandbox directory but do not forget to include, in this case, the reference to Proj4js JavaScript library before the ol3.js file.

  2. Go within the <script> tag and declare the additional projection for local projection, in this case, Lambert 93, an official projection for France:

    proj4.defs("EPSG:2154","+proj=lcc +lat_1=49 +lat_2=44 +lat_0=46.5 +lon_0=3 +x_0=700000 +y_0=6600000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs");
  3. Declare the extent and the projection reusing your knowledge about declaring custom projection:

    var extent = [-378305.81, 6093283.21, 1212610.74, 7186901.68];
    var projection = ol.proj.get('EPSG:2154');
    projection.setExtent(extent);
  4. Declare an array with one layer using a source providing a WMS-projected...