[GIS] How to bring the PostGIS map from GeoServer to Leaflet based web application

geoserverleafletpgadmin-3postgis

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.

Best Answer

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       
}).addTo(map);

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

Related Question