?? mapsearch.java
字號:
package com.oyc.mapxtreme.util;
import java.util.HashMap;
import java.util.Vector;
import com.mapinfo.dp.Attribute;
import com.mapinfo.dp.Feature;
import com.mapinfo.dp.FeatureSet;
import com.mapinfo.dp.QueryParams;
import com.mapinfo.dp.TableInfo;
import com.mapinfo.mapj.FeatureLayer;
import com.mapinfo.mapj.Layers;
import com.mapinfo.mapj.MapJ;
import com.mapinfo.util.DoublePoint;
/**
* 地圖搜索類
* @author 三峽大學理學院 歐陽超
*
*/
public class MapSearch {
/**
* 按屬性搜索: 通常用于主鍵ID搜索
* @param myMap
* @param layerName 要搜索的圖層名稱
* @param attName 屬性名
* @param att
* @param params
* @return 如果沒搜索到,則返回null
* @throws Exception
*/
public Feature searchByAttribute(MapJ myMap, String layerName, String attName, Attribute att, QueryParams params) throws Exception{
//取出搜索的圖層
FeatureLayer layer = (FeatureLayer) myMap.getLayers().get(layerName);
//創建字段向量
TableInfo tInfo = layer.getTableInfo();
Vector cols = new Vector();
for(int i=0; i<tInfo.getColumnCount(); i++){
cols.addElement(tInfo.getColumnName(i));
}
//搜索,返回圖層對象
FeatureSet fs = layer.searchByAttribute(cols, attName, att, params);
if(fs != null){
Feature feature = fs.getNextFeature();
if(feature != null){
return feature;
}
}
return null;
}
/**
* 在某個點上搜索圖元
* @param myMap
* @param point 屏幕坐標
* @param params
* @return 如果沒搜索到,則返回null
*/
public HashMap searchAtPoint(MapJ myMap, DoublePoint point, QueryParams params) throws Exception{
//取出圖層集合
Layers layers = myMap.getLayers();
if(layers == null || layers.size() < 1){
return null;
}
//當屏幕坐標轉化為實際坐標
DoublePoint p = myMap.transformScreenToNumeric(point);
FeatureLayer layer = null;
Vector cols = null;
TableInfo tInfo = null;
FeatureSet fs = null;
//遍歷各圖層
for(int i=0; i<layers.size(); i++){
layer = (FeatureLayer) layers.get(i);
if(layer.isEnabled()){ //如果該圖層可見
//創建屬性列向量
cols = new Vector();
tInfo = layer.getTableInfo();
for(int j=0; j<tInfo.getColumnCount(); j++){
cols.addElement(tInfo.getColumnName(j));
}
//搜索圖層
fs = layer.searchAtPoint(cols, p, params);
if(fs != null){
Feature feature = fs.getNextFeature();
if(feature != null){
HashMap map = new HashMap();
map.put("layer", layer);
map.put("feature", feature);
return map;
}
}
}
}
return null;
}
/**
* 在某個半徑范圍內搜索,返回圖元集
* @param myMap
* @param layerName
* @param center
* @param radius
* @param units
* @param params
* @return 如果沒有搜索到,返回null
* @throws Exception
*/
public FeatureSet searchInRadius(MapJ myMap, String layerName, DoublePoint center,
double radius, QueryParams params) throws Exception{
//取出搜索的圖層
FeatureLayer layer = (FeatureLayer) myMap.getLayers().get(layerName);
//當屏幕坐標轉化為實際坐標
DoublePoint p = myMap.transformScreenToNumeric(center);
//創建字段向量
TableInfo tInfo = layer.getTableInfo();
Vector cols = new Vector();
for(int i=0; i<tInfo.getColumnCount(); i++){
cols.addElement(tInfo.getColumnName(i));
}
//搜索
FeatureSet fs = layer.searchWithinRadius(cols, p, radius, myMap.getDistanceUnits(), params);
if(fs != null){
return fs;
}else{
return null;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -