The code below I have is working great. I'll try to explain it in a few lines (btw you can view it here http://codeshare.io/9Z1BE):

-there's a marker on the map. The lat long is returned as json from a database. There is only ever ONE marker on the map at any given time.

-Say marker is at position A. Stays there for 2 seconds, goes to position B. B to C. C to D. So on and so on. This A-B-C-D represents a flight path: ie, 'A' would be the origin, and 'D' would be the destination (say LAX to JFK).

-Now I would like to have the orientation adjust accordingly based on where the marker is going. Say you were flying from Sydney to Hong Kong: you're moving north. The marker/airplane should have a north orientation.

-After googling a bit it seems it's better to use a vector feature than a layer feature so you can use the rotation property. But how exactly do I implement this with the setTimeout function below?

    var map;
    var updateMarker = "";
    var markers;
    function init(){
      map = new OpenLayers.Map('map', {
        controls: [
          //controls here
         numZoomLevels: 10
    markers = new OpenLayers.Layer.Markers( "Markers" );

function planeDelay() {
setInterval(function() {
  url: "latlong.php",
  type: "POST",
  success: function(msg){
    var json_coords = eval('('+msg+')');
    if(updateMarker != "")
    updateMarker = new OpenLayers.Marker(new OpenLayers.LonLat(json_coords.longitude, json_coords.latitude));
}, 2000);

1 Answer 1


Figured it out finally. I guess using vectors isn't too bad after all :)


I just referred to heading in the new OpenLayers.Feature.Vector in the rotation attribute and all worked well.

point = new OpenLayers.Geometry.Point(json_coords.longitude, json_coords.latitude);
airplane = new OpenLayers.Feature.Vector(point, null, {
  externalGraphic: "aircraft-s4.png",
  graphicWidth: 50,
  graphicHeight: 50,
  rotation: json_coords.heading

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.