Changeset 11401


Ignore:
Timestamp:
Feb 24, 2011 3:06:49 AM (6 years ago)
Author:
fredj
Message:

deviceorientation addins, not finished

Location:
sandbox/sbrunner/addins/deviceorientation/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • sandbox/sbrunner/addins/deviceorientation/trunk/examples/orientation.html

    r11369 r11401  
    11<!DOCTYPE html>
    22<html>
    3 <head>
     3  <head>
    44    <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
    55    <meta name="apple-mobile-web-app-capable" content="yes"/>
    66    <title>OpenLayers Device Orientation</title>
     7
    78    <link rel="stylesheet" href="http://www.openlayers.org/dev/theme/default/style.css" type="text/css"/>
    89    <link rel="stylesheet" href="http://www.openlayers.org/dev/examples/style.css" type="text/css"/>
    9     <script type="text/javascript" src="../../../../openlayers/lib/OpenLayers.js"></script>
     10    <script type="text/javascript" src="http://www.openlayers.org/api/OpenLayers.js"></script>
    1011
    1112    <link rel="stylesheet" href="../theme/default/style.css" type="text/css"/>
    1213    <script type="text/javascript" src="../lib/OpenLayers/Control/DeviceOrientation.js"></script>
    1314    <script type="text/javascript" src="orientation.js"></script>
    14 </head>
    15 <body onload="init()">
     15  </head>
     16  <body onload="init()">
    1617    <h1>Device Orientation</h1>
    1718    <div id="map" class="smallmap"></div>
    18 </body>
     19  </body>
    1920</html>
  • sandbox/sbrunner/addins/deviceorientation/trunk/examples/orientation.js

    r11369 r11401  
    88    map.zoomToMaxExtent();
    99}
    10 
    11 //     function init() {
    12 //         var logs = document.getElementById("logs");
    13 //         orientation = new OpenLayers.Control.DeviceOrientation();
    14 //         if (orientation.supported()) {
    15 //             orientation.events.register("orientationchange", this, function(event) {
    16 //                 logs.innerHTML = "rotation: " + event.orientation;
    17 
    18 //                 var img = document.getElementById("orientation");
    19 //                 var value = "rotate(" + event.orientation + "deg)";
    20 //                 img.style.transform = value;
    21 //                 img.style.webkitTransform = value;
    22 //             });
    23 //             orientation.activate();
    24 //         } else {
    25 //             logs.innerHTML = "This device don't supports device orientation";
    26 //         }
    27 //     }
  • sandbox/sbrunner/addins/deviceorientation/trunk/lib/OpenLayers/Control/DeviceOrientation.js

    r11369 r11401  
    1010/**
    1111 * Class: OpenLayers.Control.DeviceOrientation
    12  * see: http://dev.w3.org/geo/api/spec-source-orientation.html
     12 * The DeviceOrientation displays a div on the map rotated according to
     13 * the rotation of the device, the DeviceOrientationEvent is used. 
     14 * If the device do not supports this event, the div is hidden.
     15 * <http://dev.w3.org/geo/api/spec-source-orientation.html>
     16 *
     17 * Inherits from:
     18 *  - <OpenLayers.Control>
     19 * 
    1320 */
    1421OpenLayers.Control.DeviceOrientation = OpenLayers.Class(OpenLayers.Control, {
     22
     23    /**
     24     * APIProperty: autoActivate
     25     * {Boolean} Activate the control when it is added to a map.  Default is
     26     *     true.
     27     */
     28    autoActivate: true,
    1529
    1630    /**
     
    2539
    2640    /**
    27      * Method: draw
    28      *
    29      * Returns:
    30      * {DOMElement}
     41     * APIMethod: activate
    3142     */
    32     draw: function() {
    33         OpenLayers.Control.prototype.draw.apply(this, arguments);
    34         if (this.supported()) {
    35             window.addEventListener("deviceorientation",
    36                 OpenLayers.Function.bind(this.updateOrientation, this), true);
     43    activate: function () {
     44        if (OpenLayers.Control.prototype.activate.apply(this, arguments)) {
     45            if (this.supported()) {
     46                window.addEventListener("deviceorientation",
     47                    OpenLayers.Function.bind(this.updateOrientation, this), true);
     48            } else {
     49                OpenLayers.Element.addClass(this.div, "unsupported");
     50            }
     51            return true;
    3752        } else {
    38             OpenLayers.Element.addClass(this.div, "unsupported");
     53            return false;
    3954        }
    40         return this.div;
     55    },
     56
     57    /**
     58     * APIMethod: deactivate
     59     */
     60    deactivate: function () {
     61        if (OpenLayers.Control.prototype.deactivate.apply(this, arguments)) {
     62            if (this.supported()) {
     63                window.removeEventListener("deviceorientation",
     64                    OpenLayers.Function.bind(this.updateOrientation, this), true);
     65            }
     66            return true;
     67        } else {
     68            return false;
     69        }
    4170    },
    4271
     
    4776    },
    4877
     78    /**
     79     * Method: destroy
     80     */
    4981    destroy: function() {
    50         window.removeEventListener("deviceorientation",
    51             OpenLayers.Function.bind(this.updateOrientation, this), true);
    52 
     82        this.deactivate();
    5383        OpenLayers.Control.prototype.destroy.apply(this, arguments);
    5484    },
  • sandbox/sbrunner/addins/deviceorientation/trunk/theme/default/style.css

    r11369 r11401  
    66    border: 1px solid red;
    77}
     8
     9.olControlDeviceOrientation.unsupported {
     10    display: none;
     11}
Note: See TracChangeset for help on using the changeset viewer.