gpt4 book ai didi

javascript - 如何使用 Leaflet.AwesomeMarkers 获得我想要的颜色?

转载 作者:行者123 更新时间:2023-12-03 16:46:52 30 4
gpt4 key购买 nike

我正在尝试使用令人敬畏的标记来更改图标颜色,具体取决于每个标记详细信息中的各个属性,但是它们都是红色的,而不是有些是红色的,有些是绿色的。

有人能在这里看到这个问题吗?同一种类型可以有不同的颜色吗?

我已经添加了下面的示例,geojson 我在那里设置了图标颜色,但是所有图标都是红色的,你应该可以看到吗?

谢谢

	var map = L.map('map').setView([54.0, -3.4], 6);
L.tileLayer('https://api.mapbox.com/styles/v1/{id}/tiles/{z}/{x}/{y}?access_token={accessToken}', {
attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="https://www.mapbox.com/">Mapbox</a>',
maxZoom: 18,
id: 'mapbox/streets-v11',
accessToken: 'x'
}).addTo(map);

var geo_data = [
{'type': 'Feature', 'properties': {'name': 'A', 'popupContent': 'A', 'type': 'Showroom', 'icon': 'fa-home', 'color': '#d53f3a'
}, 'geometry': {'type': 'Point', 'coordinates': [
-2.2671,
57.139383
]
}
},
{'type': 'Feature', 'properties': {'name': 'B', 'popupContent': 'B', 'type': 'Showroom', 'icon': 'fa-home', 'color': '#d53f3a'
}, 'geometry': {'type': 'Point', 'coordinates': [
0.4549,
51.611151
]
}
},
{'type': 'Feature', 'properties': {'name': 'C', 'popupContent': 'C', 'type': 'Showroom', 'icon': 'fa-home', 'color': '#47a447'
}, 'geometry': {'type': 'Point', 'coordinates': [
0.060676,
51.531023
]
}
},
]


var Showroom = L.geoJSON(geo_data, {
filter: function(feature, layer) {
if (feature.geometry.coordinates != "None") {
return feature.properties.type === "Showroom";
}
},
pointToLayer: function (feature, latlng) {
return L.marker(latlng, {
icon: L.AwesomeMarkers.icon({
icon: feature.properties.icon,
markerColor: feature.properties.color,
prefix: 'fa',
iconColor: 'white'
}
)}
);
},
onEachFeature: function (feature, layer) {
layer.bindPopup('<h3>'+feature.properties.popupContent+'</h3>');
}
});

var overlayLayers= {
"Showroom": Showroom,
};

map.addLayer(Showroom)

L.control.layers(null,overlayLayers).addTo(map);
<html>
<head>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.6.0/dist/leaflet.css"
integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ=="
crossorigin=""/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.2/leaflet.awesome-markers.css"
integrity="sha256-EFpFyBbuttUJtoocYzsBnERPWee2JYz4cn5nkUBjW0A="
crossorigin="anonymous" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/all.css">
</head>
<body>


<div id="map" style="height:700px;"></div>

<script src="https://unpkg.com/leaflet@1.6.0/dist/leaflet.js"
integrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew=="
crossorigin="">
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.2/leaflet.awesome-markers.min.js"
integrity="sha256-IqiRR5X1QtAdcq5lG4vBB1/WxwrRCkkjno4pfvWyag0="
crossorigin="anonymous">
</script>
</body>
</html>

最佳答案

Leaflet.AwesomeMarkers 有一个 有限选择可用的颜色。引自 its readme :

markerColor Color of the marker
Default blue Possible vaules: red, darkred, orange, green, darkgreen, blue, purple, darkpurple, cadetblue



由于 AwesomeMarkers 使用了 static image 的一部分,这一点得到了加强。对于标记,该图像只有有限的颜色选择:

![](https://github.com/lvoogdt/Leaflet.awesome-markers/blob/2.0/develop/dist/images/markers-matte.png)

iconColor 比较选项,可以取任何值。再次引用,强调我的:

iconColor Color of the icon Default white Possible values: white, black or css code (hex, rgba etc)



你应该考虑 other marker plugins ,保持选择中的颜色可用于 AwesomeMarkers,或提供您自己的标记图像。

关于javascript - 如何使用 Leaflet.AwesomeMarkers 获得我想要的颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59789918/

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