Javascript 筛选的几何体在传单上工作不正常
我使用filter()仅返回来自我所在国家/地区的遗产(UF),使用Axios:Javascript 筛选的几何体在传单上工作不正常,javascript,arrays,vue.js,leaflet,Javascript,Arrays,Vue.js,Leaflet,我使用filter()仅返回来自我所在国家/地区的遗产(UF),使用Axios: async created() { await axios.get('https://raw.githubusercontent.com/fititnt/gis-dataset-brasil/master/mesorregiao/geojson/mesorregiao.json') .then((response) => { const myUf = 'GO'
async created() {
await axios.get('https://raw.githubusercontent.com/fititnt/gis-dataset-brasil/master/mesorregiao/geojson/mesorregiao.json')
.then((response) => {
const myUf = 'GO'
const data = response.data.features.filter(item => item.properties.UF = myUf)
console.log(response.data.features.filter(item => item.properties.UF = myUf))
this.geojson = data;
}
)
}
工作很好,我所有的数据都记录在日志上了!但是我一直在显示所有GeoJson数据,接下来还有一些配置要做吗?所有区域都是彩色的,但我只希望过滤的区域是彩色的。
在LeaftLet doc和Vue传单上没有发现任何东西 正如所问,以下是我的代码: my data(),其中我在vue上调用geojson
data() {
return {
zoom: 6.4,
center: latLng(-15.7745457, -48.3575684),
url: 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
attribution:
'© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors | TRE-GO',
geojson: null,
fillColor: "#6a0dad",
}
},
data(){
返回{
缩放:6.4,
中心:latLng(-15.7745457,-48.3575684),
url:'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
归属:
“©;投稿人| TRE-GO”,
geojson:null,
fillColor:#6a0dad“,
}
},
这是我的L-map组件:
<l-map
:zoom="zoom"
:center="center"
style="height: 500px; width: 100%"
>
<l-tile-layer
:url="url"
:attribution="attribution"
/>
<l-geo-json :geojson="geojson"
:options-style="styleFunction"/>
</l-map>
很遗憾,您的筛选函数实际上没有筛选任何内容,因为它执行赋值(1等号)而不是比较(3或2等号): ……应该是:
item => item.properties.UF === myUf
请共享您的代码,在这里您将geojson添加到地图中。。。查看最后一节
过滤器@FalkeDesign-code-on-post-edit!谢谢你的文档链接,我将尝试一下过滤器
。
item => item.properties.UF === myUf