ThinkGeo.com    |     Documentation    |     Premium Support

Creating nice looking road numbers

Could you provide me an example how to draw the nice looking road's numbers shown in the following images:


 


I've tried this way:


 


        public static TextStyle HWNo(string textColumnName)

        {

            TextStyle ts = TextStyles.CreateSimpleTextStyle(textColumnName, "Arial", 9f, DrawingFontStyles.Bold, GeoColor.FromArgb(0xff, 0xff, 0xff, 0xff), GeoColor.StandardColors.Black, 2f, (float)0f, 0f);

            ts.Mask = new AreaStyle(new GeoPen(GeoColor.FromArgb(0xff, 0xff, 0xff, 0xff), 2f), new GeoSolidBrush(GeoColor.FromArgb(0xff, 0x00, 0x00, 0xff)));

            return ts;

        }


 


        myHWNoLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(HWNo("RoadNo"));


Its works, but it looks strange comparing to original HWs.jpg and I don't know how to write code that generate results like in the HWs.jpg. How should I go about creating round rectangles and make the blue shape like in the picture HWs.jpg?


 


So in second step I've tried to use an icon ( bmp file as a background) and draw the name on it using IconStyle:


 


myHWNoLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = new IconStyle(".\\HW.png", "RoadNo", new GeoFont("Arial", 12f, DrawingFontStyles.Bold), new GeoSolidBrush(GeoColor.StandardColors.White));


 


The result as I get is like iconstyle.jpg - The name is next to the icon, not on the top of icon.


 


I've tried to use properties like XOffsetInPixel and YOffsetInPixel but it moves the whole icon with name but just the name.


 


In the documentation I could not find any method to do this properly. Could you provide me an example code how to do this? Should I override any methods? Which styles should I use?


ERs.jpg:


HWs.jpg:


iconstyle.jpg:



MRs.jpg:




 



Steve,


IconStyle is supposed to do this. I tried your code creating an IconStyle and it works fine as the text is on top of the image. Could you please make sure you are using 3.0.199? 

Here attached is a sample as well as a snapshot.



Thanks,

ThinkGeo Support

 



706-5765.zip (13.4 KB)

Lee, 
 I use version 3.0.199. 
  
 I’ve noticed that you miss understand my questions. 
  
 What I wanted to do is: 
 Display the number of the road: 
 1. Read Road number from feature as a value from regarded dictionary (FeatureSource) 
 2. Background icon as a bitmap file (IconStyle) 
 3. Road number as a written text (TextStyle), displayed DIRECTLY on the background icon (IconStyle) 
  
 What I don’t wanted to do is: 
 Road number as a NOT written text, displayed nearly, above, under and so on to the background icon (Text Style) like was shown in iconstyle.jpg 


Krzysztof,


I think what the sample did is exacctly what you want: roud number was loaded from feature and it was drawn on the center of the image which was an icon on the disk. (you can see the “Hws.PNG” image in the sample folder, it’s an image with blue background and there is no text on it).


I added some comments in the code to help you undersand what happened behind.




private void Form1_Load(object sender, EventArgs e)
{
    winformsMap1.MapUnit = GeographyUnit.DecimalDegree;

    InMemoryFeatureLayer inMemoryFeatureLayer = new InMemoryFeatureLayer();
    inMemoryFeatureLayer.Open();
    // Add the ‘RoadNumber’ column into the inMemoryFeatureLayer.
    inMemoryFeatureLayer.Columns.Add(new FeatureSourceColumn("RoadNumber"));

    // Add a feature into inMemoryLayer
    inMemoryFeatureLayer.InternalFeatures.Add(new Feature("LINESTRING(0 0,10 0)"));
    // Add the feature value. Here the value ‘123’ is the text which will be displayed on the background image.
    inMemoryFeatureLayer.InternalFeatures[0].ColumnValues.Add("RoadNumber", "123");

    inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
    inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(HWNo("RoadNumber"));

    winformsMap1.StaticOverlay.Layers.Add(inMemoryFeatureLayer);
    winformsMap1.CurrentExtent = inMemoryFeatureLayer.GetBoundingBox();
    winformsMap1.Refresh();
}

public TextStyle HWNo(string textColumnName)
{
    TextStyle textStyle = new IconStyle(@"..\..\HWs.PNG", textColumnName, new GeoFont("Arial", 20f, DrawingFontStyles.Bold), new GeoSolidBrush(GeoColor.StandardColors.White));

    return textStyle;



If you still have any questions could you please send us a demo that will be very helpful to figure out what’s going on.


Thanks,

ThinkGeo Support

 



Lee, 
 thank you for this source code, but it doesn’t work. I get result like on the picture iconstyle.jpg. that text is close to icon. It should be on the icon.  I’ve tried to use those properties (XOffsetInPixel and YoffsetInPixel) but they move both the icon and the number, not just the number.  


Krzysztof,


 
The property XOffsetInPixel and YOffsetInPixel supposed to move both the icon and text. 
 
Do you mean my code in the last reply can not work in your code? Have you tried the sample in the attachment of my fist reply named 5765.zip? It works in version 3.0.199. As I can not recreate your issue, could you please send us a demo that will be very helpful to figure out what’s going on? You can send to support@thinkgeo.com and ask to forward to Lee if you want.
 
Thanks,
ThinkGeo Support

Krzysztof,




Thanks for your sharing of your codes. I tried the latest Desktop Edition(3.0.307), and tested with both png files(HWs.PNG, 4k and HW.png 1k), both of them seems can displayed correctly.


Following is a snapshot using the HW.png file.



Let me know if any more questions. Thanks.


Yale