ThinkGeo.com    |     Documentation    |     Premium Support

Custom hatch pattern on polygons

Hi, We are trying to draw an area with custom hatch pattern, We could get a pattern from a pat file or a from a string whichever would be possible. I could not find any sample or forum entry to do so!!

We have license of MapSuite 10 for both WPF and iOS and we have to implement the solution in both platforms, Please help.
Kind Regards,
Syed

Hi Syed,

Do you means you want to custom the area style? Please show us the sample about how to create the style based on your hatch pattern, so we can see whether we can provide you some sample code.

Regards,

Ethan

We want to fill the area with a custom hatch pattern, So if you want to imagine an example code it would be something like this

protected override void DrawCore(IEnumerable<Feature> features, GeoCanvas canvas, Collection<SimpleCandidate> labelsInThisLayer, Collection<SimpleCandidate> labelsInAllLayers)
{
         var allPolygonFeatures = features.Where(feature => feature.GetShape() is AreaBaseShape).ToArray();
         foreach (var feature in allPolygonFeatures)
          {
                var areaShapeBase = feature.GetShape() as AreaBaseShape;
                AreaStyle areaStyle = new AreaStyle();
        
                CustomHatchPattern MyCustomHatchPattern = new CustomHatchPattern(@"*BRASS, Brass material
        0, 0,0, 0,.25
        0, 0,.125, 0,.25, .125,-.0625");
                areaStyle.Advanced.FillCustomBrush = new GeoHatchBrush(MyCustomHatchPattern, GeoColor.SimpleColors.Transparent);
                areaStyle.OutlinePen = new GeoPen(GeoColor.FromArgb(255, 118, 138, 69), 1);
                areaStyle.Draw(new[] { areaShapeBase }, canvas, labelsInThisLayer, labelsInAllLayers);
           }
}

Please note: this is a custom style and ofcourse the CustomHatchPattern object is a sample class to show we intent to use the class, the *xyz is the name of a pattern which if needed we could remove also from the string, I hope I could clear the requirement.

Kind Regards,
Syed

Hi Syed,

Thanks for your further description.

I think your target should be, create style based on your custom data format.

You don’t need to override class for example DrawCore, you just need to get necessary parameters from your custom data format, then create the instance of our style, and assign it to layer, which should works.

You can pass the parameters into the API: AreaStyles.CreateHatchStyle

If some parameters are not supported by the constructor, you need to override the class.

Wish that’s helpful.

Regards,

Ethan

Dear Ethan,
Thank you for your answer. We are overriding DrawCore on a Style to draw polygon for a different reason.
My question at the moment how can I define custom parameters on a GeoHatchBrush. GeoHatchBrush only takes an enumeration(of type: GeoHatchStyle) at the moment, AreaStyles.CreateHatchStyle also requires this enumaration. How can I define custom parameters to create a hatch pattern with custom data format? An idea or some psudo code in the correct direction is appreciated.

Thanks,
Syed

Hi Syed,

Thanks to let us know that, but our ThinkGeo.MapSuite.Drawing.GeoHatchStyle don’t support custom style, all values in this enumeration is one-to-one correspondence the value in System.Drawing.Drawing2D.HatchStyle, and when we draw the style we will convert it.

If you set custom GeoHatchStyle, it cannot convert to target HatchStyle.

It looks the HatchStyle support 55 different styles, I think you should want to make sure whether your style is not contained by the 55 styles.

Regards,

Ethan

Hi,
Thank you for your reply but lets say the hatch style is not in one of 55 styles and we want to draw an area with a custom hatch pattern, how can I achieve this?
Regards,
Syed

Hi Syed,

If your hatch pattern is not contained in the 55 styles, you cannot use our default PlatformGeoCanvas for drawing.

You should want to write your custom GeoCanvas and area style, and implement the drawing logic in it.

Regards,

Ethan

Hi,
Thanks, I knew we have to implement some custom code, Can you provide some direction or some sample code in the right direction where I could get the idea on how to proceed. I hope you understand I do not see the source code of mapsuite, therefore, I can’t see the internals of the component. Or shall I create a support ticket?
Regards,
Syed

Hi Syed,

In fact we also don’t know what’s the effect you want to implement.

Could you please create a ticket, and show us some more detail information.

You can pick one of your custom HatchStyle, we need the effect image about it rendered by the System.Drawing.Graphics, and we also need some code about how to render it by GDI+ API for example graphics.FillPolygon, it also need contains the custom HatchStyle.

So our developer can look into this problem based on your information, we can provide the help on override our classes, but we don’t know more detail about your custom style.

Regards,

Ethan