I try to make this Leaflet module work with the Geolocation Field module.
But for some reason it does not grab my coordinates from this module, the map stays empty when creating a view.

How to integrate?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

VBN created an issue. See original summary.

RdeBoer’s picture

You need the Geofield module, http://drupal.org/project/geofield, for coordinate storage. Not Geolocaton Field.
When you use Leaflet in combination with IPGV&M (http://drupal.org/project/ip_geoloc) then you can use Geofield or Geolocation Field.
However, IPGV&M has not yet been ported to D8.

VBN’s picture

Had some issues and errors with the geofield module and gave up that approach.
Decided to go with geolocation field instead. Maybe a bad mistake, I'll see later.

Yes indeed, really miss the IPGV&M, top module!
When, oh when will it be ported :)

Ff doorbijten!

Frando’s picture

Version: 8.x-1.0-alpha1 » 8.x-1.x-dev
Component: Miscellaneous » Code
Status: Active » Needs review
FileSize
1.22 KB

Here's a patch that makes the leaflet field formatter work with geolocation fields.

juliencarnot’s picture

@Frando: you, Sir, just made my day. Your patch works well on dev branch and geolocation_field 8.x-1.5 for a field display on a node. It just seems like the field display set height is not applied, resulting in an invisible map, unless I add a css height property.

Any chance we can extend this compatibility to leaflet_views ? I gave it a try but no markers show on the map...

Anyways, thanks VBN for asking and Frando for submitting this patch!

VBN’s picture

I notice this request is still unassigned, can this be implanted in the next release of the alpha version?
Thx.

flocondetoile’s picture

The patch attached provide basic support for geolocation field in leaflet views. With the patch #4, we can get basic support in leaflet for geolocation field.

It's more a proof of concept than a patch to be committed, but it works even if this seems to me a little bit tricky (and I am not an export of geolocation field, so I can miss other parameters or use cases). Anyway I understand that leaflet support only geofield field for coordinate storage.

I let maintainers close this issue (works as designed) or go further on the subject.

juliencarnot’s picture

Thanks flocondetoile, I got a view working with the "Leaflet Old" style, but it does seem a bit tricky. It might be related to the general status of leaflet_views though, as its refactoring is still underway (see https://www.drupal.org/node/2745851 )

I also spotted a if ($field_storage_definition->getType() == 'geofield') { in leaflet/leaflet_views/src/Plugin/views/row/LeafletMarker.php that might need the same changes, but I'm not sure what it does...

I don't how this integration should be carried out and if geolocation and geofield are to continue their separate path in the very long run, but this is a great feature for users of geolocation_field that want to benefit from Leaflet's advantages!

pvhee’s picture

Status: Needs review » Needs work

Thanks all for the patches. Looking at the usage stats of Geolocation for Drupal 8 I think we should definitely integrate this with Leaflet:

  1. Geolocation has +2300 usage for D8 (from https://www.drupal.org/project/usage/geolocation)
  2. Geofield has +700 usage for D8 (https://www.drupal.org/project/usage/geofield)

I'd like to see Views support for geolocation as well in this patch and combine patches #4 and #7. Can this be re-rolled for the dev version of Leaflet?

juliencarnot’s picture

Thanks pvhee!

Seems like this interest for integration is shared by Geolocation maintainers, maybe you've seen these issues and discussions:
Add a Leaflet map formatter and widget
Enable multiple map providers

VBN’s picture

Thank you so much pvhee for your stats.
I experienced that geolocation is much easier in use and more stable then geofield.
It basically does the same, but for D8 geolocation has a significant advantage out of the box.
Great news for compatibility.
Looking forward.

potassiumchloride’s picture

Any chance we could get a backport to Drupal 7?

Carlos Miranda Levy’s picture

I'm happy to report that both patches still work for version 8.x-1.0-beta1 (2016-Oct-03) as of 2016-Dec-8.

+1 for integrating both patches in the stable and dev versions.

Geofield remains with a limited and incomplete list of features for Drupal 8, in particular when it comes to geocoding text addresses and autocomplete of text addresses (and picking up a geolocation from another field). If your data is in lat,long format already, or if you are willing to enter lat/long manually yourself.

I just finished testing all geolocation modules available as of Dec. 8, 2016 for Drupal 8 and geolocation is the only viable option for entering locations from an address that are stored as lat/long and available to be displayed on a map, out of the box and without tweaking or patching. (you can check out my personal quick notes in Spanish here http://www.codigoslibres.com/drupal/8/setup/georeferenciacion if interested).

flocondetoile’s picture

Status: Needs work » Needs review
FileSize
4.2 KB

Attached a reroll patch which contains #4 and #7.
To be reviewed and tested.

flocondetoile’s picture

VBN’s picture

FileSize
67.4 KB
202.95 KB

I applied the #7 and #14 patch on the 8.x-1.0-beta and i have no issues.
The format view Leaflet is not working.
Displaying a map view with the format Leaflet Map (old) renders ok.
The geolocationfield is accepted in both formats, Digital degrees and DMS (sexadesimal)

view

Render

VBN’s picture

Oh, i forgot, to work easy, i created a Global: Custom Text field with a content like this:
{{ field_master_image }}<br>{{ title }}<br>{{ field_geolocation }}

And use as the Description Field in the Leaflet map Format settings for the icon popup.

alarcombe’s picture

This patch enables geolocation fields to work with leaflet_views.

SocialNicheGuru’s picture

re-roll needed

patching file leaflet.module
patching file leaflet_views/src/Plugin/views/row/LeafletMarker.php
Hunk #1 succeeded at 168 (offset 5 lines).
Hunk #2 FAILED at 245.
1 out of 2 hunks FAILED -- saving rejects to file leaflet_views/src/Plugin/views/row/LeafletMarker.php.rej
aegir@insitehost:~/platforms/drupal/8/servers/1-dev/sng-contrib/dev-social-8.x-1.9-drupal-8.4.4/html/modules/contrib/leaflet$ more leaflet_views/src/Plugin/views/row/LeafletMarker.php.rej
--- leaflet_views/src/Plugin/views/row/LeafletMarker.php
+++ leaflet_views/src/Plugin/views/row/LeafletMarker.php
@@ -245,15 +246,30 @@
* {@inheritdoc}
*/
public function render($row) {
- $geofield_value = $this->view->getStyle()->getFieldValue($row->index, $this->options['data
_source']);

- if (empty($geofield_value)) {
- return FALSE;
+ //@todo this is now super brittle.
+ $result = NULL;
+ $geo_fieldname = $this->options['data_source'];
+
+ if (get_class($this->view->field[$geo_fieldname]) == 'Drupal\geolocation\Plugin\views\fiel
d\GeolocationField') {
+ $geolocation_field = $this->view->field[$geo_fieldname];
+ $entity = $geolocation_field->getEntity($row);
+ if (isset($entity->{$geolocation_field->definition['field_name']})) {
+ $result = leaflet_process_geolocation($entity->{$geolocation_field->definition['field_
name']});
+ }
+ }
+ else {
+ $geofield_value = $this->view->getStyle()->getFieldValue($row->index, $geo_fieldname);
+ if (!empty($geofield_value)) {
+ // @todo This assumes that the user has selected WKT as the geofield output
+ // formatter in the views field settings, and fails otherwise. Very brittle.
+ $result = leaflet_process_geofield($geofield_value);
+ }
}

- // @todo This assumes that the user has selected WKT as the geofield output
- // formatter in the views field settings, and fails otherwise. Very brittle.
- $result = leaflet_process_geofield($geofield_value);
+ if (empty($result)) {
+ return FALSE;
+ }

// Convert the list of geo data points into a list of leaflet markers.
return $this->renderLeafletMarkers($result, $row);

SocialNicheGuru’s picture

Status: Needs review » Needs work
lbrassaw’s picture

Has this been added to the current version?

Salesforce doesn't seem to want to map to geofield with lat/lon, but will to geolocation lat/lon... alas, this would be a great feature addition.