GeoExt has Legend capability but is is quite basic which shows only feature types like in example http://api.geoext.org/1.0/examples/legendpanel.html. How could it be modified display legend with count(no of values)?

enter image description here

I am using geoserver to serve map and using geoext.

The solution I am looking for is to add this feature into legend panel (may be through modification of javascript source) and not make my own solution. Any path, direction code for this would be appreciated.

2 Answers 2


To get the number of features from a layer in the server you need to use the WFS (Web Feature Service) request. You will need to call GetFeature and set the parameter resultType to hits (resultType=hits). This will just give you an integer count of the number of features you've requested (as opposed to returning all the features, as a GetFeature request using resultType=results would).

  • could you please provide any example??
    – kinkajou
    Feb 10, 2012 at 11:09
  • Here's an example request. I don't have a server to hit right now, so this may not be fully formed, but it's close: yourdomain.com:8080/geoserver/…
    – the_skua
    Feb 10, 2012 at 14:17
  • I don't have an example of how to modify legend panel to pull in the hits, that will take some customization on your end.
    – the_skua
    Feb 10, 2012 at 14:17
  • I got the xml response but I want the number of hits according to the thematic layer and not the total count i.e same layer can have two or more property. For example polygon can be red and blue different count for red and blue.
    – kinkajou
    Feb 11, 2012 at 8:15
  • 1
    Then in that case you've got to pass in a filter for each attribute of the thematic element you want to query the number of hits for. They'll have to be separate requests. Here's an example filter request that would make your notion: &filter=(<Filter><PropertyIsEqualTo><PropertyName>polygon</PropertyName><Literal>blue</Literal></Filter>) Check the OGC specs on filters. There's a lot there.
    – the_skua
    Feb 11, 2012 at 18:12

This is extremely dependent on how you're pulling data onto a map. The example you point to is from a WMS server that serves legend images which are combined with layer names to create a legend.

If you're going that route and are using a WMS server, this question doesn't really touch GeoExt or anything on the Javascript level: you'll need your WMS server to deliver the number of features in the layer, and then it's easy to add that into your legend.

If you're doing a layer from another source, like XYZ tiles or vector data, the answer is entirely different - so please expand your question.

  • I am using geoserver and it's features. I thought there is something easy way to add legend with feature count with openlayers or geoext or any library.
    – kinkajou
    Oct 17, 2013 at 5:08

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.