Quantcast
Channel: Developer Express Inc.
Viewing all articles
Browse latest Browse all 2370

WinForms Map Control (coming in 13.1)

$
0
0

As we near release I thought I would show you another WinForms gem we are adding in 13.1: the WinForms Map Control. When it comes to data analysis the key to understanding is the concise display of many dimensions. A map allows you to convey locality in a truly unparalleled way. This sample represents the top 25 US airports (zoomed into the New York/New Jersey area):

WinForms Map Control

Adding a Map to your WinForms project is a simple drag and drop operation. Once the control is on your Form, you can add an Image Layer from either Bing or OpenStreet (the example above is OpenStreet). You can additionally add any number of vector layers from either a file (KML, SHP supported), from a database, or directly in code.

WinForms Map Control Layers

For this example I used our soon-to-be-released Spreadsheet API to load a csv file of airport locations directly into the map:

var layer = (VectorItemsLayer)mapControl1.Layers[1];

DocumentModel doc = new DocumentModel();
using (var stream = File.OpenRead("airports.csv"))
    doc.LoadDocument(stream, DocumentFormat.Csv, "");

var sheet = doc.ActiveSheet;
for (int i = 1; i < sheet.Rows.Count; i++)
{
    string code = sheet[0, i].Text;
    double lat = sheet[1, i].Value.NumericValue;
    double lng = sheet[2, i].Value.NumericValue;

    MapPushpin pushpin = new MapPushpin { Location = new GeoPoint(lat, lng), ToolTipPattern = code };
    layer.Items.Add(pushpin);
}

mapControl1.ZoomLevel = 4.5;
mapControl1.CenterPoint = new GeoPoint(37.50, -98.35);

The code simply loads the csv file and creates pusphins for each airport represented in the data. Since these are only US airports, I zoom in and center the map using the ZoomLevel and CenterPoint properties in the map. Aside from the pushpin, there are a number of other map elements that can be added including Dots, Rectangles, Polygons, Paths, and even a Custom Element:

WinForms Map Control Map Elements

We are tremendously excited for the great crop of things coming during our 13.1 series of releases.

As always, if there are any comments and/or questions, feel free to get a hold of me!

Seth Juarez
Email: sethj@devexpress.com
Twitter: @SethJuarez


Viewing all articles
Browse latest Browse all 2370

Trending Articles