Adds support for:
* Views
* Select field for popup text
* Mark multiple layers as visible
* Marker image path fix

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

cescosa’s picture

+1

dasjo’s picture

rerolled the patch to current 7.x-1.x branch

here's a screenshot of this working
leaftlet views patch screenshot

also attached a leaflet test feature module that includes a place content type and a leaflet_test views that uses the leaflet_views_plugin_style

rerooting’s picture

Im trying to get the #2 patch working, and I'm running into some issues.

I made the content type and view myself rather than using the feature module. What happens is mostly specific to the style options. The first time I saved the style option, for whatever reason, no datasource came up (I had however set things up with geofield at the time).

When I go back and try to manipulate the style options again, not only do I not get a datasource, but when I got around to hit update, views spews out a json string (i reckon something regarding the required field is conflicting with the views_ui AJAX I am guessing).

I would spend some time debugging this, however I was merely testing the capability of the module as we were working it into a scope of work that is very much due today! If you have any issues duplicating the issue, I can help later tonight likely. Also, FYI, I applied the patch against the latest 7.x-1.x git branch.

geografa’s picture

I get the same json output after updating as well. This happened before the patch, however. Not sure how I fixed it but now it's back.

dasjo’s picture

hm, the procedure mentioned above worked for me so far

maybe you want to try if the feature works?
i don't think there should be any differences to the patch i posted, but you can also try the 7.x-1.x-views branch of my sandbox: http://drupal.org/sandbox/dasjo/1408378

levelos’s picture

Status: Needs review » Needs work

This is great, thanks @dasjo. I think I'd prefer to see Views integration in a submodule, E.g., modules/leaflet_views. Any chance you'd be up for re-rolling this patch in that format? The patch also mixes in a few other issues, potentially very legit ones. Lets keep those separate and address them in their own tickets here in the queue.

FWIW, I did some cleanup this morning and plan on rolling an alpha1 release as we need a tag to use against some projects we're deploying.

dasjo’s picture

having views integration in a submodule sounds good, i will see if i can re-roll the patch those days...

dasjo’s picture

Status: Needs work » Needs review
FileSize
5.43 KB

here's the patch which adds views integration as an optional submodule.

dasjo’s picture

we might also want to integrate with views_geojson
#1370448: Provide GeoJSON Layers from Views (integrating with views_geojson)

kvit’s picture

When enabling Leaflet views module from #8 get this:

Warning: include_once(.../sites/all/modules/leaflet/leaflet_views.views.inc) [function.include-once]: failed to open stream: No such file or directory in _theme_process_registry() (line 549 of .../includes/theme.inc).
Warning: include_once() [function.include]: Failed opening '.../sites/all/modules/leaflet/leaflet_views.views.inc' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in _theme_process_registry() (line 549 of .../includes/theme.inc).

The error disappears when reloading Modules list page and a view with leaflet map format works fine.
I think it's an essential feature for most users, so, I vote for including #8 to dev and posiibly making alpha 2 release with it ASAP.

dasjo’s picture

i can reproduce the errors from #10 but i really don't know why this happens

the declaration in the leaflet_views.info file should be fine
files[] = leaflet_views.views.inc

pribeh’s picture

Adding the following related issue link here just in case anyone workin on views integration has any ideas about working with multiple layers:

http://drupal.org/node/1443206

Thanks to hse and dasjo for getting a head start on views integration.

laurencemercer’s picture

Just wanted to say thanks for the Views efforts here! I've been testing mapping solutions for a current project and now have Leaflet and MapBox streets tiles working with Views and exposed filters (I'm using Addressfield, Geofield, and Geocoder to create the geo data).

During testing I ended up re-working the leaflet_views module a little bit, and thought I'd share what I found. Word of warning: I'm no Views expert - just a tinkerer ;)

  • 1.
    I created an 'includes' folder, moved leaflet_views.views.inc into the 'includes' folder, and split leaflet_views_plugin_style, which was previously in leaflet_views.views.inc, out into its own file (also in the 'includes' folder). As I understand it, this is the preferable structure. So, I now have:

    leaflet
    -leaflet_views
    --leaflet_views.info
    --leaflet_views.module
    --includes
    ---leaflet_views.views.inc
    ---leaflet_views_plugin_style_leaflet.inc

    I also renamed all instances of 'leaflet_views_plugin_style' to 'leaflet_views_plugin_style_leaflet'. Views plugin naming seems a bit of a dark art, but I think this is the prefered naming convention.

  • 2.
    Regarding the warning mentioned in #10, I got the same thing. It looks to be an issue with the path which is declared in leaflet_views_views_plugins(). Currently it's using:
    'path' => drupal_get_path('module', 'leaflet'),
    

    but I changed that to

    'path' => drupal_get_path('module', 'leaflet_views') . '/includes',
    
  • 3.
    Also in leaflet_views_views_plugins(), I removed the
    'module' => 'leaflet',
    

    line. I don't think that's necessary (though I couldn't find documentation to confirm).

  • 4.
    I then modified leaflet_views.info like so:
    name = Leaflet views
    description = Views integration for the Leaflet module.
    core = 7.x
    dependencies[] = geofield
    dependencies[] = leaflet
    dependencies[] = views
    files[] = includes/leaflet_views_plugin_style_leaflet.inc
    
  • 5.
    In leaflet_views.module I changed:
    'path' => drupal_get_path('module', 'leaflet_views')
    

    to

    'path' => drupal_get_path('module', 'leaflet_views') . '/includes',
    

    However, I'm sure I remember reading somewhere that Views will automatically look for a 'modulename.views.inc' file in a folder called 'includes', so I don't think that this line is actually strictly necessary.

Anyway, I hope that's helpful :)

luka.oman’s picture

Sorry for a trivial question but since there has not been any status report or timeline when this added support will be added to the module itself, I would like to ask you how to add this patch to the module, so even casual people could use it in views.
Thank you and regards;
Luka

pvhee’s picture

levelos, I would be interested to help support this module; I am further refactoring the Views integration with the patch from #8 to have it work with Display Formatters as well (so you can use e.g. Display Suite to theme the balloons).

I'd be looking at contributing it into a clean patch, but if I can get commit access I'll help out with new features/maintenance.

pribeh’s picture

+1 to add pvhee as a co-maintainer.

rerooting’s picture

+1 on that as well, i would love to see views support for this module!

jpstrikesback’s picture

@pvhee, just wondering if you've made progress on the display formatters end of things?

Cheers!

pvhee’s picture

I'm planning to spend the day on Views + display formatters integration during the Barcelona Dev Days (http://groups.drupal.org/node/234168). All patches will go back to this queue.

jpstrikesback’s picture

Heh heh, that was a quick response :) Look forward to it, cheers!

pvhee’s picture

Attached a reworked patch to provide Views integration for Leaflet as a submodule.

Contains some general cleanup (e.g. no warnings appear as mentioned in #10) and refactoring.

The new patch has support for node display modes (similar to what OpenLayers provides): you could use the teaser/full content modes of a node to fill out the popup, or could use Display Suite to style the content of the popups rather than working with Views fields.

Make sure also to apply #6 from #1621688: Geofield Formatter Error re: GeoPHP.

Thanks a lot to dasjo for organizing the mapping sprint at the Barcelona Drupal Developer Days

vcardoso’s picture

Tested on a sandbox site, and it works like a charm!
Just had to activate the "new" Leaflet module (was not obvious at start) and everything rolled on.

rerooting’s picture

I'll be testing it today as well, very exciting! I plan on using this for 3 projects this week. I'll make sure to report any bugs that come up.

Would be great to get this and http://drupal.org/node/1621688 #4/#6 committed as soon as possible, potentially rolled into a new full release? I'd love to help with that wherever I can, including testing other patches that are needed for the next full release.

Thanks a bunch to pvhee, dasjo and everyone else who was involved in the mapping sprint!

levelos’s picture

@pvhee, just added you as a maintainer on the module, congrats! Really glad to see all the energy around this and certainly don't want to stand in the way. I'm on vacation with my family this week so have very limited availability, so will review things as I can.

If we can tackle major initiatives in feature/issue branches to make review easier, that'd be great as well. Thanks gang and looking forward to seeing the improvements coming out of the sprint and beyond.

pvhee’s picture

@levelos Thanks a lot, I'll be pushing over the code along the weekend, and we can review other outstanding issues as well.

After the Views integration is in, we should probably put out an alpha2 release?

pribeh’s picture

My two cents: alpha2 release after http://drupal.org/node/1446418 is resolved.

pvhee’s picture

@pribeh: I'd separate that out into a (possible) alpha3 release, so we can push Views integration faster.

I'll be taking the time to review the other parts of the issue queue as well, so we can combine all the good work that has been done and make subsequent alpha releases. Then, once that is all in an tested, we can make a beta/official release.

pribeh’s picture

@pvhee, totally makes sense.

pvhee’s picture

Status: Needs review » Fixed

#21 is commited, and about to roll out an alpha2 release with an updated README.

I'll be using proper Git attribution for future patches, but the patch was done by multiple people, and it seems we cannot use git commit --author for this? http://drupal.org/node/1146430#comment-4773114

dasjo’s picture

great work!
yeah, it seems you can only specify a single author using git attribution and add the other names in the comment

sahaj’s picture

I'm not getting any map output in my view with the last dev version, while I had it working with the patch.

Am I missing something?

batigolix’s picture

Status: Fixed » Needs work

I'm also getting a blank page. The view seems not to render.

I fiddled a bit with the settings and it seems it is caused by the settings of the Leaflet Map format in views

If you leave the field Description Content empty then the view stays blank. If you assign a value then the view works.

So maybe the field Description Content should be required and have a default value ...

dasjo’s picture

FileSize
6.41 KB

i encountered the same blank page issue.

when using "entire node" + teaser or full-node for description, the maps is blank as shown above.
see the attached views export.

when using "entire row" for description, the map will show up, but popups don't work + it shows

Notice: Undefined index: #row in leaflet_views_plugin_style->render() (line 164 of /Applications/MAMP/htdocs/leaflet/sites/default/modules/leaflet/leaflet_views/leaflet_views_plugin_style.inc).

pvhee’s picture

Assigned: Unassigned » pvhee
Status: Needs work » Needs review

I've confirmed the blank page, and the reason was that we do not render anything when description was not set, as mentioned by batigolix.

Committed code (http://drupalcode.org/project/leaflet.git/commit/16b213a) to address two things:

  • show only the points on the map when no description is set, but do not fill in the pop-ups
  • removed support for rendering ''. This was code copied from OpenLayers, and unless we integrate it properly, it shouldn't be in the module. Open a new issue if you need support for rendering entire rows.

Please review the code, but it solved all the mentioned issues in my sandbox.

dasjo’s picture

using "entire node" still doesn't work for me. i have added the views export in #33.

as a side-note, there are some spaces in empty lines in the code. there is a nice tool that allows checking code-style, also online: http://drupal.org/project/pareviewsh

adamdicarlo’s picture

Views support is working for me. There's a huge pitfall, however, that took me a couple of hours to figure out:

In the view, don't use the Leaflet formatter on the Geofield. Doing so causes the field to be formatted (invoking leaflet_render_map()) which is bad news because it spits out JavaScript settings for a map you don't actually want to show (you don't want to show an individual map for each node), and latter calls to leaflet_render_map() don't change the JavaScript settings due to how drupal_add_js(_, 'setting'); works.

So if you get a blank map and a JavaScript error that says "Uncaught TypeError: Cannot read property '_leaflet' of null", there's your problem.

pvhee’s picture

@dasjo: the 'entire node' is working for me with your View (and replacing the content type filter).

@adamdicarlo: good point, you indeed need to use the WKT / lat/lng formatters for the geofield, if not a Leaflet map is generated for each field which will conflict with the map created by the style. Not sure how to change that though, but we should probably remove the leaflet formatter view when the leaflet style is used.

adamdicarlo’s picture

Just found a bug: Same content in each pop-up.

Every location I clicked was showing the same thing in the pop-up. After doing some digging I figured out why: the $raw_data array just keeps accumulating geofield values every time through the loop. Not good!

Here's the one-liner fix.

pvhee’s picture

Status: Needs review » Fixed

Thanks adamdicarlo, this is now committed.

Closing issue, please file separate issues for the views integration so we can track them better.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.