Olá amigos, abaixo o meu código completo, a questão é que consegui construir um botão que adiciona e outro que retira um marcador de um ponto específico no mapa, porém se desejo fazer isso utilizando mais botões eu não consigo uma vez que eu tento adicionar as mesmas funções dos botões 1 e 2 por exemplo em botões 3 e 4 mas dá erro, na verdade sou iniciante e não sei onde exatamente entre as chaves devo colocar o código dos botões 3 e 4 ou 5 e 6 e assim consecutivamente até a quantidade de marcadores que eu desejar, se alguém puder dar uma força ai… grato
import com.teamdev.jxmaps.;
import com.teamdev.jxmaps.swing.MapView;
import controle.ConexaoBD;
import controle.ControleMapa;
import javax.swing.;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;//painel
import javax.swing.JButton;// botoes
import javax.swing.JPanel;//painel para o jframe
import modelo.ModeloMapa;
public class Mapa extends MapView {
ConexaoBD conex = new ConexaoBD();// coloquei os tres par testar o novo formulario
ControleMapa control = new ControleMapa();
ModeloMapa mod = new ModeloMapa();
int Clique;// para if else teste
protected JFrame janela = new JFrame(“Gerenciar”);// jframe que esta junto ao mapa
protected JButton color1 = new JButton(" Liberar1");//
protected JButton color2 = new JButton(“Ocupar1”);//
protected JButton color3 = new JButton(“Livre2”);
protected JButton color4 = new JButton(“Ocupada2”);
public Mapa(MapViewOptions options) {
super(options);
setOnMapReadyHandler(new MapReadyHandler() {
@Override
public void onMapReady(MapStatus status) {
if (status == MapStatus.MAP_STATUS_OK) {
final Map map = getMap();
map.setZoom(17.0);
map.setCenter(new LatLng( -23.3120833,-51.1596366));//ADICIONEI A POSIÇÃO do local
Marker mark = new Marker(map);//ADICIONEI MARCADOR NO MAPA
mark.setPosition(map.getCenter()); // verifique se é melhor colocar numeros inves de letras
GeocoderRequest request = new GeocoderRequest(map);
request.setAddress("Londrina, PR");
// Toolkit.getDefaultToolkit().beep();//EMITIR SINAL SONORO
Circle circle = new Circle(map);//ADICIONA CIRCULO AO MAPA
circle.setCenter(map.getCenter());
circle.setRadius(100);
CircleOptions co = new CircleOptions();
co.setFillColor("#0000FF");
co.setFillOpacity(0.35);
circle.setOptions(co);
getServices().getGeocoder().geocode(request, new GeocoderCallback(map) {//MAPA
@Override
public void onComplete(GeocoderResult[] result, GeocoderStatus status) {
if (status == GeocoderStatus.OK) {
map.setCenter(result[0].getGeometry().getLocation());
Marker marker = new Marker(map);
marker.setPosition(result[0].getGeometry().getLocation());
final InfoWindow window = new InfoWindow(map);
window.setContent("x!");
window.open(map, marker);
}
}
});
}
}
});
}
public static void main(String[] args) {
MapViewOptions options = new MapViewOptions();//MAPA
options.importPlaces();//MAPA
final Mapa mapView = new Mapa(options);//MAPA
JFrame frame = new JFrame("x!");//MAPA jframe do mapa original
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);//MAPA
frame.add(mapView, BorderLayout.CENTER);//MAPA
frame.setSize(700, 500);//MAPA
frame.setLocationRelativeTo(null);//MAPA null deixa centralizado
frame.setVisible(true);//MAPA
SwingUtilities.invokeLater( new Runnable()// PARTE 2 DO JFRAME
{
public void run()
{
mapView.load();
}
});
}
public void load() { // PARTE 3 DO TESTE
janela.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// cria o jframe
janela.setSize(new Dimension(450, 700)); //estava 500 por 500 lado o primeiro muda verticalmente
janela.setResizable(false);
janela.setVisible(true);
Container c = janela.getContentPane();// ADICIONA BOTAO 1
c.setLayout(null);
color1.setBounds(280, 30, 100, 30); //original 250,50,150,50 //
c.add(color1);
setLayout(null);//para poder alinhar os botoes
Container a = janela.getContentPane();// ADICIONA BOTAO 2
a.setLayout(null);
color2.setBounds(150, 30, 100, 30);
a.add(color2);
setLayout(null);//para poder alinhar os botoes
Container w = janela.getContentPane();// ADICIONA BOTAO 3
w.setLayout(null);
color3.setBounds(150, 180, 100, 30); //,2- desce,
w.add(color3);
setLayout(null);//para poder alinhar os botoes
Container t = janela.getContentPane();// ADICIONA BOTAO 4
t.setLayout(null);
color4.setBounds(150, 220, 110, 30); //1-faz vir pro centro,2- desce,3-faz aumentar
t.add(color4);
setLayout(null);//para poder alinhar os botoes
//AQUI COMEÇA A FUNÇÃO DE MARCAR E DESMARCAR
color1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Marker marker = new Marker(getMap());
marker.setPosition(getMap().getCenter());
marker.setPosition(new LatLng(-23.312396,-51.159671));
color1.setEnabled(false);
color2.setEnabled(true);
color2.addActionListener(new ActionListener() {// adiciona marcador com um clique ESTA REMOVENDO A MARCAÇÃO DO BOTAO 1
@Override
public void actionPerformed(ActionEvent e) {
if( Clique== 1){
Marker marker = new Marker(getMap());
marker.setPosition(getMap().getCenter());
marker.setPosition(new LatLng());
}else{
marker.remove();
color2.setEnabled(false);
color1.setEnabled(true);
}
}
});
}
});
}
}
import com.teamdev.jxmaps.;
import com.teamdev.jxmaps.swing.MapView;
import controle.ConexaoBD;
import controle.ControleMapa;
import javax.swing.;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;//painel
import javax.swing.JButton;// botoes
import javax.swing.JPanel;//painel para o jframe
import modelo.ModeloMapa;
public class Mapa extends MapView {
ConexaoBD conex = new ConexaoBD();// coloquei os tres par testar o novo formulario
ControleMapa control = new ControleMapa();
ModeloMapa mod = new ModeloMapa();
int Clique;// para if else teste
protected JFrame janela = new JFrame(“Gerenciar”);// jframe que esta junto ao mapa
protected JButton color1 = new JButton(" Liberar1");//
protected JButton color2 = new JButton(“Ocupar1”);//
protected JButton color3 = new JButton(“Livre2”);
protected JButton color4 = new JButton(“Ocupada2”);
public Mapa(MapViewOptions options) {
super(options);
setOnMapReadyHandler(new MapReadyHandler() {
@Override
public void onMapReady(MapStatus status) {
if (status == MapStatus.MAP_STATUS_OK) {
final Map map = getMap();
map.setZoom(17.0);
map.setCenter(new LatLng( -23.3120833,-51.1596366));//ADICIONEI A POSIÇÃO do local
Marker mark = new Marker(map);//ADICIONEI MARCADOR NO MAPA
mark.setPosition(map.getCenter()); // verifique se é melhor colocar numeros inves de letras
GeocoderRequest request = new GeocoderRequest(map);
request.setAddress("Londrina, PR");
// Toolkit.getDefaultToolkit().beep();//EMITIR SINAL SONORO
Circle circle = new Circle(map);//ADICIONA CIRCULO AO MAPA
circle.setCenter(map.getCenter());
circle.setRadius(100);
CircleOptions co = new CircleOptions();
co.setFillColor("#0000FF");
co.setFillOpacity(0.35);
circle.setOptions(co);
getServices().getGeocoder().geocode(request, new GeocoderCallback(map) {//MAPA
@Override
public void onComplete(GeocoderResult[] result, GeocoderStatus status) {
if (status == GeocoderStatus.OK) {
map.setCenter(result[0].getGeometry().getLocation());
Marker marker = new Marker(map);
marker.setPosition(result[0].getGeometry().getLocation());
final InfoWindow window = new InfoWindow(map);
window.setContent("x!");
window.open(map, marker);
}
}
});
}
}
});
}
public static void main(String[] args) {
MapViewOptions options = new MapViewOptions();//MAPA
options.importPlaces();//MAPA
final Mapa mapView = new Mapa(options);//MAPA
JFrame frame = new JFrame("x!");//MAPA jframe do mapa original
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);//MAPA
frame.add(mapView, BorderLayout.CENTER);//MAPA
frame.setSize(700, 500);//MAPA
frame.setLocationRelativeTo(null);//MAPA null deixa centralizado
frame.setVisible(true);//MAPA
SwingUtilities.invokeLater( new Runnable()// PARTE 2 DO JFRAME
{
public void run()
{
mapView.load();
}
});
}
public void load() { // PARTE 3 DO TESTE
janela.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// cria o jframe
janela.setSize(new Dimension(450, 700)); //estava 500 por 500 lado o primeiro muda verticalmente
janela.setResizable(false);
janela.setVisible(true);
Container c = janela.getContentPane();// ADICIONA BOTAO 1
c.setLayout(null);
color1.setBounds(280, 30, 100, 30); //original 250,50,150,50 //
c.add(color1);
setLayout(null);//para poder alinhar os botoes
Container a = janela.getContentPane();// ADICIONA BOTAO 2
a.setLayout(null);
color2.setBounds(150, 30, 100, 30);
a.add(color2);
setLayout(null);//para poder alinhar os botoes
Container w = janela.getContentPane();// ADICIONA BOTAO 3
w.setLayout(null);
color3.setBounds(150, 180, 100, 30); //,2- desce,
w.add(color3);
setLayout(null);//para poder alinhar os botoes
Container t = janela.getContentPane();// ADICIONA BOTAO 4
t.setLayout(null);
color4.setBounds(150, 220, 110, 30); //1-faz vir pro centro,2- desce,3-faz aumentar
t.add(color4);
setLayout(null);//para poder alinhar os botoes
//AQUI COMEÇA A FUNÇÃO DE MARCAR E DESMARCAR
color1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Marker marker = new Marker(getMap());
marker.setPosition(getMap().getCenter());
marker.setPosition(new LatLng(-23.312396,-51.159671));
color1.setEnabled(false);
color2.setEnabled(true);
color2.addActionListener(new ActionListener() {// adiciona marcador com um clique ESTA REMOVENDO A MARCAÇÃO DO BOTAO 1
@Override
public void actionPerformed(ActionEvent e) {
if( Clique== 1){
Marker marker = new Marker(getMap());
marker.setPosition(getMap().getCenter());
marker.setPosition(new LatLng());
}else{
marker.remove();
color2.setEnabled(false);
color1.setEnabled(true);
}
}
});
}
});
}
}