Giter Site home page Giter Site logo

Comments (7)

msteiger avatar msteiger commented on July 17, 2024

Thanks - I will look at it asap ..

from jxmapviewer2.

 avatar commented on July 17, 2024

just wanted to let you know. I've also tried to add other Swing components, e.g., JPanel: the bug (?) is always the same, position is always top center.

from jxmapviewer2.

msteiger avatar msteiger commented on July 17, 2024

The original example from java.net are heavily outdated - still, the code should work. I was not able to reproduce the problem.

This is why I've created a new sample that uses JXMapKit and a roll-over tooltip.

Does this solve your problem?

from jxmapviewer2.

 avatar commented on July 17, 2024

Okay I think I've found the issue. I was iterating over a bunch of items and checked whether there was one item within a certain distance to the mouse pointer. If so, I set its position and breaked the for-loop. If not, I was calling tooltip.setVisible(false) and continued to check for the next item. Calling all these setVisible(false) before the first (and final) setVisible(true) made the functionality somehow broke. Here the broken code:

for (DataItem di : twitterDataManager.getDataItems()) {
    GeoLocation gl = twitterDataManager.getGeoLocation(di);
    ...

    // check if near the mouse
    if (screenPos.distance(e.getPoint()) < 20) {
        mytip.setLocation(screenPos);
        isVisible = true;
        break;
    } else {
        mytip.setVisible(false);
    }
}

And this is the version that works:

boolean isVisible = false;

// iter over all tweet locations
for (DataItem di : twitterDataManager.getDataItems()) {
    GeoLocation gl = twitterDataManager.getGeoLocation(di);
    ...

    // check if near the mouse
    if (screenPos.distance(e.getPoint()) < 20) {
        mytip.setLocation(screenPos);
        isVisible = true;
        break;
    } else {
    }
}
mytip.setVisible(isVisible);

So this still might be a bug, which is however caused by calling repeatedly setVisible(false) before actually calling setVisible(true) and setting the proper position.

from jxmapviewer2.

 avatar commented on July 17, 2024

However, I am experiencing flickering now. It seems like the label initially pops up at the top center position for a short time, before actually being displayed at the correct position.
This is an excerpt of the important lines of code, I think the flickering is not caused by my code but rather by some odd Swing / JXMapViewer behaviour?

if (closestDataItem != null) {
    tooltip.setDataItem(closestDataItem);
    tooltip.setLocation(closestScreenPos);
    tooltip.setVisible(true);
} else {
    tooltip.setVisible(false);
}

Here a video showing the flickering effect.
https://www.youtube.com/watch?v=XheubIIH-L8

from jxmapviewer2.

msteiger avatar msteiger commented on July 17, 2024

I can confirm this, but I cannot explain the jumping behaviour of the tooltip. Please let me know if you find the reason for that.

from jxmapviewer2.

 avatar commented on July 17, 2024

Alright, if I find something, I'll let you know here :-)

from jxmapviewer2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.