OK, MapLayerTable now seems to be working with JMapPane in GeoTools
version 8-SNAPSHOT. The layers appear in the table when they are added
to the MapContent instance, you can toggle their visibility and
selected status, change the rendering style and remove them.

The new 8-SNAPSHOT jars are building at the moment and will be
available in a few minutes.

Below is a simple app to display shapefiles in a JMapFrame with the
MapLayerTable enabled. Note, this will not work with version
2.7-SNAPSHOT at the moment.

Michael


import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.SwingUtilities;
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.renderer.lite.StreamingRenderer;
import org.geotools.styling.SLD;
import org.geotools.styling.Style;
import org.geotools.swing.JMapFrame;
import org.geotools.swing.data.JFileDataStoreChooser;

public class MapLayerTableDemo {

    final JMapFrame mapFrame;

    public static void main(String[] args) {
        MapLayerTableDemo demo = new MapLayerTableDemo();
        demo.runDemo();
    }

    private void runDemo() {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                mapFrame.setSize(800, 600);
                mapFrame.setVisible(true);
            }
        });
    }

    public MapLayerTableDemo() {
        mapFrame = new JMapFrame(new MapContent(), new StreamingRenderer());
        mapFrame.enableLayerTable(true);
        mapFrame.enableStatusBar(true);
        mapFrame.enableToolBar(true);

        initComponents();
    }

    private void initComponents() {
        JMenuBar menuBar = new JMenuBar();

        JMenu menu = new JMenu("File");

        JMenuItem item = new JMenuItem("Open shapefile...");
        item.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                openShapefile();
            }
        });

        menu.add(item);
        menuBar.add(menu);

        mapFrame.setJMenuBar(menuBar);
    }

    private void openShapefile() {
        File file = JFileDataStoreChooser.showOpenFile("shp", mapFrame);
        if (file != null) {
            try {
                FileDataStore dataStore =
FileDataStoreFinder.getDataStore(file);
                SimpleFeatureSource source = dataStore.getFeatureSource();
                Style style = SLD.createSimpleStyle(source.getSchema());

                MapContent map = mapFrame.getMapContent();
                Layer layer = new FeatureLayer(source, style);
                map.addLayer(layer);

            } catch (Exception ex) {
                throw new RuntimeException(ex);
            }
        }
    }
}

------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security 
threats, fraudulent activity, and more. Splunk takes this data and makes 
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2d-c2
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to