Book Image

PostGIS Cookbook

Book Image

PostGIS Cookbook

Overview of this book

Table of Contents (18 chapters)
PostGIS Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Consuming WMS services with Leaflet


In the previous recipe, you have seen how to create a web page with a map using the OpenLayers JavaScript API and then added to the map the WMS PostGIS layers implemented with MapServer and GeoServer in the first two recipes of this chapter.

A new, lighter alternative to the widespread, venerable OpenLayers JavaScript API has emerged in the last couple of years, named Leaflet. In this recipe, you will see how to use this JavaScript API to create a map in a web page, add a MapServer WMS layer from PostGIS to this map, and implement an identify tool sending a GetFeatureInfo request to the MapServer WMS (unlike OpenLayer, Leaflet does not come with a WMSGetFeatureInfo control).

How to do it...

Carry out the following steps:

  1. Create a new HTML file and name it leaflet.html. Open it and add the <head> and <body> tags. In the <head> section, import the Leaflet CSS and JavaScript libraries and the jQuery JavaScript library (you will use jQuery to...