Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have geoserver serving shapefiles as a WMS into Leaflet.

I'd like to add interativity that shows a popup with WMS attributes in the Leaflet map when the user hovers over or clicks on a WMS feature.

I've seen the wax/leaflet interactivity, but is that possible with WMS and Leaflet?

share|improve this question
up vote 13 down vote accepted

You should try using WMS GetFeatureInfo. Here's an example with Leaflet made available Bryan McBride. The event used for triggering the GetFeatureInfo request is onclick.

share|improve this answer
Thanks that's just what I needed. – zarbo Sep 14 '11 at 16:05
Now I'm working on formatting the GetFeatureInfo data with Geoserver Freemarker templates. Any thoughts on a Leaflet hover/mouseover interaction? – zarbo Sep 14 '11 at 16:18
As shown in the example you should try changing the event passed to the onMapClick function: line 41 » map.addEventListener('click', onMapClick); I think you should take a look at the documentation page: Regarding the Geoserver freemarker templates I never used it, but it makes more sense to me to make a WFS GetFeature request asking for the response to be formatted in GeoJson instead of the WMS GetFeatureInfo. With that GeoJson object in the client side is far more easy to build a simple HTML markup to display the feature(s) data. – Pedro Mendes Sep 14 '11 at 23:54
Sorry.. There's no way of making a GetFeature with Leaflet.. :/ Even though you could use the GeoJSON layer for the same effect (the feature's attributes are already accessible on the client). But that's I love OpenLayers =). – Pedro Mendes Sep 15 '11 at 0:02
@PedroMendes The link to the example is unfortunately broken. Could you please update it? – ustroetz Jun 4 '14 at 8:22

I get Leaflet interactivity in two ways, depending on how big the dataset is. I would recommend against WMS getFeatureInfo, because the styling is all set server-side, which is tedious to configure. So, here's my two ways:

  1. If the dataset is small, just load the whole thing as a vector (do the request as JSONP or JSON if you have CORS enabled). For example: and code:
  2. If the dataset is large, do an onClick request and return vectors for near features (using JSON or JSONP). Example: and code:

(That stormwater example is a little more complex than it really needs to be because I change whether a layer is interactive when the layers are turned on and off...)

share|improve this answer
Note that WMS GetFeatureInfo can return JSON now. – Alex Leith Apr 15 at 5:06

Here's a small plugin which achieves this well:

If you're using a leaflet version greater than 0.7.3, this is another good plugin to do the on click identification within WMS layers:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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