Create a view with a leaflet map display and an exposed filter with a default value. Ensure "use ajax" is set and the leaflet setting "hide if empty" is set. If the default exposed filter yields no results it all appears okay (ie. no map). If you change the exposed filter to a value that produces results an empty white space appears where the map would go. If, however, the default exposed filter yields at least one result, the map displays fine on initial load. Toggling then to another exposed filter value continues to work just fine. I can get around this by not ticking "hide if empty" but then I get a grey box where the map belongs.

I noticed that the following files aren't initially loaded if the map doesn't display.

  • leaflet.css
  • leaflet.js
  • leaflet.drupal.js

Which means libraries_load('leaflet'); is not being called initially, and probably not called on the ajax reload.

Is there a way to ensure the ajax load will load the leaflet library? If not, can we have a checkbox on the view to load the leaflet library regardless if there is a result or not?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mstrelan’s picture

Status: Active » Needs review
FileSize
2.11 KB
Steve Polito Design’s picture

I applied this patch, but am still not able to display a map if there are initially no results.

Hunk #1 succeeded at 59 (offset 24 lines).
Hunk #2 succeeded at 261 (offset 51 lines).
Hunk #3 FAILED at 340.
1 out of 3 hunks FAILED -- saving rejects to file leaflet_views/leaflet_views_plugin_style.inc.rej
  • Leaflet views 7.x-1.3+2-dev
  • Leaflet 7.x-1.3+2-dev
anewholm’s picture

note that this is an issue also if there are Required Filters and AJAX.

jmev’s picture

I see the issue mentioned in #3 as well. In fact, it appears that running exposed filters for valid results only works the first time, with subsequent attempts to run an altered filter doesn't do anything. I get the feeling ajax isn't behaving correctly. I'm needing to provide a solution son so I may need to drop ajax, as I can at least run a no-results redirect from the template file at that point, but when ajax is enabled, I get ajax errors, killing the execution of my code.