Giter Site home page Giter Site logo

Comments (5)

msteiger avatar msteiger commented on August 17, 2024

Hello Andy, maybe this example is helpful?
https://github.com/msteiger/jxmapviewer2/blob/master/examples/src/sample7_swingwaypoints/SwingWaypointOverlayPainter.java#L20

from jxmapviewer2.

andyrozman avatar andyrozman commented on August 17, 2024

Doesn't help... I looked at this already...

We would need to translate location on window into Graphics2D location (of the tile) and if we had that then we could use current metod pixelToGeo(). So for example item on Graphics2D has very big location (x=16195217,y=10886860 this is near of the item where I am trying to put it down to) and at the moment I am not sure how I can translate mouse location into "Tile Location"...
I also wrote new renderer and I wanted to make icon (I paint icons for specific location) clickable, which would also require similar method... I don't know your application enough (and Graphics2D either) to know which way to look, or if what I am asking is even possible, but if I wanted to have interactive adding of new items, that is something that would be needed. But maybe this project was not meant for that... Do you have alternative I could use, that would allow interactive adding of new items? This is main reason I need your application and why I took it as basis for what I am doing?

from jxmapviewer2.

andyrozman avatar andyrozman commented on August 17, 2024

Actually I was able to find solution... Maybe you could add method to viewer so that others could use it. Something like this:

Parameters you have to pass would be : this.mouseEvent.getX(), this.mouseEvent.getY()

    public Point translateMouseLocationToViewportPixel(int mouseX, int mouseY) {
        Rectangle rectangle = mapViewer.getViewportBounds();

        int pos_x = rectangle.x + mouseX;
        int pos_y = rectangle.y + mouseY;

        Point newPoint = new Point(pos_x, pos_y);

        System.out.println("Position on Viewport: " + newPoint);

        return newPoint;
    }

    public GeoPosition translateMouseLocationToGeoPosition(int mouseX, int mouseY) {
        Point point = translateMouseLocationToViewportPixel(mouseX, mouseY);
        GeoPosition geoPosition = mapViewer.getTileFactory().pixelToGeo(point, mapViewer.getZoom());

        System.out.println("GeoPosition: " + geoPosition);
        
        return geoPosition;
    }

P.S.: Consider enabling discussions for the project...

from jxmapviewer2.

msteiger avatar msteiger commented on August 17, 2024

Thanks, I will create a small example and have a look at the "Discussions" option here in Github.

from jxmapviewer2.

msteiger avatar msteiger commented on August 17, 2024

The option "General Discussions" is available now.

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.