问题描述
运行后只能出现矩形,不能将选择的图元显示出来,请问是怎么回事呢?js代码如下,实现拖动鼠标出现矩形;functionmapmousedown(){if(state=="rec"){vardivStyleObj=document.all.disRec.style;divStyleObj.left=window.event.clientX;divStyleObj.top=window.event.clientY;divStyleObj.width=0;divStyleObj.height=0;divStyleObj.visibility="visible";rec_mousedown=true;recX=window.event.clientX;recY=window.event.clientY;eventstate="eventbegin";}}functionmapmousemove(){f(state=="rec"){if(window.event.button==1){varx=window.event.clientX;vary=window.event.clientY;vardivStyleObj=document.all.disRec.style;if(x>recX)divStyleObj.left=recX;elsedivStyleObj.left=x;if(y>recY)divStyleObj.top=recY;elsedivStyleObj.top=y;divStyleObj.width=Math.abs(x-recX);divStyleObj.height=Math.abs(y-recY);}}functionmapmouseup(){if(state=="rec"){recX=parseFloat(recX)-parseFloat(document.all.mapframe.style.left);recY=parseFloat(recY)-parseFloat(document.all.mapframe.style.top);varrecNewX=window.event.clientX-parseFloat(document.all.mapframe.style.left);varrecNewY=window.event.clientY-parseFloat(document.all.mapframe.style.top);chgmapsrc("rqutype=rec"+"&recX="+recX+"&recY="+recY+"&recNewX="+recNewX+"&recNewY="+recNewY);rec_mousedown=false;vardivStyleObj=document.all.disRec.style;divStyleObj.visibility="hidden";}servlet端:elseif(rqutype!=null&&rqutype.equals("rec")){mymap=initmap(request);DoublerecX=newDouble(request.getParameter("recX"));DoublerecY=newDouble(request.getParameter("recY"));DoublePointoldscreenpoint=newDoublePoint(recX.doubleValue(),recY.doubleValue());DoublerecNewX=newDouble(request.getParameter("recNewX"));DoublerecNewY=newDouble(request.getParameter("recNewY"));DoublePointnewscreenpoint=newDoublePoint(recNewX.doubleValue(),recNewY.doubleValue());try{DoublePointoldpoint=mymap.transformScreenToNumeric(oldscreenpoint);DoublePointnewpoint=mymap.transformScreenToNumeric(newscreenpoint);ListcolumnNames=null;DoubleRectdRect=newDoubleRect(oldpoint.x,oldpoint.y,newpoint.x,newpoint.y);FeatureSetfs=mymap.getLayers().elementAt(5).searchWithinRectangle(columnNames,dRect,QueryParams.ALL_PARAMS);SelectionThemeselTheme=newSelectionTheme("recSelection");//CreateaSelectionobject,andaddtheselectedfeaturesSelectionsel=newSelection();sel.add(fs);//AssigntheSelectionobjecttotheSelectionThemeselTheme.setSelection(sel);//AssignthedisplaystyleoftheSelectionThemeRenditionrend=RenditionImpl.getDefaultRendition();rend.setValue(Rendition.FILL,Color.red);selTheme.setRendition(rend);//AddtheSelectionThemetothelayer'slistofthemesmymap.getLayers().elementAt(0).getThemeList().add(selTheme);responseimg(mymap,response);}catch(Exceptione2){//TODOAuto-generatedcatchblocke2.printStackTrace();}