|
songqian :
我在做选择图层时,用鼠标点击一个图元,但被选中的却是别的图元,如上图所示,是我点击编号为28的图元所选中的。而如果点击编号为1的图元,所选中的图元是2。即越往右端误差越大。我实在是找不出错误,我把代码列下来,请大家帮我看看。
jsp页面上的javascript:
function mapselect(){
var centerx
var centery
var sessionName="SESSION_MAP_0";
centerx=window.event.x;
centery=window.event.y;
location.href="listheap_goods.do?actn=select¢erx="+centerx+"¢ery="+centery+"&sessionName="+sessionName;
}
这是提交参数的那段代码
jsp页面的图片位置
<div id="mapframe" style="position:absolute;left:0px;top:0px;height:600px;width:800px;overflow:hidden;background-color:#FFFFFF;layer-background-color:#0000FF;border:1px #cccccc solid">
<img onMouseDown="selecHeap()" id="imgmap" src="e:\\songqian.gif" GALLERYIMG="false" style="position:relative;left:0px;top:0px;height:600px;width:800px;cursor:default">
</div>
我测试了一下,点击图片的左上角提交的参数centerx=0,centery=0,点击右下角centerx=797,centery=597,抛除我操作上的误差,基本上是正确的。
后台的函数:
/*选择*/
public Collection selection(MapJ mymap,HttpServletRequest request)throws Exception
{
ArrayList al=new ArrayList();
FeatureSet featureset = null;
try
{//获得点坐标
Double centerx = new Double(request.getParameter("centerx"));
Double centery = new Double(request.getParameter("centery"));
DoublePoint screenpoint = new DoublePoint(centerx.doublevalue(),
centery.doublevalue());
DoublePoint mappoint = mymap.transformScreenToNumeric(screenpoint);
FeatureLayer featurelayer=mymap.getLayers().getLayer("yard");
SelectionTheme selectiontheme =(SelectionTheme)featurelayer.getThemeList().getTheme("selectionToolTheme"); Selection selection=new Selection(); Rendition rendition ; if(selectiontheme == null){ selectiontheme = new SelectionTheme("selectionToolTheme"); }else{ featurelayer.getThemeList().remove(selectiontheme); selectiontheme=new SelectionTheme("selectionToolTheme"); } //保存图元属性 Vector vector = new Vector(); TableInfo tableinfo = featurelayer.getTableInfo(); for(int j = 0; j < tableinfo.getColumnCount(); j++) vector.add(tableinfo.getColumnName(j));//用向量保存地图文件列名 try{ featureset = featurelayer.searchAtPoint(vector,mappoint,null);//搜索图元 rendition=RenditionImpl.getDefaultRendition(); rendition.setvalue(Rendition.FILL,Color.BLACK); Feature feature; while((feature = featureset.getNextFeature()) != null){//遍历图元 selection.add(feature); //添加该图元 if(feature.getAttribute(0)!=null){ al.add(feature.getPrimaryKey()); al.add(feature.getAttribute(0).toString()); } } selectiontheme.setRendition(rendition); selectiontheme.setSelection(selection); featurelayer.getThemeList().add(selectiontheme); }catch(Exception e){ e.printStackTrace(); }finally{ if(featureset != null) featureset.dispose(); featureset = null; } }catch(Exception e){ e.printStackTrace(); request.setAttribute("returnedErrors", "选择图元报错"); } return al; } 以上就是有关的所有函数,这个问题困扰我多时了,请大家帮我看看,谢谢了!
songqian :
问题解决了。原因是我没有设地图的边界。输出是按地图文件的默认值输出,其大小小于800*600,而在jsp页面上人为拉大,自然鼠标点中的不是要选的图元。只要加上一句 mymap.setDeviceBounds(new DoubleRect(0.0D, 0.0D, 800, 600));就可以了。 在此再次感谢热心帮助我的朋友! |