En mi script Java, envío el Lan/Long de mi mapa a blazor. Puedo ver los cambios de longitud y latitud en el navegador, pero quiero pasarlos a mi método blazor para realizar algún procesamiento. los valores devueltos siempre 0.
Aquí está mi método have script:
function GetCircle(e){ r = document.getElementById("InputRadius").value; if (circle !== null) { map.removeLayer(circle); } circle = new L.circle([ Lat,Long],{radius:r}); map.addLayer(circle); circle.bindPopup( "<br/> Radius is : " + r +" Meter" ).openPopup(); document.getElementById("Lat").value = Lat; //send this to blazor document.getElementById("Long").value = Long; // send this to blazor }Como puede ver en el código anterior, cuando el usuario hace clic en el mapa, obtengo la longitud/latitud y luego los envío a blazor.
Mi página de afeitar: tengo las siguientes entradas que estoy usando para almacenar los datos dentro de ellas y luego pasar los datos al método blazor en la sección 'código'
<input type="text" @bind="Lat" id="Lat" name="Lat" > <input type="text" @bind="Long" id="Long" name = "Long" > @code { int InputRadius; double Long; double Lat; string date_selected; string time_selected; public async Task GetTgas() { AllTags = await Task.Run(() => tagsService.Map( InputRadius, Long,Lat,date_selected,time_selected)); } public async Task GetCircle() { await JSRuntime.InvokeVoidAsync("GetCircle"); } }Puedo ver el Lan/Long en mi vista perfectamente cuando hago clic en GetCircle, lo que significa que pasaron de JS a la página blazor con éxito, pero al hacer la función GetTags no pasan a mi método blazor.
¡Cualquier ayuda será bien recibida!
Su método GetCircle debería ser así, necesita enviar una referencia de objeto .net a la función javascript
await JS.InvokeVoidAsync("GetCircle", DotNetObjectReference.Create(this));Y su función GetTags debería ser así, debería poder invocarse desde javascript
[JSInvokable] public async Task GetTags(double lati, double longi) { AllTags = await Task.Run(() => tagsService.Map(InputRadius, longi,lati,date_selected,time_selected)); }Su función javascript debería ser así
function GetCircle(dotNetHelper){ r = document.getElementById("InputRadius").value; if (circle !== null) { map.removeLayer(circle); } circle = new L.circle([ Lat,Long],{radius:r}); map.addLayer(circle); circle.bindPopup( "<br/> Radius is : " + r +" Meter" ).openPopup(); // send this to blazor dotNetHelper.invokeMethodAsync('GetTags', Lat, Long); }