?? simpletoolframe.java
字號:
/**
* Copyright 2000 MapInfo Corporation
* You are free to use this code in your applications, but you may not
* redistribute the source code without this notice.
*/
import javax.swing.*;
import java.awt.*;
import com.mapinfo.util.*;
import oracle.jdbc.driver.OracleDriver;
import java.awt.event.*;
import com.mapinfo.beans.vmapj.*;
import com.mapinfo.beans.tools.*;
import com.mapinfo.mapdefcontainer.OraSoMapDefContainer;
import com.mapinfo.mapj.*;
import com.mapinfo.dp.tab.*;
import com.mapinfo.dp.databinding.*;
import com.mapinfo.dp.util.*;
import com.mapinfo.dp.jdbc.oraso.*;
import com.mapinfo.dp.jdbc.*;
import com.mapinfo.dp.*;
import com.mapinfo.coordsys.*;
import com.mapinfo.mapxtreme.client.*;
import com.mapinfo.mapxtreme.client.MapXtremeImageRenderer;
import com.mapinfo.xmlprot.mxtj.ImageRequestComposer;
/**
* We need to create a Frame that will house the VisualMapj to display our
* vector map data. We also will add a MapJToolBar and then add our custom
* built tool to it
*/
public class SimpleToolFrame
extends JFrame {
SimpleRulerMapTool simpleRulerMapTool = new SimpleRulerMapTool();
MapToolBar mapToolBar1 = new MapToolBar();
VisualMapJ visualMapJ1 = new VisualMapJ();
//MapJ map = new MapJ();
BorderLayout borderLayout1 = new BorderLayout();
//URL u = new URL(m_fileToLoad);
//URLConnection conn = u.openConnection();
public SimpleToolFrame() {
super();
try {
jbInit();
//bindinglayer("mapxtremetest1");
loadLayer("testlayer");
}
catch (Exception e) {
e.printStackTrace();
}
}
public Layer insertLayer(String layername) throws Exception {
return null;
}
public Layer loadLayer(String layername) throws Exception {
// specify the url to the MapXtreme servlet which remotely connects us to the map //engine
String mapXtremeURL = "http://localhost:8080/mapxtreme45/mapxtreme";
//String mapXtremeURL = "C:\\Program Files\\MapInfo\\tomcat-4.0.1\\mxj450\\webapps\\mapxtreme45\\mapxtreme";
// Create the Remote Dataprovider needed to access the Data
// Using pooled connections (Recommended) CommonDataProviderHelpers
// Using Database specific DataProviderHelper
System.out.println("-----------db access---------------------------");
OraSoDataProviderHelper oraSoDPHelper = new OraSoDataProviderHelper(
"tova-0028",
1521, "phosphor", "undemo", "tova", DriverType.thin,
"oracle.jdbc.driver.OracleDriver");
// Create a String array with the name(s) of the column(s) to
//use as a unique key for records in the TableName
//String[] idColumn = {"mi_prinx"};
String[] idColumn = {
""};
// Now create a Table Desc helper
// This code uses the Constructor required when using a tablename
System.out.println("create table desc helper");
//OraSoTableDescHelper oraTDHelper = new OraSoTableDescHelper("world",
// false, idColumn, "geoloc", null, RenditionType.none, null,
// RenditionType.none, CoordSys.longLatWGS84, 2,"undemo");
// This code uses the constructor required when using a query
OraSoTableDescHelper oraTDHelper = new OraSoTableDescHelper(
"select name,geoloc from diangan",
idColumn, "geoloc", null, RenditionType.none, null,
RenditionType.none, CoordSys.longLatWGS84, 2);
// Create the Remote Dataprovider needed to access the Data
System.out.println("create dataprovider");
//MapXtremeDataProviderRef mxtDPRef = new MapXtremeDataProviderRef(oraSoDPHelper, mapXtremeURL);
LocalDataProviderRef mxtDPRef = new LocalDataProviderRef(oraSoDPHelper);
//assign it to MapJ - note getLayers()
System.out.println("add layer");
Layer Lyr = visualMapJ1.getMapJ().getLayers().add(mxtDPRef, oraTDHelper,
layername);
visualMapJ1.getMapJ().setBounds(new DoubleRect(120.2,31.5,120.4,32));
System.out.println("............... over ............");
return Lyr;
}
public Layer bindinglayer(String layername) throws Exception {
// local strings, values edited for publication
String driverurl = "jdbc:oracle:thin:@tova-0028:1521:phosphor";
String usr = "undemo";
String pwd = "tova";
String mapsdir =
"C:\\Program Files\\MapInfo\\MapXtreme-4.5.0\\examples\\server\\data\\";
System.out.println("===============add layer==============================");
// create a tab data provider for the map objects
System.out.println("create ");
TABDataProviderHelper tabdph = new TABDataProviderHelper(mapsdir);
// create a data provider to access the tabular data
System.out.println("create provider");
JDBCDataProviderHelper jdbcdph = new JDBCDataProviderHelper(driverurl, usr,
pwd,
"oracle.jdbc.driver.OracleDriver");
// create a databindingdataproviderhelper which indicates which two data providers to "join"
System.out.println("create databindingdataproviderhelper");
DataBindingDataProviderHelper bnddph = new DataBindingDataProviderHelper(
tabdph, jdbcdph);
// create a tab table description for the map data
System.out.println("create tab");
TABTableDescHelper tabtdh = new TABTableDescHelper("world.tab");
// create a table description for the tabular data
System.out.println("create table description");
JDBCTableDescHelper jdbctdh = new JDBCTableDescHelper("world", "undemo");
// create the string arrays which specifies the columns to perform the join with
System.out.println("create string arrays");
String[] geocols = {
"Country", "Capital", "Continent"};
// note: for jdbc data sources, the column names are case sensitive.
System.out.println("state");
String[] joincols = {
"COUNTRY", "CAPITAL", "CONTINENT"};
// create the databindingtabledeschelper which describes the source of
// the data and map object tables
System.out.println("create databindingtabledeschelper");
DataBindingTableDescHelper bndtdh = new DataBindingTableDescHelper(tabtdh,
jdbctdh, geocols, joincols);
// create a data provider reference for the data provider helper
System.out.println("create provider");
LocalDataProviderRef bnddpr = new LocalDataProviderRef(bnddph);
// optional, add an aggregation method which defines how to deal with
// multiple data records for a map object
System.out.println("add aggregation");
bndtdh.addAggregation("order_amt", Aggregation.SUM);
// finally, add the layer to the map
System.out.println("add layer to map");
Layer lyr = visualMapJ1.getMapJ().getLayers().insert(bnddpr, bndtdh, 0,
layername);
return lyr;
}
private void jbInit() throws Exception {
this.getContentPane().setLayout(borderLayout1);
this.setSize(new Dimension(628, 544));
visualMapJ1.setShowToolTips(true);
// Add the Map tool bar control
this.getContentPane().add(mapToolBar1, BorderLayout.NORTH);
// Add VisualMapJ
this.getContentPane().add(visualMapJ1, BorderLayout.CENTER);
//this.getContentPane().add(map, BorderLayout.CENTER);
// Load a geoset into VMapJ
System.out.println("***********load gst file**********************");
//visualMapJ1.getMapJ().loadGeoset("C:\\Program Files\\MapInfo\\MapXtreme-4.5.0\\examples\\server\\data\\world.gst",
// "C:\\Program Files\\MapInfo\\MapXtreme-4.5.0\\examples\\server\\data\\", null);
//visualMapJ1.setBounds(new Rectangle(0, 0, 800, 600));
System.out.println("***********db access***************************");
String driverName = "oracle.jdbc.driver.OracleDriver";
String dbUrl = "jdbc:oracle:thin:@tova-0028:1521:phosphor";
String usrName = "undemo";
String pwd = "tova";
// Create an instance of MapDefContainer with the pertinent database information
//OraSoMapDefContainer mdc = new OraSoMapDefContainer(driverName, dbUrl, usrName, pwd);
//,"diangan","name","Map_Definition");
System.out.println("***********show param***************************");
//System.out.println(mdc.load("world"));
System.out.println("***********load ***************************");
//visualMapJ1.getMapJ().loadMapDefinition(mdc, "diangan");
System.out.println("***********save***************************");
//System.out.println("loadsql " + mdc.getLoadSQL());
//System.out.println("savesql " + mdc.getSaveSQL());
//System.out.println("table " + mdc.getTable());
//System.out.println("class " + mdc.getClass());
//System.out.println("driver " + mdc.getDriver());
//System.out.println("url " + mdc.getURL());
//visualMapJ1.getMapJ().saveMapDefinition(mdc,"world");
//System.out.println("***********load gst file**********************");
//map.loadGeoset("C:\\Program Files\\MapInfo\\MapXtreme-4.5.0\\examples\\server\\data\\world.gst",
// "C:\\Program Files\\MapInfo\\MapXtreme-4.5.0\\examples\\server\\data\\",
// null);
System.out.println("***********composer**********************");
//ImageRequestComposer imageRC =ImageRequestComposer.create(map, 256, Color.blue,"image/gif");
// Create a MapXtremeImageRenderer
System.out.println("***********renderer**********************");
//MapXtremeImageRenderer renderer = new MapXtremeImageRenderer("http://localhost:8080//mapxtreme40/servelet/mapxtreme");
// Render the map
//renderer.render(imageRC);
// Render the map to the file
//renderer.toFile("comp.gif");
System.out.println("***********save map to db********************");
//map.saveMapDefinition(mdc, "world");
System.out.println("*************end*****************************");
// Add our custom Tool to the MapJ tool bar
mapToolBar1.add(simpleRulerMapTool);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -