[GIS] Openlayers: Making the map move with moving vector layer (airplane) on map

javascriptopenlayers-2

So currently I have a map that has some plane data. There is a setInterval function that updates the plane data every 5 seconds, making the plane move from point to point. That is working well.

function planeInterval() {
    setInterval(function() {planeMovement()}, 5000);
    //this is currently working
}

function planeMovement() {
    //do some stuff to make the plane move around
    //this is currently working

}

Now, I would like to set up a checkbox or some sort of toggle to:

-toggle on: as the plane moves across the map, the map MOVES as the plane moves

-toggle off: the plane just does what it usually does: moves across the map while the map stays stagnant.

I was looking into OL panTo but I don't think that's the answer here. What would be the best/most simple approach in achieving this?

Best Answer

Set the center of the map to the airplane position after it has refreshed.

OpenLayers setCenter

Related Question