diff --git a/examples/data/geolocation-orientation.json b/examples/data/geolocation-orientation.json new file mode 100644 index 0000000000..0bb5d900f3 --- /dev/null +++ b/examples/data/geolocation-orientation.json @@ -0,0 +1,729 @@ +{ + "data": [{ + "coords": { + "speed": 1.7330950498580933, + "accuracy": 5, + "altitudeAccuracy": 8, + "altitude": 238, + "longitude": 5.868668798362713, + "heading": 67.5, + "latitude": 45.64444874417562 + }, + "timestamp": 1394788264972 + }, { + "coords": { + "speed": 1.9535436630249023, + "accuracy": 5, + "altitudeAccuracy": 8, + "altitude": 238, + "longitude": 5.868715401744348, + "heading": 69.609375, + "latitude": 45.64446391542036 + }, + "timestamp": 1394788266115 + }, { + "coords": { + "speed": 2.1882569789886475, + "accuracy": 10, + "altitudeAccuracy": 8, + "altitude": 238, + "longitude": 5.868768962105614, + "heading": 67.5, + "latitude": 45.644484995906836 + }, + "timestamp": 1394788267107 + }, { + "coords": { + "speed": 2.4942498207092285, + "accuracy": 5, + "altitudeAccuracy": 6, + "altitude": 237, + "longitude": 5.868825791409117, + "heading": 68.5546875, + "latitude": 45.64450435810316 + }, + "timestamp": 1394788267959 + }, { + "coords": { + "speed": 2.7581217288970947, + "accuracy": 5, + "altitudeAccuracy": 6, + "altitude": 237, + "longitude": 5.868881698703271, + "heading": 69.609375, + "latitude": 45.64452149909515 + }, + "timestamp": 1394788268964 + }, { + "coords": { + "speed": 3.3746347427368164, + "accuracy": 5, + "altitudeAccuracy": 6, + "altitude": 236, + "longitude": 5.868938528006774, + "heading": 70.3125, + "latitude": 45.644536712249405 + }, + "timestamp": 1394788270116 + }, { + "coords": { + "speed": 3.597411870956421, + "accuracy": 5, + "altitudeAccuracy": 6, + "altitude": 236, + "longitude": 5.868992004549009, + "heading": 74.8828125, + "latitude": 45.644547943999655 + }, + "timestamp": 1394788271158 + }, { + "coords": { + "speed": 3.6382505893707275, + "accuracy": 5, + "altitudeAccuracy": 6, + "altitude": 236, + "longitude": 5.869038775568706, + "heading": 73.828125, + "latitude": 45.64456005584974 + }, + "timestamp": 1394788271893 + }, { + "coords": { + "speed": 3.65671443939209, + "accuracy": 5, + "altitudeAccuracy": 6, + "altitude": 236, + "longitude": 5.869091162463528, + "heading": 73.4765625, + "latitude": 45.644572335337884 + }, + "timestamp": 1394788272903 + }, { + "coords": { + "speed": 3.7153592109680176, + "accuracy": 5, + "altitudeAccuracy": 6, + "altitude": 236, + "longitude": 5.869144219910604, + "heading": 73.125, + "latitude": 45.64458671030182 + }, + "timestamp": 1394788273914 + }, { + "coords": { + "speed": 3.8041043281555176, + "accuracy": 5, + "altitudeAccuracy": 4, + "altitude": 236, + "longitude": 5.869205072527629, + "heading": 72.421875, + "latitude": 45.64460313883204 + }, + "timestamp": 1394788274901 + }, { + "coords": { + "speed": 3.9588162899017334, + "accuracy": 5, + "altitudeAccuracy": 4, + "altitude": 236, + "longitude": 5.869268858810765, + "heading": 72.421875, + "latitude": 45.64461990263838 + }, + "timestamp": 1394788276140 + }, { + "coords": { + "speed": 4.152309417724609, + "accuracy": 5, + "altitudeAccuracy": 4, + "altitude": 235, + "longitude": 5.869351252918941, + "heading": 78.046875, + "latitude": 45.64466122542102 + }, + "timestamp": 1394788276948 + }, { + "coords": { + "speed": 4.49971866607666, + "accuracy": 5, + "altitudeAccuracy": 6, + "altitude": 236, + "longitude": 5.869433479389054, + "heading": 79.8046875, + "latitude": 45.64467040360499 + }, + "timestamp": 1394788277892 + }, { + "coords": { + "speed": 4.824056148529053, + "accuracy": 5, + "altitudeAccuracy": 6, + "altitude": 235, + "longitude": 5.869504055013758, + "heading": 91.40625, + "latitude": 45.64466089014489 + }, + "timestamp": 1394788279211 + }, { + "coords": { + "speed": 5.269814491271973, + "accuracy": 10, + "altitudeAccuracy": 6, + "altitude": 235, + "longitude": 5.869575049733621, + "heading": 91.40625, + "latitude": 45.64465967476893 + }, + "timestamp": 1394788279898 + }, { + "coords": { + "speed": 5.4861016273498535, + "accuracy": 5, + "altitudeAccuracy": 6, + "altitude": 235, + "longitude": 5.86963213049422, + "heading": 95.2734375, + "latitude": 45.64465091568012 + }, + "timestamp": 1394788280935 + }, { + "coords": { + "speed": 5.380503177642822, + "accuracy": 5, + "altitudeAccuracy": 6, + "altitude": 235, + "longitude": 5.869714859878523, + "heading": 75.5859375, + "latitude": 45.64468792178262 + }, + "timestamp": 1394788281930 + }, { + "coords": { + "speed": 5.276519775390625, + "accuracy": 5, + "altitudeAccuracy": 6, + "altitude": 234, + "longitude": 5.869746124377353, + "heading": 55.1953125, + "latitude": 45.64467706721801 + }, + "timestamp": 1394788282909 + }, { + "coords": { + "speed": 5.212399482727051, + "accuracy": 5, + "altitudeAccuracy": 6, + "altitude": 232, + "longitude": 5.8697939850444625, + "heading": 49.5703125, + "latitude": 45.64467899505574 + }, + "timestamp": 1394788284221 + }, { + "coords": { + "speed": 5.174651622772217, + "accuracy": 5, + "altitudeAccuracy": 6, + "altitude": 232, + "longitude": 5.869789123540623, + "heading": 18.984375, + "latitude": 45.64469378911484 + }, + "timestamp": 1394788284924 + }, { + "coords": { + "speed": 5.211904525756836, + "accuracy": 5, + "altitudeAccuracy": 4, + "altitude": 232, + "longitude": 5.869806222623093, + "heading": 10.1953125, + "latitude": 45.64473896757294 + }, + "timestamp": 1394788286251 + }, { + "coords": { + "speed": 5.254780292510986, + "accuracy": 5, + "altitudeAccuracy": 4, + "altitude": 233, + "longitude": 5.86982952431391, + "heading": 18.6328125, + "latitude": 45.64478381075491 + }, + "timestamp": 1394788286927 + }, { + "coords": { + "speed": 5.329030513763428, + "accuracy": 5, + "altitudeAccuracy": 4, + "altitude": 232, + "longitude": 5.869875792419417, + "heading": 33.75, + "latitude": 45.644830078860416 + }, + "timestamp": 1394788288221 + }, { + "coords": { + "speed": 5.384955883026123, + "accuracy": 5, + "altitudeAccuracy": 4, + "altitude": 232, + "longitude": 5.869927508761985, + "heading": 46.7578125, + "latitude": 45.64486025371183 + }, + "timestamp": 1394788288935 + }, { + "coords": { + "speed": 5.309582233428955, + "accuracy": 5, + "altitudeAccuracy": 4, + "altitude": 232, + "longitude": 5.869972854858143, + "heading": 47.109375, + "latitude": 45.644890596201314 + }, + "timestamp": 1394788290178 + }, { + "coords": { + "speed": 5.250724792480469, + "accuracy": 5, + "altitudeAccuracy": 6, + "altitude": 231, + "longitude": 5.870029265066488, + "heading": 46.40625, + "latitude": 45.644932673355235 + }, + "timestamp": 1394788290890 + }, { + "coords": { + "speed": 5.3057990074157715, + "accuracy": 5, + "altitudeAccuracy": 6, + "altitude": 231, + "longitude": 5.870077712466819, + "heading": 39.375, + "latitude": 45.644970224281444 + }, + "timestamp": 1394788291884 + }, { + "coords": { + "speed": 5.431822299957275, + "accuracy": 5, + "altitudeAccuracy": 6, + "altitude": 231, + "longitude": 5.870133116846783, + "heading": 43.59375, + "latitude": 45.6450097449549 + }, + "timestamp": 1394788292885 + }, { + "coords": { + "speed": 5.542125225067139, + "accuracy": 5, + "altitudeAccuracy": 6, + "altitude": 231, + "longitude": 5.870186509569986, + "heading": 43.59375, + "latitude": 45.645047421609654 + }, + "timestamp": 1394788294100 + }, { + "coords": { + "speed": 5.647174835205078, + "accuracy": 5, + "altitudeAccuracy": 6, + "altitude": 231, + "longitude": 5.870246104901535, + "heading": 42.890625, + "latitude": 45.645093647805645 + }, + "timestamp": 1394788295157 + }, { + "coords": { + "speed": 5.735793590545654, + "accuracy": 5, + "altitudeAccuracy": 6, + "altitude": 230, + "longitude": 5.870298156520231, + "heading": 42.5390625, + "latitude": 45.64514368776758 + }, + "timestamp": 1394788296124 + }, { + "coords": { + "speed": 5.809989929199219, + "accuracy": 5, + "altitudeAccuracy": 6, + "altitude": 230, + "longitude": 5.870346436282499, + "heading": 43.59375, + "latitude": 45.64519154843469 + }, + "timestamp": 1394788296960 + }, { + "coords": { + "speed": 5.877871036529541, + "accuracy": 5, + "altitudeAccuracy": 6, + "altitude": 228, + "longitude": 5.87034755932109, + "heading": 42.75193405151367, + "latitude": 45.645270362475216 + }, + "timestamp": 1394788298177 + }, { + "coords": { + "speed": 5.937166690826416, + "accuracy": 5, + "altitudeAccuracy": 6, + "altitude": 228, + "longitude": 5.870402806867787, + "heading": 42.75193405151367, + "latitude": 45.645312142096095 + }, + "timestamp": 1394788298898 + }, { + "coords": { + "speed": 6.071393966674805, + "accuracy": 5, + "altitudeAccuracy": 6, + "altitude": 229, + "longitude": 5.870464520921814, + "heading": 43.183074951171875, + "latitude": 45.64535851937182 + }, + "timestamp": 1394788299897 + }, { + "coords": { + "speed": 6.329115390777588, + "accuracy": 5, + "altitudeAccuracy": 6, + "altitude": 230, + "longitude": 5.8705368384107715, + "heading": 43.183074951171875, + "latitude": 45.645412389093565 + }, + "timestamp": 1394788300957 + }, { + "coords": { + "speed": 6.581554889678955, + "accuracy": 5, + "altitudeAccuracy": 6, + "altitude": 229, + "longitude": 5.870600162706978, + "heading": 43.183074951171875, + "latitude": 45.64545955929912 + }, + "timestamp": 1394788302211 + }, { + "coords": { + "speed": 6.605470180511475, + "accuracy": 5, + "altitudeAccuracy": 6, + "altitude": 230, + "longitude": 5.870657211053185, + "heading": 43.183074951171875, + "latitude": 45.64550205482465 + }, + "timestamp": 1394788302917 + }, { + "coords": { + "speed": 6.623170375823975, + "accuracy": 5, + "altitudeAccuracy": 4, + "altitude": 229, + "longitude": 5.870713613403495, + "heading": 43.183074951171875, + "latitude": 45.64554406917767 + }, + "timestamp": 1394788303929 + }, { + "coords": { + "speed": 6.645580768585205, + "accuracy": 5, + "altitudeAccuracy": 4, + "altitude": 229, + "longitude": 5.870773011629353, + "heading": 43.183074951171875, + "latitude": 45.64558831489415 + }, + "timestamp": 1394788304902 + }, { + "coords": { + "speed": 6.663600444793701, + "accuracy": 5, + "altitudeAccuracy": 4, + "altitude": 229, + "longitude": 5.87083890910435, + "heading": 43.183074951171875, + "latitude": 45.645637401898654 + }, + "timestamp": 1394788306035 + }, { + "coords": { + "speed": 6.664675712585449, + "accuracy": 5, + "altitudeAccuracy": 6, + "altitude": 229, + "longitude": 5.870890033475007, + "heading": 43.183074951171875, + "latitude": 45.64567548463474 + }, + "timestamp": 1394788307080 + }, { + "coords": { + "speed": 6.6489081382751465, + "accuracy": 5, + "altitudeAccuracy": 6, + "altitude": 228, + "longitude": 5.870943189474929, + "heading": 43.183074951171875, + "latitude": 45.645715080460064 + }, + "timestamp": 1394788308211 + }, { + "coords": { + "speed": 6.551820755004883, + "accuracy": 5, + "altitudeAccuracy": 6, + "altitude": 228, + "longitude": 5.871005613698799, + "heading": 43.183074951171875, + "latitude": 45.64576158014743 + }, + "timestamp": 1394788308904 + }, { + "coords": { + "speed": 6.467689514160156, + "accuracy": 5, + "altitudeAccuracy": 6, + "altitude": 229, + "longitude": 5.871058030061249, + "heading": 43.183074951171875, + "latitude": 45.64580062501799 + }, + "timestamp": 1394788310161 + }, { + "coords": { + "speed": 6.3997955322265625, + "accuracy": 5, + "altitudeAccuracy": 6, + "altitude": 229, + "longitude": 5.871062579208228, + "heading": 43.183074951171875, + "latitude": 45.64580401381376 + }, + "timestamp": 1394788310957 + }, { + "coords": { + "speed": 5.799798488616943, + "accuracy": 5, + "altitudeAccuracy": 6, + "altitude": 230, + "longitude": 5.8710817079554545, + "heading": 43.183074951171875, + "latitude": 45.64581826277647 + }, + "timestamp": 1394788312036 + }, { + "coords": { + "speed": 4.424941062927246, + "accuracy": 5, + "altitudeAccuracy": 6, + "altitude": 230, + "longitude": 5.871121835629857, + "heading": 175.4296875, + "latitude": 45.645828271551544 + }, + "timestamp": 1394788312951 + }, { + "coords": { + "speed": 4.3496222496032715, + "accuracy": 5, + "altitudeAccuracy": 6, + "altitude": 231, + "longitude": 5.8710026017471595, + "heading": 176.484375, + "latitude": 45.645752236602775 + }, + "timestamp": 1394788315227 + }, { + "coords": { + "speed": 5.076380252838135, + "accuracy": 5, + "altitudeAccuracy": 6, + "altitude": 232, + "longitude": 5.871189236646398, + "heading": 176.1328125, + "latitude": 45.64553692475487 + }, + "timestamp": 1394788316970 + }, { + "coords": { + "speed": 5.102786064147949, + "accuracy": 5, + "altitudeAccuracy": 6, + "altitude": 231, + "longitude": 5.871200384577616, + "heading": 171.2109375, + "latitude": 45.64548554368843 + }, + "timestamp": 1394788317965 + }, { + "coords": { + "speed": 4.705626964569092, + "accuracy": 5, + "altitudeAccuracy": 6, + "altitude": 231, + "longitude": 5.871210945775612, + "heading": 164.1796875, + "latitude": 45.645453105723156 + }, + "timestamp": 1394788318956 + }, { + "coords": { + "speed": 4.378190040588379, + "accuracy": 5, + "altitudeAccuracy": 6, + "altitude": 231, + "longitude": 5.87124749087344, + "heading": 126.2109375, + "latitude": 45.645433282522156 + }, + "timestamp": 1394788320197 + }, { + "coords": { + "speed": 4.208680152893066, + "accuracy": 5, + "altitudeAccuracy": 6, + "altitude": 233, + "longitude": 5.871283365419014, + "heading": 125.859375, + "latitude": 45.6454103999265 + }, + "timestamp": 1394788320894 + }, { + "coords": { + "speed": 4.072604179382324, + "accuracy": 5, + "altitudeAccuracy": 6, + "altitude": 233, + "longitude": 5.871314043184622, + "heading": 103.359375, + "latitude": 45.645410819021656 + }, + "timestamp": 1394788322169 + }, { + "coords": { + "speed": 3.7680623531341553, + "accuracy": 5, + "altitudeAccuracy": 6, + "altitude": 234, + "longitude": 5.871355114510163, + "heading": 92.4609375, + "latitude": 45.645418111277415 + }, + "timestamp": 1394788322898 + }, { + "coords": { + "speed": 3.537794351577759, + "accuracy": 10, + "altitudeAccuracy": 6, + "altitude": 234, + "longitude": 5.871393922721847, + "heading": 92.4609375, + "latitude": 45.64541693781097 + }, + "timestamp": 1394788323968 + }, { + "coords": { + "speed": 3.3741507530212402, + "accuracy": 10, + "altitudeAccuracy": 6, + "altitude": 234, + "longitude": 5.8714455552453835, + "heading": 75.5859375, + "latitude": 45.645444011358215 + }, + "timestamp": 1394788324896 + }, { + "coords": { + "speed": 3.3729660511016846, + "accuracy": 10, + "altitudeAccuracy": 6, + "altitude": 235, + "longitude": 5.87150791660498, + "heading": 70.3125, + "latitude": 45.64547209073384 + }, + "timestamp": 1394788325971 + }, { + "coords": { + "speed": 3.463883876800537, + "accuracy": 10, + "altitudeAccuracy": 6, + "altitude": 235, + "longitude": 5.871554352348551, + "heading": 70.3125, + "latitude": 45.64548374157925 + }, + "timestamp": 1394788327122 + }, { + "coords": { + "speed": 3.5247886180877686, + "accuracy": 10, + "altitudeAccuracy": 6, + "altitude": 235, + "longitude": 5.871567260479435, + "heading": 67.1484375, + "latitude": 45.645496733529164 + }, + "timestamp": 1394788328164 + }, { + "coords": { + "speed": 3.455146551132202, + "accuracy": 10, + "altitudeAccuracy": 6, + "altitude": 235, + "longitude": 5.871608583262071, + "heading": 68.90625, + "latitude": 45.64550293613751 + }, + "timestamp": 1394788328985 + }, { + "coords": { + "speed": 3.382997989654541, + "accuracy": 10, + "altitudeAccuracy": 8, + "altitude": 236, + "longitude": 5.871640518313154, + "heading": 78.75, + "latitude": 45.6454965658911 + }, + "timestamp": 1394788329900 + }, { + "coords": { + "speed": 3.242330312728882, + "accuracy": 10, + "altitudeAccuracy": 8, + "altitude": 236, + "longitude": 5.871667759498462, + "heading": 92.4609375, + "latitude": 45.64548562750746 + }, + "timestamp": 1394788331120 + }, { + "coords": { + "speed": 3.074465274810791, + "accuracy": 10, + "altitudeAccuracy": 8, + "altitude": 236, + "longitude": 5.871691312646374, + "heading": 110.0390625, + "latitude": 45.645468402696444 + }, + "timestamp": 1394788332219 + }] +} diff --git a/examples/data/geolocation_marker.png b/examples/data/geolocation_marker.png new file mode 100644 index 0000000000..6258640647 Binary files /dev/null and b/examples/data/geolocation_marker.png differ diff --git a/examples/data/geolocation_marker_heading.png b/examples/data/geolocation_marker_heading.png new file mode 100644 index 0000000000..5edfadccce Binary files /dev/null and b/examples/data/geolocation_marker_heading.png differ diff --git a/examples/geolocation-orientation.html b/examples/geolocation-orientation.html new file mode 100644 index 0000000000..4308692300 --- /dev/null +++ b/examples/geolocation-orientation.html @@ -0,0 +1,53 @@ + + + + + + + + + + + Mobile Geolocation Tracking with Orientation + + + +
+
+ +
+ + +
+ + + + + +
+
Geolocation tracking with orientation example
+
Example of a geolocated and oriented map.
+
fullscreen, geolocation, orientation, mobile
+
+ + diff --git a/examples/geolocation-orientation.js b/examples/geolocation-orientation.js new file mode 100644 index 0000000000..f1ef9fb80a --- /dev/null +++ b/examples/geolocation-orientation.js @@ -0,0 +1,222 @@ +goog.require('ol.Geolocation'); +goog.require('ol.Map'); +goog.require('ol.Overlay'); +goog.require('ol.View2D'); +goog.require('ol.geom.LineString'); +goog.require('ol.layer.Tile'); +goog.require('ol.proj'); +goog.require('ol.source.OSM'); + +// creating the view +var view = new ol.View2D({ + center: ol.proj.transform([5.8713, 45.6452], 'EPSG:4326', 'EPSG:3857'), + zoom: 19 +}); + +// creating the map +var map = new ol.Map({ + layers: [ + new ol.layer.Tile({ + source: new ol.source.OSM() + }) + ], + target: 'map', + view: view +}); + +// Geolocation marker +var markerEl = document.getElementById('geolocation_marker'); +var marker = new ol.Overlay({ + positioning: 'center-center', + element: markerEl, + stopEvent: false +}); +map.addOverlay(marker); + +// LineString to store the different geolocation positions. This LineString +// is time aware. +// The Z dimension is actually used to store the rotation (heading). +var positions = new ol.geom.LineString([], 'XYZM'); + +// Geolocation Control +var geolocation = new ol.Geolocation(/** @type {olx.GeolocationOptions} */ ({ + trackingOptions: { + maximumAge: 10000, + enableHighAccuracy: true, + timeout: 600000 + } +})); +geolocation.bindTo('projection', view); + +var deltaMean = 500; // the geolocation sampling period mean in ms + +// Listen to position changes +geolocation.on('change', function(evt) { + var position = geolocation.getPosition(); + var accuracy = geolocation.getAccuracy(); + var heading = geolocation.getHeading() || 0; + var speed = geolocation.getSpeed() || 0; + var m = Date.now(); + + addPosition(position, heading, m, speed); + + var coords = positions.getCoordinates(); + var len = coords.length; + if (len >= 2) { + deltaMean = (coords[len - 1][3] - coords[0][3]) / (len - 1); + } + + var html = [ + 'Position: ' + position[0].toFixed(2) + ', ' + position[1].toFixed(2), + 'Accuracy: ' + accuracy, + 'Heading: ' + Math.round(radToDeg(heading)) + '°', + 'Speed: ' + (speed * 3.6).toFixed(1) + ' km/h', + 'Delta: ' + Math.round(deltaMean) + 'ms' + ].join('
'); + document.getElementById('info').innerHTML = html; +}); + +geolocation.on('error', function() { + alert('geolocation error'); + // FIXME we should remove the coordinates in positions +}); + +// convert radians to degrees +function radToDeg(rad) { + return rad * 360 / (Math.PI * 2); +} +// convert degrees to radians +function degToRad(deg) { + return deg * Math.PI * 2 / 360; +} +// modulo for negative values +function mod(n) { + return ((n % (2 * Math.PI)) + (2 * Math.PI)) % (2 * Math.PI); +} + +function addPosition(position, heading, m, speed) { + var x = position[0]; + var y = position[1]; + var fCoords = positions.getCoordinates(); + var previous = fCoords[fCoords.length - 1]; + var prevHeading = previous && previous[2]; + if (prevHeading) { + var headingDiff = heading - mod(prevHeading); + + // force the rotation change to be less than 180° + if (Math.abs(headingDiff) > Math.PI) { + var sign = (headingDiff >= 0) ? 1 : -1; + headingDiff = - sign * (2 * Math.PI - Math.abs(headingDiff)); + } + heading = prevHeading + headingDiff; + } + positions.appendCoordinate([x, y, heading, m]); + + // only keep the 20 last coordinates + positions.setCoordinates(positions.getCoordinates().slice(-20)); + + // FIXME use speed instead + if (heading && speed) { + markerEl.src = 'data/geolocation_marker_heading.png'; + } else { + markerEl.src = 'data/geolocation_marker.png'; + } +} + +var previousM = 0; +// change center and rotation before render +map.beforeRender(function(map, frameState) { + if (frameState !== null) { + // use sampling period to get a smooth transition + var m = frameState.time - deltaMean * 1.5; + m = Math.max(m, previousM); + previousM = m; + // interpolate position along positions LineString + var c = positions.getCoordinateAtM(m, true); + var view = frameState.view2DState; + if (c) { + view.center = getCenterWithHeading(c, -c[2], view.resolution); + view.rotation = -c[2]; + marker.setPosition(c); + } + } + return true; // Force animation to continue +}); + +// recenters the view by putting the given coordinates at 3/4 from the top or +// the screen +function getCenterWithHeading(position, rotation, resolution) { + var size = map.getSize(); + var height = size[1]; + + return [ + position[0] - Math.sin(rotation) * height * resolution * 1 / 4, + position[1] + Math.cos(rotation) * height * resolution * 1 / 4 + ]; +} + +// postcompose callback +function render() { + map.render(); +} + +// geolocate device +var geolocateBtn = document.getElementById('geolocate'); +geolocateBtn.addEventListener('click', function() { + geolocation.setTracking(true); // Start position tracking + + map.on('postcompose', render); + map.render(); + + disableButtons(); +}, false); + +// simulate device move +var simulationData; +$.getJSON('data/geolocation-orientation.json', function(data) { + simulationData = data.data; +}); +var simulateBtn = document.getElementById('simulate'); +simulateBtn.addEventListener('click', function() { + var coordinates = simulationData; + + var first = coordinates.shift(); + simulatePositionChange(first); + + var prevDate = first.timestamp; + function geolocate() { + var position = coordinates.shift(); + if (!position) { + return; + } + var newDate = position.timestamp; + simulatePositionChange(position); + window.setTimeout(function() { + prevDate = newDate; + geolocate(); + }, (newDate - prevDate) / 0.5); + } + geolocate(); + + map.on('postcompose', render); + map.render(); + + disableButtons(); +}, false); + +function simulatePositionChange(position) { + var coords = position.coords; + geolocation.set('accuracy', coords.accuracy); + geolocation.set('heading', degToRad(coords.heading)); + var position_ = [coords.longitude, coords.latitude]; + var projectedPosition = ol.proj.transform(position_, 'EPSG:4326', + 'EPSG:3857'); + geolocation.set('position', projectedPosition); + geolocation.set('speed', coords.speed); + geolocation.dispatchChangeEvent(); +} + +function disableButtons() { + geolocateBtn.disabled = 'disabled'; + simulateBtn.disabled = 'disabled'; +} diff --git a/src/ol/geom/circle.js b/src/ol/geom/circle.js index e0c7916c06..72457fd35d 100644 --- a/src/ol/geom/circle.js +++ b/src/ol/geom/circle.js @@ -13,13 +13,14 @@ goog.require('ol.geom.flat.deflate'); * @extends {ol.geom.SimpleGeometry} * @param {ol.geom.RawPoint} center Center. * @param {number=} opt_radius Radius. - * @param {ol.geom.GeometryLayout=} opt_layout Layout. + * @param {ol.geom.GeometryLayout|string=} opt_layout Layout. * @todo stability experimental */ ol.geom.Circle = function(center, opt_radius, opt_layout) { goog.base(this); var radius = goog.isDef(opt_radius) ? opt_radius : 0; - this.setCenterAndRadius(center, radius, opt_layout); + this.setCenterAndRadius(center, radius, + /** @type {ol.geom.GeometryLayout|undefined} */ (opt_layout)); }; goog.inherits(ol.geom.Circle, ol.geom.SimpleGeometry); diff --git a/src/ol/geom/linearring.js b/src/ol/geom/linearring.js index 389ccf561e..18250e7613 100644 --- a/src/ol/geom/linearring.js +++ b/src/ol/geom/linearring.js @@ -15,7 +15,7 @@ goog.require('ol.geom.flat.simplify'); * @constructor * @extends {ol.geom.SimpleGeometry} * @param {ol.geom.RawLinearRing} coordinates Coordinates. - * @param {ol.geom.GeometryLayout=} opt_layout Layout. + * @param {ol.geom.GeometryLayout|string=} opt_layout Layout. * @todo stability experimental */ ol.geom.LinearRing = function(coordinates, opt_layout) { @@ -34,7 +34,8 @@ ol.geom.LinearRing = function(coordinates, opt_layout) { */ this.maxDeltaRevision_ = -1; - this.setCoordinates(coordinates, opt_layout); + this.setCoordinates(coordinates, + /** @type {ol.geom.GeometryLayout|undefined} */ (opt_layout)); }; goog.inherits(ol.geom.LinearRing, ol.geom.SimpleGeometry); diff --git a/src/ol/geom/linestring.js b/src/ol/geom/linestring.js index 6dc2319725..92d99f5d98 100644 --- a/src/ol/geom/linestring.js +++ b/src/ol/geom/linestring.js @@ -19,7 +19,7 @@ goog.require('ol.geom.flat.simplify'); * @constructor * @extends {ol.geom.SimpleGeometry} * @param {ol.geom.RawLineString} coordinates Coordinates. - * @param {ol.geom.GeometryLayout=} opt_layout Layout. + * @param {ol.geom.GeometryLayout|string=} opt_layout Layout. * @todo stability experimental */ ol.geom.LineString = function(coordinates, opt_layout) { @@ -50,7 +50,8 @@ ol.geom.LineString = function(coordinates, opt_layout) { */ this.maxDeltaRevision_ = -1; - this.setCoordinates(coordinates, opt_layout); + this.setCoordinates(coordinates, + /** @type {ol.geom.GeometryLayout|undefined} */ (opt_layout)); }; goog.inherits(ol.geom.LineString, ol.geom.SimpleGeometry); diff --git a/src/ol/geom/multilinestring.js b/src/ol/geom/multilinestring.js index abe2ca7f5a..895bf6472e 100644 --- a/src/ol/geom/multilinestring.js +++ b/src/ol/geom/multilinestring.js @@ -19,7 +19,7 @@ goog.require('ol.geom.flat.simplify'); * @constructor * @extends {ol.geom.SimpleGeometry} * @param {ol.geom.RawMultiLineString} coordinates Coordinates. - * @param {ol.geom.GeometryLayout=} opt_layout Layout. + * @param {ol.geom.GeometryLayout|string=} opt_layout Layout. * @todo stability experimental */ ol.geom.MultiLineString = function(coordinates, opt_layout) { @@ -44,7 +44,8 @@ ol.geom.MultiLineString = function(coordinates, opt_layout) { */ this.maxDeltaRevision_ = -1; - this.setCoordinates(coordinates, opt_layout); + this.setCoordinates(coordinates, + /** @type {ol.geom.GeometryLayout|undefined} */ (opt_layout)); }; goog.inherits(ol.geom.MultiLineString, ol.geom.SimpleGeometry); diff --git a/src/ol/geom/multipoint.js b/src/ol/geom/multipoint.js index 19326bd8ed..1e5c12d91f 100644 --- a/src/ol/geom/multipoint.js +++ b/src/ol/geom/multipoint.js @@ -17,12 +17,13 @@ goog.require('ol.math'); * @constructor * @extends {ol.geom.SimpleGeometry} * @param {ol.geom.RawMultiPoint} coordinates Coordinates. - * @param {ol.geom.GeometryLayout=} opt_layout Layout. + * @param {ol.geom.GeometryLayout|string=} opt_layout Layout. * @todo stability experimental */ ol.geom.MultiPoint = function(coordinates, opt_layout) { goog.base(this); - this.setCoordinates(coordinates, opt_layout); + this.setCoordinates(coordinates, + /** @type {ol.geom.GeometryLayout|undefined} */ (opt_layout)); }; goog.inherits(ol.geom.MultiPoint, ol.geom.SimpleGeometry); diff --git a/src/ol/geom/multipolygon.js b/src/ol/geom/multipolygon.js index 659e1bf12f..1030852894 100644 --- a/src/ol/geom/multipolygon.js +++ b/src/ol/geom/multipolygon.js @@ -24,7 +24,7 @@ goog.require('ol.geom.flat.simplify'); * @constructor * @extends {ol.geom.SimpleGeometry} * @param {ol.geom.RawMultiPolygon} coordinates Coordinates. - * @param {ol.geom.GeometryLayout=} opt_layout Layout. + * @param {ol.geom.GeometryLayout|string=} opt_layout Layout. * @todo stability experimental */ ol.geom.MultiPolygon = function(coordinates, opt_layout) { @@ -73,7 +73,8 @@ ol.geom.MultiPolygon = function(coordinates, opt_layout) { */ this.orientedFlatCoordinates_ = null; - this.setCoordinates(coordinates, opt_layout); + this.setCoordinates(coordinates, + /** @type {ol.geom.GeometryLayout|undefined} */ (opt_layout)); }; goog.inherits(ol.geom.MultiPolygon, ol.geom.SimpleGeometry); diff --git a/src/ol/geom/point.js b/src/ol/geom/point.js index 19275c48f4..fafd43f30b 100644 --- a/src/ol/geom/point.js +++ b/src/ol/geom/point.js @@ -13,12 +13,13 @@ goog.require('ol.math'); * @constructor * @extends {ol.geom.SimpleGeometry} * @param {ol.geom.RawPoint} coordinates Coordinates. - * @param {ol.geom.GeometryLayout=} opt_layout Layout. + * @param {ol.geom.GeometryLayout|string=} opt_layout Layout. * @todo stability experimental */ ol.geom.Point = function(coordinates, opt_layout) { goog.base(this); - this.setCoordinates(coordinates, opt_layout); + this.setCoordinates(coordinates, + /** @type {ol.geom.GeometryLayout|undefined} */ (opt_layout)); }; goog.inherits(ol.geom.Point, ol.geom.SimpleGeometry); diff --git a/src/ol/geom/polygon.js b/src/ol/geom/polygon.js index f3694430be..a857b367fe 100644 --- a/src/ol/geom/polygon.js +++ b/src/ol/geom/polygon.js @@ -23,7 +23,7 @@ goog.require('ol.geom.flat.simplify'); * @constructor * @extends {ol.geom.SimpleGeometry} * @param {ol.geom.RawPolygon} coordinates Coordinates. - * @param {ol.geom.GeometryLayout=} opt_layout Layout. + * @param {ol.geom.GeometryLayout|string=} opt_layout Layout. * @todo stability experimental */ ol.geom.Polygon = function(coordinates, opt_layout) { @@ -72,7 +72,8 @@ ol.geom.Polygon = function(coordinates, opt_layout) { */ this.orientedFlatCoordinates_ = null; - this.setCoordinates(coordinates, opt_layout); + this.setCoordinates(coordinates, + /** @type {ol.geom.GeometryLayout|undefined} */ (opt_layout)); }; goog.inherits(ol.geom.Polygon, ol.geom.SimpleGeometry);