ClassMapSource
Abstract base class for all data sources that provide shapefile data to the MapShapeReader. Provides factory methods to create MapSource instances from various sources including embedded resources, files, streams, and URIs.
Definition
Namespace:Telerik.Maui.Controls.Map
Assembly:Telerik.Maui.Controls.dll
Syntax:
public abstract class MapSource : NotifyPropertyChangedBase, INotifyPropertyChanged
Inheritance: objectNotifyPropertyChangedBaseMapSource
Derived Classes:
Implements:
Inherited Members
Constructors
MapSource()
Declaration
protected MapSource()
Methods
FromFile(string)
Creates a MapSource from a file path on the local file system. Use this method to load shapefiles from the device's storage or application bundle.
Declaration
public static MapSource FromFile(string file)
Parameters
file
The full or relative path to the shapefile on the local file system.
Returns
A MapSource that reads from the specified file.
Example
var source = MapSource.FromFile("/path/to/shapefile.shp");
// Or using a relative path
var source = MapSource.FromFile("Data/world.shp");
FromResource(string, Assembly)
Creates a MapSource from an embedded resource within an assembly. This is the most common way to include shapefile data with your application.
Declaration
public static MapSource FromResource(string resource, Assembly sourceAssembly = null)
Parameters
resource
The full name of the embedded resource containing the shapefile (e.g., "MyApp.Data.world.shp").
sourceAssembly
The assembly containing the embedded resource. If null, uses the calling assembly.
Returns
A MapSource that reads from the specified embedded resource.
Example
// Load from embedded resource in current assembly
var source = MapSource.FromResource("MyApp.Data.world.shp");
// Load from embedded resource in specific assembly
var assembly = typeof(MyPage).Assembly;
var source = MapSource.FromResource("MyApp.Data.world.shp", assembly);
FromResource(string, Type)
Creates a MapSource from an embedded resource using a type to resolve the assembly. This is a convenience overload that automatically determines the assembly from the provided type.
Declaration
public static MapSource FromResource(string resource, Type resolvingType)
Parameters
resource
The full name of the embedded resource containing the shapefile.
resolvingType
A type from the assembly containing the embedded resource.
Returns
A MapSource that reads from the specified embedded resource.
Example
var source = MapSource.FromResource("MyApp.Data.world.shp", typeof(MainPage));
FromStream(Stream)
Creates a MapSource from a Stream containing shapefile data. Use this method when you have shapefile data in memory or from a custom source.
Declaration
public static MapSource FromStream(Stream stream)
Parameters
stream
The stream containing the shapefile data. The stream should remain open until reading is complete.
Returns
A MapSource that reads from the specified stream.
Example
using var fileStream = File.OpenRead("path/to/shapefile.shp");
var source = MapSource.FromStream(fileStream);
Operators
implicit operator MapSource(Stream)
Provides implicit conversion from a Stream to a MapSource. This allows direct assignment of streams to MapSource properties.
Declaration
public static implicit operator MapSource(Stream stream)
Parameters
stream
The stream to convert to a MapSource.
Returns
A MapSource created from the stream, or null if the stream is null.
Example
// Implicit conversion allows direct assignment
using var fileStream = File.OpenRead("shapefile.shp");
reader.Source = fileStream;
implicit operator MapSource(string)
Provides implicit conversion from a string file path to a MapSource. This allows direct assignment of file paths to MapSource properties.
Declaration
public static implicit operator MapSource(string source)
Parameters
source
The file path to convert to a MapSource.
Returns
A MapSource created from the file path, or null if the string represents an absolute non-file URI.
Example
// Implicit conversion allows direct assignment
reader.Source = "Data/world.shp";