for geocluster, i was looking for a way to add the cluster information to data provided by views_geojson.
the attached patch adds a views_geojson_render_fields_alter which i currently use in a working draft of my geocluster module.
also note, that i successfully use the bounding box strategy with leaflet.
i'd be happy to hear your thoughts on my approach to clustering and the related views_geojson integration.
also see #1547610: Plan server-side geo clustering for drupal 7
more general thoughts on integrating geocluster with views are posted here: #1791796: Allow to inject a custom aggregation implementation
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | views_geojson-1799870-7.patch | 406 bytes | basvredeling |
| views_geojson_render_fields_alter.patch | 497 bytes | dasjo |
Comments
Comment #1
clemens.tolboomYou should use module_invoke_all
Isn't there a more general hook_field_alter available in views context? Maybe I'm just garbling ;)
Comment #2
clemens.tolboomYou could add some documentation just before the _alter call too.
Comment #3
dasjohi clemens,
ad #1: module_invoke_all doesn't help, because it doesn't accept arguments being passed by reference. alternatively drupal_alter would be an option, but it only allows 2 (+1 deprecated) argument to be passed. in the end, i think the current implementation is most straight forward.
ad #2: it says, "Let modules modify the data". i guess that's what it does.
Comment #4
pol@dasjo, Is this the only way to achieve this ? There are no cleaner way using views hook ?
Comment #5
basvredelingI think the only applicable views hook here could be hook_views_post_render. But that will likely be slower in many cases because you're altering already rendered output and doing an extra iteration over the results to access individual rows.
Regarding the proposed solutions:
Finally there is #2370471: Make patching Views GeoJSON obsolete. That takes a different approach that looks pretty solid. But it probably also requires a rewrite of non-leaflet js to catch clustering properties.
Comment #6
mpgeek commentedAlso related is #2578785: Large-scale location mapping in Drupal 8 (Views).
Comment #7
basvredelingHere's a patch containing the drupal_alter implementation. I'm also submitting an issue at the geocluster issue queue to properly implement the alter hook.
As a side note: I think this hook should be named hook_views_geojson_feature_alter() instead, because we're altering a "$feature", not a "$render_fields", within the contexts $view and $row. That's why I renamed the hook. This'll break the already broken geocluster implementation. See: #2370471: Make patching Views GeoJSON obsolete and http://cgit.drupalcode.org/geocluster/tree/geocluster.module#n169
Comment #8
basvredelingComment #9
basvredelingchanged title to match patch in #7