import ilog.views.*; import ilog.views.maps.*; import ilog.views.maps.beans.*; import ilog.views.maps.datasource.*; import ilog.views.maps.format.image.IlvRasterBasicImageReader; import ilog.views.maps.graphic.style.IlvPolylineStyle; import ilog.views.maps.raster.datasource.IlvRasterDataSourceFactory; import ilog.views.maps.srs.coordsys.IlvCoordinateSystem; import ilog.views.maps.srs.coordsys.IlvGeographicCoordinateSystem; import ilog.views.swing.IlvJManagerViewControlBar; import ilog.views.swing.IlvJScrollManagerView; import java.awt.*; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.File; import java.net.URL; import javax.swing.JFrame; import javax.swing.JTabbedPane;
BuildMapDemo
,
which defines the basic building blocks of the Map Builder: public class BuildMapDemo extends JFrame { IlvManagerView view;// Map View IlvJScrollManagerView viewScroll;// scroll around the Map View IlvJManagerViewControlBar viewToolbar; // zoom & selection toolbar IlvLayerTreePanel layerTreePanel = new IlvLayerTreePanel(); // layer visibility and properties control IlvJCoordinateSystemEditorPanel csPanel;// coordinate system choice. IlvJMouseCoordinateViewer locator;// coordinate information
public BuildMapDemo() { super(); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
view=new IlvManagerView(); view.setManager(new IlvGrapher()); viewScroll=new IlvJScrollManagerView(view); viewToolbar = new IlvJManagerViewControlBar(); csPanel=new IlvJCoordinateSystemEditorPanel(); viewToolbar.setView(view); locator=new IlvJMouseCoordinateViewer(); locator.setView(view); viewToolbar.add(locator); view.setKeepingAspectRatio(true); view.setBackground(new Color(80, 180, 240)); view.setAntialiasing(false); view.setSize(new Dimension(900, 450)); viewScroll.setPreferredSize(view.getSize()); layerTreePanel.setView(view);
view.getManager().setNamedProperty(new IlvCoordinateSystemProperty(IlvGeographicCoordinateSystem.WGS84));
csPanel.setCoordinateSystem(IlvCoordinateSystemProperty.GetCoordinateSystem (view.getManager())); csPanel.addCoordinateSystemChangeListener(new PropertyChangeListener(){ public void propertyChange(PropertyChangeEvent evt) { IlvCoordinateSystem system = (IlvCoordinateSystem) evt.getNewValue(); view.getManager().setNamedProperty(new IlvCoordinateSystemProperty(system)); clearManager(); loadData(); } });
loadData(); getContentPane().add(viewToolbar,BorderLayout.NORTH); getContentPane().add(viewScroll,BorderLayout.CENTER); JTabbedPane tabPane=new JTabbedPane(); tabPane.addTab("Map layers",layerTreePanel); tabPane.addTab("Coordinate System",csPanel); getContentPane().add(tabPane,BorderLayout.LINE_START); getContentPane().add(locator,BorderLayout.SOUTH); }
private void loadData() { URL shpFile = findURL("data/world.shp"); URL gifFile = findURL("data/world.gif"); try { // Create a data source for the shape file. IlvShapeDataSource shpDataSource = new IlvShapeDataSource(shpFile.getFile(), true); shpDataSource.setCoordinateSystem(IlvGeographicCoordinateSystem.WGS84); // Create a raster reader for the .gif file (necessary to create the datasource that follows). IlvRasterBasicImageReader imageReader = new IlvRasterBasicImageReader(); imageReader.loadImage(gifFile.getFile()); // Georeference this image (it covers the whole earth). imageReader.setImageBounds(0,-Math.PI,Math.PI/2,Math.PI,-Math.PI/2); // Create a datasource for the .gif file. IlvMapDataSource imageDataSource = IlvRasterDataSourceFactory.buildImageDataSource( view.getManager(),imageReader,true,true,true,null); // Insert it in the data source tree of the manager. IlvMapDataSourceModel dataSourceModel = IlvMapDataSourceProperty.GetMapDataSourceModel(view.getManager()); dataSourceModel.insert(shpDataSource); dataSourceModel.insert(imageDataSource); // Start reading the model (recursively start all data sources of this model). dataSourceModel.start(); // Get the shape map layer used to display the data source. IlvMapLayer shpLayer = shpDataSource.getInsertionLayer(); shpLayer.setName("ESRI layer (world.shp)"); IlvMapLayer imageLayer = imageDataSource.getInsertionLayer(); // Insert it in the Map layer tree of the manager. IlvMapLayerTreeModel ltm = IlvMapLayerTreeProperty.GetMapLayerTreeModel(view.getManager()); ltm.addChild(null, shpLayer); ltm.addChild(null, imageLayer); // Set up the shape layer style. shpLayer.getStyle().setAttribute(IlvPolylineStyle.FOREGROUND,Color. black); shpLayer.getStyle().setAttribute(IlvPolylineStyle.BACKGROUND,new Color(1,1,1,0.25f)); imageLayer.setName("Image layer (world.gif)"); } catch (Exception e1) { e1.printStackTrace(); }
view.fitTransformerToContent(); view.repaint(); }
static public void main(String args[]) { javax.swing.SwingUtilities.invokeLater( new Runnable() { public void run() { final JFrame frame = new BuildMapDemo(); frame.setTitle("Simple map building demo"); frame.pack(); frame.setVisible(true); } ); }
private void clearManager() { IlvManager manager = view.getManager(); IlvMapLayerTreeModel model = IlvMapLayerTreeProperty.GetMapLayerTreeModel(manager); model.clearAllObjects(); while (manager.getLayersCount() > 0) { IlvManagerLayer layer = manager.getManagerLayer(0); manager.removeLayer(0, false); } manager.removeNamedProperty(IlvMapLayerTreeProperty.NAME); manager.removeNamedProperty(IlvMapDataSourceProperty.NAME); manager.removeNamedProperty(IlvAreasOfInterestProperty.NAME); } }