Unplanned
Last Updated: 28 Jan 2025 12:21 by ADMIN
Phil
Created on: 31 Jan 2023 17:34
Category: Map
Type: Feature Request
5
Add Bounding Box Support

Hi

Can bounding box support be considered for the map please. It would be great if we can reference at runtime the current bounds that are displayed on the screen in bounding box format (https://wiki.openstreetmap.org/wiki/Bounding_Box) such as the open street map format below.

Im hoping as the map uses open street map this can be made available to the component.

bbox = min Longitude , min Latitude , max Longitude , max Latitude 
1 comment
ADMIN
Dimo
Posted on: 28 Jan 2025 12:21

Hi Phil and anyone else how is interested in this feature,

Currently, the Map provides its current bounding box through the Extent property of its OnPanEnd and OnZoomEnd event arguments. So this part of the request is complete.

What remains is to expose the Map Extent (bounding box) on demand, which will cover the initial component state. A possible workaround is to simulate a user zoom or pan action with the Map buttons. Here is a REPL example. The code below is the same:

@using System.Text.Json

@inject IJSRuntime js

<PageTitle>Index</PageTitle>

<TelerikMap Center="@Center"
            OnPanEnd="@OnPanEnd"
            OnZoomEnd="@OnZoomEnd"
            Zoom="3">
    <MapLayers>
        <MapLayer Type="@MapLayersType.Tile"
                  Attribution="@Attribution"
                  Subdomains="@Subdomains"
                  UrlTemplate="@UrlTemplate">
        </MapLayer>
    </MapLayers>
</TelerikMap>

<h3>Map Extent</h3>
<pre>@MapExtent</pre>

<script suppress-error="BL9992">
    function zoomMap() {
        document.querySelector(".k-map .k-zoom-in").click();
    }
</script>

@code {
    private string[] Subdomains { get; set; } = new string[] { "a", "b", "c" };
    private string UrlTemplate { get; set; } = "https://#= subdomain #.tile.openstreetmap.org/#= zoom #/#= x #/#= y #.png";
    private string Attribution { get; set; } = "&copy; <a href='https://osm.org/copyright'>OpenStreetMap contributors</a>";
    private double[] Center { get; set; } = new double[] { 30.268107, -97.744821 };

    private string MapExtent { get; set; }

    private void OnPanEnd(MapPanEndEventArgs args)
    {
        var center = args.Center;
        var extent = args.Extent;

        MapExtent = JsonSerializer.Serialize(extent, new JsonSerializerOptions() { WriteIndented = true });
    }

    private void OnZoomEnd(MapZoomEndEventArgs args)
    {
        var center = args.Center;
        var extent = args.Extent;

        MapExtent = JsonSerializer.Serialize(extent, new JsonSerializerOptions() { WriteIndented = true });
    }

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (firstRender)
        {
            await Task.Delay(1); // ensure the HTML is rendered in the browser
            await js.InvokeVoidAsync("zoomMap");
        }

        await base.OnAfterRenderAsync(firstRender);
    }
}

 

Regards,
Dimo
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.