📄 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 + -