I have added MouseMoveOverlay on OpenStreetMap but no mouse event are listened when i perform an event.
I want to add a Marker on map on double click. Here is my Main Code:
//creating map:
public JMap createMap() {
final JMap jMap = new JMap();
jMap.addMapOverlay(new MouseMoveOverlay());
ArrayList<String> tileServerURLs = new ArrayList<String>();
tileServerURLs.add("http://otile1.mqcdn.com/tiles/1.0.0/osm/");
tileServerURLs.add("http://otile2.mqcdn.com/tiles/1.0.0/osm/");
tileServerURLs.add("http://otile3.mqcdn.com/tiles/1.0.0/osm/");
tileServerURLs.add("http://otile4.mqcdn.com/tiles/1.0.0/osm/");
String attribution = "Data, imagery and map information provided by " +
"<a href=\"http://www.mapquest.com\">MapQuest</a>, " +
"<a href=\"http://www.openstreetmap.org\">OpenStreetMap.org</a> " +
"and contributors, " +
"<a href=\"http://creativecommons.org/licenses/by-sa/2.0/\">CCBYSA</a>";
// create and add the OpenStreetMapLayer
OpenStreetMapLayer osmLayer = new OpenStreetMapLayer(tileServerURLs, 0, 18, attribution);
// if a key is required to use the tiles, use the setKey method on the layer
//osmLayer.setKey("");
// set the extent
jMap.setExtent(new Envelope(-19856505, -8827900, 18574809, 16806021));
NavigatorOverlay navigatorOverlay = new NavigatorOverlay();
navigatorOverlay.setLocation(LocationOnMap.TOP_LEFT);
jMap.addMapOverlay(navigatorOverlay);
return jMap;
}
//Mouse Event
private class MouseMoveOverlay extends MapOverlay {
private static final long serialVersionUID = 1L;
@Override
public void onMouseClicked(MouseEvent event) {
try {
if (!map.isReady()) {
return;
} else {
if (event.getClickCount() == 2 && !event.isConsumed()) {
java.awt.Point screenPoint = event.getPoint();
com.esri.core.geometry.Point mapPoint = map.toMapPoint(
screenPoint.x, screenPoint.y);
double xyz = Double.parseDouble(decimalFormat.format(mapPoint.getX()));
double yy = Double.parseDouble(decimalFormat.format(mapPoint.getY()));
map.setMarkerGraphicPopupsEnabled(true);
map.addMarkerGraphic(yy, xyz, "House", "this is a house");
}
}
}
finally
{
super.onMouseClicked(event);
}
}
}