【发布时间】:2016-11-04 11:31:32
【问题描述】:
我需要通过 2 种样式,我目前有:
第一种风格:
function style(feature) {
return {
weight: 2,
opacity: 1,
color: 'white',
dashArray: '3',
fillOpacity: 0.7,
fillColor: getColor(feature.properties.density)
};
}
我做的:
var classNameMap = <?php echo JSON_encode($classesForCountries); ?>;
geojson = L.geoJson(statesData, {
style: style,
style: function(feature) {
var classes = classNameMap[feature.properties.name];
return {className: classes};
},
onEachFeature: onEachFeature
}).addTo(map);
但这忽略了第一个style
我尝试将其作为数组传递:
geojson = L.geoJson(statesData, {
style: [style, function(){
var classes = classNameMap[feature.properties.name];
return {className: classes};
}],
onEachFeature: onEachFeature
}).addTo(map);
但是,第一个样式被忽略了。
【问题讨论】:
-
您需要发送 2 个不同/单独的值还是两个值的组合?
-
@aManHasNoName 一个组合。然而我得到了解决方案并将其粘贴在下面
-
好的。您也可以检查$.extend 来组合对象值。
标签: javascript jquery json leaflet geojson