Maps in the Mapping for WPF are represented by the Map class. Its LoadFromStream method can load map data from files in the ESRI Shapefile format. Shapefiles come with an associated DBF database, that can provide various attribute values for the map elements. To load the DBF database along with the main map file, set the dbfStream parameter of LoadFromFile. The loaded database can be accessed via the Database property, and each record associated with a map element is exposed via the DatabaseRow property of the Shape class.
To display a map once it is loaded, assign it to the BaseMap property of the MapView control, or add a new MapLayer to the view and assign the map to its Map property. The following code demonstrates how to load a map with associated database from the application's XAP file and assign it to BaseMap:
C# Copy Code |
---|
private void OnLoaded(object sender, RoutedEventArgs e) |
Visual Basic Copy Code |
---|
Private Sub OnLoaded(sender As Object, e As RoutedEventArgs) |
Maps can be loaded as well from XAML code by setting the MapLocation property of a map layer. The following example loads a map file:
Xaml Copy Code |
---|
<ScrollViewer HorizontalScrollBarVisibility="Auto"> |