c# - Blazor - 带有 OSM 的单页
问题描述
我正在尝试使用 Blazor 和 OSM 使用BlazorLeaflet NuGet 包创建一个简单的 web 地图。将 100% 覆盖 OSM 地图的单个页面。当宽度和高度值固定为某些值时,一切正常。但是,当我尝试将宽度和高度属性设置为 100% 时,页面完全是空白的。
MainLayout.razor
@inherits LayoutComponentBase
@Body
索引剃刀
@page "/"
@using System.Drawing
@using BlazorLeaflet
@using BlazorLeaflet.Models
@using BlazorWebMap.Data
@inject IJSRuntime jsRuntime
<div id="map">
<LeafletMap Map="_map" />
</div>
<style>
body {
padding: 0;
margin: 0;
}
html, body, #map {
height: 100%;
width: 100%;
}
</style>
@code
{
private Map _map;
protected override void OnInitialized()
{
_map = new Map(jsRuntime)
{
Center = _startAt,
Zoom = 12.2f
};
_map.OnInitialized += () =>
{
_map.AddLayer(new TileLayer
{
UrlTemplate = "https://a.tile.openstreetmap.org/{z}/{x}/{y}.png",
Attribution = "© <a href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap</a> contributors",
});
};
}
private LatLng _startAt = new LatLng(53.13344f, 23.15026f);
}
我知道只使用HTML就可以做到这一点,但我想在 Blazor 中做到这一点,这是我的应用程序的起点。
解决方案
position
有价值的财产fixed
可以帮助您解决问题
html, body, #map {
height: 100%;
width: 100%;
position: fixed;
}
推荐阅读
- laravel - 使用正确的工具扩展 Laravel 包
- php - 从 file.php 访问 CF7 标签
- python - 为 Windows 激活 venv (Python 3.7.2)
- codeigniter - 如何使用 codeigniter 表单验证库验证依赖下拉列表?
- c++ - std::pair 中的模板模板参数
- python - 如何从容器应用程序检查 docker 主机上的磁盘空间?
- .htaccess - 如何将 301 这个链接(https://www.example.com/?lang=en)重定向到这个链接(https://www.example2.com/en/)?
- javascript - ReferenceError: stopFireworks 未定义
- github - 如何为 GitHub 页面中的单个页面自定义 Jekyll 主题?
- angular - ngFor 基于类型