+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    koko is offline Global Mapper User
    Join Date
    Jun 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default fill color to area

    Help me please,

    i use Visual C# (VS2008) Sample Application , load shape file it have 2000 areas and i want to fill color some area but it can't.

    this is my code

    private void FillColor()
    {
    // theAreaStyle is global variable, i set value to it on load layer.
    theAreaStyle.mBrushColor = ColorToUInt(Color.Red);

    for (UInt32 i = 0; i <= 500; i++)
    {
    LastGMError = GlobalMapperDLL.GM_SetAreaFeatureDrawStyle(clsGlob alVARS.LayerHandles[0], i, ref theAreaStyle);
    }
    DrawLayersToBitmap();
    }
    private uint ColorToUInt(Color color)
    {
    return (uint)((color.A << 24) | (color.R << 16) |
    (color.G << 8) | (color.B << 0));
    }
    public static extern GM_Error_t32 GM_SetAreaFeatureDrawStyle
    (
    IntPtr aLayer, // Layer the area is in
    UInt32 aAreaIndex, // Index of area in layer
    ref GM_AreaStyle_t aAreaStyle // New style to use for area
    );

    when i call FillColor function
    LastGMError = GM_Error_None alway but area don't fill color.
    Last edited by koko; 07-09-2009 at 05:54 AM.

  2. #2
    global_mapper is online now Administrator
    Join Date
    Jun 2007
    Posts
    7,495
    Thanks
    2
    Thanked 641 Times in 624 Posts

    Default

    What do the other members of your global variable 'theAreaStyle' look like? You are just setting the color, but you will also need to set the fill style, etc. otherwise the fill color might not even be used.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com

  3. #3
    koko is offline Global Mapper User
    Join Date
    Jun 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    i set theAreaStyle :

    theAreaStyle.mBorderPenStyle = 0;
    theAreaStyle.mBorderPenWidth = 1;
    theAreaStyle.mBorderPenColor = 0;
    theAreaStyle.mBrushColor = 2164195328;
    theAreaStyle.mBrushStyle = GM_BrushStyle_t16.GM_BRUSH_SOLID;
    theAreaStyle.mDrawLabel = 1;
    theAreaStyle.mDrawLabelAlways = 0;

    it can work with C++ Sample Application but Visual C# (VS2008) Sample Application can't work. I must update about DrawLayersToBitmap() Function Right?

  4. #4
    Osei is offline Global Mapper User
    Join Date
    Mar 2008
    Posts
    88
    Thanks
    14
    Thanked 0 Times in 0 Posts

    Default

    A quick look suggests everything is ok. I am trying to identify the problem.
    I suggest you use the ColorTranslator class rather than bit shifting.
    System.Drawing.ColorTranslator.ToWin32((uint)Color .Red)

    In your GM_AreaStyle_t structure, make sure the size of the structure is correct. You can check the size of the same structure in the C++ sample by getting the value of
    sizeof(GM_AreaStyle_t).

    The size being reported must be the same as
    Marshal.SizeOf(typeof(GM_AreaStyle_t))

    If the two are not the same, then you have to fix that ASAP as it can lead to memory issues that can affect the entire program later.

  5. #5
    global_mapper is online now Administrator
    Join Date
    Jun 2007
    Posts
    7,495
    Thanks
    2
    Thanked 641 Times in 624 Posts

    Default

    I'm not sure what your DrawLayersToBitmap function does, but typically after making changes to the display characteristics you would call Invalidate to cause your window to redraw.

    If you can post your GM_AreaStyle_t declaration we can check that as well. Osei's recommendation to check the sizes between C++ and C# is good to help verify your declaration is correct.

    Thanks,

    Mike
    Global Mapper Support
    support@globalmapper.com

  6. #6
    koko is offline Global Mapper User
    Join Date
    Jun 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thank you very much Osei , Mike :

    I check my GM_AreaStyle_t declaration and try it then it can work.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts