Hello,
I'm using the SFMaps component.
I understand how to set the MapsCenterPosition and ZoomSettings in order to position the map.
But I need a way to get the minimum and maximum visible latitude and longitude each time the map is (a) loaded, (b) panned, or (c) zoomed
I tried searching the MapsEvents, but I can't find anything.
Hello Indumathi,
Thank you for your reply.
I think this would be a necessary feature for any serious map application.
For example, google maps Javascript API supports this function: https://developers.google.com/maps/documentation/javascript/reference/map#Map.getBounds
Also, this need comes up for example on StackOverflow even 10 years ago: https://stackoverflow.com/questions/6910847/get-boundaries-longitude-and-latitude-from-current-zoom-google-maps
Thanks,
Sorin
Hi Sorin,
We have implemented the feature “Provide minimum and maximum values of latitude and longitude coordinates as event arguments” in the Maps component and the fix is included in our Essential Studio 2022 Volume 1 Main release v20.1.0.47 which is rolled out and is available for download under the following link.
The minimum and maximum values of the latitude and the longitude is now available in the event arguments of “Loaded”, “OnPan”, “OnZoom” and “OnZoomComplete” events with the properties such as “MaxLatitude”, “MinLatitude”, “MaxLongitude” and “MinLongitude”. Please find the code snippet below.
Code Snippet:
<SfMaps> <MapsZoomSettings Enable="true" EnablePanning="true"></MapsZoomSettings> <MapsEvents Loaded ="Loaded" OnZoom="Zoom" OnPan="Pan" OnZoomComplete="ZoomComplete"></MapsEvents> <MapsLayers> <MapsLayer ShapeData='new {dataOptions= https://cdn.syncfusion.com/maps/map-data/world-map.json}' TValue="string"> </MapsLayer> </MapsLayers> </SfMaps>
<div> MaxLatitude = @MaxLatitude </div> <div> MinLatitude = @MinLatitude </div> <div> MaxLongitude = @MaxLongitude </div> <div> MinLongitude = @MinLongitude </div>
@code{
public double MaxLatitude { get; set; } public double MinLatitude { get; set; } public double MaxLongitude { get; set; } public double MinLongitude { get; set; }
public void Loaded(LoadedEventArgs args) { MaxLatitude = args.MaxLatitude; MinLatitude = args.MinLatitude; MaxLongitude = args.MaxLongitude; MinLongitude = args.MinLongitude; }
public void Zoom(MapZoomEventArgs args) { MaxLatitude = args.MaxLatitude; MinLatitude = args.MinLatitude; MaxLongitude = args.MaxLongitude; MinLongitude = args.MinLongitude; }
public void Pan(MapPanEventArgs args) { MaxLatitude = args.MaxLatitude; MinLatitude = args.MinLatitude; MaxLongitude = args.MaxLongitude; MinLongitude = args.MinLongitude; }
public void ZoomComplete(MapZoomEventArgs args) { MaxLatitude = args.MaxLatitude; MinLatitude = args.MinLatitude; MaxLongitude = args.MaxLongitude; MinLongitude = args.MinLongitude; } } |
We have created a sample application to demonstrate the same and it can be downloaded from the below link.
https://www.syncfusion.com/downloads/support/directtrac/general/ze/MapsMinMax-103201391
We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you would require any further assistance.
Regards,
Indumathi R
Wow, thank you so much Indumathi, this is great news and will be very helpful!
Hi Sorin,
Most Welcome.
Please get back to us if you need any further assistance.
Regards,
Indumathi R.