I have created a group of shapefiles using QGIS and I have stored their corresponding information in PostGIS database by importing the shapefile into pgAdmin3 using shapefile and DBF loader. Then I imported the whole PostGIS database to GeoServer. It works fine using OpenLayers link in layer preview option of GeoServer. The attribute values are showing up in tabular form when I click on each object.

What I need now is to create a web based application using Leaflet or OpenLayers where the attribute value is showing as pop-ups and I want the facility to add more shapefiles/PostGIS table dynamically.

1 Answer 1


Here is a code sample to show how you could publish a WMS layer hosted on geoserver in Leaflet:

var map = L.map('map').setView([51.505, -0.09], 8);
var forest2000 = L.tileLayer.wms("http://138.26.24.xxx:8080/geoserver/tiger/wms",{
    layers: 'forest2000',
    format: 'image/png',
    transparent: true,    
    opacity: 0.7       

Change this to match to the url of your geoserver instance. The working openlayers examples you mention above will help you to figure out what url and path to use.

If you want to get attribute values from feature clicks (getFeatureInfo), check out this code snippet using "BetterWMS": https://gist.github.com/rclark/6908938

  • Thanks for the answer. The above code snippet works fine But the link you provided is not working well... the map is loading, but not the layers
    – Kc Yoosuf
    May 26, 2015 at 11:54
  • L.TileLayer.BetterWMS is meant as a general approach to getting feature info from a wms server, not a live demo, and I don't have control over the wms server used in that example (you could contact the owner of that gist, or leave a comment there). In any case, you would want to use your own wms tiles.
    – toms
    May 26, 2015 at 16:30
  • Is there any method to get the attribute values via PostGIS and display it in the pop-up ?
    – Kc Yoosuf
    May 26, 2015 at 17:31
  • 1
    Yes, but that is a much different problem (you can ask a new question). Presented here is a Leaflet implementation of GetFeatureInfo which is a specific type of operation you can use with a single WMS layer to get information for a pixel location on a map.
    – toms
    May 26, 2015 at 18:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.