There are two modules providing lat/lon storage in Drupal 8/8: geolocation and geofield. I went with geofield simply because geocluster is using it. geocluster clusters on the server side and that lets you display an astonishing amount of elements on a single map. While geolocation is mostly a single module, there’s an entire family of modules we will need here. Also, as far as I can tell, we are limited to leaflet here because I can’t find ready made geojson support for anything else.

  1. composer require drupal/geocluster drupal/views_geojson drupal/leaflet drupal/leaflet_geojson
  2. Add a geofield (NOT a geocluster — that’s a bug, a patch has been filed), I called it coordinates
  3. Add a view, no page, no block, nothing.
  4. leave the pager in place. We will remove it later.
  5. Add field Geocluster lat (coordinates). Leave aggregator settings on Group results together”.
  6. Add field Geocluster lon (coordinates)
  7. Add field Geocluster result count (coordinates)
  8. Add field coordinates and exclude it from display
  9. Add title and exclude it from display. Set aggregator settings to GROUP_CONCAT”.
  10. Remove sort criteria.
  11. Now add a GeoJSON export and in settings click Enable geocluster for this search.
    1. Set Map Data Sources to Other: Lat/Lon Point
    2. Set Latitute field to Geocluster lat (coordinates)
    3. Set Longitude field to Geocluster lon (coordinates)
    4. Set Title field to Title.
  12. Now magic has happened! If you set up Views to show the query, you will see GROUP BY node__coordinates_coordinates_geocluster_index_1 is the only GROUP BY left. This is why it works at all.
  13. You can now remove the pager.
  14. Add a Views GeoJSON: Bounding box contextual filter
    1. Provide default value
    2. Type: Query Parameter
    3. Query parameter: bbox
    4. Fallback value: -180,-90,180,90
  15. The leaflet_geojson module provides a block which miraculously (well, based on the GeoJSON export) will pick up up our views and it’ll just work.

August 28, 2020

Previous post
Our bug was views-view-field. Our bug was coming back empty for the entity API field on the node 80136. The template only prints the variable. Where is that coming from? In I
Next post
USB C is a physical connector. It has four high speed lanes and assorted tidbits: most importantly, power, a separate pair of wires for USB 2.0 and