Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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);



    }
}
share|improve this question
    
how is it working? –  iant Jul 16 '13 at 14:52
add comment

1 Answer

JMapFrame.showMap(map);

This will call showMap method of the JMapFrame class or geotools but not your App2 class showMap method please correct it and try again

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.