在OpenLayers 3

时间:2016-09-13 10:15:21

标签: openlayers-3

我有一个带有旋转属性的矢量图层。我使用rotation属性在Style属性中定义要素图标的方向,如下所示:

var style_outer = new ol.style.Style({
 image: new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({
     anchor: [0.5, 0.5],
     anchorXUnits: 'fraction',
     anchorYUnits: 'fraction',
     src: './images/Feature_icons/Logo_Arrow_07.png',
     rotation: rotation,
     scale: photo_icon_resolution_function()
   }))
});

根据属性+地图旋转角度定义旋转,如下所示:

var map_rotation = map.getView().getRotation();
var rotation = feature.get(bearing) + map_rotation;

当用户旋转地图时,图标不会旋转以实时匹配。它仅在用户移动地图时捕捉到正确的角度,或在旋转后与地图交互。这是有道理的,因为只有在这些事情发生时才调用样式函数。

我的问题是,如何在用户旋转地图的同时旋转图标?

我尝试按如下方式捕获旋转事件:

map.getView().on('propertychange', function(e) 
    {
       loaded_layers[p].getSource().forEachFeature(function(feature){
       feature.setStyle(Photo_Style(feature));
       feature.changed();  //This is an alternative which also works
    });

});

这适用于它在旋转期间触发,但它仍然不会在旋转过程中更新图标,只有在用户停止旋转之后(这肯定是必须让用户平移地图以获得更新,但仍然不是我正在寻找的。)

1 个答案:

答案 0 :(得分:3)

rotateWithView: true上使用ol.style.Icon