vue.js - Vue Leaflet 获取颜色函数
问题描述
我正在使用 VueLeaflet 创建一个地图,如下例所示:https ://vue2-leaflet.netlify.com/examples/geo-json.html
我喜欢在这个例子中为多边形添加一些颜色:https ://leafletjs.com/examples/choropleth/
这是我在这里的尝试:https ://codesandbox.io/s/old-framework-mlc7b
getcolorFunction(d) {
return d > 1000
? "#800026"
: d > 500
? "#BD0026"
: d > 200
? "#E31A1C"
: d > 100
? "#FC4E2A"
: d > 50
? "#FD8D3C"
: d > 20
? "#FEB24C"
: d > 10
? "#FED976"
: "#FFEDA0";
},
styleFunction() {
const fillColor = this.fillColor; // important! need touch fillColor in computed for re-calculate when change fillColor
return () => {
return {
weight: 2,
color: "#ECEFF1",
opacity: 1,
fillColor: getColor(feature.properties.sales),
fillOpacity: 1
};
};
},
onEachFeatureFunction() {
if (!this.enableTooltip) {
return () => {};
}
return (feature, layer) => {
layer.bindTooltip(
"<div>Name Province:" +
feature.properties.varname_1 +
"</div><div>Sales: " +
feature.properties.sales +
"</div>",
{ permanent: false, sticky: true }
);
};
}
},
我怎样才能在 Vue.js 中使用 getColor 函数?
解决方案
onEachFeatureFunction() {
return (feature, layer) => {
layer.options.fillColor = this.getcolorFunction(
feature.properties.sales
?feature.properties.sales
: 0
);
layer.on("click", function (e) {
console.log(e, feature);
})
};
}
推荐阅读
- graph - 如何绘制上面的两张图?
- android - 滚动到最后一个位置时如何将项目添加到 PagingListAdpter
- javascript - 如何使用 JavaScript 获取 CSS 属性的计算(或指定)值(不是解析或使用的值)?
- django - 添加 djoser 后 Apache2 未显示网站,内部服务器错误 500
- azure-cognitive-search - 如何在 Azure 搜索索引中通过 csv 导入 geography.point 的集合
- linux - IP标头可以在不同机器上具有不同的偏移量吗?
- java - 错误:无法访问 jarfile 错误消息
- r - 您如何根据常见的行值组织 2 个数据框?
- tensorflow - 如何使用最新版本的 CUDA 和 cuDNN 安装 Tensorflow GPU
- react-native - React Native firebase 电话身份验证