# Custom Styles

**URL:** <https://community.thinkgeo.com/t/custom-styles/424>\
**Category:** WinForms\
**Created:** [May 21, 2009, 2:16pm UTC](https://community.thinkgeo.com/t/custom-styles/424 "2009-05-21T14:16:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Charles](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/c/6f9a4e/32.png) [@Charles](https://community.thinkgeo.com/u/Charles)\
**Post date:** [May 21, 2009, 2:16pm UTC](https://community.thinkgeo.com/t/custom-styles/424/1 "2009-05-21T14:16:52Z")

</div>

I&nbsp;am&nbsp;using&nbsp;a&nbsp;custom&nbsp;point&nbsp;style&nbsp;to&nbsp;draw&nbsp;rotated&nbsp;and&nbsp;scaled&nbsp;point&nbsp;symbols&nbsp;based&nbsp;on&nbsp;database&nbsp;values.&nbsp;&nbsp;I&nbsp;have&nbsp;successfully&nbsp;implemented&nbsp;this&nbsp;code.&nbsp;&nbsp;I&nbsp;found&nbsp;that&nbsp;I&nbsp;couldn't&nbsp;use&nbsp;DefaultLineStyle&nbsp;if&nbsp;I&nbsp;have&nbsp;added&nbsp;a&nbsp;CustomStyle,&nbsp;so&nbsp;I&nbsp;am&nbsp;trying&nbsp;to&nbsp;implement&nbsp;a&nbsp;custom&nbsp;line&nbsp;style&nbsp;as&nbsp;well.&nbsp;&nbsp;This&nbsp;will&nbsp;work&nbsp;out&nbsp;well&nbsp;for&nbsp;my&nbsp;project,&nbsp;but&nbsp;I&nbsp;have&nbsp;run&nbsp;into&nbsp;an&nbsp;problem.&nbsp;&nbsp;The&nbsp;DrawCore&nbsp;override&nbsp;in&nbsp;the&nbsp;custom&nbsp;line&nbsp;style&nbsp;trys&nbsp;to&nbsp;draw&nbsp;point&nbsp;symbols&nbsp;as&nbsp;well.&nbsp;&nbsp;&nbsp;Code&nbsp;is&nbsp;as&nbsp;follows:

&nbsp;

`using System;using System.Collections.Generic;using System.Collections.ObjectModel;using System.Linq;using System.Text;using ThinkGeo.MapSuite.Core;using ThinkGeo.MapSuite.DesktopEdition;class MyLineStyle : LineStyle{    private LineStyle lineStyle;    public MyLineStyle()        : this(new LineStyle())    { }    public MyLineStyle(LineStyle lineStyle)    {        this.lineStyle = lineStyle;    }    protected override void DrawCore(IEnumerable<Feature> features, GeoCanvas canvas, System.Collections.ObjectModel.Collection<SimpleCandidate> labelsInThisLayer, System.Collections.ObjectModel.Collection<SimpleCandidate> labelsInAllLayers)    {        foreach (Feature feature in features)        {            float Width = Convert.ToSingle(feature.ColumnValues["Width"]);            GeoColor Color = new GeoColor(0, 0, 0);            if (MyProject.UseLayers)            {                Color = GeoColor.FromWin32(DataInterface.GetLayerColor(Convert.ToInt32(feature.ColumnValues["Layer"])));            }            else            {                Color = GeoColor.FromWin32(Convert.ToInt32(feature.ColumnValues["Color"]));            }            canvas.DrawLine(feature, new GeoPen(Color, Width), DrawingLevel.LevelFour, 0, 0);        }        //base.DrawCore(features, canvas, labelsInThisLayer, labelsInAllLayers);    }        protected override Collection<string> GetRequiredColumnNamesCore()    {        Collection<string> columns = new Collection<string>();        columns = lineStyle.GetRequiredColumnNames();        if (!columns.Contains("FeatureText"))        {            columns.Add("FeatureText");        }        if (!columns.Contains("TextJust"))        {            columns.Add("TextJust");        }        if (!columns.Contains("Angle"))        {            columns.Add("Angle");        }        if (!columns.Contains("RScale"))        {            columns.Add("RScale");        }        if (!columns.Contains("SymbolImage"))        {            columns.Add("SymbolImage");        }        if (!columns.Contains("Width"))        {            columns.Add("Width");        }        if (!columns.Contains("Color"))        {            columns.Add("Color");        }        if (!columns.Contains("Layer"))        {            columns.Add("Layer");        }        return columns;    }}`&nbsp;

&nbsp;

The&nbsp;error&nbsp;occurs&nbsp;at&nbsp;canvas.DrawLine.&nbsp;&nbsp;When&nbsp;I&nbsp;check&nbsp;Feature.GetWellKnownText&nbsp;I&nbsp;get&nbsp;"POINT(582429.33&nbsp;266601.63)".&nbsp;&nbsp;I&nbsp;could&nbsp;check&nbsp;this&nbsp;but&nbsp;it&nbsp;seems&nbsp;a&nbsp;waste&nbsp;of&nbsp;processing&nbsp;time&nbsp;since&nbsp;point&nbsp;features&nbsp;shouldn't&nbsp;go&nbsp;through&nbsp;LineStyle.DrawCore.&nbsp;&nbsp;What&nbsp;am&nbsp;I&nbsp;doing&nbsp;wrong?&nbsp;&nbsp;Do&nbsp;all&nbsp;features&nbsp;go&nbsp;through&nbsp;DrawCore&nbsp;for&nbsp;all&nbsp;styles?&nbsp;&nbsp;Is&nbsp;there&nbsp;an&nbsp;easier&nbsp;way&nbsp;to&nbsp;check&nbsp;the&nbsp;feature&nbsp;type?&nbsp;&nbsp;&nbsp;

---

<div class="post-metadata">

**Author:** ![David](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@David](https://community.thinkgeo.com/u/David)\
**Post date:** [May 21, 2009, 6:21pm UTC](https://community.thinkgeo.com/t/custom-styles/424/2 "2009-05-21T18:21:59Z")

</div>

Charles,&nbsp;  
&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;I&nbsp;think&nbsp;I&nbsp;can&nbsp;help&nbsp;you&nbsp;on&nbsp;your&nbsp;questions.&nbsp;&nbsp;The&nbsp;first&nbsp;this&nbsp;is&nbsp;the&nbsp;use&nbsp;of&nbsp;the&nbsp;CustomStyles&nbsp;collection&nbsp;with&nbsp;DefaultLineStyle.&nbsp;&nbsp;The&nbsp;reason&nbsp;we&nbsp;did&nbsp;this&nbsp;was&nbsp;people&nbsp;were&nbsp;confused&nbsp;by&nbsp;the&nbsp;drawing&nbsp;order&nbsp;or&nbsp;always&nbsp;wanted&nbsp;a&nbsp;different&nbsp;one&nbsp;ie&nbsp;CutomsStyles&nbsp;before&nbsp;default&nbsp;styles&nbsp;or&nbsp;vice&nbsp;versa.&nbsp;&nbsp;What&nbsp;we&nbsp;decided&nbsp;to&nbsp;do&nbsp;was&nbsp;to&nbsp;say&nbsp;if&nbsp;you&nbsp;want&nbsp;to&nbsp;use&nbsp;a&nbsp;custom&nbsp;style&nbsp;then&nbsp;you&nbsp;need&nbsp;to&nbsp;use&nbsp;the&nbsp;collection,&nbsp;take&nbsp;full&nbsp;control&nbsp;and&nbsp;leave&nbsp;the&nbsp;default&nbsp;properties&nbsp;behind.&nbsp;&nbsp;It&nbsp;is&nbsp;easy&nbsp;to&nbsp;create&nbsp;a&nbsp;LineStyle&nbsp;and&nbsp;place&nbsp;it&nbsp;in&nbsp;the&nbsp;CustomStyle.&nbsp;&nbsp;Just&nbsp;some&nbsp;background&nbsp;on&nbsp;this.&nbsp;&nbsp;The&nbsp;default&nbsp;styles&nbsp;are&nbsp;there&nbsp;to&nbsp;really&nbsp;just&nbsp;fill&nbsp;the&nbsp;case&nbsp;where&nbsp;you&nbsp;want&nbsp;some&nbsp;simple&nbsp;rendering,&nbsp;once&nbsp;you&nbsp;move&nbsp;to&nbsp;something&nbsp;complex&nbsp;then&nbsp;the&nbsp;CustomStyles&nbsp;collection&nbsp;is&nbsp;the&nbsp;place&nbsp;you&nbsp;want&nbsp;to&nbsp;be.&nbsp;  
&nbsp;&nbsp;  
&nbsp;The&nbsp;Style&nbsp;system&nbsp;is&nbsp;pretty&nbsp;flexible&nbsp;and&nbsp;we&nbsp;don’t&nbsp;limit&nbsp;one&nbsp;type&nbsp;of&nbsp;shape&nbsp;per&nbsp;style.&nbsp;&nbsp;Since&nbsp;LineStyle&nbsp;inherits&nbsp;from&nbsp;Style&nbsp;we&nbsp;really&nbsp;don’t&nbsp;know&nbsp;it&nbsp;is&nbsp;a&nbsp;line&nbsp;style&nbsp;per&nbsp;say.&nbsp;&nbsp;Many&nbsp;people&nbsp;have&nbsp;designed&nbsp;styles&nbsp;that&nbsp;handle&nbsp;multiple&nbsp;shape&nbsp;types.&nbsp;&nbsp;We&nbsp;recommend&nbsp;that&nbsp;people&nbsp;try&nbsp;and&nbsp;keep&nbsp;it&nbsp;to&nbsp;one&nbsp;style&nbsp;type&nbsp;per&nbsp;shape&nbsp;type&nbsp;for&nbsp;sanity&nbsp;sakes&nbsp;but&nbsp;we&nbsp;don’t&nbsp;impose&nbsp;that&nbsp;limitation.&nbsp;&nbsp;In&nbsp;our&nbsp;default&nbsp;implementation&nbsp;of&nbsp;LineStyle&nbsp;we&nbsp;do&nbsp;check&nbsp;the&nbsp;type&nbsp;but&nbsp;that&nbsp;got&nbsp;replaced&nbsp;when&nbsp;you&nbsp;overrode&nbsp;DrawCore.&nbsp;&nbsp;In&nbsp;our&nbsp;previous&nbsp;Map&nbsp;Suite&nbsp;Versions&nbsp;where&nbsp;we&nbsp;just&nbsp;handled&nbsp;shape&nbsp;file&nbsp;things&nbsp;were&nbsp;like&nbsp;this&nbsp;however&nbsp;with&nbsp;the&nbsp;advent&nbsp;of&nbsp;spatial&nbsp;databases&nbsp;and&nbsp;other&nbsp;formats&nbsp;it&nbsp;is&nbsp;possible&nbsp;to&nbsp;get&nbsp;points&nbsp;&nbsp;or&nbsp;areas&nbsp;mixed&nbsp;in&nbsp;with&nbsp;all&nbsp;kinds&nbsp;of&nbsp;other&nbsp;shape&nbsp;types.&nbsp;&nbsp;Not&nbsp;to&nbsp;worry&nbsp;as&nbsp;what&nbsp;we&nbsp;typically&nbsp;do&nbsp;is&nbsp;inside&nbsp;of&nbsp;the&nbsp;DrawCore&nbsp;inside&nbsp;the&nbsp;features&nbsp;loop&nbsp;we&nbsp;do&nbsp;a&nbsp;feature.GetWellKnownType(),&nbsp;an&nbsp;enumeration,&nbsp;and&nbsp;check&nbsp;it.&nbsp;&nbsp;This&nbsp;will&nbsp;pass&nbsp;back&nbsp;the&nbsp;well&nbsp;known&nbsp;type&nbsp;like&nbsp;point,&nbsp;polygon&nbsp;etc.&nbsp;&nbsp;It&nbsp;is&nbsp;pretty&nbsp;efficient&nbsp;because&nbsp;it&nbsp;just&nbsp;indexes&nbsp;into&nbsp;a&nbsp;fixed&nbsp;location&nbsp;in&nbsp;the&nbsp;byte&nbsp;array&nbsp;that&nbsp;stores&nbsp;the&nbsp;well&nbsp;known&nbsp;binary.&nbsp;&nbsp;Every&nbsp;feature&nbsp;is&nbsp;just&nbsp;a&nbsp;structure&nbsp;shell&nbsp;around&nbsp;an&nbsp;array&nbsp;of&nbsp;well&nbsp;known&nbsp;binary&nbsp;that&nbsp;holds&nbsp;the&nbsp;shape&nbsp;&nbsp;itself.&nbsp;&nbsp;We&nbsp;tried&nbsp;to&nbsp;make&nbsp;this&nbsp;very&nbsp;efficient.&nbsp;  
&nbsp;&nbsp;  
&nbsp;David

---

<div class="post-metadata">

**Author:** ![Charles](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/c/6f9a4e/32.png) [@Charles](https://community.thinkgeo.com/u/Charles)\
**Post date:** [May 22, 2009, 7:51am UTC](https://community.thinkgeo.com/t/custom-styles/424/3 "2009-05-22T07:51:18Z")

</div>

David,&nbsp;  
&nbsp;&nbsp;  
&nbsp;Thanks&nbsp;for&nbsp;the&nbsp;quick&nbsp;reply.&nbsp;&nbsp;I&nbsp;thought&nbsp;it&nbsp;might&nbsp;be&nbsp;something&nbsp;like&nbsp;that,&nbsp;and&nbsp;I&nbsp;event&nbsp;thought&nbsp;about&nbsp;creating&nbsp;one&nbsp;style&nbsp;to&nbsp;handle&nbsp;everything&nbsp;but&nbsp;I&nbsp;think&nbsp;I&nbsp;will&nbsp;stick&nbsp;to&nbsp;two&nbsp;(text&nbsp;is&nbsp;just&nbsp;a&nbsp;point&nbsp;with&nbsp;text&nbsp;data&nbsp;rather&nbsp;than&nbsp;symbol&nbsp;data).&nbsp;  
&nbsp;&nbsp;  
&nbsp;Charles

---

<div class="post-metadata">

**Author:** ![David](https://community.thinkgeo.com/letter_avatar_proxy/v4/letter/d/aeb1de/32.png) [@David](https://community.thinkgeo.com/u/David)\
**Post date:** [May 22, 2009, 8:27am UTC](https://community.thinkgeo.com/t/custom-styles/424/4 "2009-05-22T08:27:07Z")

</div>

Charles,&nbsp;  
&nbsp;&nbsp;  
&nbsp;&nbsp;&nbsp;It&nbsp;was&nbsp;my&nbsp;pleasure.&nbsp;&nbsp;Styles&nbsp;are&nbsp;cheap&nbsp;and&nbsp;easy&nbsp;to&nbsp;build&nbsp;so&nbsp;I&nbsp;say&nbsp;build&nbsp;them&nbsp;to&nbsp;optimize&nbsp;your&nbsp;specific&nbsp;case.&nbsp;&nbsp;As&nbsp;a&nbsp;shameless&nbsp;plug&nbsp;for&nbsp;my&nbsp;video…&nbsp;&nbsp;If&nbsp;you&nbsp;haven’t&nbsp;watched&nbsp;the&nbsp;45&nbsp;minute&nbsp;video&nbsp;on&nbsp;building&nbsp;styles&nbsp;then&nbsp;I&nbsp;highly&nbsp;recommend&nbsp;it.&nbsp;&nbsp;It&nbsp;is&nbsp;full&nbsp;of&nbsp;helpful&nbsp;advise&nbsp;on&nbsp;building&nbsp;all&nbsp;kinds&nbsp;of&nbsp;powerfull&nbsp;styles.&nbsp;  
&nbsp;&nbsp;  
&nbsp;You&nbsp;can&nbsp;find&nbsp;the&nbsp;video&nbsp;as&nbsp;a&nbsp;link&nbsp;here:&nbsp;  
&nbsp;[gis.thinkgeo.com/Support/DiscussionForums/tabid/143/aff/16/aft/5418/afv/topic/Default.aspx](http://gis.thinkgeo.com/Support/DiscussionForums/tabid/143/aff/16/aft/5418/afv/topic/Default.aspx)&nbsp;  
&nbsp;&nbsp;  
&nbsp;David
