cuốn sách gpt4 ai đã làm

javascript - 无法识别传单上的颜色

In lại Tác giả: Walker 123 更新时间:2023-11-28 07:59:42 25 4
mua khóa gpt4 Nike

var non_tfl_lines_JubileetoIlford = L.geoJson(non_tfl_lines_JubileetoIlford, {
pointToLayer: function(feature, latlng) {
switch (feature.geometry.type) {
case 'LineString': return new L.polyline(latlng, {
color: feature.properties.color
});
case 'Point': return new L.Circle(latlng, 400, {
color: getColor(feature.properties.relief_JtI)});
}
onEachFeature: popup
}
}).addTo(bản đồ);

由于某种原因,折线的颜色是默认颜色,而不是指定的颜色。同时它给了我正确的圆圈颜色。知道可能出了什么问题吗?

câu trả lời hay nhất

正如您在 tài liệu 中看到的那样, pointToLayer 回调用于 GeoJSON 点;这就是您的代码适用于积分的原因。

如果您想使用 geojson 结构中的信息设置颜色,最好是有一个颜色属性...

   {
"type": "Feature",
"properties": {
"color": "#ff7800"
},
"geometry": {
"type": "LineString",
"coordinates": [

并在样式回调中使用它

L.geoJson(non_tfl_lines_JubileetoIlford, {
style: function(feature) {
if(feature.geometry.type == "LineString") {
trở lại {
"color": feature.properties.color,
"weight": 5,
"opacity": 0.65
};
}
}

这是一个示例 http://jsfiddle.net/FranceImage/myxd1ooy/

关于javascript - 无法识别传单上的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25587820/

25 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress