This code is not working as needed. I need just to make a window with addlayer button.
import java.awt.BorderLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.File;import java.io.IOException;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JPanel;import javax.swing.WindowConstants;import org.geotools.data.FileDataStore;import org.geotools.data.FileDataStoreFinder;import org.geotools.data.simple.SimpleFeatureSource;import org.geotools.map.FeatureLayer;import org.geotools.map.Layer;import org.geotools.map.MapContent;import org.geotools.styling.SLD;import org.geotools.styling.Style;//import org.geotools.renderer.GTRenderer;//import org.geotools.renderer.lite.StreamingRenderer;import org.geotools.swing.JMapFrame;import org.geotools.swing.JMapPane;import org.geotools.swing.data.JFileDataStoreChooser;public class App2 {public static void showMap(final MapContent map) throws IOException { final JMapPane mapPane = new JMapPane(map); // mapPane.setMapArea(map.getLayerBounds()); JFrame frame = new JFrame("cis"); frame.setLayout(new BorderLayout()); frame.add(mapPane, BorderLayout.CENTER); JPanel buttons = new JPanel(); /* JButton zoomInButton = new JButton("Zoom In"); zoomInButton.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) { mapPane.repaint(); } }); buttons.add(zoomInButton); JButton zoomOutButton = new JButton("Zoom Out"); zoomOutButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { mapPane.repaint(); } }); buttons.add(zoomOutButton); JButton pamButton = new JButton("Move"); pamButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { mapPane.repaint(); } }); buttons.add(pamButton); */ JButton addLayer = new JButton("Add Layer"); addLayer.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try{ File file = JFileDataStoreChooser.showOpenFile("shp", null); if (file == null) { return; } FileDataStore store = FileDataStoreFinder.getDataStore(file); SimpleFeatureSource featureSource = store.getFeatureSource(); Style style = SLD.createSimpleStyle(featureSource.getSchema()); Layer layer = new FeatureLayer(featureSource, style); map.addLayer(layer); }catch(IOException f){} } }); buttons.add(addLayer); frame.add(buttons, BorderLayout.NORTH); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setSize(600, 400); frame.setVisible(true); } public static void main(String s){ MapContent map = new MapContent(); map.setTitle("Climate information system"); JMapFrame.showMap(map); }}
أكثر...
import java.awt.BorderLayout;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.File;import java.io.IOException;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JPanel;import javax.swing.WindowConstants;import org.geotools.data.FileDataStore;import org.geotools.data.FileDataStoreFinder;import org.geotools.data.simple.SimpleFeatureSource;import org.geotools.map.FeatureLayer;import org.geotools.map.Layer;import org.geotools.map.MapContent;import org.geotools.styling.SLD;import org.geotools.styling.Style;//import org.geotools.renderer.GTRenderer;//import org.geotools.renderer.lite.StreamingRenderer;import org.geotools.swing.JMapFrame;import org.geotools.swing.JMapPane;import org.geotools.swing.data.JFileDataStoreChooser;public class App2 {public static void showMap(final MapContent map) throws IOException { final JMapPane mapPane = new JMapPane(map); // mapPane.setMapArea(map.getLayerBounds()); JFrame frame = new JFrame("cis"); frame.setLayout(new BorderLayout()); frame.add(mapPane, BorderLayout.CENTER); JPanel buttons = new JPanel(); /* JButton zoomInButton = new JButton("Zoom In"); zoomInButton.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) { mapPane.repaint(); } }); buttons.add(zoomInButton); JButton zoomOutButton = new JButton("Zoom Out"); zoomOutButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { mapPane.repaint(); } }); buttons.add(zoomOutButton); JButton pamButton = new JButton("Move"); pamButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { mapPane.repaint(); } }); buttons.add(pamButton); */ JButton addLayer = new JButton("Add Layer"); addLayer.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try{ File file = JFileDataStoreChooser.showOpenFile("shp", null); if (file == null) { return; } FileDataStore store = FileDataStoreFinder.getDataStore(file); SimpleFeatureSource featureSource = store.getFeatureSource(); Style style = SLD.createSimpleStyle(featureSource.getSchema()); Layer layer = new FeatureLayer(featureSource, style); map.addLayer(layer); }catch(IOException f){} } }); buttons.add(addLayer); frame.add(buttons, BorderLayout.NORTH); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setSize(600, 400); frame.setVisible(true); } public static void main(String s){ MapContent map = new MapContent(); map.setTitle("Climate information system"); JMapFrame.showMap(map); }}
أكثر...