gpt4 book ai didi

javascript - 如何更改标记的颜色

转载 作者:行者123 更新时间:2023-12-03 06:03:14 31 4
gpt4 key购买 nike

这是我在 map 上添加标记的代码:

var marker = {'depart':null, 'arrivee':null};
var DEPART = "depart";
var ARRIVEE = "arrivee";
function addMarkerIti(statut, data, countMarker) {
if (statut === "")
statut = DEPART;
var link = '<button type="submit" onclick="removeEtape('+ (statut === DEPART ? 1 : statut === ARRIVEE ? 2 : countRemoveMarker) + ');" class="btn btn-danger btn-xs btn-block btn-popup">Supprimer ce marker</button>';
var mm = L.marker([data.coordonnee[0], data.coordonnee[1]], statut === DEPART ? {icon: blueIcon} : statut === ARRIVEE ? {icon: greenIcon} : {icon: yellowIcon})
.addTo(lgMarkers).bindPopup((data.rue != "" ? "<strong>Adresse : </strong>" + (data.numero != "" ? data.numero + " " : "") + data.rue + "</br>" : "" )
+ (data.quartier != "" ? "<strong>Quartier : </strong>" + data.quartier + "</br>" : "")
+ (data.cp != "" ? "<strong>Code Postal : </strong>" + data.cp + "</br>" : "")
+ (data.ville != "" ? "<strong>Ville : </strong>" + data.ville + "</br>" : "")
+ "<strong>Latitude : </strong>" + data.coordonnee[0] + "</br>"
+ "<strong>Longitude : </strong>" + data.coordonnee[1] + "</br>" + link);

if (statut === DEPART || statut === ARRIVEE) {
marker[statut] = mm;
}

标记的颜色由 {icon:blueIcon}、{icon:greenIcon} 等定义...

var blueIcon = new MarkerIcon({iconUrl: '../js/leaflet/images/marker-icon.png'});
var greenIcon = new MarkerIcon({iconUrl: '../js/leaflet/images/marker-icon-green.png'});
var yellowIcon = new MarkerIcon({iconUrl: '../js/leaflet/images/marker-icon-yellow.png'});

我需要创建一个更改标记颜色的函数({icon: ...Icon})。如何修改标记的图标?

感谢您的帮助。

最佳答案

标记有 setIcon方法

要使您的案例中的标记为黄色:

marker.setIcon(yellowIcon);

关于javascript - 如何更改标记的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39663917/

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