Downloaded v1.1.0 of the Leaflet library and couldn't get the module to recognize the version. Went and downloaded v1.0.3 and everything is working fine. Was there some sort of refactoring of Leaflet or am I missing something?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Train created an issue. See original summary.

mstrelan’s picture

Looks like 1.1.0 has a few API changes, but not sure if that affects the Drupal module. The leaflet.js file no longer containers the version number, so the module may need to be updated to look at leaflet-src.js instead.

jantoine’s picture

Version: 7.x-1.4 » 7.x-1.x-dev
Status: Active » Needs review
FileSize
895 bytes

This also exists in the 1.x-dev release. The attached patch makes the following changes:

  • Updates the download url pointing the the latest release
  • Updates the file used to the leaflet-src.js file (the leaflet-src.js file is included with the 1.0.3 release, but I didn't check previous releases)
  • Updates the pattern to include A-Z characters since the latest version includes 'HEAD' in the version.

I tested this using API calls and the example features in the documentation, and everything seemed to work, but I have not tested this extensively to see if other features are broken. I've also not tested this against releases older than 1.0.3.

heliogabal’s picture

I tested this against leaflet module 1.4 with library version 0.7.3 and 1.1.0 and 1.2.0. Here's my findings:

  • library recognition and map is working fine with 0.7.3
  • library recognition is only working fine with 1.0.3 once I copied all files from leaflet/dist/ to leaflet folder, but map is not working
  • library recognition is only working fine with 1.1.0 once I copied all files from leaflet/dist/ to leaflet folder, but map is not working
  • library recognition is only working fine with 1.2.0 once I copied all files from leaflet/dist/ to leaflet folder, but map is not working

Does the map work with the newer leaflet library for anyone?

joel_osc’s picture

Map is not working for me with the 1.2 library.

darrenwh’s picture

I cant get this to work with version 1.2.0 either

darrenwh’s picture

Status: Needs review » Needs work
jtjones23’s picture

Just an update that leaflet.js 1.3.1 has been released.

pvasili’s picture

Title: Leaflet v1.1.0 'version not recognized'? » Leaflet v1.3.1 'version not recognized'?
timwood’s picture

I was able to get this Drupal Leaflet module (7.x-1.4) working with Leaflet library v1.3.1 by modifying leaflet.module with the following, which just eliminates the library version check.

diff --git a/docroot/sites/all/modules/contrib/leaflet/leaflet.module b/docroot/sites/all/modules/contrib/leaflet/leaflet.module
index 74ada78fb..93702f76f 100644
--- a/docroot/sites/all/modules/contrib/leaflet/leaflet.module
+++ b/docroot/sites/all/modules/contrib/leaflet/leaflet.module
@@ -52,11 +52,7 @@ function leaflet_libraries_info() {
     'name' => 'Leaflet JavaScript Library',
     'vendor url' => 'http://leafletjs.com/',
     'download url' => 'http://cdn.leafletjs.com/leaflet/v1.0.2/leaflet.zip',
-    'version arguments' => array(
-      'file' => 'leaflet.js',
-      // Handle patterns like  version: "1.0.2+4bbb16c"
-      'pattern' => '/version[=: ]*[\'"]([\d+\.]+[\-a-z\.\d]*)[\'"]/',
-    ),
+    'version' => 0, // do not check version
     'files' => array(
       'js' => array(
         // This setting is needed in order to properly render market images.
eit2103’s picture

Hi Tim - I just found the same solution in another post from 4 years ago. While there is no more error in the status report, I still dont get maps loaded. Did this solution work for you?

timwood’s picture

Hey eit2103 - yes, maps load on a content type with geofield manage display settings using leaflet and OSM Mapnik map. I had some other issues with using Google maps for geocoding, but resolved that as well. Maps are also loading in a view leveraging https://www.drupal.org/project/ip_geoloc module and Leaflet API as the map format.

Do you get any errors in browser console or inspector?

Joel MMCC’s picture

I propose changing the version 'pattern' to:

      'file' => 'leaflet-src.js',  ///MMCC: changed to “…-src” file for Libraries module version detection
      // Handle patterns like  version: "1.0.2+4bbb16c"
      'pattern' => '/version[=: ]*[\'"]([\d+\.]+[\-\+\.\w]*)[\'"]/',  ///MMCC: enabled uppercase and “+” in version string to accommodate “+HEAD” 

The use of \w means all “word” characters which means all uppercase and lowercase letters, digits, and underscores, so by also adding in the escaped literals for hyphen, plus, and period, that should handle most any reasonable version string that gets thrown at us in the future.

Tested it on a local server and it detected correctly, and maps work for me whether as GeoFields displaying Leaflet maps on an Entity page, or Views Displays with IP Geolocation & Maps using their Leaflet View Display plugin. Plugins such as leaflet_markercluster that work with ip_geoloc also continue to work, and it seems to be faster than it was before with version 1.0.3. I also tested my heavily modified version of Leaflet Widget-Point (#2950605: HTML5 Geolocation (GPS) — implemented!), but still haven’t managed to get it to work alongside a Leaflet-Widget map on the same entity form (the former to enter a single Point location into one GeoField, the latter to allow drawing polygons into a second GeoField).

Version 1.3.1 may fix some other issues that have been plaguing users of this and related modules, such as the issue with many maps in Leaflet More Maps, since it parses map tokens differently and should handle map layers that provide them in a non-standard way (like the Bing maps with the {q} token) more gracefully. I’ll experiment some with that as well.

Asogan’s picture

Hi, same issue, the solution #70 on this link seems to have worked https://www.drupal.org/project/leaflet/issues/2152423

Hope this helps (I'm a noob).

Joel MMCC’s picture

@Asogan, thanks for your link to #2152423-70: Leaflet Library 0.7.1: The version of the Leaflet library could not be detected. It appears that this has been an ongoing problem, almost as if the Leaflet library makers were going out of their way to break Drupal-module and perhaps some other version detection mechanisms.

Originally the version was a simple two-element numeric string: “0.7” for instance. Then another element was added, like “0.7.3,” which, as that Issue shows, caused problems. Later they added a plus sign and some lowercase letters. Now “+HEAD” is in there as well. And, since the version detection tries to be efficient and only scan the first 20 lines and first I’m not sure how many columns of each line by default, their recent moving of the version to near the very end of the minified version of the module (whose main code is all on one line) means that you’d have to set the ['version_arguments'] -> ['cols'] to some ungodly hugemongous number (nearly the file size of leaflet.js!) just to have it detect, which defeats the whole point of using this method to try to save on resources and keep from reading in the whole library just to detect the version. This is why I said to set the ['version_arguments'] -> ['file'] to the source version, 'leaflet-src.js' instead, which still (for now) has its version string up front, well within the first 20 lines.

I thought about coming up with some really loose regex that would match anything between the two quotes after version = (with or without spaces around the =), but then it occurred to me: why not just dispense with this whole trying to parse the version string by scanning the JavaScript file thing, and instead have the module load the Leaflet library and ask it for its version string the proper way (L.version), and use that? That’s what it’s there for! That way, even if they later encode some PHP variable(s) into the version string or break it up into multiple places in the code, it’ll still work. I suspect that they may have been doing all of this specifically to get client modules to do that instead of trying to parse the file.

It shouldn’t slow things down too much to do that. As far as I can tell (being a Drupal n00b), it only needs to do so at Install time for a new install or version upgrade, when generating the Status Report (neither of which would be inside some loop that has to be as efficient as possible), and when the module is actually invoked, and in the latter case it needs to load the whole Leaflet library anyway so why the heck not?

Joel MMCC’s picture

altbzh1’s picture

#13 does not works for me with library 1.3.1 ... module 7.x-1.4
any idea ?
Thank you

Joel MMCC’s picture

@altbzh1, this was intended for 7.x-1.x-dev. Have you tried that?

The line 'file' => 'leaflet-src.js', is very important even if you’re using the minified version of the library since as I said in #15, the minified version has its version string way towards the end of the file (which, being minified, is all one hugemongous line), and the version detecting code defaults to checking only the first parts of the first 20 lines of source to save time and resources. Telling it to use the “…-src” file here does not load the source instead of the minified version for actual use. It just scans the first few lines of it to determine the version.

altbzh1’s picture

Thank you for your answer.
I have not tried with .dev because I believe there was not any change with the 7.x-1.4 (same date ...)
Ok I try .dev to morrow.

altbzh1’s picture

I have not waited for to-morrow and it does not work with .dev .

I have modified the module like this :

// Only used in administrative UI of Libraries API.
'name' => 'Leaflet JavaScript Library',
'vendor url' => 'http://leafletjs.com/',
'download url' => 'http://cdn.leafletjs.com/leaflet/v1.3.1/leaflet.zip',
'version arguments' => array(
'file' => 'leaflet-src.js',
// Handle patterns like version: "1.0.2+HEAD.4bbb16c"
'pattern' => '/version[=: ]*[\'"]([\d+\.]+[\-A-Za-z\.\d]*)[\'"]/',
),
'files' => array(

and I use 1.3.1 leaflet library :

/* /* @preserve
* Leaflet 1.3.1+Detached: ba6f97fff8647e724e4dfe66d2ed7da11f908989.ba6f97f, a JS library for interactive maps. http://leafletjs.com
* (c) 2010-2017 Vladimir Agafonkin, (c) 2010-2011 CloudMade
*/

(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.L = {})));
}(this, (function (exports) { 'use strict';

var version = "1.3.1+HEAD.ba6f97f";

/*
* @namespace Util

I do not see where is my error ... (cache was cleared ...)
Thank you for your help

Joel MMCC’s picture

@altbzh1 #20, your line:
'pattern' => '/version[=: ]*[\'"]([\d+\.]+[\-A-Za-z\.\d]*)[\'"]/',

is not the one I suggested to use in my #13. That one is:
'pattern' => '/version[=: ]*[\'"]([\d+\.]+[\-\+\.\w]*)[\'"]/', ///MMCC: enabled uppercase and “+” in version string to accommodate “+HEAD”
(You don’t need the comment part starting and after the triple slash.)

Its big difference is that the RegEx pattern’s third [square brackets] group has inserted \+ (which matches a literal plus sign) and replaced the former A-Za-z (which matches any upper-case or lower-case letter, respectively [two characters separated by a hyphen match any character whose numeric ASCII or Unicode value is between the two characters, so in this case the entire Roman alphabet] and \d (which matches any digit and semantically equivalent to 0-9) with \w which matches any “word” character (upper-or-lowercase letters, digits, and certain other characters including underscores).

The key factor here is the inclusion of the \+ since the new version numbers now include +HEAD which begins with a plus sign, which is not matched by the previous RegEx which you’re still using. Merely adding that would probably get it to work for this version, but doing the \w replacement as well would help handle future versions that might have underscores or some such.

altbzh1’s picture

Thank you Joel,

I had tried but it's did not work.
I try again and it does not work :

'version arguments' => array(
'file' => 'leaflet_src.js',
// Handle patterns like version: "1.0.2+HEAD.4bbb16c"
'pattern' => '/version[=: ]*[\'"]([\d+\.]+[\-\+\.\w]*)[\'"]/',
),
'files' => array(

Joel MMCC’s picture

Here’s mine, minus my added comments:

    'version arguments' => array(
      'file' => 'leaflet-src.js',
      // Handle patterns like  version: "1.0.2+HEAD.4bbb16c"
      'pattern' => '/version[=: ]*[\'"]([\d+\.]+[\-\+\.\w]*)[\'"]/',
    ),

It worked fine for me. Have you flushed all caches since editing that? If using Drush, do “drush cc all”.

altbzh1’s picture

Thank you Joel,
Yes I have flushed my cache.
I have the 1.3.1 version of library.

I will try to desinstall leaflet and its modules and RAZ data base for these modules.

It's work with version 0.7 ... ;-)

altbzh1’s picture

Hello Joel,
it work ... now I have to reinstall all modules and test.
Either it was a bad installation either there was an incompatible module or library ...
I try to morrow.
Thank you again

altbzh1’s picture

Hello Joel,
it work ... now I have to reinstall all modules and test.
Either it was a bad installation either there was an incompatible module or library ...
I try to morrow.
Thank you again

ShaneOnABike’s picture

Priority: Normal » Critical

Life saver!

The repair in #13 totally worked!

AaronELBorg’s picture

For version 1.3.1+HEAD.ba6f97f I changed the pattern to be case insensitive (/version[=: ]*[\'"]([\d+\.]+[\-a-z\.\d]*)[\'"]/i) and added "lines => 1200":

/**
 * Implements hook_libraries_info().
 */
function leaflet_libraries_info() {
  $libraries['leaflet'] = array(
    // Only used in administrative UI of Libraries API.
    'name' => 'Leaflet JavaScript Library',
    'vendor url' => 'http://leafletjs.com/',
    'download url' => 'http://cdn.leafletjs.com/leaflet/v1.0.2/leaflet.zip',
    'version arguments' => array(
      'file' => 'leaflet.js',
      // Handle patterns like  version: "1.3.1+HEAD.ba6f97f"
      // The stock pattern will work but you gotta make it case insensitive (notice the "i" at the end)
      'pattern' => '/version[=: ]*[\'"]([\d+\.]+[\-a-z\.\d]*)[\'"]/i',
      // Cast a really wide net
      'lines' => 1200,

    ),
    'files' => array(.......
sano’s picture

I used patch #3 modified with #13 and all seems to be working now. Thank you.

Joel MMCC’s picture

Priority: Critical » Major

Again, as I said in #15, this whole “detect the version number by RegEx-parsing the source file” technique needs to Go Away. The Leaflet makers want you to use the function they made: L.version. It’s as simple as that. The module should be patched accordingly.

mikude’s picture

I don't know which of these threads for a basic regex issue I am supposed to choose to report that in v 1.3.4 http://cdn.leafletjs.com/leaflet/v1.3.4/leaflet.zip

I just installed this 1.3.4 per the instructions and guess what my status report says today in september 2018:

The version of the Leaflet JavaScript Library library could not be detected.

And I flushed the cache. I am not convinced yet to run the .patch as no one says that helped them and the magic step in #13 I don't know if I'm supposed to just know from telepathy which file is supposed to be changed but I don't know.

In the 3 or so threads about this simple regex problem that have been going on for 5 years, I could find no human readable solution to the problem.

As someone who just jumped into drupal because I was asked to do some things, and then to see this, I hope you can see how I am like 'whaa?' How can there be a problem this simple for 5 years and it's still broken?

With no suggestions for even what to do, as in, if it's just a single line of code that needs to be altered, what is it? Or if it's just one version that works in D7, what is it? If there's just one step to make it work, what is it?

And if any of these answers exists, why is it not in the readme(link broken btw) or installation instructions?

A bug is one thing, but whatever is going on here the management of this project, which otherwise looks pretty great and appears to have taken a lot of work, is dropping the ball in a way that is incongruous with what I would otherwise expect.

Joel MMCC’s picture

@mikude #31, I was the one who posted #13 which you referenced, but that was an addition to @jantoine’s #3 which has the initial patch, and @timwood’s #10 which has a patch in code (designed to disable the version check entirely) prior to my suggested modification of the #3 patch in my #13. That comment clearly says that it’s patching the file leaflet.module, both in his description and in the displayed patch code itself.

The combination of #3’s patch with my #13 (repeated minus comments in my #23)’s proposed change to the RegEx 'pattern' has been tested and found to work by me (in #13), @ShaneOnABike in #27, and @sano in #29. One person had problems but it turned out to be a corrupted install.

The instructions on how to apply a patch differ depending on the system you’re running Drupal on and how you’re accessing it, so I can’t give you a step-by-step. It would involve properly running a command like patch apply or git apply from an SSH into the Linux or Unix system running the Drupal site, after having downloaded into there the .patch file in #3. Then you’d hand-edit the now-patched leaflet.module file to change the RegEx pattern to my suggested one as per #13 or #23. How you’d do that differs based on which Linux / Unix text editor you have installed. Or maybe you have an IDE (recommended) such as NetBeans or any of a number of others, and apply the patch there, then test it locally, upload it to staging and test there, then sync staging with live to update it there.

If you’re hosting on Windows, the process to do all of this would be different.

The point is, it’s up to you to learn how to apply patches on your particular development, staging, and (if needed) hosting services (better to apply to a staging server, then upload the patched files to the live hosting server once thoroughly tested). Instructions on doing that cannot efficiently be done in every single Issue thread on all of Drupal.org such as this one. These provide the patches. Applying them to your systems is your job.

diroots’s picture

Hello There,

I confirm the #14 comment by @Asogan

the solution #70 on this link seems to have worked https://www.drupal.org/project/leaflet/issues/2152423

you only need to change the line :
'pattern' => '/version[=: ]*[\'"]([\d+\.]+[\-a-z\.\d]*)[\'"]/'

to

       'pattern' => '/version[=: ]*[\'"]([\d+\.]+[\-a-z\.\d]*)[\'"]/',
      'lines' => 1200

and of course clear all caches

and the map shows on content type correctly on a field type geofield with the edition widget : google map (geolocation_googlemap submodule of geolocation module) , and display : leaflet.
Drupal : version 7.40 (I know, outdaaated, but it's not exposed to internet!)
Leaflet module : Version: 7.x-1.4
Leaflet library : Leaflet 1.3.4 installed in sites/all/libraries/leaflet

PS : before adding the above line, I only had a blank map area and even no console or error message, just a map reserved blank area
PS2 : trying to upgrade to last leaflet version to be able to use leaflet extra to customise map's appearance,...

joep.hendrix’s picture

FileSize
430 bytes

And here's the patch for #33

joep.hendrix’s picture

FileSize
543 bytes

Ignore the previous patch.

timwood’s picture

joep.hendrix’s picture

Status: Needs work » Needs review
cbrowndc’s picture

The solution at #33 works to make the map appear for me.

mfernea’s picture

I think it's better to test leaftlet-src.js rather than leaflet.js. Also the pattern

'/version[=: ]*[\'"]([\d+\.]+[\-a-z\.\d]*)[\'"]/'

doesn't work with versions for 1.3.1 or 1.3.4.

var version = "1.3.4+HEAD.0e566b2";

Here is the patch to make it work.

mfernea’s picture

FileSize
754 bytes

I mean here! :)

leistiko_texvet’s picture

The patch in #40 saved my sanity. Thanks, mferena!

jelo’s picture

Status: Needs review » Reviewed & tested by the community

Numerous people confirmed that the patch is working. I just applied it to my site with latest leaflet.js 1.3.4 and it works. Should this be committed?

CProfessionals’s picture

Patch #40 worked for me! Thank you.
This was the 4th post that I found. Other solutions did not work

darrenwh’s picture

Issue tags: +Microserve
bogdog400’s picture

Patch #40 worked for me.

It's clear that the Leaflet folks are going to keep changing their version numbers. Maybe an elaborate regular expression isn't the best way to handle this? How about something that just snarfs what's between the two quote marks?

Joel MMCC’s picture

@bogdog400 re: your #45, better yet, see my #15. The Leaflet people apparently don’t want their code to be parsed with RegEdits at all for the purposes of determining the version number. They provided a simple function call for that: L.version.

bogdog400’s picture

@Joel-MMCC Sure. I think loading would be great -- but how often does the PHP server have a JavaScript stack available?

ownage’s picture

Leaflet 1.4 has been available since December 2018. Is there any plan to integrate a fix for this version as well?

ownage’s picture

Also worth noting, I see a console notice with the 1.3.1 library installed with this patch:

Deprecated include of L.Mixin.Events: this property will be removed in future releases, please inherit from L.Evented instead.
Error
at y (/sites/all/libraries/leaflet/leaflet.js?pqam3g:5:2081)
at Function.v.extend (/sites/all/libraries/leaflet/leaflet.js?pqam3g:5:14792)
at /sites/all/modules/leaflet/leaflet.drupal.js?pqam3g:418:39
at /sites/all/modules/leaflet/leaflet.drupal.js?pqam3g:499:3

mfernea’s picture

@ownage: This patch doesn't alter library's js files, but the Drupal module code.

mfernea’s picture

@ownage: The patch is not version specific. I've just checked and it works with the 1.4 version of the library too.

nattyweb’s picture

Thanks. #40 did it for me, with Leaflet library version 1.5.1

VaanDeFanel’s picture

Thanks. #40 did it for me, with Leaflet library version 1.6.0

PhilY’s picture

Status: Reviewed & tested by the community » Patch (to be ported)

#40 tested with success using Drupal 7.69 & Leaflet library version 1.6.0
But as said above, the patch has no impact on the module itself as it only allows the correct library release number to be detected in the libraries report (admin/reports/libraries).

wescleyteixeira’s picture

Thanks. Patch #40 worked for me. I'm using Leaflet module 7.x-1.4 with Leaflet library version 1.6.0.

nagy.balint’s picture

Patch #40 works here too.

Only problem is "Deprecated include of L.Mixin.Events: this property will be removed in future releases, please inherit from L.Evented instead."
It is likely because of line 419
" includes: L.Mixin.Events," in leaflet.drupal.js
So that would still need to be changed to not show these deprecation messages.

But it works even with the latest leaflet js 1.7.1

Not sure why this has status "Patch (to be ported)" maybe incorrect status.

edvanleeuwen’s picture

Confirming that the patch works not only to get rid of the warning but to display maps as well.

I think this will solve a lot of other issues where the maps do not show.

steinmb’s picture

Title: Leaflet v1.3.1 'version not recognized'? » Leaflet v1.3.1 and newer 1.x version not recognized
Status: Patch (to be ported) » Needs review
Issue tags: -Microserve
steinmb’s picture

Status: Needs review » Reviewed & tested by the community

Re-tested. Patch apply cleanly and even lates version of Leaflet works (v1.9.3) - https://github.com/Leaflet/Leaflet/releases

steinmb’s picture

8 months and still RTBC, any of the maintainers around to commit this?