Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/455.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在Leavelt中设置一个不同于其他数组元素的样式?_Javascript_Function_If Statement_Leaflet - Fatal编程技术网

Javascript 如何在Leavelt中设置一个不同于其他数组元素的样式?

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

我试图在数组中只设置一个元素的样式,但我不确定如何编写if语句。我希望实现
日期[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++;

  });
可能重复的