Articles in this section
Category / Section

How to zoom and pan programmatically in the .NET MAUI Maps (SfMaps)?

2 mins read

In the Syncfusion® .NET MAUI Maps control, you can programmatically zoom and pan the SfMaps through the following steps:

Step 1: Add the SfMaps control and a Button control to trigger the zoom and pan functionality.

XAML:

<Grid RowDefinitions="0.85*, 0.15*">
   <map:SfMaps>
   </map:SfMaps>

   <Button Grid.Row="1"
           x:Name="ZoomPanButton"
           HorizontalOptions="Center"
           VerticalOptions="Center"
           Text="Northern Territory, Australia"
           Clicked="ZoomPanButton_Clicked" />
</Grid> 

Step 2: Initialize the MapTileLayer and set the OSM tiles provider to the UrlTemplate property of the MapTileLayer, as shown in the following code sample.

XAML:

<map:SfMaps.Layer>
   <map:MapTileLayer x:Name="layer"
                     UrlTemplate="https://tile.openstreetmap.org/{z}/{x}/{y}.png" />
</map:SfMaps.Layer> 

Step 3: In the Button.Clicked event, initialize the MapZoomPanBehavior object and set the value of its ZoomLevel property to 4. Then, initialilze the MapLatLng object with the specified Latitude and Longitude coordinates and set it as the Center point of the MapTileLayer. The following code sample explains how to implement this step.

C#:

private void ZoomPanButton_Clicked(object sender, EventArgs e)
{
   this.layer.ZoomPanBehavior = new MapZoomPanBehavior();
   this.layer.ZoomPanBehavior.ZoomLevel = 4;
   this.layer.Center = new MapLatLng(-19.49, 132.55);
} 

Download the complete sample from GitHub.

Output:

Programmatic zoom and pan in Syncfusion .NET MAUI Maps

Conclusion:
I hope you enjoyed learning how to programmatically zoom and pan 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. You can also 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