Consuming WMS services with Leaflet
In the previous recipe, you have seen how to create a webGIS using the OpenLayers JavaScript API and then added the WMS PostGIS layers served from MapServer and GeoServer .
A lighter alternative to the widespread OpenLayers JavaScript API was created, named Leaflet. In this recipe, you will see how to use this JavaScript API to create a webGIS, add a WMS layer from PostGIS to this map, and implement an identify tool, sending a GetFeatureInfo
request to the MapServer WMS. However, unlike OpenLayers, Leaflet does not come with a WMSGetFeatureInfo
control, so we will see in this recipe how to create this functionality.
How to do it...
Carry out the following steps:
- Create a new HTML file and name it
leaflet.html
(available in the book source code package). 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 send an AJAX request...