3

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.


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?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Sphvn
  • 5,247
  • 8
  • 39
  • 57

1 Answers1

3

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

geographika
  • 6,458
  • 4
  • 38
  • 56
  • 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? – Sphvn May 10 '10 at 07:40
  • 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 May 10 '10 at 10:27