文章正文

利用SelectionTheme实现查找图元的高亮显示

文章来源:MapInfo技术论坛 文章作者: 2006-12-25  字体:[ 我要投稿!
服务器端servlet处理选择工具点击后的代码如下:
  (当然,可以将该段代码按照规范写成bean。目前只是在学习api以及摸索某些功能的实现,所以没做

具体的封装了。)

字串3


//todo:the selectFeature operation;利用mapj对象来获得特定图层,根据点来获取附近的图元,并进

字串4

行图元的高亮渲染后生成新地图,返回客户端
          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


                AtPoint = myMap.transformScreenToNumeric(screenpoint);
              }

字串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));
             }
              

字串5

//以下是利用专题图来高亮显示图元
        
         FeatureSet fs = null;

字串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

 

字串4

              //以下是渲染地图,以流方式返回客户端
              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


          }

字串5


上一篇:如何在MapXtreme里实现地图鹰眼功能
下一篇:Oracle Spatial 9i入门资料[教程下载]
收藏本文: Del.icio.us Google书签 Digg Live Bookmark 365Key网摘 天极网摘 和讯网摘 QQ书签 Digbuzz我挖网 该页面添加到 Mister Wong
精彩图片推荐
今日推荐
用户名:新注册) 密码: 匿名评论
评论内容:不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
 最新评论
搜索:
  • 第一视频联播网广告联盟 群视传播文内广告联盟
  • 通过BackLinks卖链接赚美元 注册Text Link Ads 就送25美元
   网站首页 -  关于我们 -  联系我们 -  网站地图 -    RSS订阅 - 网站博客 -  网站投稿 -  链接申请 -  网站留言
Copyright 2007 www.gispark.com All Rights Reserved 闽ICP备06027130号