Rotating marker (icon) in openlayers 3

早过忘川 提交于 2019-12-24 07:00:07

问题


I m using openlayers 3 in my project. I created a custom marker (icon) and i need to rotate marker with angle.

Is anybody tried this before? It is a critical part of my code and i couldnt figure it out.

Note: Not the map. just marker.


回答1:


Set up an overlay like in the icon example and apply CSS rotation to it (ie. transform: rotate(120deg);, add browser prefixed versions as needed). If you need this to be dynamic, adjust the property through JavaScript.




回答2:


In current versions of OpenLayers 3, you can use the rotation property of ol.style.Icon like this:

new ol.style.Style({
    image: new ol.style.Icon({
        anchor: [0.5, 0.5],
        anchorXUnits: 'fraction',
        anchorYUnits: 'fraction',
        rotation: Math.PI / 2.0,
        src: 'icon.png'
    })
)


来源:https://stackoverflow.com/questions/25983417/rotating-marker-icon-in-openlayers-3

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!