JButton btnAddMarker = new JButton("AddMarker");
btnAddMarker.setFont(new Font("Tahoma", Font.BOLD, 9));
btnAddMarker.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
map.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
java.awt.Point screenPoint = e.getPoint();
com.esri.core.geometry.Point mapPoint = map.toMapPoint(screenPoint.x, screenPoint.y);
SimpleMarkerSymbol simpleMarker = new SimpleMarkerSymbol(Color.BLUE, 10, Style.CIRCLE);
Point pointGeometry = new Point(mapPoint.getX(),mapPoint.getY());
Graphic pointGraphic = new Graphic(pointGeometry, simpleMarker);
myGraphicsLayer.addGraphic(pointGraphic);
}
});
}
});
btnAddMarker.setBounds(781, 56, 93, 23);
contentPane.add(btnAddMarker);
JButton btnAddgreen = new JButton("AddGreen");
btnAddgreen.setFont(new Font("Tahoma", Font.BOLD, 9));
btnAddgreen.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
map.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
java.awt.Point screenPoint = e.getPoint();
com.esri.core.geometry.Point mapPoint = map.toMapPoint(screenPoint.x, screenPoint.y);
Point pointGeometry = new Point(mapPoint.getX(),mapPoint.getY());
Graphic pointGraphic = new Graphic(pointGeometry, symPoint);
myGraphicsLayer.addGraphic(pointGraphic);
}
});
}
});
btnAddgreen.setBounds(781, 90, 89, 23);
contentPane.add(btnAddgreen);
我尝试添加一个蓝色标记,然后添加一个绿色标记,但是当我使用绿色标记时,前一个鼠标事件中的前一个蓝色标记仍处于活动状态,并且我在同一点有2个点蓝色和绿色。
答案 0 :(得分:0)
如果您要删除以前的图片,请尝试调用
myGraphicsLayer.removeAll()
前
myGrapicsLayer.addGraphic(...)