In this step, you will create a class with two properties, Name and LatLong, and populate them with an array collection. In addition, you will add a C1VectorLayer containing a C1VectorPlacemark to the control. You will then bind the Name property to the C1VectorPlacemark's Label property and the LatLong property to the C1VectorPlacemark's GeoPoint property.
Complete the following steps:
This class creates a class with two properties: a string property named Name and a Point property named LongLat.
Visual Basic |
Copy Code
|
---|---|
Public Class City Private _LongLat As Point Public Property LongLat() As Point Get Return _LongLat End Get Set(ByVal value As Point) _LongLat = value End Set End Property Private _Name As String Public Property Name() As String Get Return _Name End Get Set(ByVal value As String) _Name = value End Set End Property Public Sub New(ByVal location As Point, ByVal cityName As String) Me.LongLat = location Me.Name = cityName End Sub End Class |
C# |
Copy Code
|
---|---|
public class City { public Point LongLat { get; set; } public string Name { get; set; } public City(Point location, string cityName) { this.LongLat = location; this.Name = cityName; } } |
Note: In the C1Maps control, geographic coordinates are specified using longitude and latitude. Longitude is the X value, and latitude is the Y value. The coordinates are not marked with N, S, E, or W to designate the hemisphere.
Positive X and Y values mark the Northern and Eastern Hemispheres. Negative X and Y values mark the Southern and Western hemispheres.
Visual Basic |
Copy Code
|
---|---|
Dim cities() As City = New City() { New City(New Point(-58.40, -34.36), "Buenos Aires"), New City(New Point(-47.92, -15.78), "Brasilia"), New City(New Point(-70.39, -33.26), "Santiago"), New City(New Point(-78.35, -0.15), "Quito"), New City(New Point(-66.55, 10.30), "Caracas"), New City(New Point(-77.03, -12.03), "Lima"), New City(New Point(-57.40, -25.16), "Asuncion"), New City(New Point(-74.05, 4.36), "Bogota"), New City(New Point(-68.09, -16.30), "La Paz"), New City(New Point(-58.10, 6.48), "Georgetown"), New City(New Point(-55.10, 5.50), "Paramaribo"), New City(New Point(-56.11, -34.53),"Montevideo") } maps.DataContext = cities |
C# |
Copy Code
|
---|---|
City[] cities = new City[] { new City(){ LongLat= new Point(-58.40, -34.36), Name="Buenos Aires"}, new City(){ LongLat= new Point(-47.92, -15.78), Name="Brasilia"}, new City(){ LongLat= new Point(-70.39, -33.26), Name="Santiago"}, new City(){ LongLat= new Point(-78.35, -0.15), Name="Quito"}, new City(){ LongLat= new Point(-66.55, 10.30), Name="Caracas"}, new City(){ LongLat= new Point(-56.11, -34.53), Name="Montevideo"}, new City(){ LongLat= new Point(-77.03, -12.03), Name="Lima"}, new City(){ LongLat= new Point(-57.40, -25.16), Name="Asuncion"}, new City(){ LongLat= new Point(-74.05, 4.36), Name="Bogota"}, new City(){ LongLat= new Point(-68.09, -16.30), Name="La Paz"}, new City(){ LongLat= new Point(-58.10, 6.48), Name="Georgetown"}, new City(){ LongLat= new Point(-55.10, 5.50), Name="Paramaribo"}, }; maps.DataContext = cities; |
Markup |
Copy Code
|
---|---|
<C1:C1Maps.Resources> <DataTemplate x:Key="templPts"> <C1:C1VectorPlacemark GeoPoint="{Binding Path=LongLat}" Fill="Aqua" Stroke="Aqua" Label="{Binding Path=Name}" LabelPosition="Top" > <C1:C1VectorPlacemark.Geometry> <EllipseGeometry RadiusX="2" RadiusY="2" /> </C1:C1VectorPlacemark.Geometry> </C1:C1VectorPlacemark> </DataTemplate> </C1:C1Maps.Resources> <C1:C1VectorLayer ItemsSource="{Binding}" ItemTemplate="{StaticResource templPts}" Width="403" /> |
In this step, you created a data source and bound it to the properties of the C1VectorPlacemark. In the next step, you'll run the program and view the results of the quick start project.