[OpenLayers-Commits] r11549 - in trunk/openlayers: build examples
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Sat Feb 26 10:21:41 EST 2011
Author: crschmidt
Date: 2011-02-26 07:21:40 -0800 (Sat, 26 Feb 2011)
New Revision: 11549
Added:
trunk/openlayers/examples/game-accel-ball.html
Modified:
trunk/openlayers/build/mobile.cfg
Log:
Simple demo game-like thing showing how to use the accelerometer to control
a vector feature on a map.
Modified: trunk/openlayers/build/mobile.cfg
===================================================================
--- trunk/openlayers/build/mobile.cfg 2011-02-26 10:09:59 UTC (rev 11548)
+++ trunk/openlayers/build/mobile.cfg 2011-02-26 15:21:40 UTC (rev 11549)
@@ -16,6 +16,7 @@
OpenLayers/Control/SelectFeature.js
OpenLayers/Layer/Vector.js
OpenLayers/Renderer/SVG.js
+OpenLayers/Renderer/Canvas.js
OpenLayers/Format/GeoJSON.js
[exclude]
Added: trunk/openlayers/examples/game-accel-ball.html
===================================================================
--- trunk/openlayers/examples/game-accel-ball.html (rev 0)
+++ trunk/openlayers/examples/game-accel-ball.html 2011-02-26 15:21:40 UTC (rev 11549)
@@ -0,0 +1,80 @@
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" />
+ <meta name="apple-mobile-web-app-capable" content="yes" />
+ <title>OpenLayers Game: Bounce Ball</title>
+ <link rel="stylesheet" href="../theme/default/style.css" type="text/css" />
+ <link rel="stylesheet" href="style.css" type="text/css" />
+ <script src="../lib/OpenLayers.js?mobile"></script>
+ <style type="text/css">
+ html, body { height: 100%; }
+ #shortdesc { display: none; }
+ #tags { display: none; }
+ </style>
+
+ <script type="text/javascript">
+ var map, vlayer;
+ function adjustLocation(delta, feature) {
+ feature.geometry.move(delta.x, delta.y);
+ var me = map.maxExtent;
+ var rad = 6;
+ if (feature.geometry.x > (me.right - rad)) {
+ feature.geometry.x = me.right - rad;
+ } else if (feature.geometry.x < (me.left+rad)) {
+ feature.geometry.x = me.left+rad;
+ }
+ if (feature.geometry.y > (me.top-rad)) {
+ feature.geometry.y = me.top-rad;
+ } else if (feature.geometry.y < (me.bottom+rad)) {
+ feature.geometry.y = me.bottom+rad;
+ }
+ vlayer.drawFeature(feature);
+ }
+ function init() {
+ map = new OpenLayers.Map( 'map',
+ {
+ 'maxExtent': new OpenLayers.Bounds(0, 0, $("map").clientWidth, $("map").clientHeight),
+ controls: [],
+ maxResolution: 'auto'}
+ );
+ var layer = new OpenLayers.Layer("",
+ {isBaseLayer: true} );
+ map.addLayer(layer);
+ map.zoomToMaxExtent();
+ vlayer = new OpenLayers.Layer.Vector();
+ var feature = new OpenLayers.Feature.Vector(
+ new OpenLayers.Geometry.Point(map.getCenter().lon, map.getCenter().lat));
+ vlayer.addFeatures(feature);
+ map.addLayer(vlayer);
+ if (window.DeviceMotionEvent) {
+ window.addEventListener('devicemotion', function (evt) {
+ var delta = null;
+ if (typeof(evt.accelerationIncludingGravity) != 'undefined') {
+ delta = {
+ 'x': evt.accelerationIncludingGravity.x * 3,
+ 'y': evt.accelerationIncludingGravity.y * 3,
+ 'z': evt.accelerationIncludingGravity.z
+ }
+ }
+ adjustLocation(delta, feature);
+ }, true);
+ } else {
+ alert("This demo does not work on your browser.");
+ }
+ }
+ </script>
+ </head>
+ <body onload="init()">
+ <h1 id="title">Accelerometer Example</h1>
+ <div id="tags">
+ mobile, game
+ </div>
+ <div id="shortdesc">Simple acceleration demo; roll a vector feature around
+ on a map. (Only tested on iOS 4.)</div>
+
+ <div id="map" width="100%" height="100%" style="background-color: grey"></div>
+ <div id="docs">
+ Demo works best when device is locked in portrait mode.
+ </div>
+ </body>
+</html>
More information about the Commits
mailing list