ichim / LeafletForBlazor-NuGet

LeafletForBlazor NuGet Package - You can quickly add a map control to your Blazor application - 2.2.2.2 version. #12 issue, StreamLegend customization
https://www.nuget.org/packages/LeafletForBlazor#versions-body-tab
74 stars 9 forks source link

Map.Overlays not working - adding OpenRailwayMap #44

Closed avresial closed 3 months ago

avresial commented 3 months ago

Hi

I'm having issue with using overlays. My goal is to add OpenRailwayMap on to of the OpenStreetMap

Uppon initializing an application, I'm getting following error.

Unhandled Exception:
Microsoft.JSInterop.JSException: Could not find 'stream_points_update' ('stream_points_update' was undefined).
Error: Could not find 'stream_points_update' ('stream_points_update' was undefined).
    at https://localhost:7043/_framework/blazor.web.js:1:537
    at Array.forEach (<anonymous>)
    at l.findFunction (https://localhost:7043/_framework/blazor.web.js:1:505)
    at b (https://localhost:7043/_framework/blazor.web.js:1:5248)
    at https://localhost:7043/_framework/blazor.web.js:1:3041
    at new Promise (<anonymous>)
    at y.beginInvokeJSFromDotNet (https://localhost:7043/_framework/blazor.web.js:1:3004)
    at Object.ri [as invokeJSJson] (https://localhost:7043/_framework/blazor.web.js:1:164916)
    at https://localhost:7043/_framework/dotnet.runtime.8.0.7.p9y0lritgl.js:3:178364
    at Tl (https://localhost:7043/_framework/dotnet.runtime.8.0.7.p9y0lritgl.js:3:179198)
   at Microsoft.JSInterop.JSRuntime.<InvokeAsync>d__16`1[[Microsoft.JSInterop.Infrastructure.IJSVoidResult, Microsoft.JSInterop, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60]].MoveNext()
   at Microsoft.JSInterop.JSObjectReferenceExtensions.InvokeVoidAsync(IJSObjectReference jsObjectReference, String identifier, Object[] args)
   at LeafletForBlazor.CoreJsInterop.LoadMapPartialAsync(ParametersInitialization parameters, ParametersInitialization esri_api_parameters, ParametersInitialization plugins_parameters, ParametersInitialization ui_controls_parameters, ParametersInitialization images_overlay, DotNetObjectReference`1 dotNetObject)
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_1(Object state)
   at System.Threading.QueueUserWorkItemCallbackDefaultContext.Execute()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading.ThreadPool.BackgroundJobHandler()

I know that in the latest nugget version there is RealTimeMap component. But it seems not to support overlays. Maybe ImagesAndBoundsCoordinates is not the right element to use. What is the correct way to achieve my goal?

My razor component:

<Map height="50vh" width="100%" Parameters="@mapParameters" MapOverlays="Overlays"></Map>

C# code:

public Map.LoadParameters mapParameters = new Map.LoadParameters()
{
    anyway_overlay_layers_control = true,
    basemap = new Map.Basemap()
    {

        basemap_layers = new List<Map.BasemapConfigLayer>
        {
            new Map.BasemapConfigLayer()
            {
                url = "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
                attribution = "©Open Street Map",
                title = "Open Street Map",
                detect_retina = true,

            }
        }
    }

};

public Map.Overlays Overlays = new Map.Overlays()
{
    images = new Map.ImageOverlay()
    {
        images_and_bounds = new List<Map.ImagesAndBoundsCoordinates>()
        {
            new ImagesAndBoundsCoordinates()
            {
                url = "http://{s}.tiles.openrailwaymap.org/standard/{z}/{x}/{y}.png"
            }
        }
    }
};
ichim commented 3 months ago

Hello sir,

ImagesAndBoundsCoordinates is a class that allows adding images to the map. In your example, you have the url of a basemap service (is not a image). The image must appear in the browser when you have the url of the image in the address(bar).