问题场景: 1.Mars3d的materialType: "Text",无法读取矢量对象属性里的name字段 2.相关代码:
const graphicLayer = new mars3d.layer.GeoJsonLayer({
data: {
type: "Feature",
properties: {
name: "文本内容",
id: "m-eaa34273-b8f9-4011-9f0b-716e154d3a61",
type: "rectangle",
angle: 40,
options: {}
},
geometry: {
type: "LineString",
coordinates: [
[121.479392, 29.79173, 15.1],
[121.478901, 29.791919, 15.4]
]
}
},
symbol: {
styleOptions: {
rotationDegree: "{angle}",
outline: false,
clampToGround: true,
materialType: "Text",
materialOptions: {
text: "{name}",
color: "pink",
font_size: 300
}
}
}
})
map.addLayer(graphicLayer)
3.实现效果:
解决方案:
1.
目前是不支持直接读取适量对象的text数据的,是材质内materialOptions的属性,需要callback回调,比如:
symbol: {
styleOptions: {
color: "#0d3685",
outlineColor: "#0d3685",
opacity: 0.8
},
callback: function (attr, styleOpt) {
return {
materialType: "Text",
materialOptions: {
text: attr.name,
color: "pink",
font_size: 300
}
}
}
},