Openlayers-3 Force a map refresh

2019-05-04 17:18发布

I have a custom styling that shows/hides features on the map, but when it is applied it doesn't activate until the map refreshes due to a feature update, but I need it to trigger immediately.

I tried map.render and renderSync() but they did nothing. mapResize() doesn't appear to do anything either, but if I wait for a feature to be updated or move the map it works.

Any ideas? How can I FORCE the map to redraw on demand, regardless of a feature update?

5条回答
Evening l夕情丶
2楼-- · 2019-05-04 18:03

Use yourlayer.source().updateParams({CQL_FILTER:"1=1"});

It will definitely work.

查看更多
Juvenile、少年°
3楼-- · 2019-05-04 18:05

I've finally found a solution to refresh a layer on openlayers 3.

You have to update params of the layer source like this:

var source = yourLayer.getSource();
var params = source.getParams();
params.t = new Date().getMilliseconds();
source.updateParams(params);
查看更多
相关推荐>>
4楼-- · 2019-05-04 18:13

I believe you need to force your layer's source to update, you can do so by calling the changed function on it:

yourLayer.getSource().changed();

see: http://openlayers.org/en/v3.6.0/apidoc/ol.source.Source.html

查看更多
我命由我不由天
5楼-- · 2019-05-04 18:17

In case Sarumanatee doesn't work for you, you can try this one:

map.render();

I am using ol3.

查看更多
对你真心纯属浪费
6楼-- · 2019-05-04 18:18

one way is to group your features based on their purpose and put each group on different layers, then you can easily show or hide specified layer that have the features your want to hide or show.

查看更多
登录 后发表回答