I’ve got an error which I can’t explain.
I want to use google map + google map marker inside a vaadin dialog (I also tried leaflet map and leaflet marker and I’ve got also some issues).
I will explain my test case (I tried to remove all useless stuff around this)
I create a component ExampleTemplate (template in html) with google-map + marker.
I create a view (template in html) with 2 buttons:
→ 1st button: Open a vaadin-dialog templated html
→ 2nd button: Open a vaadin-dialog templated in JAVA (ExampleTemplate included)
When i click on “Show dialog” it’s working (i removed api-key in my example but there is the same bug). I close the dialog and re-open it. It’s working.
When i click on “Show dialog2” it’s working (the 1st time). I close the dialog and re-open it. It’s not working.
There is an error Cannot read property ‘click’ of undefined “google-map-marker.html:470”
I think I don’t explain what i want to do. I would like a google map + marker inside a form (I created an app from Full stack spring) as the form is opened inside a dialog I’ve got this problem.
I tried to remove all the unnecessary code.
I don’t understand how the dialog works. For example, if the components inside the dialog template are created after opening or if it’s created the 1st time then “reused” the 2nd time …
This looks like the issue we should fix, thank you for reporting.
I’ve created a ticket here: https://github.com/vaadin/flow/issues/4374 please subscribe to see the progress.
I will check this the pull request.
I saw this in the bug : “When there are multiple google-map with markers on different pages an error is thrown when showing the second map.”
I don’t understand how vaadin-dialog is working. In Java dialog is created once (its content is created once) but in the view google-map component is created twice ? (and the old one is not “destroyed”)
I don’t “want” to create 2 google-map + marker. Is it possible to create one component (so I won’t have the google-map bug) ?
You’re absolutely right, the Java dialog and html dialog is created once only.
What dialog does is basically adding/removing of its contents to the DOM (html): when you open it, it adds on the page a special thing called overlay (https://github.com/vaadin/vaadin-overlay/) with the contents you’ve added to the dialog.
And when you close the dialog, the overlay gets removed from the dom.
What makes it more complicated here, is the fact that the dialog actually contains a custom element.
When a custom element is added to the DOM, some JavaScript logic should be executed to make it look and work like the actual WebComponent, otherwise instead of the map only an empty tag will be displayed.
If I open dialog with the 1st button, there is a google-map. When I close it, it’s still there
If I open dialog with the 2nd button (after refeshing the page), there is a google-map. When I close it, there is no google-map (but some observers on a ghost google-map)
So the error message is a google-map bug but the unclean observer is a bug from which component ?
Thanks for your answer (it’s not easy to understand the difference of behaviour between these 2 cases)
The main difference is that on the second case, there’s a webcomponent in between the overlay and the actual map: a <flow-component-renderer>. This component is needed to allow the Java server to keep track of the rendered components on the client-side, when those components are created via the Polymer templating (which is the case for content inside Dialogs).
Unfortunately I don’t have an immediate fix or workaround for this situation, other than using what you are already using (creating the Dialog from the template instead of from Java). We need to investigate further what is causing the different behavior.
Yes I knew this date-picker issue (I opened it). It’s quite hard to use vaadin features and have this kind of issues (especially to be sure that I don’t code that weird behaviour then look for a workaround).
I think I will avoid vaadin dialog for some times (at least when I try custom field or some new vaadin 10 cool features).
Thanks for your answers, I will follow updates for vaadin-dialog project closely