Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 3 down vote accepted
+50

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).

share|improve this answer
    
could you please provide any example?? –  kinkajou Feb 10 '12 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 '12 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 '12 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 '12 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 '12 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.

share|improve this answer
    
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 '13 at 5:08

Your Answer

 
discard

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.