具体的封装了。)
//todo:the selectFeature operation;利用mapj对象来获得特定图层,根据点来获取附近的图元,并进
行图元的高亮渲染后生成新地图,返回客户端
private void selectF(HttpSession session,HttpServletRequest req,
HttpServletResponse res)
throws Exception
{
String reqParam; // to hold request parameter
Double xStr = null; // to hold x request params 字串4
Double yStr = null; // to hold y request params 字串8
// Try to retrieve the user's previous MapJ object.
MapJ myMap = (MapJ) session.getAttribute("mapinfo.mapj");
if (myMap == null) {
// This is probably the user's first time requesting a map.
myMap = initMapJ();
} 字串7
// Get the previous center point locations
DoublePoint newpoint = myMap.getCenter();
//以下是定义一个对象来获得点的位置
DoublePoint AtPoint=new DoublePoint();
if ( (reqParam = req.getParameter("ptx")) != null) {
xStr = new Double(reqParam);
}
if ( (reqParam = req.getParameter("pty")) != null) { 字串8
yStr = new Double(reqParam);
}
if (xStr != null && yStr != null) {
// 把GIF的象素位置转化为实际的地理坐标
DoublePoint screenpoint = new DoublePoint(xStr.doublevalue(),
yStr.doublevalue());
字串9
字串3
double newZoom = myMap.getZoom();
// Reset the bounding rectangle, note - Pan handled by default
myMap.setZoomAndCenter(newZoom, newpoint);
字串5
// 以下是进行图元的查找和渲染
Layer toDoLayer=myMap.getLayers().getLayer("jumindi");
//删除以上操作已经添加的theme列表
toDoLayer.getThemeList().removeAll(true); 字串1
System.out.println(toDoLayer.getName());
Vector columns = new Vector();
TableInfo tabInfo = toDoLayer.getTableInfo();
for (int i = 0; i < tabInfo.getColumnCount(); i++) {
System.out.println(tabInfo.getColumnName(i) + " -- ");
columns.addElement(tabInfo.getColumnName(i));
}
字串8
// 选择图元。其中ATPoint是前面获得的鼠标客户端点击的实际位置。
fs = toDoLayer.searchAtPoint(columns, AtPoint, null);
// 创建一个 SelectionTheme
SelectionTheme selTheme = new SelectionTheme("PointSelection"); 字串1
// 创建一个Selection对象并且把选择的图元加入
Selection sel = new Selection();
sel.add(fs);
字串6
// 把Selection对象加入到SelectionTheme
selTheme.setSelection(sel); 字串3
// 设置SelectionTheme的显示渲染的样式
Rendition rend = RenditionImpl.getDefaultRendition();
rend.setvalue(Rendition.FILL, Color.red);
selTheme.setRendition(rend);
字串4
// 添加SelectionTheme到指定layer的theme列表中
toDoLayer.getThemeList().add(selTheme);
字串7
//以下是渲染地图,以流方式返回客户端
try {
MapXtremeImageRenderer rr = new MapXtremeImageRenderer(m_mxtURL);
rr.render(ImageRequestComposer.create(
myMap, 256, Color.white, "image/jpeg"));
字串4
System.out.println(
"render:now render the image over and back to client."); 字串8
//Output the map
rr.toStream(res.getOutputStream());
}
catch (Exception e) {
log(e.getMessage());
throw e;
}
字串9
// Save state info for next time around.保存mapj对象,维持会话
session.setAttribute("mapinfo.mapj", myMap);
字串2
}

| 最新评论: |