For concrete example, I send the "SimpleMap2.java" and "RouteLayer.java" ...
I want to add a menu on map when I click right on OMGraphic and also on any
side of map.
If I click on any side of map, menu will include "ADD" and "DELETE" but If
I click on one of the OMGraphics that I created with mapmouseListener
(fighter.gif), menu will include "ADD" and "DELETE" options.Then I click
left one of these options and do the operations.
What should I do to create this menu and to add listener to menu options?
import java.awt.event.MouseEvent;
import java.util.Properties;
import com.bbn.openmap.LatLonPoint;
import com.bbn.openmap.LayerHandler;
import com.bbn.openmap.MapBean;
import com.bbn.openmap.MapHandler;
import com.bbn.openmap.MouseDelegator;
import com.bbn.openmap.MultipleSoloMapComponentException;
import com.bbn.openmap.event.MapMouseEvent;
import com.bbn.openmap.event.MapMouseListener;
import com.bbn.openmap.event.SelectMouseMode;
import com.bbn.openmap.gui.BasicMapPanel;
import com.bbn.openmap.gui.MapPanel;
import com.bbn.openmap.gui.OMToolSet;
import com.bbn.openmap.gui.OpenMapFrame;
import com.bbn.openmap.gui.ToolPanel;
import com.bbn.openmap.layer.GraticuleLayer;
import com.bbn.openmap.layer.shape.ShapeLayer;
public class SimpleMap2 {
public MapHandler mapHandler;
public RouteLayer routeLayer;
public SimpleMap2(){
OpenMapFrame frame = new OpenMapFrame("Simple Map 2");
frame.setSize(640, 480);
try {
MapPanel mapPanel = new BasicMapPanel();
mapHandler = mapPanel.getMapHandler();
mapHandler.add(frame);
final MyMapMouseListener myMapMouseListener = new
MyMapMouseListener();
mapHandler.add(myMapMouseListener);
MapBean mapBean = mapPanel.getMapBean();
mapBean.setCenter(new LatLonPoint(43.0f, -95.0f));
mapBean.setScale(120000000f);
mapHandler.add(new LayerHandler());
MouseDelegator mouseDelegator = new MouseDelegator();
mapHandler.add(mouseDelegator);
SelectMouseMode selectMouseMode = new SelectMouseMode();
mapHandler.add(selectMouseMode);
mouseDelegator.setActive(selectMouseMode);
ShapeLayer shapeLayer = new ShapeLayer(){
public synchronized MapMouseListener getMapMouseListener() {
return myMapMouseListener;
}
};
Properties shapeLayerProps = new Properties();
shapeLayerProps.put("prettyName", "Political Solid");
shapeLayerProps.put("lineColor", "000000");
shapeLayerProps.put("fillColor", "BDDE83");
shapeLayerProps.put("shapeFile",
"C:/openmap-4.6.4/share/data/shape/dcwpo-browse.shp");
shapeLayerProps.put("spatialIndex",
"C:/openmap-4.6.4/share/data/shape/dcwpo-browse.ssx");
shapeLayer.setProperties(shapeLayerProps);
shapeLayer.setVisible(true);
mapHandler.add(shapeLayer);
mapHandler.add(new GraticuleLayer());
OMToolSet omts = new OMToolSet();
ToolPanel toolBar = new ToolPanel();
mapHandler.add(omts);
mapHandler.add(toolBar);
frame.setVisible(true);
} catch (MultipleSoloMapComponentException msmce) {
}
}
public class MyMapMouseListener implements MapMouseListener {
public String[] getMouseModeServiceList() {
return new String[] { SelectMouseMode.modeID };
}
protected void pasteImage(MouseEvent e) {
if (e instanceof MapMouseEvent) {
MapMouseEvent mme = (MapMouseEvent) e;
mapHandler.add(new
RouteLayer(mme.getLatLon().getLatitude(),mme.getLatLon().getLongitude()));
}
}
public boolean mousePressed(MouseEvent e) {
return false;
}
public boolean mouseReleased(MouseEvent e) {
return true;
}
public boolean mouseClicked(MouseEvent e) {
pasteImage(e);
return true;
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public boolean mouseDragged(MouseEvent e) {
return true;
}
public boolean mouseMoved(MouseEvent e) {
return true;
}
public void mouseMoved() {
}
}
public static void main(String[] argv) {
SimpleMap2 simplemap=new SimpleMap2();
}
}
import javax.swing.ImageIcon;
import com.bbn.openmap.Layer;
import com.bbn.openmap.omGraphics.OMGraphicList;
import com.bbn.openmap.omGraphics.OMRaster;
import com.bbn.openmap.omGraphics.OMScalingIcon;
import com.bbn.openmap.event.ProjectionEvent;
public class RouteLayer extends Layer {
private OMGraphicList omgraphics;
private OMRaster omRaster;
public RouteLayer(float lat,float lon) {
omgraphics = new OMGraphicList();
ImageIcon io=new ImageIcon("fighter.gif");
omRaster=new OMScalingIcon(lat,lon,io);
createGraphics(omgraphics);
}
public OMGraphicList createGraphics(OMGraphicList graphics) {
graphics.clear();
graphics.addOMGraphic(omRaster);
return graphics;
}
public void paint(java.awt.Graphics g) {
omgraphics.render(g);
}
public void projectionChanged(ProjectionEvent e) {
omgraphics.project(e.getProjection(), true);
repaint();
}
}
--
View this message in context: http://www.nabble.com/adding-menu-on-map-tp19121509p19232077.html
Sent from the OpenMap mailing list archive at Nabble.com.
--
[To unsubscribe to this list send an email to "majdart_at_bbn.com"
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Sat Aug 30 2008 - 06:19:15 EDT