在 OpenLayers 3 中的地图旋转期间旋转特征
Rotate feature during map rotation in OpenLayers 3
我有一个矢量图层,其特征具有旋转属性。我正在使用旋转属性来定义 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
});
});
它的工作原理是它在旋转期间触发,但它仍然不会在旋转过程中更新图标,只有在用户停止旋转之后(这肯定是必须让用户将地图平移到获取更新,但仍然不是我想要的)。
在 ol.style.Icon
上使用 rotateWithView: true
。
我有一个矢量图层,其特征具有旋转属性。我正在使用旋转属性来定义 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
});
});
它的工作原理是它在旋转期间触发,但它仍然不会在旋转过程中更新图标,只有在用户停止旋转之后(这肯定是必须让用户将地图平移到获取更新,但仍然不是我想要的)。
在 ol.style.Icon
上使用 rotateWithView: true
。