Understanding NetAdvantage for Visual Studio LightSwitch – Creating Maps (Part 3)

[Infragistics] Mihail Mateev / Friday, August 5, 2011

Infragistics Inc. released the new NetAdvantage for Visual Studio LightSwitch 2011.1. This product includes two map control extensions:

  • Infragistics Map Control (value based map)
  • Infragistics Geospatial Map (series based map)

Microsoft Visual Studio LightSwitch 2011 uses WCF RIA Services to maintain data. This framework for now doesn’t support spatial data (SQL Server Spatial). That is the reason map controls to use own implementation to access spatial data.

These controls have more settings than other controls in NetAdvantage for Visual Studio LightSwitch 2011.1. because of requirement to cover different cases when use spatial data.

Visual Studio LightSwitch control extensions are 3 main groups defined by the type of the bound data

  • Value based controls
  • Group based controls
  • Collection based controls

This article is about value based controls and especially for Infragistics Map Control.

Value based control use for data source scalar values (that means a value from the specified property from one entity).
These could be used inside another collection based or croup based controls like List, DataGrid etc.

Infragistics Map Control is  used to represent spatial objects, related with the selected item on the screen. Relation between selected item and spatial elements is based on the value of the specified property from the selected object. This value should match to the name property  of the map elements. How to set Name property via DataMapping String is describes below in this article.

Sample application.

Sample application is based on the application, used in the part 2 of this article.

Sample database is Northwind. Link could be found in the part 1 of this article.

Create a new List and Detail Screen and name it “CustomersMap”.

Change the Customers List with DataGrid control and leave in the UI only three properties:

  • Company Name
  • Contact Name
  • Contact Title

Add second time Country in details column and select “Infragistics Map Control” to represent this value.

Select the map control and press “F4” to see the properties grid.

There are several important properties:

  1. Map Brushes
  2. DataMapping String
  3. Shapefile Projection
  4. Map Projection
  5. Map Control SourceUriString
  6. Show Navigation
  7. Spatial Data Source
  8. Use Tile Source
  9. Highlight Color
  10. Highlight Selection
  11. Zoom to Selection
  12. BingMaps Key

1. Map Brushes are used to set the theme for the thematic maps according to Value DataMapping String property.

2. DataMapping String used to be set in four matches characteristics of the elements of the map - Name, Value, Caption and ToolTip. Selecting an object is based on correspondence between the value of the data source and Name elements in the map. Thematic maps are colored according to Map Brushes and value of Value

3. Shapefile Projection is a projection. set to shapefile. Map control provides several predefined the most popular geographic projections. The default is the Spherical Mercator. More about geographic coordinate systems and projections you could find below in this article.

4. Map Projection is a projection, used to visualize data in the Infragistics Map Control. All details are the same like in the Shapefile Projection. It is possible to have data in one projection and display it in another one.

5. Map Control SourceUriString used to specify the relative path for shapefiles from the place where is generated the client part the LightSwitch Application.

This part is located in [LightSwitch Application Project Path]\Bin\[Configuration]. Configuration means Debug, Release or other specific build configuration.

Relative path includes [Relative Path]\[Shapefile Name]. Shapefile Name means the name of the file without file extension.

In the sample application SourceUriString “ShapeFiles\World\Cntry00” means you have relative path “ShapeFiles\World” and “Cntry00” as the name of the file.

Shapefile spatial data source is composed of several files with same name and different extensions. Only two files are required - [shapefile name]. shp and [shapefile name]. dbf. The first contains information on the graph and the second - attribute data. The relationship between the two files is the record id of [shapefile name]. Dbf, which requires use of specialized software for editing data. The remaining files contain indexes and their presence is not mandatory.

6. Show Navigation property is used to show and hide navigation panel inside the map control.

7. Spatial Data Source property defines the type of the data source.

Infragistics Map Control supports three spatial data source types:

  • Shapefile
  • WCF
  • Silverlight Enabled WCF

In the sample application is used the first one. WCF and Silverlight Enabled WCF propose spatial data like a nested collections via WCF services. This post does not affect these two data sources.

8. Use Tile Source property is used to include or exclude raster data from BingMaps service. To be possible to use it you should have BingMaps developer key. You can receive a key from here.

9. Highlight Color property specifies the color for the highlighted map element.

10. Highlight Selection property is used to specify the map behavior when change the selected element. If this property is true (checked) than the selected element will be highlighted on the map.

11. Zoom to Selection property determines whether the map showing the area around the selected item.

12. BingMaps Key is used to set the BingMaps Key for tile source.

Shapefile structure

Geographic Coordinate Systems and Projections

Geographic Coordinate Systems 

The most common locational reference system is the spherical coordinate system measured in latitude and longitude. This system can be used to identify point locations anywhere on the earth's surface. Because of its ability to reference locations, the spherical coordinate system is usually referred to as the Geographic Coordinate System, also known as the Global Reference System.
Longitude and latitude are angles measured from the earth's center to a point on the earth's surface. Longitude is measured east and west, while latitude is measured north and south. Longitude lines, also called meridians, stretch between the north and south poles. Latitude lines, also called parallels, encircle the globe with parallel rings.
Latitude and longitude are traditionally measured in degrees, minutes, and seconds (DMS). Longitude values range from 0° at the Prime Meridian (the meridian that passes through Greenwich, England) to 180° when traveling east and from 0° to –180° when traveling west from the Prime Meridian.

Geographic Projections

Because it is difficult to make measurements in spherical coordinates, geographic data is projected into planar coordinate systems (often called Cartesian coordinates systems). On a flat surface, locations are identified by x,y coordinates on a grid, with the origin at the center of the grid. Each position has two values that reference it to that central location; one specifies its horizontal position and the other its vertical position. These two values are called the x coordinate and the y coordinate.

More information about the shapefiles you can find here .

Spatial data in shapefile can be viewed only with special software. One popular solution is free MapWindow GIS.

Another popular solution is ESRI ArcGIS.

You can create, view and edit spatial data, including shapefiles with MapWindow GIS Desktop.

Change the properties in accordance with the screen below:

  • Map Control SourceUriString: “ShapeFiles\World\Cntry00”
  • Show Navigation: checked

Run the application and change the selected item.

Design in runtime mode

Select customize screen and change these properties:

  • Map Brushes: Grey Blue Magenta Red Orange
  • Highlight Color: Yellow
  • Use Tile Source - checked
  • Zoom to Selection – unchecked

Changes will be available in the design screen.

Save changes and go back to the “Customers Map” screen.

Change the selected customer. Now map will no zoom around the selected element.