Pergunta

TLDR I want to rotate a Feature in my open layers.
I want it to face a certain heading that I am receiving from server.


I know that you can make a feature spin on a point or so on:

window.setInterval(function() {rotateFeature(
       pointFeature, 360 / 20, origin)}, 100);

as from the open layers example.

But I want to be able to face it towards a heading I am given, so.

  1. Can I face a feature towards a heading?
  2. Can I face a feature(image) in the same way?
  3. If not is it possible to automatically calculate the rotation required and position it that way?
  4. Or any ideas on how I could do this with the image? (hoping not to have 360 images)

An example or such would be appreciated :D

Thanks in advance.


No luck so far using:

      window.setInterval(function() {rotateFeature(
        imagefeature, 150 / 360, origin)}, 1000);
        function rotateFeature(feature, angle, origin) {
            feature.geometry.rotate(angle, origin);
            }

Where origin is the centeroid of the image object.

Any ideas code side?

Foi útil?

Solução

You can use images / icons to represent vector points e.g.

http://openlayers.org/dev/examples/vector-features.html

Uses this png file alt text http://openlayers.org/dev/img/marker.png You should then be able to rotate the point as in the other example. You can rotate to any angle:

http://dev.openlayers.org/releases/OpenLayers-2.8/doc/apidocs/files/OpenLayers/Geometry/Point-js.html#OpenLayers.Geometry.Point.rotate

rotate: function(angle,origin)

Rotate a point around another. Parameters

angle {Float} Rotation angle in degrees (measured counterclockwise from the positive x-axis)

origin {OpenLayers.Geometry.Point} Center point for the rotation

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top