javascript - 为什么 Maps here.com 仅在更改屏幕大小或按 F12 时显示在 Modal Bootstrap 中?
问题描述
故事是这样的:我想在 Modal Bootstrap 4 中显示 Maps here.com,但是当我对其进行测试时,出现了一个奇怪的错误,Maps here.com 仅在我更改屏幕大小或单击 F12 时才显示。
这是代码,所以你们可以测试一下:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" integrity="sha384-B0vP5xmATw1+K9KRQjQERJvTumQW0nPEzvF6L/Z6nronJ3oUOFUFpCjEUQouq2+l" crossorigin="anonymous">
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<link rel="stylesheet" type="text/css" href="https://js.api.here.com/v3/3.1/mapsjs-ui.css" />
<style>
html, body { border: 0; margin: 0; padding: 0; }
#map { height: 300px; width: 100%; }
</style>
<div id="map"></div>
<script src="https://js.api.here.com/v3/3.1/mapsjs-core.js"></script>
<script src="https://js.api.here.com/v3/3.1/mapsjs-service.js"></script>
<script src="https://js.api.here.com/v3/3.1/mapsjs-ui.js"></script>
<script src="https://js.api.here.com/v3/3.1/mapsjs-mapevents.js"></script>
<script>
const platform = new H.service.Platform({ apikey: 'M2xwqVT_KT8dAM06R3yboaycYBCDJ-gp3a_qr8s4Ndk' });
const defaultLayers = platform.createDefaultLayers();
const map = new H.Map(document.getElementById('map'),
defaultLayers.vector.normal.map, {
center: { lat: 37.773972, lng: -122.431297 },
zoom: 13,
pixelRatio: window.devicePixelRatio || 1
});
window.addEventListener('resize', () => map.getViewPort().resize());
const behavior = new H.mapevents.Behavior(new H.mapevents.MapEvents(map));
const ui = H.ui.UI.createDefault(map, defaultLayers);
</script>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-Piv4xVNRyMGpqkS2by6br4gNJ7DXjqk09RmUpJ8jgGtD7zP9yug3goQfGII0yAns" crossorigin="anonymous"></script>
解决方案
推荐阅读
- macos - 如何从 mac 上的 node.js 脚本启动电子应用程序?
- swift - navigationItem 显示很高 swift 5
- asp.net-core - 如何在 IIS 上使用 ASP.NET Core 3.1 API 部署 Angular SPA?
- dom - 我可以从 Geotools 中的 DOM 节点解析 GML Surface 吗?
- visual-studio - 未知解决方案项目类型 Visual Studio for MAC
- javascript - 根据范围滑块的值更新 HTML
- python - PyPDF2:从 zip 文件中读取 pdf
- c - 尝试在两个文件之间交换数据时出现问题
- javascript - 将值 date.now() "JS" 转换为日期格式 "MM/dd/yyyy HH:mm:ss"
- sql - 将 0019 年更改为 2019