Book Image

OpenLayers 3.x Cookbook - Second Edition

By : Peter J. Langley, Antonio Santiago Perez
Book Image

OpenLayers 3.x Cookbook - Second Edition

By: Peter J. Langley, Antonio Santiago Perez

Overview of this book

OpenLayers 3 is one of the most important and complete open source JavaScript mapping libraries today. Throughout this book, you will go through recipes that expose various features of OpenLayers 3, allowing you to gain an insight into building complex GIS web applications. You will get to grips with the basics of creating a map with common functionality and quickly advance to more complicated solutions that address modern challenges. You will explore into maps, raster and vector layers, and styling in depth. This book also includes problem solving and how-to recipes for the most common and important tasks.
Table of Contents (14 chapters)
OpenLayers 3.x Cookbook Second Edition
About the Authors
About the Reviewer

Creating an image layer

Sometimes a tiled layer, such as Bing Maps, OpenStreetMap, or from WMS services, is not what you need. You may have access to a georeferenced image or know of a server that can return an image for arbitrary extents and resolutions.

In these cases, OpenLayers offers the ol.layer.Image class that allows us to create a layer that is based on an image. For this recipe, we hook up to a WMS service that returns a single image on request for a given bounding box. The source code can be found in ch02/ch02-image-layer/.

This recipe will use the ol.source.ImageWMS source class to connect to the WMS server. However, if you have a static georeferenced image, then you should use ol.source.ImageStatic, which works in much the same way.

How to do it…

To create an image layer, perform the following steps:

  1. Create an HTML file with the OpenLayers dependencies and a div for the map container.

  2. Within your custom JavaScript file, create an extent, which will be used to center the map and restrict...