maplibre / ngx-maplibre-gl

Angular binding of maplibre-gl
https://maplibre.org/ngx-maplibre-gl/
MIT License
77 stars 26 forks source link

Example shows a blank map when "exiting" Display a popup on click example #207

Closed HarelM closed 3 weeks ago

HarelM commented 1 month ago

Following these steps:

  1. Surf to https://maplibre.org/ngx-maplibre-gl/demo/popup-on-click
  2. Click on a different example in the menu
  3. --> Blank map

The error in the console is as follows:

ERROR TypeError: Cannot read properties of undefined (reading 'layers')
    at Y.findLayersBySourceId (map.service.ts:666:45)
    at map.service.ts:531:12
    at f.invoke (zone.js:369:28)
    at Y.run (zone.js:111:43)
    at e.runOutsideAngular (core.mjs:6943:24)
    at Y.removeSource (map.service.ts:530:15)
    at Y.removeSource (source.directive.ts:60:23)
    at source.directive.ts:35:42
    at Sy (core.mjs:10998:7)
    at wi (core.mjs:10935:5)

It looks like a timing issue when requesting the style from the map returns a null style object.

HarelM commented 1 month ago

I tend to think this might be related to the usage of both ngOnDestroy and destoryRef. @marcjulian @n-elhk I think we should try and move all the library code to use the same destruction mechanism. I don't know if it will solve this issue, but I believe it's worth the effort. What do you think?

marcjulian commented 1 month ago

I can reproduce the above error. Yes would be worth a try to use the same destroy logic for the whole library. Hopefully the issue and similar issues will be solved at the same time.