We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Map reset behaviour and auto zoom on shape

Howdy,

How can I achieve that when the user presses the "reset" button in maps toolbar the maps center on MapsCenterPosition with the initial ZoomFactor ?

I draw a geoshape (MapsLayer ShapeData) on the maps, I then compute the center points of the shape and set the MapsCenterPosition to it. Is there a way to zoom the map to fit the whole shape automatically? Or how am I supposed to  compute the ZoomFactor to fit the shape?

Thanks, Sergio


4 Replies

IR Indumathi Ravi Syncfusion Team March 6, 2023 07:46 PM UTC

Hi Sergio,


Please find the details for your queries from the below table.

Queries

Details

How can I achieve that when the user presses the "reset" button in maps toolbar the maps center on MapsCenterPosition with the initial ZoomFactor?

To achieve your scenario, you can set the initial zoom factor in the "MinZoom" property of the "MapsZoomSettings" tag in the Maps component. Meanwhile, when we click on the reset button in the zoom toolbar of the Maps, "OnZoom" event will be triggered. In this event, "Scale" property of the event argument will be returned as "1". At that instance, you can call the "ZoomByPosition" method to reset the Maps to its initial center position with the initial zoom factor. Please find the code snippet for the same below.

 

Code Snippet:

<SfMaps @ref="maps">

    <MapsZoomSettings ZoomFactor="@Factor" Enable="true" MinZoom="@Factor">

    </MapsZoomSettings>

    <MapsCenterPosition Latitude="@Latitude" Longitude="@Longitude"></MapsCenterPosition>

    <MapsEvents OnZoom="@OnZoom"></MapsEvents>

    <MapsLayers>

        <MapsLayer ShapeData='new {dataOptions= https://cdn.syncfusion.com/maps/map-data/world-map.json}' TValue="string">

        </MapsLayer>

    </MapsLayers>

</SfMaps>

 

@code {

    SfMaps maps;

    public void OnZoom(Syncfusion.Blazor.Maps.MapZoomEventArgs args)

    {

        if(args.Scale == 1)

        {

            MapsCenterPosition centerPosition = new MapsCenterPosition();

            centerPosition.Latitude =49.95121990866204;

            centerPosition.Longitude = 18.468749999999998;

            maps.ZoomByPosition(centerPosition, Factor);

        }  

    }

}

 

You can find the sample and video from the below link.

Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/ResetMaps587227249

Video: https://www.syncfusion.com/downloads/support/directtrac/general/ze/minzoom-1975847347

I draw a geoshape (MapsLayer ShapeData) on the maps, I then compute the center points of the shape and set the MapsCenterPosition to it. Is there a way to zoom the map to fit the whole shape automatically? Or how am I supposed to  compute the ZoomFactor to fit the shape?

We do not support to zoom the Maps to fit an entire shape. However, you can achieve this by obtaining the minimum and maximum latitude and longitude of the shape and passing it to the "ZoomToCoordinates" method of the Maps component. Now, the Maps will be zoomed to fit the shape.

 

You can find the sample from the below link.

Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/MapsZoomtoCoordinates2087792284

 

Please find the documentation link below to know more about the "ZoomToCoordinates" method.

https://blazor.syncfusion.com/documentation/maps/maps-method#zoomtocoordinates

 

However, currently we are facing an issue with the zoom factor calculation in this method. We are currently working to improve the zoom factor from this method to fit the shape. The fix will be available in our 2023 Volume 1 release. Please find the feedback link below to keep track of this issue.

 

https://www.syncfusion.com/feedback/41658


Please let us know if the above sample meets your requirement and let us know if you need any further assistance.



IR Indumathi Ravi Syncfusion Team March 24, 2023 04:35 PM UTC

Hi Sergio,


Sorry for the inconvenience.


We have not included the fix for the reported issue in our 2023 Volume 1 release. However, the fix will be included in our next weekly patch release, which is expected to be available by the first week of April 2023.



SE Sergio April 24, 2023 08:01 AM UTC

Hi Indumathi, 

Is the patch released yet?



IR Indumathi Ravi Syncfusion Team April 25, 2023 07:33 AM UTC

Hi Sergio,


We have fixed the reported issue - “When the bound of the Maps is set as parameter to ‘ZoomToCoordinates’ method, position of the map is improper” and the fix is included in our latest weekly patch release (v21.1.41). Please update the “Syncfusion.Blazor.Maps” package to the latest version in your application to resolve the reported issue. Please find the package link below.


https://www.nuget.org/packages/Syncfusion.Blazor.Maps


Loader.
Live Chat Icon For mobile
Up arrow icon