Javascript 如何在Leavelt中设置一个不同于其他数组元素的样式?
我试图在数组中只设置一个元素的样式,但我不确定如何编写if语句。我希望实现Javascript 如何在Leavelt中设置一个不同于其他数组元素的样式?,javascript,function,if-statement,leaflet,Javascript,Function,If Statement,Leaflet,我试图在数组中只设置一个元素的样式,但我不确定如何编写if语句。我希望实现日期[0]返回的权重为3,而数组中的其余元素返回的权重为1。这可能吗 功能: var dates=[] function mostRecent(time) { dates.push(time) if (dates[0]){ weight = 3 } else { weight = 1 } return weight } pointToLayer: func
日期[0]
返回的权重为3
,而数组中的其余元素返回的权重为1
。这可能吗
功能:
var dates=[]
function mostRecent(time) {
dates.push(time)
if (dates[0]){
weight = 3
} else {
weight = 1
}
return weight
}
pointToLayer: function(feature, latlng){ // changes default icons to circles and styles accordingly
return new L.CircleMarker(latlng, {
radius: circleSize(feature.properties.mag),
fillColor: getColor(feature.properties.mag),
color: "#000",
weight: mostRecent(feature.properties.time),
opacity: 1,
fillOpacity: 0.5,
});
风格:
var dates=[]
function mostRecent(time) {
dates.push(time)
if (dates[0]){
weight = 3
} else {
weight = 1
}
return weight
}
pointToLayer: function(feature, latlng){ // changes default icons to circles and styles accordingly
return new L.CircleMarker(latlng, {
radius: circleSize(feature.properties.mag),
fillColor: getColor(feature.properties.mag),
color: "#000",
weight: mostRecent(feature.properties.time),
opacity: 1,
fillOpacity: 0.5,
});
请尝试以下操作:
var i = 0;
pointToLayer: function(feature, latlng){
if(i === 0){
return new L.CircleMarker(latlng, {
radius: circleSize(feature.properties.mag),
fillColor: getColor(feature.properties.mag),
color: "#000",
weight: 3,
opacity: 1,
fillOpacity: 0.5,
}
);
}else{
return new L.CircleMarker(latlng, {
radius: circleSize(feature.properties.mag),
fillColor: getColor(feature.properties.mag),
color: "#000",
weight: 1,
opacity: 1,
fillOpacity: 0.5,
}
);
}
i++;
});
可能重复的