次のアプリケーションは、JViews Maps デモ・ソフトウェアの一部としてディレクトリー
<installdir>
/jviews-maps89/samples/loadmap/index.html にあります。これは、
.ivl
フォーマットで、以前に保存した読み取り専用地図をアプリケーションで読み込み、Map Builder のメイン・ウィンドウに表示する簡単な例です。このタイプの地図は、以下のように Map Builder または JViews Maps API を使用して作成できます。-
必要なパッケージとクラスをインポートします。
import ilog.views.IlvManagerView; import ilog.views.maps.IlvCoordinateSystemProperty; import ilog.views.maps.beans.IlvJMouseCoordinateViewer; import ilog.views.maps.beans.IlvMapLegend; import ilog.views.maps.srs.coordsys.IlvGeographicCoordinateSystem; import ilog.views.swing.IlvJManagerViewControlBar; import ilog.views.swing.IlvJScrollManagerView; import java.awt.BorderLayout; import java.awt.Dimension; import java.io.File; import javax.swing.JFrame;
-
Map Builder の基本構築ブロックを作成します。地図 Bean を含むフレームを作成し、「閉じる」ボタンを押すとそのフレームが終了するように設定し、その地図 Bean をセットアップし、メイン・ウィンドウ・レイアウトを配置します。
public class LoadMapDemo extends JFrame { IlvManagerView view=new IlvManagerView(); IlvJScrollManagerView viewScroll=new IlvJScrollManagerView(view); IlvJManagerViewControlBar viewToolbar = new IlvJManagerViewControlBar(); IlvJMouseCoordinateViewer locator=new IlvJMouseCoordinateViewer(); IlvMapLegend legend=new IlvMapLegend(); public LoadMapDemo() { super(); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); viewToolbar.setView(view); locator.setView(view); legend.setView(view); view.setSize(new Dimension(900, 450)); view.setKeepingAspectRatio(true); viewScroll.setPreferredSize(view.getSize()); view.getManager().setNamedProperty(new IlvCoordinateSystemProperty(IlvGeographicCoordinateSystem.WGS84)); getContentPane().add(viewToolbar,BorderLayout.NORTH); getContentPane().add(viewScroll,BorderLayout.CENTER); getContentPane().add(locator,BorderLayout.SOUTH); getContentPane().add(legend,BorderLayout.LINE_START); loadFile("data/county.ivl"); //$NON-NLS-1$ }
-
ビューのマネージャーにファイルをロードします。
public void loadFile(String filename){ try { IlvMapInputStream mapInput = new IlvMapInputStream(filename); mapInput.read(view.getManager()); view.fitTransformerToContent(); pack(); } catch(Exception ex){ ex.printStackTrace(); } }
-
main メソッドを記述します。
static public void main(String args[]) { javax.swing.SwingUtilities.invokeLater( new Runnable() { public void run() { final JFrame frame = new LoadMapDemo(); frame.pack(); frame.setVisible(true); } ); }