admin管理员组文章数量:1650772
方法是,给geojson中的每一个feature的propreties设置一个color属性,用于承载不同的颜色,然后在layer加载时候,给paint使用["get","color"],具体代码如下:
var myLocation={
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"id":1,
"name": "kunming",
"color":"red"
},
"geometry": {
"coordinates": [102.73,25.04],
"type": "Point"
}
},
{
"type": "Feature",
"properties": {
"id":10,
"name": "kunming",
"color":"green"
},
"geometry": {
"coordinates": [102.83,25.04], //获取color字段,设置点的颜色
"type": "Point"
}
}
]
};
map.addSource('mySource', { type: 'geojson', data: myLocation });
map.addLayer({
"id": "myLayer",
"type": "circle",
"source": "mySource",
"paint": {
"circle-color": ["get",'color']
}
});
版权声明:本文标题:mapbox中对同一图层(layer)的不同要素(feature)设置不同的颜色 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/xitong/1729534867a1205288.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论