Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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?
Comment | File | Size | Author |
---|---|---|---|
#18 | leaflet_geolocation_views-2720901-18.patch | 3.45 KB | alarcombe |
#16 | Leaflet Map Render.jpg | 202.95 KB | VBN |
#16 | Leaflet Map view.jpg | 67.4 KB | VBN |
#14 | leaflet_geolocation-2720901-14.patch | 4.2 KB | flocondetoile |
Comments
Comment #2
RdeBoerYou 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.
Comment #3
VBN CreditAttribution: VBN as a volunteer commentedHad 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!
Comment #4
Frando CreditAttribution: Frando as a volunteer commentedHere's a patch that makes the leaflet field formatter work with geolocation fields.
Comment #5
juliencarnot CreditAttribution: juliencarnot commented@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!
Comment #6
VBN CreditAttribution: VBN as a volunteer commentedI notice this request is still unassigned, can this be implanted in the next release of the alpha version?
Thx.
Comment #7
flocondetoileThe 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.
Comment #8
juliencarnot CreditAttribution: juliencarnot commentedThanks 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!
Comment #9
pvhee CreditAttribution: pvhee at Marzee commentedThanks all for the patches. Looking at the usage stats of Geolocation for Drupal 8 I think we should definitely integrate this with Leaflet:
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?
Comment #10
juliencarnot CreditAttribution: juliencarnot commentedThanks 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
Comment #11
VBN CreditAttribution: VBN as a volunteer commentedThank 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.
Comment #12
potassiumchloride CreditAttribution: potassiumchloride commentedAny chance we could get a backport to Drupal 7?
Comment #13
Carlos Miranda Levy CreditAttribution: Carlos Miranda Levy as a volunteer commentedI'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).
Comment #14
flocondetoileAttached a reroll patch which contains #4 and #7.
To be reviewed and tested.
Comment #15
flocondetoileComment #16
VBN CreditAttribution: VBN as a volunteer commentedI 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)
Comment #17
VBN CreditAttribution: VBN as a volunteer commentedOh, 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.
Comment #18
alarcombe CreditAttribution: alarcombe commentedThis patch enables geolocation fields to work with leaflet_views.
Comment #19
SocialNicheGuru CreditAttribution: SocialNicheGuru commentedre-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);
Comment #20
SocialNicheGuru CreditAttribution: SocialNicheGuru commentedComment #21
lbrassaw CreditAttribution: lbrassaw as a volunteer and commentedHas 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.