Skip to main content

Adding MouseListener for the CustomOverlay-JXMapViewer

12 replies [Last post]
question
Offline
Joined: 2009-05-11
Points: 0

Hi

Can any one of you help me in adding the MouseListener to the CustomOverlay such as to an image. I need to get the popup for the entire map and the another popup for the CustomOverlay respective to the click on the map or customoverlay

Thanks

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
question
Offline
Joined: 2009-05-11
Points: 0

Hi

If you want more clear information please let me know

anhsirk
Offline
Joined: 2009-05-21
Points: 0

what _count or count in Waypointrenderer refers to ??

anhsirk
Offline
Joined: 2009-05-21
Points: 0

i am not getting the logic. can u pls explain ..

question
Offline
Joined: 2009-05-11
Points: 0

Ok I will send some sample code so that you can understand it very clearly but give me some time

Have you worked on dragging the waypoints? If yes can you please tell the logic or send me sample code

Please can you send me ASAP

question
Offline
Joined: 2009-05-11
Points: 0

Thank you for the quick response

What happens if the image is round in shape?

For the same i have used JButton as a waypoint to which i added MouseListener, everything is working fine but the problem is when i pan the map some Jbuttons are getting strucked in the corners. Have you ever work on this scenario?

anhsirk
Offline
Joined: 2009-05-21
Points: 0

If the image is in round shape form a cicle insted of triangle.

can u pls give me code , for how u have added jbuttons as waypoints . ..

even i wanted to use mouse listner for way points

i ll try form my side to solve the problesm u r facing ..

question
Offline
Joined: 2009-05-11
Points: 0

Here is the sample code which paints jbutton as a waypoint and adds mouselistener for the waypoint. If you need more clarification please let me know so that i can help you

public class SampleWaypointPainter extends WaypointPainter {
SampleButton[] _buttons;
public void setSampleRenderer(){
setRenderer(new WaypointRenderer() {
@Override
public boolean paintWaypoint(Graphics2D g, JXMapViewer map,
Waypoint wp) {
// TODO Auto-generated method stub
GeoPosition gp = wpoint.getValue();//.getPosition();
//convert to world bitmap
gp_pt = map.getTileFactory().geoToPixel(gp, map.getZoom());
//convert to screen
Rectangle rect = map.getViewportBounds();
Point converted_gp_pt = new Point((int)gp_pt.getX()-rect.x,
(int)gp_pt.getY()-rect.y);
_buttons[_count].setLocation(converted_gp_pt);
_buttons[count].addMouseMotionListener(new MouseImplementation()));
}
});
}
//Sets the current set of waypoints to paint
public void setSampleWaypoints(){
_button = new SampleButton[details.size()];
count = details.size();
int count=0;
while (it.hasNext()) {
Map.Entry entry = (Map.Entry) it.next();
waypoints.add(new Waypoint(entry.getValue()));
_button[count] = new SampleButton();
map.add(_button[count]);
count++;
}
this.setWaypoints(waypoints);
this.setPVESRenderer();
}

question
Offline
Joined: 2009-05-11
Points: 0

Hi

I you want more clear information please let me know

anhsirk
Offline
Joined: 2009-05-21
Points: 0

I added mouse Listener to JXMAPKIT .

and when JXMAPKIT is clicked , i am taking the point and checking weahther it falls in my waypoints geoposition(forming a triagle upward )
then when its matched i paint the waypoint details there.

And its working fine for me .

But it would be good if there is a mousListener to way point.

public void mouseClicked(Event e){

point pt = r.getpoint()

WayPoint wyPoint = (wyPoint)vcGeoPositions.get(i);
Point2D point = map.getTileFactory().geoToPixel(wyPoint.getPosition(), map.getZoom());
int x = (int)(point.getX() - bounds.getX());
int y = (int)(point.getY() - bounds.getY());
Polygon triangle = new Polygon();
triangle.addPoint(x,y);
triangle.addPoint(x+iconWidth/3,y-iconHeight);
triangle.addPoint(x-iconWidth/3,y-iconHeight);
if (triangle.contains(pt)) {
// do ur painting stuff here

g.setColor(Color.Black);
int width = (int) g.getFontMetrics().getStringBounds(msg, g).getWidth();
g.fillRoundRect(x-width/2 -5+100, y-100, width+10, 50, 10, 10);

}

}

question
Offline
Joined: 2009-05-11
Points: 0

Thank you soo much

But what happens when the image is round in shape?
Can you please tell me what refers to the r and i values from the following code so that i can implement in that way?
point pt = r.getpoint()
WayPoint wyPoint = (wyPoint)vcGeoPositions.get(i);

anhsirk
Offline
Joined: 2009-05-21
Points: 0

type error it not r.getPoint its e.getpoint()

and reg ' i ' : i am using this code inside a for loop ..

i am iterrating through the list of waypoints

anhsirk
Offline
Joined: 2009-05-21
Points: 0

if the image is in round shape for a circle and apply the same logic.
ie i am forming a triangle , instead of that u ll have to form a cirlce