Creating animated map
Open sample in a new windows
<!doctype html>
<html>
<head>
<title>Animation Examples</title>
<link rel="stylesheet" href="../assets/ol3/css/ol.css" type="text/css" />
<link rel="stylesheet" href="../assets/css/samples.css" type="text/css" />
</head>
<body>
<div id="map" class="map"></div>
<button onclick="doBounce(london);">Bounce To London</button><br />
<button onclick="doBounce(rome);">Bounce To Rome</button><br />
<button onclick="doPan(london);">Pan To London</button><br />
<button onclick="doPan(rome);">Pan To Rome</button><br />
<button onclick="doRotate();">Rotate</button><br />
<button onclick="doZoom(2);">Zoom Out</button><br />
<button onclick="doZoom(0.5);">Zoom In</button>
<script src="../assets/ol3/js/ol.js"></script>
<script>
var layer = new ol.layer.Tile({
source: new ol.source.OSM()
});
var london = ol.proj.transform([-0.12755, 51.507222], 'EPSG:4326', 'EPSG:3857');
var rome = ol.proj.transform([12.5, 41.9], 'EPSG:4326', 'EPSG:3857');
var view = new ol.View({
center: london,
zoom: 6
});
var map = new ol.Map({
target: 'map',
layers: [layer],
view: view
});
function doBounce(location) {
var bounce = ol.animation.bounce({
resolution: map.getView().getResolution() * 2
});
var pan = ol.animation.pan({
source: map.getView().getCenter()
});
map.beforeRender(bounce);
map.beforeRender(pan);
map.getView().setCenter(location);
}
function doPan(location) {
var pan = ol.animation.pan({
source: map.getView().getCenter()
});
map.beforeRender(pan);
map.getView().setCenter(location);
}
function doRotate() {
var rotate = ol.animation.rotate({
rotation: Math.PI * 2
});
map.beforeRender(rotate);
}
function doZoom(factor) {
var zoom = ol.animation.zoom({
resolution: map.getView().getResolution()
});
map.beforeRender(zoom);
map.getView().setResolution(map.getView().getResolution() * factor);
}
</script>
</body>
</html>