Patternslib / pat-leaflet

Patternslib Leaflet integration
https://patternslib.github.io/pat-leaflet/
0 stars 3 forks source link

background layers don't initialise and geolocationbehavior lat/long fields and marker on map sometimes disconnect #17

Open fredvd opened 2 years ago

fredvd commented 2 years ago

@thet @petschki A discussed yesterday on discord I'm posting this issue on the pat-leaflet repo, but I'm not sure yet technically how/if the code here is used in Plone 5.2 / Plone 6.

So have set up some content to use the geolocationbehavior on a Plone 5.2.7 Python3.8.12 setup.

The packages involved are:

1) The first issue I noticed is that the map didn't initialise the background or location until I used a control to jump to my current location. I solved this with specifying coordinates in the control panel, but these were then also used as default values and I found @laulaz branch that fixes this double role (https://github.com/collective/plone.formwidget.geolocation/pull/32) With correct lat/long values the leaflet map initalises correctly in the center of the country/website for which my setup is needed.

(There's another minor issue here: the control panel fields give a decimal error when you try to use more than 3 digits behind the . or , I suspect a dot/comma internationaliastion issue here. The lat/long fields in the behavoir doen't have this problem)

2) The second issue is that sometimes the red marker that connects to the lat/long fields below the map sometimes disappers when you try to inser a location. This for example happens when using the built-in and default configure street address lookup. Most of the time when a valid location is found the map jumps to that address and the marker is reposiioned there. And you can then drag the marker and see the lag/long update. The address seek control shows a spinner in it's icon that doesn stop, you are moved to the location (Brussels, Amsterdam) but the red marker is gone.

spinner

When I add the add'ons above to a clean Plone 5.2.8.dev0 coredev buidout and set the resources to develop and I develop the pat-leaflet bundlle I can see a traceback at exactly this line (well the developer tools report the line in the MarkerCluster-src.js bundle)

https://github.com/plone/plone.patternslib/blob/061473c1026f1a3a01d27c4ea5d33c9095b054fd/src/plone/patternslib/static/components/leaflet.markercluster/src/MarkerClusterGroup.js#L863

I think it tries to adapt the zoomlevel but in some instances the parent object doesn't exist, so you see

ncaught TypeError: parent is undefined
    _addLayer http://localhost:8080/Plone/++plone++patternslib/components/leaflet.markercluster/dist/leaflet.markercluster-src.js:868
    addLayer http://localhost:8080/Plone/++plone++patternslib/components/leaflet.markercluster/dist/leaflet.markercluster-src.js:111
    initUndefined http://localhost:8080/Plone/++plone++patternslib/components/pat-leaflet/src/pat-leaflet.js:222
    fireEvent http://localhost:8080/Plone/++plone++patternslib/components/leaflet/dist/leaflet-src.js:461
    _showLocation http://localhost:8080/Plone/++plone++patternslib/components/L.GeoSearch/src/js/l.control.geosearch.js:236
    _processResults http://localhost:8080/Plone/++plone++patternslib/components/L.GeoSearch/src/js/l.control.geosearch.js:201
    onreadystatechange http://localhost:8080/Plone/++plone++patternslib/components/L.GeoSearch/src/js/l.control.geosearch.js:165

I do suspect some timing/race condition as the error seems more difficult to trigger when in development mode.

petschki commented 2 years ago

Maybe fixed here https://github.com/Leaflet/Leaflet.markercluster/issues/635 ... updating leaflet.js might solve some problems here ...

petschki commented 2 years ago

or maybe my ajax-geojson feature broke something here https://github.com/Patternslib/pat-leaflet/pull/6/files#diff-f7ccd7fc07479ea39673cd369a65aa456b8a385d61b80105ce52db8990821676