我有一个OpenLayers 3.2.0地图,其中包含一些矢量源(ol.source.Vector)和关联的矢量层(ol.layer.Vector)
将功能(ol.Feature)添加到矢量源时,会为它们提供一个data属性,该属性设置为该功能代表的javascript对象。TypeScript跟着...
vectorSource.addFeature(new ol.Feature({
    geometry: /* ... */,
    data: vectorData,
}));
然后,矢量层具有一个样式功能,该功能可以读取data属性并检索其样式:
vectorLayer = new ol.layer.Vector({
    source: vectorSource,
    renderBuffer: /* ... */,
    style: function (feature: ol.Feature, resolution: any) {
        var data = </* TypeScript Type */>feature.get('data');
        if ((data) && (data.style)) {
            return [data.style];
        }
        else {
            /* return default style */
        }
    }
});
有时,与地图无关的事件会导致样式更改。例如,当一个对象变为无效时,其样式会更改。显然,由于data.style完全在我的控制范围内,因此更改它是微不足道的。
问题在于地图不知道样式已更改。如果更改对象的样式,然后缩放地图,迫使它重新绘制,我会注意到我的样式功能运行并返回新样式,并且该特征也被重新绘制。如何以编程方式强制刷新地图?
经过一些搜索和试验,我尝试了:
- 调用
render()的ol.Map本身。 - 调用
dispatchChangeEvent()上ol.source.Vector - 调用
redraw()上ol.layer.Vector 
提出了这些建议,但没有一个可行,这不足为奇,因为OpenLayers 3.2.0 API文档中甚至只列出了第一种方法,并且未将其标记为稳定方法。