Skip to content

Instantly share code, notes, and snippets.

@pgiraud
Created February 28, 2014 13:52
Show Gist options
  • Select an option

  • Save pgiraud/9271456 to your computer and use it in GitHub Desktop.

Select an option

Save pgiraud/9271456 to your computer and use it in GitHub Desktop.
OL3 - Geolocation simlulated
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
<title>Mobile full screen example</title>
<style type="text/css">
html, body, .map {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
</style>
<link href="http://erilem.net/ol3/rotation-anchor/css/ol.css" rel='stylesheet' type='text/css' />
</head>
<body>
<div id="map" class="map"></div>
<script src="http://erilem.net/ol3/rotation-anchor/build/ol.js" type="text/javascript"></script>
<script src="index.js?" type="text/javascript"></script>
</body>
</html>
var view = new ol.View2D({
center: [652308.4811066509,5724304.682257481],
zoom: 18
});
var map = new ol.Map({
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
target: 'map',
view: view
});
var coordinates = [
[[652308.4811066509,5724304.682257481], NaN],
[[652343.1166350927,5724313.04255745], 60],
[[652384.3209706526,5724335.734800221], 62],
[[652450.0090418352,5724384.105107184], 55],
[[652491.2133773952,5724409.783171373], 90],
[[652538.3893557899,5724405.603021389], 100],
[[652606.4660841064,5724399.03421427], 97],
[[652630.3526554456,5724399.03421427], 120],
[[652661.3703305458,5724371.947817162], 142],
[[652683.7446548837,5724337.2650756], 148],
[[652719.1927660435,5724303.562025624], 130],
[[652756.495544545,5724270.952628432], 136],
[[652798.4144569746,5724232.7974523], 132],
[[652832.1947543311,5724203.8791667055], 145],
[[652842.2213776499,5724150.24562137], 190],
[[652829.761035643,5724108.229570617], 240],
[[652782.5650678759,5724102.510806185], 262],
[[652702.4727562283,5724100.082245467], 265]
];
var interval;
window.setTimeout(function() {
interval = window.setInterval(function() {
var c = coordinates.shift();
recenterOnPosition(c[0], c[1] / 360 * Math.PI * 2);
if (coordinates.length === 0) {
window.clearInterval(interval);
}
}, 1000);
}, 2000);
function recenterOnPosition(position, heading) {
var newCenter = position;
var pan = ol.animation.pan({
duration: 1000,
source: view.getCenter()
});
var currentRotation = view.getRotation();
var rotate = ol.animation.rotate({
anchor: position,
duration: 1000,
rotation: currentRotation
});
map.beforeRender(pan, rotate);
view.setCenter(newCenter);
view.rotate(-heading, position);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment