📄 mapperservlet.java
字号:
{
////PrintWriter out = new PrintWriter(res.getOutputStream());
////String thisServletName = HttpUtils.getRequestURL(req).toString();
//sDistance = new java.text.DecimalFormat("###.##").format(iDistance);
//res.encodeURL(sDistance);
//sDistance.toStream(res.getOutputStream());
////out.println(res.encodeURL(thisServletName));
////out.print("the fucking distance :"+sDistance);
//// System.out.println("test" + sDistance);
////out.close();
PrintWriter out = new PrintWriter(res.getOutputStream());
String thisServletName = HttpUtils.getRequestURL(req).toString();
res.encodeURL(String.valueOf(iDistance).toString());
out.println(String.valueOf(iDistance).toString());
System.out.println("the period of distance : "+ String.valueOf(iDistance).toString());
out.close();
}
} // End if tool used
}
//解析收到的定位信息
public Vector getPosMessage(String Msg)
{
Vector v=new Vector();
String k="";
double j=0.0;
String ff="";
String sub="/";
String result="";
String dd="";
// 0000000000000000$GPRMC 064935.000 A 3955.5850 N 11619.6262 E 009 312 281004 *FF
// 0000000000000400$GPRMC 221018.000 V 4057.3118 N 11757.6691 E 000 120 031104 *FF
//in_string=0000000000000000$GPRMC 084754.000 V 4057.3174 N 11757.6659 E 000 144 051104 *FF
int index1=Msg.indexOf(" ");
int index2=Msg.indexOf(" ",index1+1);
int index3=Msg.indexOf(" ",index2+1);
int index4=Msg.indexOf(" ",index3+1);
k=Msg.substring(index3+3,index4);
j = Double.valueOf(k).doubleValue()/60;
DecimalFormat nf = new DecimalFormat("0.####");
ff =nf.format(j);
ff = ff.substring(2,ff.length());
// ff = Integer.toString(j);
String Latitude=Msg.substring(index3+1,index3+3)+"."+ff;
// double Lati=Double.parseDouble(Latitude)*0.01;
// Latitude=String.valueOf(Lati);
int index5=Msg.indexOf(" ",index4+1);
int index6=Msg.indexOf(" ",index5+1);
k=Msg.substring(index5+4,index6);
j = Double.valueOf(k).doubleValue()/60;
// DecimalFormat nf = new DecimalFormat("0.####");
ff =nf.format(j);
ff = ff.substring(2,ff.length());
// ff = Integer.toString(j);
String Longitude=Msg.substring(index5+1,index5+4)+"."+ff;
// double Longi=Double.parseDouble(Longitude)*0.01;
// Longitude=String.valueOf(Longi);
int index7=Msg.indexOf(" ",index6+1);
int index8=Msg.indexOf(" ",index7+1);
String Speed=Msg.substring(index7+1,index8);
double Sp=Double.parseDouble(Speed)*1.85;
Speed=String.valueOf(Sp);
int index9=Msg.indexOf(" ",index8+1);
int index10=Msg.indexOf(" ",index9+1);
String Date=Msg.substring(index9+1,index10);
Date = Date.substring(0,2)+"/"+Date.substring( 2,4)+"/" +Date.substring(4);
String Time = Msg.substring(index1+1,index2);
String OriginalHours = Time.substring(0,2);
int Add_Hours = (Integer.parseInt(OriginalHours)+8);
if(Add_Hours>24){
Add_Hours = Add_Hours-24;
}
String AlterHours=String.valueOf(Add_Hours);
Time = AlterHours+":"+Time.substring(2,4)+":" +Time.substring(4,6);
Date = Date+" "+Time;
v.addElement(Latitude);
v.addElement(Longitude);
v.addElement(Speed);
v.addElement(Date);
return v;
}
/*//////////////////////////////////////////////////////////////////////////////////////////////////
转换字符
///////////////////////////////////////////////////////////////////////////////////////////////////*/
public static String convertToChinese(String chineseStr)
{
if(chineseStr != null)
{
try
{
chineseStr = new String(chineseStr.getBytes("ISO8859_1"), "GBK");
}
catch(Exception e)
{
e.printStackTrace();
}
}
return chineseStr;
}
/*//////////////////////////////////////////////////////////////////////////////////////////////////
显示车辆
///////////////////////////////////////////////////////////////////////////////////////////////////*/
public boolean showResult(MapJ mapj,DoublePoint m_dPoint,String tel) {
String StrAnnLayerName = tel;//"AnnLayer";
Layer lyrAnn;
Attribute attrib[] = new Attribute[7];
attrib[0] = new Attribute(tel);
attrib[1] = new Attribute("china");
attrib[2] = new Attribute("beijng");
attrib[3] = new Attribute("bj");
attrib[4] = new Attribute("100000");
attrib[5] = new Attribute(116.196084);
attrib[6] = new Attribute(39.555990);
String columns[] = {"Name", "Address", "city", "State", "Zip", "x", "y"};
int types[] = { TableInfo.COLUMN_TYPE_STRING,
TableInfo.COLUMN_TYPE_STRING,
TableInfo.COLUMN_TYPE_STRING,
TableInfo.COLUMN_TYPE_STRING,
TableInfo.COLUMN_TYPE_STRING,
TableInfo.COLUMN_TYPE_DOUBLE,
TableInfo.COLUMN_TYPE_DOUBLE};
if (mapj.getLayers().getLayer(StrAnnLayerName)!=null) {
lyrAnn = mapj.getLayers().getLayer(StrAnnLayerName);
if (!lyrAnn.isAnnotationLayer()) return false;
try {
ArrayList columns_a = new ArrayList();
TableInfo tabInfo = lyrAnn.getTableInfo();
for (int i=0; i<tabInfo.getColumnCount();++i) {
columns_a.add(tabInfo.getColumnName(i));
}
RewindableFeatureSet rFtrSet = new RewindableFeatureSet(lyrAnn.searchAll(columns_a, null));
Feature ftr = rFtrSet.getNextFeature();
while (ftr != null) {
lyrAnn.removeFeature(ftr.getPrimaryKey());
ftr = rFtrSet.getNextFeature();
}
rFtrSet.dispose();
} catch (Exception ed) {
ed.printStackTrace();
return false;
}
}else {
try {
CoordSys curCoordSys = mapj.getNumericCoordSys();
int[] primarykey = new int[1];
TableInfoImpl tii = new TableInfoImpl(StrAnnLayerName, curCoordSys, columns, types,7,primarykey, false);
AnnotationTableDescHelper annTDHelper = new AnnotationTableDescHelper(StrAnnLayerName);
AnnotationDataProviderHelper annDPHelper = new AnnotationDataProviderHelper(tii);
LocalDataProviderRef localDPRef = new LocalDataProviderRef(annDPHelper);
lyrAnn = mapj.getLayers().insert(localDPRef, annTDHelper, 0, StrAnnLayerName);
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
//创建车辆
Rendition rend = RenditionImpl.getDefaultRendition();
rend.setValue(Rendition.SYMBOL_MODE ,Rendition.SymbolMode.IMAGE );
rend.setValue(Rendition.SYMBOL_URL,"http://219.237.4.34:8080/samples47/images/car.gif");
//沿线绘制车辆轨迹
//创建Feature,然后加入到AnnLayer。
PrimaryKey pkey = new PrimaryKey(attrib);
FeatureFactory ff = mapj.getFeatureFactory();
try {
Feature feat = ff.createPoint(m_dPoint,rend,attrib, pkey);
lyrAnn.setVisible(true);
lyrAnn.addFeature(feat);
BaseLabelProperties blp = new BaseLabelProperties();
blp = lyrAnn.getLabelProperties();
blp.setLabelExpression(columns[0]);
lyrAnn.setLabelProperties(blp);
lyrAnn.setAutoLabel(true);
} catch (Exception ec) {
ec.printStackTrace();
return false;
}
return true;
}
/*//////////////////////////////////////////////////////////////////////////////////////////////////
显示车辆
///////////////////////////////////////////////////////////////////////////////////////////////////*/
public boolean showName(MapJ mapj,DoublePoint m_dPoint,String m_name) {
String StrAnnLayerName = m_name;//"PlaceNameLayer";
Layer lyrAnn;
Attribute attrib[] = new Attribute[7];
attrib[0] = new Attribute(m_name);
attrib[1] = new Attribute("china");
attrib[2] = new Attribute("beijng");
attrib[3] = new Attribute("bj");
attrib[4] = new Attribute("100000");
attrib[5] = new Attribute(116.196084);
attrib[6] = new Attribute(39.555990);
String columns[] = {"Name", "Address", "city", "State", "Zip", "x", "y"};
int types[] = { TableInfo.COLUMN_TYPE_STRING,
TableInfo.COLUMN_TYPE_STRING,
TableInfo.COLUMN_TYPE_STRING,
TableInfo.COLUMN_TYPE_STRING,
TableInfo.COLUMN_TYPE_STRING,
TableInfo.COLUMN_TYPE_DOUBLE,
TableInfo.COLUMN_TYPE_DOUBLE};
if (mapj.getLayers().getLayer(StrAnnLayerName)!=null) {
lyrAnn = mapj.getLayers().getLayer(StrAnnLayerName);
if (!lyrAnn.isAnnotationLayer()) return false;
try {
ArrayList columns_a = new ArrayList();
TableInfo tabInfo = lyrAnn.getTableInfo();
for (int i=0; i<tabInfo.getColumnCount();++i) {
columns_a.add(tabInfo.getColumnName(i));
}
RewindableFeatureSet rFtrSet = new RewindableFeatureSet(lyrAnn.searchAll(columns_a, null));
Feature ftr = rFtrSet.getNextFeature();
while (ftr != null) {
lyrAnn.removeFeature(ftr.getPrimaryKey());
ftr = rFtrSet.getNextFeature();
}
rFtrSet.dispose();
} catch (Exception ed) {
ed.printStackTrace();
return false;
}
}else {
try {
CoordSys curCoordSys = mapj.getNumericCoordSys();
int[] primarykey = new int[1];
TableInfoImpl tii = new TableInfoImpl(StrAnnLayerName, curCoordSys, columns, types,7,primarykey, false);
AnnotationTableDescHelper annTDHelper = new AnnotationTableDescHelper(StrAnnLayerName);
AnnotationDataProviderHelper annDPHelper = new AnnotationDataProviderHelper(tii);
LocalDataProviderRef localDPRef = new LocalDataProviderRef(annDPHelper);
lyrAnn = mapj.getLayers().insert(localDPRef, annTDHelper, 0, StrAnnLayerName);
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
//创建车辆
Rendition rend = RenditionImpl.getDefaultRendition();
// Use the mapInfo Miscellaneous font
rend.setValue(Rendition.FONT_FAMILY, "宋体");
// Make the font 14 pts
rend.setValue(Rendition.FONT_SIZE, new Float(14));
// The weight should be greater than 0. 1.0 = normal, 2.0 = bold, etc.
rend.setValue(Rendition.FONT_WEIGHT, new Float(2));
// Make it a leaning garbage can
//rend.setValue(Rendition.FONT_STYLE, Rendition.FontStyle.ITALIC);
// indicate that we are using a font for the symbol
rend.setValue(Rendition.SYMBOL_MODE, Rendition.SymbolMode.FONT);
// the number 4 is the garbage can
rend.setValue(Rendition.SYMBOL_STRING, m_name);
// make the symbol yellow on a red background
//rend.setValue(Rendition.SYMBOL_FOREGROUND, Color.red );
rend.setValue(Rendition.SYMBOL_BACKGROUND, Color.black);
//沿线绘制车辆轨迹
//创建Feature,然后加入到AnnLayer。
PrimaryKey pkey = new PrimaryKey(attrib);
FeatureFactory ff = mapj.getFeatureFactory();
try {
Feature feat = ff.createPoint(m_dPoint,rend,attrib, pkey);
lyrAnn.setVisible(true);
lyrAnn.addFeature(feat);
//BaseLabelProperties blp = new BaseLabelProperties();
//blp = lyrAnn.getLabelProperties();
//blp.setLabelExpression(columns[0]);
//lyrAnn.setLabelProperties(blp);
//lyrAnn.setAutoLabel(true);
} catch (Exception ec) {
ec.printStackTrace();
return false;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -