I spent some time trying to figure out how to make the 'Global: View result counter' work as marker labels. There were a few problems.
This is how I solved the problem:
* I am using the most recent version of Open Layers which has strk's dynamic styles.
* The Views field for the View result counter provides an attribute 'counter' - only the attribute ${counter_rendered} is available.
* One problem is that since this is a Views global field, it had an 'unknown' field alias. If you also use 'Custom Text' or any location fields, I noticed there were some little problems that seem to do with unaccounted for field data getting shoved into 'unknown' - however, when OpenLayers rendered fields, it will read through all the fields and count 'unknown' as processed.
To fix that problem, the field needs a field alias. The best place I could think to add the field alias was in the 'views_handler_field_counter.inc' in Views module. Then the alias will be counter & the attribute will be available as expected.
The other problem is that the counter handler needs the row_index to actually do its counting. To fix that problem, the map_features function in 'openlayers_views_style_data.inc' needed to set the row_index.
Attaching two patches, one for views, and one for OpenLayers.
I know this will *fix* the problem, but in terms of proper use of the Views API and if these are the best places to add the data...I'm not totally sure. If patching Views is too much of a pain, the OL could probably look to see if the handler is the one for the 'counter' - since there are probably only 2 'unknown' views fields.
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | views_handler_field_counter_openlayers-905830.patch | 1015 bytes | chachasikes |
| #1 | openlayers_views_style_data-905830.patch | 544 bytes | chachasikes |
Comments
Comment #1
chachasikes commentedHere are two patches, one for views, one for OL.
I welcome suggestions about the right way to approach this.
Comment #2
chachasikes commentedoh, and to actually set this up...
In your style, set the label attribute style to ${counter_rendered} - and set the label offset, font etc. These are new feature that were recently committed to the dev version of OpenLayers.
The syntax ${counter_rendered} - that is Open Layer's replacement syntax (it took me a long time to figure out that I needed to use this, and then zzolo explained what it actually is to me)
In the Views data display settings, the 'Attributes & Styles' drop down shows which attributes are supposed to be available, assuming you do not exclude them, or there are not problems, as seen here in this issue.
Comment #3
zzolo commentedHi @chachasikes. Thanks for the patches.
The row index thing is pretty straightforward and something to put in easily.
As far as the alias, this is a bigger problem. See this as well: http://drupal.org/node/840998
I think the problem at hand is that we should not actually be using the field aliases. I decided to use these originally because they are much easier to reference and more easier on the eyes. But given this issue and the other, it is better to use a unique ID.
So, I am going to make the focus of this ticket for adding the index into the view, and then move the alias problem to that other issue.
Also, there is some documentation currently. We would always love more. :)
http://drupal.org/node/754480
Comment #4
zzolo commentedThis (the OL part) is currently in the 7.x dev version.