使用Leaflet.VectorGrid I在传单地图上加载向量块。我试图根据接收到的瓷砖值对瓷砖进行样式化,但是函数options.vectorTileLayerStyles不加载。代码示例:
function getColor(val) {
return val > 85 ? '#2172ff':
val >= 75 ? '#42baff':
val >= 50 ? '#a8e8ff':
val >= 25 ? '#ffcea8':
val >= 1 ? '#fc9803':
'#fc0303';
}
var options = {
interactive: true,
maxNativeZoom: 15,
fetchOptions: {
headers: { 'Authorization': 'Basic ' + key }
}
};
//Doesn't get used, althought it should based on the layer's constructor definition
options.vectorTileLayerStyles = function(properties){
var val = properties.val;
return {
mountains: {
radius: 1,
weight: 1,
fillOpacity: 1,
fill: true,
fillColor: getColor(val)
}
}
}
layer = L.vectorGrid.protobuf(url, options).addTo(leafletMap);发布于 2020-09-04 07:47:54
选项必须是一个对象,而不是一个函数:
vectorTileLayerStyles对象 一种数据结构,包含矢量特征的初始符号化定义。
图层样式可以是:
尝试传递一个为mountains层定义函数的对象,如下所示
options.vectorTileLayerStyles = {
mountains: function(properties) {
var val = properties.val;
return {
radius: 1,
weight: 1,
fillOpacity: 1,
fill: true,
fillColor: getColor(val)
};
}
}https://stackoverflow.com/questions/63732473
复制相似问题