TiddlyWiki / TiddlyWiki5

A self-contained JavaScript wiki for the browser, Node.js, AWS Lambda etc.
https://tiddlywiki.com/
Other
7.97k stars 1.18k forks source link

[BUG] Geospatial plugin javascript error when using bounds and empty geolayer widget #8452

Closed btheado closed 2 weeks ago

btheado commented 1 month ago

Describe the bug

When startPosition is bounds with an empty geolayer widget like this:

<$geomap startPosition="bounds">
<$geolayer/>
</$geomap>

A javascript exception "Bounds are not valid" is thrown.

Expected behavior

Error should be displayed or some other behavior better than RSOD.

To Reproduce

Go to https://tiddlywiki.com/prerelease/plugins/tiddlywiki/geospatial/ and add the following text to a tiddler:

<$geomap startPosition="bounds">
<$geolayer/>
</$geomap>

Screenshots

No response

TiddlyWiki Configuration

Online version accessed using firefox

Additional context

No response

btheado commented 1 month ago

I'm looking into whether wrapping the following code with if(featureBounds.isValid()) { will fix it:

https://github.com/TiddlyWiki/TiddlyWiki5/blob/2bc7ec4b946f6a1cd3db5146f02ff7717eef6355/plugins/tiddlywiki/geospatial/widgets/geomap.js#L265-L269

Initial testing seems to indicate it does.

However, I've gotten distracted trying to get testcase tiddlers to work for the geomap widget. I notice the existing test cases are tagged to not be run. For example:

https://github.com/TiddlyWiki/TiddlyWiki5/blob/2bc7ec4b946f6a1cd3db5146f02ff7717eef6355/plugins/tiddlywiki/geospatial/tests/widgets/geomap.tid

If I try to run them in the browser, leaflet throws infinite bounds exception (some information here: https://github.com/Leaflet/Leaflet/issues/6416)

For example, this code will give the exception:

<$testcase>
<$data title=Output text="<$geomap/>"/>
</$testcase>

but this does not:

<$testcase>
<$data title=Output text="<$geomap/>"/>
<$data $tiddler="$:/plugins/tiddlywiki/geospatial"/>
</$testcase>
  1. I don't think test case tiddlers have the ability to do the equivalent of <$data $tiddler="$:/plugins/tiddlywiki/geospatial"/>
  2. Maybe the exception is due to missing default base layers or something. Probably the geomap widget code should have some extra checks to do some better leaflet initialization when the default base layers are missing (or whatever the issue is).