WebGIS小结之五(控制地图显示)

看到地图图像后,你可能需要查看地图的其他部分,看看整体或地图细节。下面介绍一些控制地图显示的方法。

1. 设置地图视野(Zoom

Zoom值是地图的横向跨度,单位有地图的距离单位决定。设置zoom可以放大或缩小地图。当地图加载时,zoom就被设定了。

    改变zoom的方法是setZoom()
       
示例:

// Assuming that the current distance units are kilometers, this command will set the //map zoom to 500 kilometers.

myMap.setZoom(500);

2.设置地图中心

有时会将地图中心定位在找到的目标上或将中心定位在鼠标所点击的图像上某一点。这时需要设置地图中心。

设置地图中心的方法是setCenter()

下面的示例实现了将地图中心定位在鼠标点击的某一点。

示例:

// 创建屏幕坐标的Point对象

screenpoint = new DoublePoint(event.getX(),event.getY());

// 将屏幕坐标转换为地理坐标

worldpoint = myMap.transformScreenToNumeric(screenpoint);

// 设置地图中心

myMap.setCenter(worldpoint);

3.设置地图边界

地图边界不是图象的边界,而是地图坐标系的边界,所有的地图操作都在这个边界内进行。

设置地图边界有两种方法:

方法1

给定边界的左下角和右上角,设定边界。

DoubleRect bounds = new DoubleRect(-180,-90,180,90);

myMap.setBounds(bounds); 

方法2

给定地图的中心,宽度和高度,设定边界。

DoubleRect bounds = new DoubleRect(new DoublePoint(0,0),360,180);

myMap.setBounds(bounds); 

4. 添加图层

使用Layers.add方法向地图添加额外的图层,该图层可以来自文件或数据库。MapXtreme使用DataProvider来管理这些信息。

文件添加图层

private MapJ addLayer(MapJ myMap) {
try {

String m_localMapPath = " C://Program Files//MapInfo//maps ";

String m_remoteMapPath =

"http://219.245.117.110:8090/mapxtreme45/servlet/mapxtreme"

TABDataProviderHelper tabDPH = 

new TABDataProviderHelper(m_ localMapPath);

//使用本地数据访问
DataProviderRef dpRef = new LocalDataProviderRef(tabDPH);
//
使用远程数据访问
//MapXtremeDataProviderRef dpRef = 

//new MapXtremeDataProviderRef(tabDPH,m_ remoteMapPath);

            TABTableDescHelper tabDesc = new TABTableDescHelper("OCN_ASIA");
            myMap.getLayers().insert(dpRef, tabDesc, 1, "OCN_ASIA");
                }
            catch (Exception e) {
            e.printStackTrace();
                }

return myMap;
}

oracle空间数据库里添加图层

示例

//本示例引自http://www.mygis.com.cn 放在这仅供参考

private Layer addBoundLayer(MapJ map, String layerName) throws Exception {

// local strings, values edited for publication
String driverUrl = "jdbc:oracle:oci8:@SERVER";
String usr = "SCOTT";
String pwd = "TIGER";
String mapsDir = "c://mapxtreme40//maps//";

// create a tab data provider for the map objects
TABDataProviderHelper tabDPH = new TABDataProviderHelper(mapsDir);

// create a data provider to access the tabular data
JDBCDataProviderHelper jdbcDPH = new JDBCDataProviderHelper(driverUrl, usr, pwd,
"oracle.jdbc.driver.OracleDriver");

// create a DataBindingDataProviderHelper which indicates which //two data providers to "join"
DataBindingDataProviderHelper bndDPH = new DataBindingDataProviderHelper(tabDPH, jdbcDPH);

// create a TAB table description for the map data
TABTableDescHelper tabTDH = new TABTableDescHelper("states2.tab");

// create a table description for the tabular data
JDBCTableDescHelper jdbcTDH = new JDBCTableDescHelper("US_CUST","TS");

// create the string arrays which specifies the columns to perform //the join with
String [] geoCols = {"state"};

// note: for JDBC data sources, the column names are case //sensitive.
String [] joinCols = {"STATE"};

// create the DataBindingTableDescHelper which describes the //source of
// the data and map object tables
DataBindingTableDescHelper bndTDH = new DataBindingTableDescHelper(tabTDH, jdbcTDH, geoCols, joinCols);

// create a data provider reference for the data provider helper
LocalDataProviderRef bndDPR = new LocalDataProviderRef(bndDPH);

// optional, add an aggregation method which defines how to deal with
// multiple data records for a map object
bndTDH.addAggregation("ORDER_AMT", Aggregation.SUM);

// finally, add the layer to the map
Layer lyr = map.getLayers().insert(bndDPR, bndTDH, 0, layerName);

return lyr;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值