Raruto / leaflet-elevation

Leaflet plugin that allows to add elevation profiles using d3js
GNU General Public License v3.0
255 stars 85 forks source link

Undefined "map" variable after updating to 2.1.0 #184

Closed hupe13 closed 2 years ago

hupe13 commented 2 years ago

Hi Raruto,

testing version 2.1.0 I get an error:

Uncaught (in promise) ReferenceError: map is not defined

When I change in leaflet-elevation.js the lines 910, 917 and 918 from "map" to "this._map" the error is gone and I get a map with an elevation chart. It looks different than before, but it works.

But more errors must exist. Many of the users (including me) have multiple maps on one page, this does not work. Or the acceleration of my test data is "Infinity" (with version 1.7.6 it is correct). The developer console does not show any errors. And I don't know what could be wrong.

Thank you very much.

Raruto commented 2 years ago

Hi hupe,

When I change in leaflet-elevation.js the lines 910, 917 and 918 from "map" to "this._map" the error is gone and I get a map with an elevation chart. It looks different than before, but it works.

please make use of line permalinks to src files when describing an issue (this way anyone reading it now and in the future can understand exactly what you are referring to).

But more errors must exist. Many of the users (including me) have multiple maps on one page, this does not work.

Yep, version 2.x has undergone a lot of code refactoring (and unfortunately I don't have much time to devote to testing). In order to solve this problem faster I suggest you propose yourself a pull that adds an example that loads two maps (that way at least we have some material to work on).

Or the acceleration of my test data is "Infinity" (with version 1.7.6 it is correct).

If I'm not mistaken you are referring to the values calculated by the following functions (if you get infinity I assume that a numerical value is never calculated), essentially these functions iteratively update the max / min value every time a new point is added to the chart (during initial data loading):

https://github.com/Raruto/leaflet-elevation/blob/0a2523d786ec9495262754a5c4956d66a7caa595/src/utils.js#L134-L135

To help you in debugging, I point out below the points in the code where they are called:

https://github.com/Raruto/leaflet-elevation/blob/2bbaa3dd271087e77685dc018730bf7769f6514b/src/handlers/acceleration.js#L22

https://github.com/Raruto/leaflet-elevation/blob/2bbaa3dd271087e77685dc018730bf7769f6514b/src/control.js#L1033-L1039

This last portion creates and assigns the value track_info.acceleration_max and track_info.acceleration_min (it may seem convoluted but on this point I have tried to maintain a minimum of compatibility with the nomenclature of the previous versions).

The developer console does not show any errors. And I don't know what could be wrong.

When in doubt, see what your computed data contains (eg. console.log(controlElevation._data);):

Have a nice day, Raruto

Raruto commented 2 years ago

PS anyway take a look at this whole function too because I guess the bug could be hiding in there

https://github.com/Raruto/leaflet-elevation/blob/2bbaa3dd271087e77685dc018730bf7769f6514b/src/control.js#L988-L991

https://github.com/Raruto/leaflet-elevation/blob/2bbaa3dd271087e77685dc018730bf7769f6514b/src/control.js#L1000-L1058

Raruto commented 2 years ago

Or it's just a matter of wrong logic:

(iVal, max) => (iVal > max ? iVal : max) || -Infinity;  

For example:

But:

hupe13 commented 2 years ago

When the setting for time is false, the charts for acceleration and speed do not work, the values are always "0".

I have detected the parameter hotline, but only falseand "elevation" work. With "elevation" the track is nice and colorful. It may be that I don't have the right example for it, but with "slope" and the others the track is always red .

Raruto commented 2 years ago

When the setting for time is false, the charts for acceleration and speed do not work, the values are always "0".

I have detected the parameter hotline, but only false and "elevation" work. With "elevation" the track is nice and colorful. It may be that I don't have the right example for it, but with "slope" and the others the track is always red .

Hi hupe, I don't quite understand what this has to do with the problem described above (please try to open only one issue per problem, otherwise it becomes difficult for everyone to follow the thread)

Have a nice day, Raruto

hupe13 commented 2 years ago

Sorry, you are right, I will open new issues. When I solved all my problems with version 2.1.0, I will make a pull request, if necessary.

Raruto commented 2 years ago

Ok, don't bother asking questions when in doubt 😉

Raruto

hupe13 commented 2 years ago

Of course I will ask ..., I have many questions (see above).