label - OpenLayers - 矢量标签未显示在小特征上
问题描述
我有一个项目,我使用 Openlayers 来显示功能。在我的每个功能之上,我显示了一个包含该特定功能描述的标签。
我注意到在细特征上没有显示矢量标签。我不知道为什么会发生这种情况,因为我从未设置不应显示文本的值。
这是我用来设置每个特征的样式和矢量标签的函数:
style: (feature) => {
return new Style({
fill: new Fill({ color: 'rgba(43, 146, 190, 0.4)' }),
stroke: new Stroke({
width: 3,
color: 'rgba(43, 146, 190, 1)',
}),
text: new Text({
font: '13px Calibri,sans-serif',
fill: new Fill({ color: '#fff' }),
stroke: new Stroke({
color: '#000',
width: 2,
}),
text: feature.get('description'),
}),
});
},
在这里,您可以看到为大多数特征设置了标签,除了那些很小或很薄的特征。
解决方案
我已经找到了解决方案。为了在小特征或细特征上显示标签,您需要将overflow
文本对象的值设置为true
。
所以基于特征生成标签的函数应该如下:
style: (feature) => {
return new Style({
fill: new Fill({ color: 'rgba(43, 146, 190, 0.4)' }),
stroke: new Stroke({
width: 3,
color: 'rgba(43, 146, 190, 1)',
}),
text: new Text({
font: '13px Calibri,sans-serif',
fill: new Fill({ color: '#fff' }),
stroke: new Stroke({
color: '#000',
width: 2,
}),
text: feature.get('description'),
overflow: true,
}),
});
},
推荐阅读
- java - 在 Google Dataflow 中将失败的原始对象插入 GBQ
- docker - 如何在构建时将代码放入 docker 映像
- reactjs - 运行 React App“关于 webpack”时出错
- reactjs - 提交后表单未重置-react js
- mule - Mule 4 中的 ForEach 聚合
- html - flexbox 中的 Flexbox 不适用于省略号文本溢出
- spring-boot - 在 SpringBoot 集成测试中使用 TestContainers 填充数据库
- android - Android Kotlin 添加复选框 onclicklisener
- glsl - 如何检测三角形边缘并访问形成它的两个顶点?
- sql - sql 命令查找过去 6 个月内用户访问网站的平均次数