Articles in this section
Category / Section

How to Add/Draw Polylines in the .NET MAUI Maps (SfMaps)?

4 mins read

In the Syncfusion® .NET MAUI Maps control, you can add or draw polylines in the SfMaps through the following steps:

 

Step 1: Add the SfMaps control to your layout. Initialize the MapShapeLayer, as shown in the following code sample.

 

XAML:

<map:SfMaps>
    <map:SfMaps.Layer>
        <map:MapShapeLayer>
        </map:MapShapeLayer>
    </map:SfMaps.Layer>
</map:SfMaps>

 

Step 2: Set the ShapesSource property for geographical rendering and define the ShapeStroke to DarkGray to separate state borders:

 

XAML:

<map:MapShapeLayer ShapesSource="https://cdn.syncfusion.com/maps/map-data/india.json"
                   ShapeStroke="DarkGray">
</map:MapShapeLayer>

 

Note:

The ShapesSource can be a GeoJSON or shapefile from a local file, URL, Stream, or Resource.

 

Step 3: Add the MapPolylineLayer to the MapShapeLayer’s Sublayers, and set the AnimationDuration and AnimationEasing properties, as shown in the following code sample.

 

XAML:

<map:MapShapeLayer.Sublayers>
    <map:MapPolylineLayer AnimationDuration="3000"
                          AnimationEasing="{x:Static Easing.SinInOut}">
    </map:MapPolylineLayer>
</map:MapShapeLayer.Sublayers>

 

Step 4: Add the Polyline Points of type MapLatLng to connect multiple location coordinates, as shown in the following code sample.

 

XAML:

<map:MapPolylineLayer.Polylines>
    <map:MapPolyline>
        <map:MapPolyline.Points>
            <map:MapLatLng Latitude="13.0827"
                           Longitude="80.2707" />
            <map:MapLatLng Latitude="13.1746"
                           Longitude="79.6117" />
            <map:MapLatLng Latitude="13.6373"
                           Longitude="79.5037" />
            <map:MapLatLng Latitude="14.4673"
                           Longitude="78.8242" />
            <map:MapLatLng Latitude="14.9091"
                           Longitude="78.0092" />
            <map:MapLatLng Latitude="16.2160"
                           Longitude="77.3566" />
            <map:MapLatLng Latitude="17.1557"
                           Longitude="76.8697" />
            <map:MapLatLng Latitude="18.0975"
                           Longitude="75.4249" />
            <map:MapLatLng Latitude="18.5204"
                           Longitude="73.8567" />
            <map:MapLatLng Latitude="19.0760"
                           Longitude="72.8777" />
        </map:MapPolyline.Points>
    </map:MapPolyline>
</map:MapPolylineLayer.Polylines>

Download the complete sample on GitHub.


Output:

 

Polyline in Syncfusion .NET MAUI Maps

 

 

Conclusion:

 

Hope you enjoyed learning how to add or draw polylines in the .NET MAUI Maps (SfMaps).

You can refer to our .NET MAUI Maps feature tour page to learn about its other groundbreaking feature representations. Explore our .NET MAUI Maps documentation to understand how to present and manipulate data.

For current customers, check out our .NET MAUI components from the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to check out our .NET MAUI Maps and other .NET MAUI components.

Please let us know in the comments section if you have any queries or require clarification. Contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied