?? createmap.java~132~
字號:
package myfirstmap;
import com.mapinfo.mapj.MapJ;
import com.mapinfo.mapdefcontainer.MapDefContainer;
import com.mapinfo.mapdefcontainer.FileMapDefContainer;
import com.mapinfo.util.DoubleRect;
import com.mapinfo.util.DoublePoint;
import com.mapinfo.mapxtreme.client.MapXtremeImageRenderer;
import com.mapinfo.xmlprot.mxtj.ImageRequestComposer;
import java.awt.Color;
import java.awt.Event;
import com.mapinfo.mapdefcontainer.OraSoMapDefContainer;
import com.mapinfo.dp.tab.TABTableDescHelper;
import java.io.File;
import com.mapinfo.dp.tab.TABDataProviderHelper;
import com.mapinfo.mapxtreme.client.MapXtremeDataProviderRef;
import com.mapinfo.dp.jdbc.oraso.OraSoDataProviderHelper;
import com.mapinfo.dp.jdbc.DriverType;
import com.mapinfo.dp.jdbc.oraso.OraSoTableDescHelper;
import com.mapinfo.dp.RenditionType;
import com.mapinfo.coordsys.CoordSys;
import com.mapinfo.mapj.Layers;
import com.mapinfo.mapj.DataLayer;
import com.mapinfo.mapj.AbstractLayer;
import com.mapinfo.unit.LinearUnit;
import com.mapinfo.unit.Distance;
import com.mapinfo.mapj.FeatureLayer;
import com.mapinfo.mapj.LabelProperties;
import com.mapinfo.mapj.Layer;
public class CreateMap
{
private MapJ myMap;
private MapDefContainer mdc;
public CreateMap()
{
}
public void CreateOneMap(String gstName,String saveFileName)
{//map source comes from .gst file
myMap=new MapJ();
try
{
//loading one geoset
// myMap.loadGeoset("E:\\MapInfo\\study\\mapgst\\"+gstName,
// "E:\\MapInfo\\study\\mapgst",null);
/*myMap.loadGeoset("E:\\MapInfo\\study\\mapgst\\world.gst",
"E:\\MapInfo\\study\\mapgst",
"http://901-32:8083/mapxtreme47/mapxtreme");*/
//load a map difinition
//to load a map definition ,we must create a MapDefContainer which is abstraction that represents
//where the map difinition is stored
// mdc=new FileMapDefContainer("E:\\MapInfo\\study\\mapmdf");
//load the name map definition
// myMap.loadMapDefinition(mdc,"world.mdf");
//set the device bounds
myMap.setDeviceBounds(new DoubleRect(0,0,800,600)) ;
//to render the map,we must instantiate a render object
//the following statement use a MapXtremeImageRenderer and render the image as gif
String mapxtremeServletUrl="http://901-32:8083/mapxtreme47/mapxtreme";
MapXtremeImageRenderer render=new MapXtremeImageRenderer(mapxtremeServletUrl);
//create an ImageRequestComposer
myMap.setZoom(10) ;
//add one layer
// specify the url to the MapXtreme servlet which remotely connects us to the map engine
String mapXtremeURL = "http://901-32:8083/mapxtreme47/mapxtreme";
// create the tab TableDescHelper
TABTableDescHelper tabTDHelper = new TABTableDescHelper( new File("e:\\MapInfo\\studymap\\line.tab").getName());
// create the tab DataProviderHelper
TABDataProviderHelper tabDPHelper = new TABDataProviderHelper("e:\\MapInfo\\studymap");
// Create the Remote DataProviderRef needed to access the Data
MapXtremeDataProviderRef mxtDPRef = new MapXtremeDataProviderRef(tabDPHelper, mapXtremeURL);
// assign it to MapJ
myMap.getLayers().addLayer(mxtDPRef, tabTDHelper, "tabLayer");
//
ImageRequestComposer imageRC=ImageRequestComposer.create(myMap,256,Color.BLUE ,"image/png");
//render the map
render.render(imageRC) ;
//export the rendered map to file
render.toFile("e:\\mapinfo\\study\\mapimage\\"+saveFileName) ;
}catch(java.io.IOException ioe)
{
System.out.println("get a "+ioe.getClass() +"\nwith message "+ioe.getMessage() ) ;
}catch(java.lang.Exception e)
{
System.out.println("get a "+e.getClass() +"\nwith message "+e.getMessage() ) ;
e.printStackTrace() ;
}
}
public void CreateOneMap2()
{//map source comes from map definition file
myMap=new MapJ();
try
{
//loading one geoset
/*myMap.loadGeoset("E:\\MapInfo\\study\\mapgst\\Administrative.gst",
"E:\\MapInfo\\study\\mapgst",null);*/
/*myMap.loadGeoset("E:\\MapInfo\\study\\mapgst\\world.gst",
"E:\\MapInfo\\study\\mapgst",
"http://901-32:8083/mapxtreme47/mapxtreme");*/
//load a map difinition
//to load a map definition ,we must create a MapDefContainer which is abstraction that represents
//where the map difinition is stored
mdc=new FileMapDefContainer("E:\\MapInfo\\study\\mapmdf");
//load the name map definition
myMap.loadMapDefinition(mdc,"ADMINISTRATIVE3.mdf");
//set the device bounds
myMap.setDeviceBounds(new DoubleRect(0,0,800,600)) ;
Layer layer=(Layer)myMap.getLayers() .get(0) ;
//to render the map,we must instantiate a render object
//the following statement use a MapXtremeImageRenderer and render the image as gif
String mapxtremeServletUrl="http://901-32:8083/mapxtreme47/mapxtreme";
MapXtremeImageRenderer render=new MapXtremeImageRenderer(mapxtremeServletUrl);
//create an ImageRequestComposer
LinearUnit distUnit = LinearUnit.kilometer;
//LinearUnit distUnit=LinearUnit.meter ;
myMap.setDistanceUnits(distUnit);
myMap.setZoom(42.35) ;//設置不是比例尺,設置的是視野范圍,即窗口寬度。
// DoubleRect bounds = new DoubleRect(new DoublePoint(108.9607,34.2729),0.31,0.21);
//設置該地圖的中心為(108.9607,34.2729)單位為經緯度單位,0.31表示該地圖的經度的最大值與最小值之差為0.31
//0.21表示該地圖的緯度的最大值與最小值之差為0.21
// myMap.setBounds(bounds);
ImageRequestComposer imageRC=ImageRequestComposer.create(myMap,256,Color.BLUE ,"image/png");
//render the map
render.render(imageRC) ;
//export the rendered map to file
render.toFile("e:\\mapinfo\\study\\mapimage\\administrative_24.png") ;
}catch(java.io.IOException ioe)
{
System.out.println("get a "+ioe.getClass() +"\nwith message "+ioe.getMessage() ) ;
}catch(java.lang.Exception e)
{
System.out.println("get a "+e.getClass() +"\nwith message "+e.getMessage() ) ;
e.printStackTrace() ;
}
}
public void saveToMapDef()
{
String drivername="oracle.jdbc.driver.OracleDriver";
String dburl="jdbc:oracle:thin:@901-32:1521:xianmap";
String username="userstoremap2";
String password="Icando41";
String tablename="mapdefinition";
String nameCol="name";
String mapDefCol="mapdef";
try
{
OraSoMapDefContainer mdc = new OraSoMapDefContainer(drivername, dburl,
username, password,tablename,nameCol,mapDefCol);
//最后三個參數解釋一下,tablename表示將world.gst所對應的數據保存到哪個表中
//nameCol表示存儲表名的字段名稱是什么,mapDefCol表示存儲地圖數據的字段名稱又是什么
MapJ map=new MapJ();
map.loadGeoset("E:\\MapInfo\\study\\mapgst\\world.gst",
"E:\\MapInfo\\study\\mapgst",null);
map.saveMapDefinition(mdc,"world");//"world" indicate the value in field "name",don't mean file world.gst
}catch(java.sql.SQLException sqle)
{
System.out.println("get a "+sqle.getClass() +"\nwith message "+sqle.getMessage() ) ;
sqle.printStackTrace() ;
}catch(java.io.IOException ioe)
{
System.out.println("get a "+ioe.getClass() +"\nwith message "+ioe.getMessage() ) ;
ioe.printStackTrace() ;
}catch(java.lang.Exception e)
{
System.out.println("get a "+e.getClass() +"\nwith message "+e.getMessage() ) ;
e.printStackTrace() ;
}
}
public void loadDataFromOracle(String imageName)
{
//specify the url to mapxtremeservelt that will be used to access the data
String strUrl="http://901-32:8083/mapxtreme47/mapxtreme";
//use database specify DataProviderHelper
OraSoDataProviderHelper oraDPHelper = new OraSoDataProviderHelper(
"901-32", 1521, "xianmap",
"userstoremap2", "Icando41", DriverType.thin,
"oracle.jdbc.driver.OracleDriver");
//create a string array with the name(s) of the column(s) to use as unique key for the records in the table
String[] idColumns={"MI_PRINX"};
//create a tableDescHelper
//required constructuor when use a tablename
OraSoTableDescHelper oraDTHelper=new OraSoTableDescHelper("ADMINISTRATIVE3",false,idColumns,
"GEOLOC",null,RenditionType.none,null,RenditionType.none, CoordSys.longLatWGS84 ,2,"USERSTOREMAP2");
//reference the remote data provider need to access the data
try
{
MapXtremeDataProviderRef mxtDPRef = new MapXtremeDataProviderRef(
oraDPHelper, strUrl);
MapJ map=new MapJ();
map.setDeviceBounds(new DoubleRect(0,0,800,600)) ;
map.getLayers() .insertLayer(mxtDPRef,oraDTHelper,0,"onelayer");
MapXtremeImageRenderer render=new MapXtremeImageRenderer(strUrl);
ImageRequestComposer imageRC=ImageRequestComposer.create(map,256,Color.cyan ,"image/png");
render.render(imageRC) ;
render.toFile("e:\\mapinfo\\study\\mapimage\\"+imageName) ;
}catch(java.lang.Exception e)
{
System.out.println("get a "+e.getClass() +"\nwith message "+e.getMessage() ) ;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -