Skip to content
This repository has been archived by the owner on Nov 16, 2022. It is now read-only.

Markers dismiss after 1 second #20

Closed
ModdyLP opened this issue Mar 7, 2017 · 2 comments
Closed

Markers dismiss after 1 second #20

ModdyLP opened this issue Mar 7, 2017 · 2 comments

Comments

@ModdyLP
Copy link

ModdyLP commented Mar 7, 2017

Hello,

i had written an Application with your MapjFx Libary. Now i have the Problem that the Marker will disapear after one second.
Marker marker = Marker.createProvided(Marker.Provided.GREEN).setPosition(cords).setVisible(true); MapLabel label = new MapLabel(string).setPosition(cords).setVisible(true); marker.attachLabel(label); mapView.addMarker(marker); mapView.setCenter(cords);

Can you say me why?
The Map is fully initialized at the moment where i call the function.

As second problem, i get multiple caching errors like the following:
Mär 07, 2017 2:03:00 PM com.sothawo.mapjfx.offline.OfflineCache readCachedDataInfo SCHWERWIEGEND: could not read dataInfo from C:\Users\######\workspace\######\mapjfx-cache\https%3A%2F%2Fx.tile.openstreetmap.org%2F15%2F17294%2F10579.png.dataInfo

@sothawo
Copy link
Owner

sothawo commented Mar 7, 2017

is the marker variable local to the method where you call it? The MapView only keeps a weak reference to the Marker object, so if you do not keep a reference to the Marker object, it will be garbage collected and disappear from the Map. This is documented in the JavaDoc for MapView.addMarker().

The reason for this is, that if the MapView would keep strong references and the user of the MapView does not remove the Markers from the Map, they would be kept until the MapView is disposed and this would be a memory leak. So to keep it safe, the MapView does not take any responsibility to keep a reference to the Marker objects.

You have to either make them fields in the class using the MapView or put them in some collection of markers which prevents them from being garbage collected - this collection itself must be a field or still be referenced somewhere.

As to the second error: this should only be a warning which appears on first accessing the map tiles; I have to change the logging level.

@ModdyLP
Copy link
Author

ModdyLP commented Mar 7, 2017

Thank you very much, i solved it with a collection of the markers on my own. But your explanation is very good 👍

Best Regards

@ModdyLP ModdyLP closed this as completed Mar 7, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants