I created a plunkr which has a moving marker like a car.
var olview = new ol.View({
center: [-5484111.13, -1884437.22],
zoom: 18,
minZoom: 2,
maxZoom: 20
});
var osm = new ol.source.OSM();
var lineString = new ol.geom.LineString([]);
var map = new ol.Map({
target: 'map',
view: olview,
renderer: 'canvas',
layers: [
new ol.layer.Tile({
source: osm,
opacity: 0.6
})
]
});
var car = document.getElementById('geo1');
var marker = new ol.Overlay({
positioning: 'center-center',
offset: [0, 0],
element: car,
stopEvent: false
});
map.addOverlay(marker);
var path = [
[-5484101.57, -1884475.44],
[-5484114.71, -1884432.74],
[-5484117.70, -1884416.62],
[-5484106.95, -1884392.28]
];
lineString.setCoordinates(path);
map.once('postpose', function(event) {
console.info('postpose');
interval = setInterval(animation, 500);
});
var i = 0, interval;
var animation = function(){
if (i == path.length){
i = 0;
}
marker.setPosition(path[i]);
i++;
};
This is written in openlayers, I want it to look smooth when moving similar to this.
I'm a plete beginner in openlayers, can someone help me with this? Thanks!
I created a plunkr which has a moving marker like a car.
var olview = new ol.View({
center: [-5484111.13, -1884437.22],
zoom: 18,
minZoom: 2,
maxZoom: 20
});
var osm = new ol.source.OSM();
var lineString = new ol.geom.LineString([]);
var map = new ol.Map({
target: 'map',
view: olview,
renderer: 'canvas',
layers: [
new ol.layer.Tile({
source: osm,
opacity: 0.6
})
]
});
var car = document.getElementById('geo1');
var marker = new ol.Overlay({
positioning: 'center-center',
offset: [0, 0],
element: car,
stopEvent: false
});
map.addOverlay(marker);
var path = [
[-5484101.57, -1884475.44],
[-5484114.71, -1884432.74],
[-5484117.70, -1884416.62],
[-5484106.95, -1884392.28]
];
lineString.setCoordinates(path);
map.once('postpose', function(event) {
console.info('postpose');
interval = setInterval(animation, 500);
});
var i = 0, interval;
var animation = function(){
if (i == path.length){
i = 0;
}
marker.setPosition(path[i]);
i++;
};
This is written in openlayers, I want it to look smooth when moving similar to this.
https://github./terikon/marker-animate-unobtrusive
I'm a plete beginner in openlayers, can someone help me with this? Thanks!
Share Improve this question asked Jun 11, 2015 at 9:18 The BassmanThe Bassman 2,3615 gold badges30 silver badges41 bronze badges1 Answer
Reset to default 5I've made three tests. First and second are pure ol3 and last is with tween.js.
I'm using Arc.js to create a path.
The first example is using setInterval
.
The second example is using window.requestAnimationFrame
.
And the last with Tween.js
.
Your example doesn't run smoothly because it is just a few coordinates.
Note that the Tween.js
integration is not an integration at all. It is just a tricky CSS manipulation.