?? infovisitservlet.java
字號:
package com.oyc.mapxtreme.servlet;
import java.io.IOException;
import java.util.HashMap;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.mapinfo.dp.Feature;
import com.mapinfo.mapj.FeatureLayer;
import com.mapinfo.mapj.MapJ;
import com.mapinfo.util.DoublePoint;
import com.oyc.mapxtreme.beans.SightBean;
import com.oyc.mapxtreme.beans.TravelAgencyBean;
import com.oyc.mapxtreme.dao.SightDAO;
import com.oyc.mapxtreme.dao.TravelAgencyDAO;
import com.oyc.mapxtreme.util.MapSearch;
import com.oyc.wakeup.Session;
/**
* 信息訪問: 用戶在地圖上用信息訪問工具單擊時,顯示相應的信息
* @author 三峽大學理學院 歐陽超
*
*/
public class InfoVisitServlet extends BaseHttpServlet {
/**
* 顯示地圖上某個點的信息
*
*/
public void showInfo(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//取得點坐標
double x = Double.parseDouble(request.getParameter("x"));
double y = Double.parseDouble(request.getParameter("y"));
//取出地圖對象
HttpSession session = request.getSession();
MapJ myMap = (MapJ) session.getAttribute("mapj");
//搜索
MapSearch mapSrh = new MapSearch();
HashMap map = null;
try {
map = mapSrh.searchAtPoint(myMap, new DoublePoint(x, y), null);
} catch (Exception e) {
e.printStackTrace();
}
if(map != null && map.size() > 0){ //
FeatureLayer layer = (FeatureLayer) map.get("layer");
Feature feature = (Feature) map.get("feature");
//取出圖元ID
int id = -1;
try {
id = feature.getAttribute(0).getInt();
} catch (Exception e) {
e.printStackTrace();
}
//根據圖層創建DAO,取出數據
if(layer.getName().equals("旅行社")){
Session sess = super.getWakeupSession();
TravelAgencyDAO dao = new TravelAgencyDAO(sess);
TravelAgencyBean bean = dao.getTravelById(id);
sess.close();
request.removeAttribute("taBean");
request.setAttribute("taBean", bean);
String url = "travelInfo.jsp";
super.forward(url, request, response);
}else if(layer.getName().equals("景點")){
Session sess = super.getWakeupSession();
SightDAO dao = new SightDAO(sess);
SightBean bean = dao.getSightById(id);
sess.close();
request.removeAttribute("sightBean");
request.setAttribute("sightBean", bean);
String url = "sightInfo.jsp";
super.forward(url, request, response);
}else{ //"道路"圖層,不顯示信息
this.htmlToClient(response, "當前對象為大地: 沒有詳細信息 !");
}
}else{ //當前沒有可顯示圖層或單擊點為空白處
this.htmlToClient(response, "當前點沒有任何信息 !");
}
}
/**
* 返回html代碼給客戶端,說明當前沒有查找到任何信息
* @param response
* @param content
* @throws IOException
*/
private void htmlToClient(HttpServletResponse response, String content) throws IOException {
response.setContentType("text/html;charset=gb2312");
ServletOutputStream out = response.getOutputStream();
out.print("<html><head><title>信息訪問</title>");
out.print("<link href='css/popwindow.css' rel='stylesheet' type='text/css' /></head><body>");
out.print("<div class='noinfo'>"+ content +"</div>");
out.print("<div class='button_div'><input type='button' value='確定' class='button' onclick='window.close();'/></div>");
out.print("</body></html>");
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -