gpt4 book ai didi

angular - 传单 divIcon 未以 Angular 显示在 map 上

转载 作者:行者123 更新时间:2023-12-04 02:50:54 24 4
gpt4 key购买 nike

我正在尝试在 Angular 传单中添加一个 divicon 标记。

组件.css:

.leaflet-div-icon2
{
background: #e5001a;
border:5px solid rgba(255,255,255,0.5);
color:blue;
font-weight:bold;
text-align:center;
border-radius:50%;
line-height:30px;
}

组件.ts:

var map = L.map('map', {
attributionControl: false,
crs: L.CRS.Simple
});

var bounds = [[0,0], [1000,1000]];
var image = L.imageOverlay('cust_image.png', bounds).addTo(map);
var customMarkerIcon = L.divIcon({className: 'leaflet-div-icon2'});

var m3 = L.latLng([ 348,278.2]);
L.marker(m3, {icon: customMarkerIcon }).addTo(map);

我在控制台中没有收到任何错误,但无法在 map 上查看标记。

它适用于带有 css 和 js 的基本 html 页面,但不适用于 Angular 。

我是不是漏掉了什么?

最佳答案

我不确定为什么它不适合你,但你需要将代码放在 inside ngOnInit lifecycle hook 和 L.divIcon class selector style inside global styles.css。这是您要实现的类似示例:

应用.ts:

ngOnInit() {
const map = L.map("map", {
crs: L.CRS.Simple
});

const bounds = [[0, 0], [1000, 1000]];

map.fitBounds(bounds);

const image = L.imageOverlay(
"https://leafletjs.com/examples/crs-simple/uqm_map_full.png",
bounds
).addTo(map);
const customMarkerIcon = L.divIcon({
className: "leaflet-div-icon2"
});

const m3 = L.latLng([348, 278.2]);
L.marker(m3, {
icon: customMarkerIcon
}).addTo(map);
}

样式.css:

.leaflet-div-icon2 {
background: #e5001a;
border: 5px solid rgba(255, 255, 255, 0.5);
color: blue;
font-weight: bold;
text-align: center;
border-radius: 50%;
line-height: 30px;
}

Demo

关于angular - 传单 divIcon 未以 Angular 显示在 map 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55133973/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com