这是一段demo,请按照您的实际情况去写代码。
var colors = [
'rgba(0, 0, 154,1)', // rgb(24, 255, 93)
'rgba(80, 170, 255,1)', // rgb(24, 255, 93)
'rgba(165, 243, 255,1)', // rgb(10, 25, 68)
'rgba(255, 249, 0,1)', // rgb(10, 25, 250)
'rgba(255, 48, 0,1)', // rgb(255, 133, 102)
'rgba(170, 0, 0,1)', // rgb(255, 233, 15)
'rgba(141, 0, 0,1)' // rgb(255, 15, 15)
]
const rule = {
fieldName: "name",
type: 'subsection',
rule: [
{
minValue: -100,
maxValue: -40,
color: '#ff0000',
show: true
},
{
minValue: -40,
maxValue: -20,
color: '#000000',
show: true
},
{
minValue: -20,
maxValue: 0,
color: '#FF457F',
show: true
},
{
minValue: 0,
maxValue: 20,
color: '#FF45AA',
},
{
minValue: 20,
maxValue: 40,
color: '#FF45D4',
show: true
},
],
}
setStyleMapBoxlayer('testMVT', rule)
function setStyleMapBoxlayer (name, rule) {
const mvtlayer = viewer.scene.getVectorTilesLayer(name)
resetStlye(name)
switchStyle(rule, mvtlayer)
}
function switchStyle (rule, mvtlayer) {
const filedname = rule.fieldName
let newStyleLayer
switch (rule.type) {
case 'subsection':
subsectrans(rule.rule, filedname, mvtlayer.mapboxStyle.layers[0], mvtlayer)
break
case 'singlevalue':
matchtrans(rule.rule, filedname, mvtlayer.mapboxStyle.layers[0], mvtlayer)
break
}