Global Mapper v24.0

How to draw a line

Qiao
Qiao Global Mapper UserTrusted User
edited May 2009 in SDK
Hi,

I have been trying to draw a line based on some mouse clicks. Here is what I have done using the provided sample_app as a template in Visual Studio 2005 (64-bit OS).

CGMDLL_TesterDlg::OnLoadLayer()
...
GM_Projection_t theCurProj;
GM_Error_t32 theErr = GM_GetProjection( &theCurProj );

// customVectorLayer is a protected member of this Dlg
customVectorLayer=GM_CreateCustomVectorLayer("Custom Vector Layer",&theCurProj);
mMapWindow.AddLayer(customVectorLayer);
...


CGMDLL_TesterDlg::OnLButtonUp()
...
GM_LineStyle_t theDrwLineStyle;
theDrwLineStyle.mPenColor = RGB(255,0,0);
theDrwLineStyle.mFont.mWeight = FW_BOLD;
GM_SetLineFeatureDrawStyle(customVectorLayer,0,&theDrwLineStyle);
GM_LineFeature_t theDrwLineFeature;

// Cur_Points_Num is a member of the Dlg
theDrwLineFeature.mNumPoints= Cur_Points_Num;
theDrwLineFeature.mLineStyle= theDrwLineStyle;
// Cur_Points is a member of the Dlg: an array of GM_Point_t
theDrwLineFeature.mPointList= Cur_Points;

GM_AddLineToVectorLayer(customVectorLayer,&theDrwLineFeature,TRUE);

...

The program gave an "Unhandler exception ..." at the last line above.

Could you help me on this?

Thanks,

Qiao

Comments

  • global_mapper
    global_mapper Administrator
    edited May 2009
    Qiao,

    Where is your theDrwLineFeature structure initialized? Make sure that you are zeroing out the structure with the following call to make sure you aren't getting some garbage in members that you aren't explicitly initializing:

    memset( &theDrwLineFeature, 0, sizeof theDrwLineFeature );

    Let me know if I can be of further assistance.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • Qiao
    Qiao Global Mapper User Trusted User
    edited May 2009
    Hi Mike,

    Thanks, yes the error goes away after I added that line.

    Now I still can not get the lines shown in the map. Here are some lines afterwards in CGMDLL_TesterDlg::OnLButtonUp().

    GM_DrawFlags_t32 aDrawFlags=GM_DrawFlags_SeparateVectorLayers ; // 0x00001000 ;
    CRect mDrwRect= mMapWindow.GetDrawWndRect();
    CPaintDC thePaintDC( this );
    GM_DrawLayerList(thePaintDC,&customVectorLayer,1,aDrawFlags,&(mMapWindow.GetCurrentViewRect)),mDrwRect.left,mDrwRect.top,mDrwRect.Width(),mDrwRect.Height());


    Do I need to add something under ::OnPaint()?

    Thanks,

    Qiao
  • global_mapper
    global_mapper Administrator
    edited May 2009
    Qiao,

    You don't want to do your drawing in your left button handler. Instead just call Invalidate() in your OnLButtonUp handler which will trigger your map window to redraw. Since it contains your custom vector layer it will be redrawn as well.

    Let me know if I can be of further assistance.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • Qiao
    Qiao Global Mapper User Trusted User
    edited May 2009
    Hi Mike,

    Thanks again. I added that line after GM_DrawLayerList(). The lines are still not shown. Do you see any problems in my GM_DrawLayerList() call? I am not sure whether the hDC parameter has been correctly set.

    I checked the mPointList of the "theDrwLineFeature". It seems correctly assigned.

    Thanks,

    Qiao
  • global_mapper
    global_mapper Administrator
    edited May 2009
    Qiao,

    You need to move all of your drawing code to OnPaint and just call Invalidate from the OnLButton handler. The DC in the OnPaint call should be the CPaintDC that is already available there.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • Qiao
    Qiao Global Mapper User Trusted User
    edited May 2009
    Great, I can see the lines now. Only the color is not the one I am askinf for. It shows gray level instead of red. Here is the block I put under OnPait() before "isDrawing=false".

    if(Cur_Points_Num>1)
    {
    GM_LineStyle_t theDrwLineStyle;
    theDrwLineStyle.mPenColor = RGB(255,0,0);
    theDrwLineStyle.mFont.mWeight = FW_BOLD;
    GM_SetLineFeatureDrawStyle(customVectorLayer,0,&theDrwLineStyle);

    GM_LineFeature_t theDrwLineFeature;
    memset( &theDrwLineFeature, 0, sizeof theDrwLineFeature );
    theDrwLineFeature.mNumPoints= Cur_Points_Num;
    theDrwLineFeature.mLineStyle= theDrwLineStyle;
    theDrwLineFeature.mPointList= Cur_Points;

    GM_AddLineToVectorLayer(customVectorLayer,&theDrwLineFeature,TRUE);
    GM_DrawFlags_t32 aDrawFlags=GM_DrawFlags_SeparateVectorLayers ; // 0x00001000 ;
    CRect mDrwRect= mMapWindow.GetDrawWndRect();
    GM_DrawLayerList(thePaintDC,&customVectorLayer,1,aDrawFlags,&(mMapWindow.GetCurrentViewRect()),mDrwRect.left,mDrwRect.top,mDrwRect.Width(),mDrwRect.Height());
    }

    Thanks,

    Qiao
  • global_mapper
    global_mapper Administrator
    edited May 2009
    You need to pass FALSE for the 3rd parameter to GM_AddLineToVectorLayer otherwise the default style for the type will be used.

    Note that I would still add the line to the vector layer in your OnLButton handler, just only do the drawing part in OnPaint.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
  • Qiao
    Qiao Global Mapper User Trusted User
    edited May 2009
    Thanks for your suggestions. I moved the line-to-layer part under LButtonUp().

    However, the color is still not rgiht. Please see the attached for the quick watch screenshot of the defined LineStyle.
  • global_mapper
    global_mapper Administrator
    edited May 2009
    Qiao,

    Looking at your code, you need to be initializing the mDrawStyle member of the GM_LineFeature_t structure, not setting up a separate structure. You also wouldn't call the GM_SetLineFeatureDrawStyle function for a new feature since the style is provided when you add the line.

    Let me know if I can be of further assistance.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com
Sign In or Register to comment.