Openlayers 3 在OpenLayers 3中地图旋转期间旋转特征
我有一个具有旋转属性的特征的向量层。我使用“旋转”属性在“样式”属性中定义特征图标的方向,如下所示:Openlayers 3 在OpenLayers 3中地图旋转期间旋转特征,openlayers-3,Openlayers 3,我有一个具有旋转属性的特征的向量层。我使用“旋转”属性在“样式”属性中定义特征图标的方向,如下所示: 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', sr
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()
}))
});
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
});
});
其中旋转是基于属性+贴图旋转角度定义的,如下所示:
var map_rotation = map.getView().getRotation();
var rotation = feature.get(bearing) + map_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()
}))
});
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
我希望2小时前就知道;)