I think we should make center a required parameter in hook_leaflet_map_info().

Comments

joelrosen’s picture

I'm also looking at this problem.

A map view should have some way to display a default map even if no results are returned from the view. I think there's two ways you could go on this:

1) Provide a "No Results Behavior" plugin that lets you select a map to render if there are no results. The user can then be responsible for specifying "center" in hook_leaflet_map_info(). That would work fine but it seems a little silly to have to define two maps, one for a view with results and one that specifies "center" for no results.

2) Add some more configuration options to the map display plugin, something the likes of:
- Center (lat + lon)
- Zoom
- Initial viewport behavior (select from "fixed -- use center and zoom", or "auto -- use fixed center and zoom only for no results")

I'm willing to write a patch for either way, but can the maintainers provide some direction on this? #1 might be nice to have, since a no results behavior plugin might be a nice addition anyway. #2 might be more user-friendly, but then again it might be bloating up the configuration options and starting to look more like the OpenLayers module, which is probably not the direction you want to go.

joelrosen’s picture

Title: Leaflet doesn't display a map when its center is not specified » Leaflet doesn't display a map when its center is not specified or a View contains no results
Status: Active » Needs review
StatusFileSize
new4.02 KB

Heh, again, I figured it would be easy and doesn't interfere with existing configuration so I went ahead and wrote a patch for #1.

The patch adds a Views area handler that renders a map, very simple. I also added some helpful comments to leaflet.api.php that instructs users how to define 'center' for maps that don't auto-focus or have no results. You might consider it a temporary solution to this issue.

mstrelan’s picture

Issue summary: View changes

Nice work on the views handler, but the default position should not be hardcoded in to the module and users should not have to modify module code. Perhaps the views handler could allow you to set the default position? Or like the gmap module, leaflet could have a global setting for this.

jmev’s picture

Does using the views area to display this same view in it for no results cause some kind of a looping situation, where the user may try and run the query again from the nested view and confuse ajax or views even further?

labboy0276’s picture

Version: 7.x-1.x-dev » 7.x-1.4
StatusFileSize
new4.06 KB

Here is the same patch against 1.4

labboy0276’s picture

StatusFileSize
new4.12 KB

The patch in #5 is failing on the info, here is a better patch, sorry.

jenlampton’s picture

Status: Needs review » Needs work

I think it would make more sense if the map settings asked for a center (similar to geofield_map) and then appeared all the time -- even when there were no results. There's already a Hide empty checkbox: Hide the Leaflet map if there are no results to display. If that box is checked then the map should be hidden, if not, it should display. Shouldn't that be fixed? I'm not sure I understand the approach taken here.