Category / Section
How to load shape files as stream in maps
1 min read
Instead of referring the shape files directly to maps using the URI property, you can convert them into stream and load to maps using the ReadAsStream method. In this approach, you can also dynamically load the shape files.
The following code snippet demonstrates the stream conversion of a shape file. The shape file added in the project is converted into stream.
C#
assembly = typeof(MainPage).GetTypeInfo().Assembly; stream = assembly.GetManifestResourceStream("Maps.ShapeFiles.world1.shp");
The following code snippet demonstrates how to load the converted stream into shape file layer.
C#
//// Stream of the shape file accessed from any location can be loaded here. layer.ReadAsStream(stream);
The following code snippet demonstrates the maps defined in xaml.
XAML
<maps:SfMaps x:Name="sfmap" Grid.Row="2" BackgroundColor="White" > <maps:SfMaps.Layers > <maps:ShapeFileLayer x:Name="layer"> </maps:ShapeFileLayer> </maps:SfMaps.Layers> </maps:SfMaps>
Sample for loading shape files as stream: https://github.com/SyncfusionExamples/How-to-load-shape-files-as-stream-in-map