How to create map from GeoJson shape file using .NET MAUI Maps?
This article describes how to create map from the GeoJson data or shapefile in the Syncfusion .NET MAUI Maps control.
The Syncfusion .NET MAUI Maps support both shape and json files. you can load from various sources.
- FromFile returns a MapSource that reads a shape source from a local file.
- FromUri returns an MapSource that downloads and reads a shape source from a specified URI.
- FromResource returns a MapSource that reads a shape source file embedded in an assembly.
- FromStream returns a MapSource that reads a shape source from a stream that supplies source data.
How to load an embedded file
- You can load both the json data and shapefile.
- For example, placing australia.json in the root folder of a project named MyProject will result in a resource ID of MyProject.australia.json. Similarly, placing world1.shp in the Assets folder of a project named MyProject will result in a resource ID of MyProject.Assets.world1.shp
- Right-click the added shapefile and navigate to properties.
- Choose the EmbeddedResource option under the BuildAction of the respective shapefile.
The following code sample demonstrates how to load a shape file from embedded.
C#
SfMaps map = new SfMaps();
MapShapeLayer layer = new MapShapeLayer();
layer.ShapesSource = MapSource.FromResource("GeoJsonMap.ShapeFiles.world1.shp ");
map.Layer = layer;
The following code snippet demonstrates how to load a json file from embedded.
C#
SfMaps map = new SfMaps();
MapShapeLayer layer = new MapShapeLayer();
layer.ShapesSource = MapSource.FromResource("GeoJsonMap.ShapeFiles.world-map.json ");
map.Layer = layer;
Please refer to the following reference links for more information on how to load the shapes from other sources.
Output
View sample in the GitHub.
See also
Conclusion
I hope you enjoyed learning about how to create map from GeoJson shape file using .NET MAUI Maps.
You can refer to our .NET MAUI Map’s feature tour page to know about its other groundbreaking feature representations. You can also explore our documentation to understand how to create and manipulate data.
For current customers, you can check out our .NET MAUI components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our .NET MAUI Maps and other .NET MAUI components.
If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!