Back to Devexpress

GeoJsonFileDataAdapter Class

wpf-devexpress-dot-xpf-dot-map-d4af6251.md

latest6.4 KB
Original Source

GeoJsonFileDataAdapter Class

A data adapter that loads data from GeoJSON files, and displays it on vector layers.

Namespace : DevExpress.Xpf.Map

Assembly : DevExpress.Xpf.Map.v25.2.dll

NuGet Package : DevExpress.Wpf.Map

Declaration

csharp
public class GeoJsonFileDataAdapter :
    MapGeoDataAdapter
vb
Public Class GeoJsonFileDataAdapter
    Inherits MapGeoDataAdapter

Remarks

The Map Control allows you to display data from GeoJSON files that store geographical objects in the JSON format.

The following table lists supported GeoJSON elements and corresponding map items:

|

GeoJSON element

|

Map item

| | --- | --- | |

Point

|

MapDot

| |

MultiPoint

|

A list of MapDot objects

| |

LineString

|

MapPolyline

| |

MultiLineString

|

MapPath

| |

Polygon, MultiPolygon

|

MapPath

| |

GeometryCollection

|

MapDot, MapPolyline, MapPath

|

Follow the steps below to load data from a .GeoJSON file:

  1. Add a VectorLayer object to the MapControl.Layers collection.
  2. Create a GeoJsonFileDataAdapter object.
  3. Specify the path to a GeoJSON file via the MapGeoDataAdapter.FileUri property.
  4. Assign the GeoJsonFileDataAdapter to the VectorLayer.Data property.
  5. Optionally, you can customize generated items in the MapGeoDataAdapter.ShapesLoaded event handler.
xaml
<Window xmlns:dxm="http://schemas.devexpress.com/winfx/2008/xaml/map"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:FileDataAdapters"
        x:Class="FileDataAdapters.MainWindow"
        xmlns:sys="clr-namespace:System;assembly=System"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <dxm:MapControl x:Name="mapControl">
            <dxm:ImageLayer>
                <dxm:BingMapDataProvider Kind="Road" 
                                         BingKey="Your-BingKey-here"/>
            </dxm:ImageLayer>
            <dxm:VectorLayer x:Name="vectorLayer" DataLoaded="OnVectorLayerDataLoaded">
                <dxm:VectorLayer.Data>
                    <dxm:GeoJsonFileDataAdapter ShapesLoaded="OnDataAdapterShapesLoaded">
                        <dxm:GeoJsonFileDataAdapter.FileUri>
                            <sys:Uri>pack://application:,,,/FileDataAdapters;component/Data/subway-entrances.geojson</sys:Uri>
                        </dxm:GeoJsonFileDataAdapter.FileUri>
                    </dxm:GeoJsonFileDataAdapter>
                </dxm:VectorLayer.Data>
            </dxm:VectorLayer>
        </dxm:MapControl>
    </Grid>
</Window>
csharp
using DevExpress.Xpf.Map;
using System.Windows;
using System.Windows.Media;
namespace FileDataAdapters {
    public partial class MainWindow : Window {
        public MainWindow() {
            InitializeComponent();
        }
        private void OnVectorLayerDataLoaded(object sender, DataLoadedEventArgs e) {
            mapControl.ZoomToFitLayerItems(new LayerBase[] { vectorLayer });
        }
        private void OnDataAdapterShapesLoaded(object sender, ShapesLoadedEventArgs e) {
            foreach (MapDot item in e.Shapes) {
                item.Fill = Brushes.Red;
                item.Size = 8;
            }
        }
    }
}
vb
Imports DevExpress.Xpf.Map
Imports System.Windows
Imports System.Windows.Media
Namespace FileDataAdapters
    Public Partial Class MainWindow
        Inherits Window
        Public Sub New()
            InitializeComponent()
        End Sub
        Private Sub OnVectorLayerDataLoaded(ByVal sender As Object, ByVal e As DataLoadedEventArgs)
            mapControl.ZoomToFitLayerItems(New LayerBase() {vectorLayer})
        End Sub
        Private Sub OnDataAdapterShapesLoaded(ByVal sender As Object, ByVal e As ShapesLoadedEventArgs)
            For Each item As MapDot In e.Shapes
                item.Fill = Brushes.Red
                item.Size = 8
            Next
        End Sub
    End Class
End Namespace

Note : In the example above, the GeoJson file’s Build Action is set to Resource.

Inheritance

Object DispatcherObject DependencyObject Freezable MapDependencyObject MapDataAdapterBase MapGeoDataAdapter GeoJsonFileDataAdapter

See Also

GeoJsonFileDataAdapter Members

Load Vector Items from Vector Format Source

DevExpress.Xpf.Map Namespace