Listen up all objects graphics users:
I never can say this enough. When working with object graphics and
something isn't displaying as expected, work from the bottom up testing
your elements until you determine where things are going wrong. And the
tool for testing? XOBJVIEW. You'll be surprised what you will learn :)
This isn't directed at you specifically, Shengbaojun, but I did stress
that point in my responses to your earlier post. Especially since your
application was complicated by the C# + axIDLWidgetControl aspect.
I pasted your code into IDL, provided my own XY data, and in less than a
minute was displaying your symbols in XOBJVIEW and provides a simplified
test environment. The first thing I noticed was that your symbols no
longer are centered on your data points:
pro test_sym
xy = rotate([[findgen(10)], [findgen(10)]],180)
;define the symbol
pentagon=OBJ_NEW('IDLgrPolygon', [0.1,0.5,0.9,0.7,0.3], $
[0.6,0.9,0.6,0.1,0.1], $
COLOR=Color_cities)
symModel = OBJ_NEW('IDLgrModel')
symModel -> Add, pentagon
symModel -> Scale, 0.5, 0.5, 1
symModel -> Translate, -1, -1, 0
ocitiesSymbol = OBJ_NEW('IDLgrSymbol', symModel)
oSymbol2 = OBJ_NEW('IDLgrSymbol', 1, SIZE=0.5)
oPlotCities=OBJ_NEW('IDLgrPolyline',xy[0,*],xy[1,*], $
Symbol=ocitiesSymbol,$
_Extra=extra,$
;Thick=2 ,$
LINESTYLE = 6)
oPlot2=OBJ_NEW('IDLgrPolyline',xy[0,*],xy[1,*], $
Symbol=oSymbol2,$
COLOR=[255,0,0], $
_Extra=extra,$
LINESTYLE = 6)
oModel = OBJ_NEW('IDLgrModel')
oModel->ADD,[oPlotCities,oPlot2]
XOBJVIEW, oModel, /block
OBJ_DESTROY, [oModel, symModel, ocitiesSymbol, oSymbol2]
end
My guess is that since the Cartesian coords returned from the MAP_PROJ
functions are very large, the offset created by your incorrect transform
has move your symbols out of the view.
Either understand how transforms are applied or don't transform your
symbols. If you isometrically scale an object whose data is not
centered about the origin it will move the center of that object. So
the first thing you need to do is translate your object such that it is
centered on the origin. Your data range is 0 to 1 so your original
translation of [-1,-1,0] is incorrect. You only need to translate it
-0.5 units in X and Y.
symModel -> Translate, -0.5, -0.5, 0
Now that your symbol is centered on the origin you can scale it (note
that I have provided scaling factors appropriate for my code above and
you would want to scale it to your data):
symModel -> Scale, 0.5, 0.5, 1
Make the changes to the above code and the symbols should line up and
they will probably appear in your display.
Also, I personally would use IDLgrPolyline instead of IDLgrPlot.
In regards to your second question:
command="MouseMove,IDLDrawWidget1,"+e.x.ToString()+","+myYY.ToString();
I don't think you are referencing your draw widget correctly. AFAICT,
the string "IDLDrawWidget1" has no context in either your C# code or
your IDL code. It is just a collection of chars. You need to send the
draw id: axIDLDrawWidget1.DrawID. Something like
char drawIDstr[20];
_itoa(axIDLDrawWidget1.DrawID, drawIDstr, 10);
command="MouseMove,"drawIDstr","+e.x.ToString()+","+myYY.ToString();
Note that I'm not a C# programmer so there probably is a better way to
do the conversion but you get the point.
-Rick
shengbaojun wrote:
> Hello,I have draw the background map.Thanks for Mr.Rick Towler and
> Mr.Mark Hadfield a lot.
> But I met some difficulties when I try something else,so could you give
> me some adivce please.
>
> 1, I want to draw some cities above the background map,but the symbols
> can not be showed.
> I use the code as follows:
> ;-----------------------------------------------------
> ;draw cities
> cityUV = map_proj_forward(lon, lat, $
> map=map_info.smap $
> )
> ;define the symbol
> pentagon=OBJ_NEW('IDLgrPolygon', [0.1,0.5,0.9,0.7,0.3], $
> [0.6,0.9,0.6,0.1,0.1], $
> COLOR=Color_cities $
> )
> symModel = OBJ_NEW('IDLgrModel')
> symModel -> Add, pentagon
> symModel -> Scale, 8, 8, 1
> symModel -> Translate, -1, -1, 0
> ocitiesSymbol = OBJ_NEW('IDLgrSymbol', symModel)
> ; ocitiesSymbol=OBJ_NEW('IDLgrSymbol',4,$
> ; color=Color_NoData,$
> ; thick=8.0,$
> ; size=[9.0,9.0]$
> ; )
> map_info.ocitiesSymbol=ocitiesSymbol
>
> oPlotCities=OBJ_NEW('IDLgrPlot',cityUV[0,*],cityUV[1,*], $
> Symbol=ocitiesSymbol,$
> _Extra=extra,$
> ;Thick=2 ,$
> LINESTYLE =6 $
> )
>
> map_info.omodel->ADD,oPlotCities
> map_info.owindow->DRAW,map_info.oview,/draw_instance
> ;--------------------------------------------------------
> If I change the LINESTYLE value from 6 to 3,The lines has been
> showed,but the Symbols also can not be showed .
>
> 2,I use the develop model of C# plus axIDLWidgetControl 3.0,I write
> the mouse event in C#,so I must obtain the value of IDL's variable from
> IDL's .pro file.But I can not get them .The code is as follows:
>
> IDL's code
> //////////////////////////////////////////////////////////// ///////////
>
> PRO MouseMove,drawid,x,y
>
> common lonlat_mousemovex,lonlat_mousemovey
> widget_control,drawid,get_uvalue=map_info,/no_copy
>
> if size(map_info, /type) eq 0 then return
> result = map_info.owindow -> pickdata(map_info.oview, $
> map_info.omodel,$
> [x,y], xy)
> lonlat_mousemove = map_proj_inverse(xy, map = map_info.smap)
> map_info.lonlat_mousemovex=lonlat_mousemove[0]
> map_info.lonlat_mousemovey=lonlat_mousemove[1]
> widget_control,drawid,set_uvalue=map_info,/no_copy
> END
>
> C# 's code
> ///////////////////////////////////////////////////////
> private void axIDLDrawWidget1_MouseMoveEvent(object sender,
> AxIDLDRAWX3Lib._DIDLDrawX3Events_MouseMoveEvent
>
> e)
> {
>
> int myYY=axIDLDrawWidget1.Height-e.y;
> string
> command="MouseMove,IDLDrawWidget1,"+e.x.ToString()+","+myYY.ToString();
> int temp=axIDLDrawWidget1.ExecuteStr(command);
> temp=axIDLDrawWidget1.ExecuteStr("widget_control,IDLDrawWidget1,get_value=map_info ");
> object
> lonlat_mousemovex=axIDLDrawWidget1.GetNamedData("map_info.lonlat_mousemovex ");
> object
> lonlat_mousemovey=axIDLDrawWidget1.GetNamedData("map_info.lonlat_mousemovey ");
> }
>
> I try my best to test above codes,but did not success.
> I wish you can help me.
>
> Thanks you
>
|