views:

203

answers:

1

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?

+1  A: 

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 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

geographika
Thanks for the info. But if I were to rotate a single point(image) do I have to rotate it around based on another point or can i base it on itself and rotate it that way?
Thqr
The origin parameter can be any point. To use the centroid of the vector feature (if it is a point the centroid will be the point) use:http://dev.openlayers.org/releases/OpenLayers-2.8/doc/apidocs/files/OpenLayers/Geometry/Point-js.html#OpenLayers.Geometry.Point.getCentroid
geographika