我使用 Openlayers 来绘制字符和形状。
我想根据形状的大小动态更改字符大小。
function setStyle(feature: RenderFeature | Feature<any>, resolution: number): void | Style | Style[] {
const props: IProps = feature.getProperties()
const options: IStyleOptions = this.styleOptions(props)
// const area: number = feature.getGeometry().getArea()
const fontSize: number = Math.floor(1 / resolution)
const style: Style = new Style({
fill: new Fill({
color: options.fillColor
}),
stroke: new Stroke({
color: options.strokeColor,
width: 1
}),
text: new Text({
font: `bold ${fontSize}px/1 Malgun Gothic`,
text: options.text,
overflow: true
})
})
return style
}