Angular 13传单无法正确渲染地图

发布于 2025-02-01 09:53:32 字数 1103 浏览 6 评论 0原文

我正在遇到一个问题,当我尝试在Angular 13中使用传单渲染地图时,我会得到以下...

我有flue.css and styles.css.css加载在aggular.json文件中...

"styles": ["src/styles.scss", 
           "node_modules/leaflet/dist/leaflet.css"]

我有app.component.ts中加载的feflet.css and styles.css.css ...

styleUrls: ['./on-site-proctor-locator.component.scss',
            '../../../../../node_modules/leaflet/dist/leaflet.css']

在app.com.ponent中。

this.map = L.map('map').setView([ lat, lon ], zoom); 
const tiles = L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
  maxZoom: 20,
  attribution: '&copy; <a href="https://stadiamaps.com/">Stadia Maps</a>, &copy; <a href="https://openmaptiles.org/">OpenMapTiles</a>' +
            '&copy; <a href="openstreetmap.org">OpenStreetMap</a> contributors'
});
tiles.addTo(this.map);

<div id="map" class="map-div"></div>

​我。我将感谢有关解决这个问题的任何建议。谢谢。

I am having an issue where when I attempt to render a map using Leaflet in Angular 13, I am getting the following...

Incorrectly Rendered Map

I have the leaflet.css and styles.css loaded in the angular.json file...

"styles": ["src/styles.scss", 
           "node_modules/leaflet/dist/leaflet.css"]

I have the leaflet.css and styles.css loaded in the app.component.ts...

styleUrls: ['./on-site-proctor-locator.component.scss',
            '../../../../../node_modules/leaflet/dist/leaflet.css']

In the app.component.ts file, here is where I initialize the map...

this.map = L.map('map').setView([ lat, lon ], zoom); 
const tiles = L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
  maxZoom: 20,
  attribution: '© <a href="https://stadiamaps.com/">Stadia Maps</a>, © <a href="https://openmaptiles.org/">OpenMapTiles</a>' +
            '© <a href="openstreetmap.org">OpenStreetMap</a> contributors'
});
tiles.addTo(this.map);

Here is what I have setup in the app.component.html file for the div...

<div id="map" class="map-div"></div>

I have looked at other posts of similar struggles and have found nothing that has helped me. I would appreciate any suggestions on what I can do to resolve this issue. Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

赠我空喜 2025-02-08 09:53:32

这对我有用(Angular 14项目+传单1.8):

在这条线上

<div id="map" class="map-div"></div>

增加了宽度和高度,以读取此类

<div id="map" class="map-div" style="width: 100%; height: 300px"></div>

传单需要可见容器,并且具有参考宽度/高度才能正确渲染。

我希望它有帮助

this is what worked for me (angular 14 project+leaflet 1.8):

on this line

<div id="map" class="map-div"></div>

add a width and height, to read something like this

<div id="map" class="map-div" style="width: 100%; height: 300px"></div>

leaflet requires the container to be visible, and have a reference width/height in order to render correctly.

I hope it helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文