如何将多边形渲染为点要素?

How to render a polygon as a point feature?

drawGeometry 方法不会将点样式应用于多边形。这是有道理的,但我有一个要求,即多边形特征应该用适合该特征的笔划+填充样式以及点样式来表示,IMO,不太适合该特征。

例如:

结合使用多边形和点要素样式:

[
 {
  "fill": {
   "pattern": {
    "orientation": "diagonal",
    "color": "rgba(230,113,26,1)",
    "spacing": 3,
    "repitition": "repeat"
   }
  }
 },
 {
  "circle": {
   "fill": { "color": "blue" },
   "opacity": 1,
   "stroke": {
    "color": "rgba(0,255,0,1)",
    "width": 1
   },
   "radius": 20
  }
 },
 {
  "image": {
   "anchor": [
    16,
    48
   ],
   "imgSize": [
    32,
    48
   ],
   "anchorXUnits": "pixels",
   "anchorYUnits": "pixels",
   "src": "http://openlayers.org/en/v3.17.1/examples/data/icon.png"
  }
 }
]

我想到的一个解决方案是替换 drawGeometry 以同时调用 drawPolygon 和 drawPoint:

但似乎应该以其他方式支持使用点样式渲染多边形。也许在 drawPolygon 实现中它应该检测点样式并做出相应反应?

使用样式对象的几何选项,然后使用 geometry.getInteriorPoint() return 内部点,参见:http://openlayers.org/en/latest/examples/polygon-styles.html?q=geometry+style 示例