Home News a .NET wrapper for CartoType

a .NET wrapper for CartoType

By Graham Asher on 04 February 2010

Several people have asked about using CartoType in the .NET framework. One great advantage of this approach is the use of a standard type system; another is that a .NET component works with any .NET language, on any .NET platform.

We have now created a simple CartoType .NET component with an accompanying C# demonstration program which loads a map and allows the user to move around it and zoom in and out. Quite a lot can be done with very simple code. For example, here is the entire code needed to load a map into a Form control and display it:

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            iEngine = new CartoTypeWrapper.Engine();             iEngine.LoadFont("C:/CartoType/src/font/DejaVuSans.ttf");             iMap = iEngine.CreateMap("C:/OpenStreetMap/data/stockholm.ctm1",                                      "C:/CartoType/src/style/osm-style.xml",512,512);             iMap.SetScale(10000);         }
        private CartoTypeWrapper.Engine iEngine;         private CartoTypeWrapper.Map iMap;
        private void Form1_Paint(object sender, PaintEventArgs e)         {             Bitmap bitmap = iMap.GetBitmap();             e.Graphics.DrawImageUnscaled(bitmap, 0, 0);         }

// ... snip ...

}

This is quite experimental at the moment, and a full .NET API would not necessarily resemble this one closely. But our main aim would be to preserve the simplicity and ease of use, while providing access to the full functionality of CartoType.

If you're interested in evaluating CartoType using the .NET component please contact us.