[OpenLayers-Commits] r11832 - in sandbox/cmoullet/openlayers: . examples lib/OpenLayers lib/OpenLayers/Handler tests/Handler

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Thu Mar 31 07:22:16 EDT 2011


Author: cmoullet
Date: 2011-03-31 04:22:15 -0700 (Thu, 31 Mar 2011)
New Revision: 11832

Modified:
   sandbox/cmoullet/openlayers/
   sandbox/cmoullet/openlayers/examples/mobile-base.js
   sandbox/cmoullet/openlayers/examples/mobile-jq.js
   sandbox/cmoullet/openlayers/examples/mobile-layers.js
   sandbox/cmoullet/openlayers/examples/mobile-sencha.html
   sandbox/cmoullet/openlayers/lib/OpenLayers/Handler/Feature.js
   sandbox/cmoullet/openlayers/lib/OpenLayers/Handler/Point.js
   sandbox/cmoullet/openlayers/lib/OpenLayers/Util.js
   sandbox/cmoullet/openlayers/tests/Handler/Feature.html
   sandbox/cmoullet/openlayers/tests/Handler/Point.html
Log:
Merge with trunk



Property changes on: sandbox/cmoullet/openlayers
___________________________________________________________________
Modified: svn:mergeinfo
   - /sandbox/roberthl/openlayers:9745-9748
/trunk/openlayers:11161-11775,11777-11825
   + /sandbox/roberthl/openlayers:9745-9748
/trunk/openlayers:11161-11775,11777-11831

Modified: sandbox/cmoullet/openlayers/examples/mobile-base.js
===================================================================
--- sandbox/cmoullet/openlayers/examples/mobile-base.js	2011-03-31 09:52:33 UTC (rev 11831)
+++ sandbox/cmoullet/openlayers/examples/mobile-base.js	2011-03-31 11:22:15 UTC (rev 11832)
@@ -4,6 +4,7 @@
 
 // initialize map when page ready
 var map;
+var sprintersLayer;
 var gg = new OpenLayers.Projection("EPSG:4326");
 var sm = new OpenLayers.Projection("EPSG:900913");
 
@@ -28,8 +29,8 @@
         numZoomLevels: 18,
         maxResolution: 156543.0339,
         maxExtent: new OpenLayers.Bounds(
-            -20037508.34, -20037508.34, 20037508.34, 20037508.34
-        ),
+                -20037508.34, -20037508.34, 20037508.34, 20037508.34
+                ),
         controls: [
             new OpenLayers.Control.Attribution(),
             new OpenLayers.Control.TouchNavigation({
@@ -66,44 +67,104 @@
                 type: "AerialWithLabels",
                 name: "Bing Aerial + Labels",
                 transitionEffect: 'resize'
-            }), 
+            }),
             vector
         ],
         center: new OpenLayers.LonLat(0, 0),
         zoom: 1
     });
 
+    var sprintersLayer = new OpenLayers.Layer.Vector("Sprinters", {
+        styleMap: new OpenLayers.StyleMap({
+            externalGraphic: "img/mobile-loc.png",
+            graphicOpacity: 1.0,
+            graphicWith: 16,
+            graphicHeight: 26,
+            graphicYOffset: -26
+        })
+    });
+
+    var sprinters = getFeatures();
+    sprintersLayer.addFeatures(sprinters);
+
+    map.addLayer(sprintersLayer);
+
     var style = {
         fillOpacity: 0.1,
         fillColor: '#000',
         strokeColor: '#f00',
         strokeOpacity: 0.6
     };
-    geolocate.events.register("locationupdated",this,function(e) {
+    geolocate.events.register("locationupdated", this, function(e) {
         vector.removeAllFeatures();
         vector.addFeatures([
             new OpenLayers.Feature.Vector(
-                e.point,
-                {},
-                {
-                    graphicName: 'cross',
-                    strokeColor: '#f00',
-                    strokeWidth: 2,
-                    fillOpacity: 0,
-                    pointRadius: 10
-                }
-            ),
+                    e.point,
+            {},
+            {
+                graphicName: 'cross',
+                strokeColor: '#f00',
+                strokeWidth: 2,
+                fillOpacity: 0,
+                pointRadius: 10
+            }
+                    ),
             new OpenLayers.Feature.Vector(
-                OpenLayers.Geometry.Polygon.createRegularPolygon(
-                    new OpenLayers.Geometry.Point(e.point.x, e.point.y),
-                    e.position.coords.accuracy/2,
-                    50,
-                    0
-                ),
-                {},
-                style
-            )
+                    OpenLayers.Geometry.Polygon.createRegularPolygon(
+                            new OpenLayers.Geometry.Point(e.point.x, e.point.y),
+                            e.position.coords.accuracy / 2,
+                            50,
+                            0
+                            ),
+            {},
+                    style
+                    )
         ]);
         map.zoomToExtent(vector.getDataExtent());
     });
+
+    function getFeatures() {
+        var features = {
+            "type": "FeatureCollection",
+            "features": [
+                { "type": "Feature", "geometry": {"type": "Point", "coordinates": [1332700, 7906300]},
+                    "properties": {"Name": "Igor Tihonov", "Country":"Sweden", "City":"Gothenburg"}},
+                { "type": "Feature", "geometry": {"type": "Point", "coordinates": [790300, 6573900]},
+                    "properties": {"Name": "Marc Jansen", "Country":"Germany", "City":"Bonn"}},
+                { "type": "Feature", "geometry": {"type": "Point", "coordinates": [568600, 6817300]},
+                    "properties": {"Name": "Bart van den Eijnden", "Country":"Netherlands", "City":"Utrecht"}},
+                { "type": "Feature", "geometry": {"type": "Point", "coordinates": [-7909900, 5215100]},
+                    "properties": {"Name": "Christopher Schmidt", "Country":"United States of America", "City":"Boston"}},
+                { "type": "Feature", "geometry": {"type": "Point", "coordinates": [-937400, 5093200]},
+                    "properties": {"Name": "Jorge Gustavo Rocha", "Country":"Portugal", "City":"Braga"}},
+                { "type": "Feature", "geometry": {"type": "Point", "coordinates": [-355300, 7547800]},
+                    "properties": {"Name": "Jennie Fletcher ", "Country":"Scotland", "City":"Edinburgh"}},
+                { "type": "Feature", "geometry": {"type": "Point", "coordinates": [657068.53608487, 5712321.2472725]},
+                    "properties": {"Name": "Bruno Binet ", "Country":"France", "City":"Chambéry"}},
+                { "type": "Feature", "geometry": {"type": "Point", "coordinates": [667250.8958124, 5668048.6072737]},
+                    "properties": {"Name": "Eric Lemoine", "Country":"France", "City":"Theys"}},
+                { "type": "Feature", "geometry": {"type": "Point", "coordinates": [653518.03606319, 5721118.5122914]},
+                    "properties": {"Name": "Antoine Abt", "Country":"France", "City":"La Motte Servolex"}},
+                { "type": "Feature", "geometry": {"type": "Point", "coordinates": [657985.78042416, 5711862.6251028]},
+                    "properties": {"Name": "Pierre Giraud", "Country":"France", "City":"Chambéry"}},
+                { "type": "Feature", "geometry": {"type": "Point", "coordinates": [742941.93818208, 5861818.9477535]},
+                    "properties": {"Name": "Stéphane Brunner", "Country":"Switzerland", "City":"Paudex"}},
+                { "type": "Feature", "geometry": {"type": "Point", "coordinates": [736082.61064069, 5908165.4649505]},
+                    "properties": {"Name": "Frédéric Junod", "Country":"Switzerland", "City":"Montagny-près-Yverdon"}},
+                { "type": "Feature", "geometry": {"type": "Point", "coordinates": [771595.97057525, 5912284.7041793]},
+                    "properties": {"Name": "Cédric Moullet", "Country":"Switzerland", "City":"Payerne"}},
+                { "type": "Feature", "geometry": {"type": "Point", "coordinates": [744205.23922364, 5861277.319748]},
+                    "properties": {"Name": "Benoit Quartier", "Country":"Switzerland", "City":"Lutry"}},
+                { "type": "Feature", "geometry": {"type": "Point", "coordinates": [1717430.147101, 5954568.7127565]},
+                    "properties": {"Name": "Andreas Hocevar", "Country":"Austria", "City":"Graz"}},
+                { "type": "Feature", "geometry": {"type": "Point", "coordinates": [-12362007.067301,5729082.2365672]},
+                    "properties": {"Name": "Tim Schaub", "Country":"United States of America", "City":"Bozeman"}}
+            ]
+        };
+
+        var reader = new OpenLayers.Format.GeoJSON();
+
+        return reader.read(features);
+    }
+
 };

Modified: sandbox/cmoullet/openlayers/examples/mobile-jq.js
===================================================================
--- sandbox/cmoullet/openlayers/examples/mobile-jq.js	2011-03-31 09:52:33 UTC (rev 11831)
+++ sandbox/cmoullet/openlayers/examples/mobile-jq.js	2011-03-31 11:22:15 UTC (rev 11832)
@@ -44,23 +44,8 @@
             control.activate();
         }
     });
-
-    var sprintersLayer = new OpenLayers.Layer.Vector("Sprinters", {
-        styleMap: new OpenLayers.StyleMap({
-            externalGraphic: "img/mobile-loc.png",
-            graphicOpacity: 1.0,
-            graphicWith: 16,
-            graphicHeight: 26,
-            graphicYOffset: -26
-        })
-    });
     
-    var sprinters = getFeatures();
-    sprintersLayer.addFeatures(sprinters);
-    
-    map.addLayer(sprintersLayer);
-    
-    var selectControl = new OpenLayers.Control.SelectFeature(sprintersLayer, {onSelect: function(feature){
+    var selectControl = new OpenLayers.Control.SelectFeature(map.getLayersByName("Sprinters")[0], {onSelect: function(feature){
         selectedFeature = feature;
         $.mobile.changePage($("#popup"), "pop");
     }});
@@ -167,48 +152,4 @@
             $(item).toggleClass('checked');
         }
     });
-}
-
-function getFeatures(){
-    var features = {
-      "type": "FeatureCollection", 
-      "features": [
-            { "type": "Feature", "geometry": {"type": "Point", "coordinates": [1332700, 7906300]}, 
-            "properties": {"Name": "Igor Tihonov", "Country":"Sweden", "City":"Gothenburg"}},
-            { "type": "Feature", "geometry": {"type": "Point", "coordinates": [790300, 6573900]}, 
-            "properties": {"Name": "Marc Jansen", "Country":"Germany", "City":"Bonn"}},
-            { "type": "Feature", "geometry": {"type": "Point", "coordinates": [568600, 6817300]}, 
-            "properties": {"Name": "Bart van den Eijnden", "Country":"Netherlands", "City":"Utrecht"}},
-            { "type": "Feature", "geometry": {"type": "Point", "coordinates": [-7909900, 5215100]}, 
-            "properties": {"Name": "Christopher Schmidt", "Country":"United States of America", "City":"Boston"}},
-            { "type": "Feature", "geometry": {"type": "Point", "coordinates": [-937400, 5093200]}, 
-            "properties": {"Name": "Jorge Gustavo Rocha", "Country":"Portugal", "City":"Braga"}},
-            { "type": "Feature", "geometry": {"type": "Point", "coordinates": [-355300, 7547800]}, 
-            "properties": {"Name": "Jennie Fletcher ", "Country":"Scotland", "City":"Edinburgh"}},
-            { "type": "Feature", "geometry": {"type": "Point", "coordinates": [657068.53608487, 5712321.2472725]}, 
-            "properties": {"Name": "Bruno Binet ", "Country":"France", "City":"Chambéry"}},
-            { "type": "Feature", "geometry": {"type": "Point", "coordinates": [667250.8958124, 5668048.6072737]}, 
-            "properties": {"Name": "Eric Lemoine", "Country":"France", "City":"Theys"}},
-            { "type": "Feature", "geometry": {"type": "Point", "coordinates": [653518.03606319, 5721118.5122914]}, 
-            "properties": {"Name": "Antoine Abt", "Country":"France", "City":"La Motte Servolex"}},
-            { "type": "Feature", "geometry": {"type": "Point", "coordinates": [657985.78042416, 5711862.6251028]}, 
-            "properties": {"Name": "Pierre Giraud", "Country":"France", "City":"Chambéry"}},
-            { "type": "Feature", "geometry": {"type": "Point", "coordinates": [742941.93818208, 5861818.9477535]}, 
-            "properties": {"Name": "Stéphane Brunner", "Country":"Switzerland", "City":"Paudex"}},
-            { "type": "Feature", "geometry": {"type": "Point", "coordinates": [736082.61064069, 5908165.4649505]},
-            "properties": {"Name": "Frédéric Junod", "Country":"Switzerland", "City":"Montagny-près-Yverdon"}},
-            { "type": "Feature", "geometry": {"type": "Point", "coordinates": [771595.97057525, 5912284.7041793]},
-            "properties": {"Name": "Cédric Moullet", "Country":"Switzerland", "City":"Payerne"}},
-            { "type": "Feature", "geometry": {"type": "Point", "coordinates": [744205.23922364, 5861277.319748]},
-            "properties": {"Name": "Benoit Quartier", "Country":"Switzerland", "City":"Lutry"}},
-            { "type": "Feature", "geometry": {"type": "Point", "coordinates": [1717430.147101, 5954568.7127565]}, 
-            "properties": {"Name": "Andreas Hocevar", "Country":"Austria", "City":"Graz"}},
-            { "type": "Feature", "geometry": {"type": "Point", "coordinates": [-12362007.067301,5729082.2365672]}, 
-            "properties": {"Name": "Tim Schaub", "Country":"United States of America", "City":"Bozeman"}}
-       ]
-    };
-
-    var reader = new OpenLayers.Format.GeoJSON();
-    
-    return reader.read(features);
-}
+}
\ No newline at end of file

Modified: sandbox/cmoullet/openlayers/examples/mobile-layers.js
===================================================================
--- sandbox/cmoullet/openlayers/examples/mobile-layers.js	2011-03-31 09:52:33 UTC (rev 11831)
+++ sandbox/cmoullet/openlayers/examples/mobile-layers.js	2011-03-31 11:22:15 UTC (rev 11832)
@@ -37,6 +37,11 @@
                     "http://vmap0.tiles.osgeo.org/wms/vmap0", {layers: 'basic'}, {isBaseLayer: true, transitionEffect: 'resize'})
         ]
     });
+
+    // allow testing of specific renderers via "?renderer=Canvas", etc
+    var renderer = OpenLayers.Util.getParameters(window.location.href).renderer;
+    renderer = (renderer) ? [renderer] : OpenLayers.Layer.Vector.prototype.renderers;
+
     var sundials = new OpenLayers.Layer.Vector("KML", {
         projection: map.displayProjection,
         strategies: [new OpenLayers.Strategy.Fixed()],
@@ -46,15 +51,12 @@
                 extractStyles: true,
                 extractAttributes: true
             })
-        })
+        }),
+        renderers: renderer
     });
 
-    // allow testing of specific renderers via "?renderer=Canvas", etc
-    var renderer = OpenLayers.Util.getParameters(window.location.href).renderer;
-    renderer = (renderer) ? [renderer] : OpenLayers.Layer.Vector.prototype.renderers;
-
     var wfs = new OpenLayers.Layer.Vector("States", {
-        strategies: [new OpenLayers.Strategy.BBOX()],
+        strategies: [new OpenLayers.Strategy.Fixed()],
         protocol: new OpenLayers.Protocol.WFS({
             url: "http://demo.opengeo.org/geoserver/wfs",
             featureType: "states",

Modified: sandbox/cmoullet/openlayers/examples/mobile-sencha.html
===================================================================
--- sandbox/cmoullet/openlayers/examples/mobile-sencha.html	2011-03-31 09:52:33 UTC (rev 11831)
+++ sandbox/cmoullet/openlayers/examples/mobile-sencha.html	2011-03-31 11:22:15 UTC (rev 11832)
@@ -1,122 +1,142 @@
 <!DOCTYPE html>
 <html>
-    <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" />
-        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
-        <title>OpenLayers with Sencha Touch</title>
-        <script src="../lib/OpenLayers.js?mobile"></script>
-        <link rel="stylesheet" href="style.mobile.css" type="text/css">
-        <link rel="stylesheet" href="http://dev.sencha.com/deploy/touch/resources/css/sencha-touch.css">
-        <script src="http://dev.sencha.com/deploy/touch/sencha-touch.js"></script>
-        <script src="mobile-sencha.js"></script>
-        <script src="mobile-base.js"></script>
-        <style>
-            .searchList {
-                min-height: 150px;
-            }
-            .close-btn {
-                position: absolute;
-                right: 10px;
-                top: 10px;
-            }
-            img.minus {
-                -webkit-mask-image: url(img/minus1.png);
-            }
-            img.layers {
-                -webkit-mask-image: url(img/list.png);
-            }
-            .gx-layer-item {
-                margin-left: 10px;
-            }
-            #map {
-                width: 100%;
-                height: 100%;
-            }
-            .olControlAttribution {
-                font-size: 10px;
-                bottom: 5px;
-                right: 5px;
-            }
-            #title, #tags, #shortdesc {
-                display: none;
-            }
-        </style>
-        <script>
+<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"/>
+    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+    <title>OpenLayers with Sencha Touch</title>
+    <script src="../lib/OpenLayers.js?mobile"></script>
+    <link rel="stylesheet" href="style.mobile.css" type="text/css">
+    <link rel="stylesheet" href="http://dev.sencha.com/deploy/touch/resources/css/sencha-touch.css">
+    <script src="http://dev.sencha.com/deploy/touch/sencha-touch.js"></script>
+    <script src="mobile-sencha.js"></script>
+    <script src="mobile-base.js"></script>
+    <style>
+        .searchList {
+            min-height: 150px;
+        }
 
+        .close-btn {
+            position: absolute;
+            right: 10px;
+            top: 10px;
+        }
+
+        img.minus {
+            -webkit-mask-image: url(img/minus1.png);
+        }
+
+        img.layers {
+            -webkit-mask-image: url(img/list.png);
+        }
+
+        .gx-layer-item {
+            margin-left: 10px;
+        }
+
+        #map {
+            width: 100%;
+            height: 100%;
+        }
+
+        .olControlAttribution {
+            font-size: 10px;
+            bottom: 5px;
+            right: 5px;
+        }
+
+        #title, #tags, #shortdesc {
+            display: none;
+        }
+    </style>
+    <script>
+        var featurePopup;
+
         var app = new Ext.Application({
             name: "ol",
             launch: function() {
                 this.viewport = new Ext.Panel({
                     fullscreen: true,
-                    dockedItems: [{
-                        dock: "bottom",
-                        xtype: "toolbar",
-                        ui: "light",
-                        layout: {
-                            pack: "center"
-                        },
-                        items: [{
-                            iconCls: "search",
-                            iconMask: true,
-                            handler: function(){
-                                // this is the app
-                                if (!app.searchFormPopupPanel) {
-                                    app.searchFormPopupPanel = new App.SearchFormPopupPanel({
-                                        map: map
-                                    });
+                    dockedItems: [
+                        {
+                            dock: "bottom",
+                            xtype: "toolbar",
+                            ui: "light",
+                            layout: {
+                                pack: "center"
+                            },
+                            items: [
+                                {
+                                    iconCls: "search",
+                                    iconMask: true,
+                                    handler: function() {
+                                        // this is the app
+                                        if (!app.searchFormPopupPanel) {
+                                            app.searchFormPopupPanel = new App.SearchFormPopupPanel({
+                                                map: map
+                                            });
+                                        }
+                                        app.searchFormPopupPanel.show('pop');
+                                    }
+                                },
+                                {
+                                    iconCls: "locate",
+                                    iconMask: true,
+                                    handler: function() {
+                                        var geolocate = map.getControlsBy("id", "locate-control")[0];
+                                        if (geolocate.active) {
+                                            geolocate.getCurrentLocation();
+                                        } else {
+                                            geolocate.activate();
+                                        }
+                                    }
+                                },
+                                {
+                                    xtype: "spacer"
+                                },
+                                {
+                                    iconMask: true,
+                                    iconCls: "add",
+                                    handler: function() {
+                                        map.zoomIn();
+                                    }
+                                },
+                                {
+                                    iconMask: true,
+                                    iconCls: "minus",
+                                    handler: function() {
+                                        map.zoomOut();
+                                    }
+                                },
+                                {
+                                    xtype: "spacer"
+                                },
+                                {
+                                    iconMask: true,
+                                    iconCls: "layers",
+                                    handler: function() {
+                                        if (!app.popup) {
+                                            app.popup = new Ext.Panel({
+                                                floating: true,
+                                                modal: true,
+                                                centered: true,
+                                                hideOnMaskTap: true,
+                                                width: 240,
+                                                items: [
+                                                    {
+                                                        xtype: 'app_layerlist',
+                                                        map: map
+                                                    }
+                                                ],
+                                                scroll: 'vertical'
+                                            });
+                                        }
+                                        app.popup.show('pop');
+                                    }
                                 }
-                                app.searchFormPopupPanel.show('pop');
-                            }
-                        }, {
-                            iconCls: "locate",
-                            iconMask: true,
-                            handler: function() {
-                                var geolocate = map.getControlsBy("id", "locate-control")[0];
-                                if (geolocate.active) {
-                                    geolocate.getCurrentLocation();
-                                } else {
-                                    geolocate.activate();
-                                }
-                            }
-                        }, {
-                            xtype: "spacer"
-                        }, {
-                            iconMask: true,
-                            iconCls: "add",
-                            handler: function() {
-                                map.zoomIn();
-                            }
-                        }, {
-                            iconMask: true,
-                            iconCls: "minus",
-                            handler: function() {
-                                map.zoomOut();
-                            }
-                        }, {
-                            xtype: "spacer"
-                        }, {
-                            iconMask: true,
-                            iconCls: "layers",
-                            handler: function() {
-                                if (!app.popup) {
-                                    app.popup = new Ext.Panel({
-                                        floating: true,
-                                        modal: true,
-                                        centered: true,
-                                        hideOnMaskTap: true,
-                                        width: 240,
-                                        items: [{
-                                            xtype: 'app_layerlist',
-                                            map: map
-                                        }],
-                                        scroll: 'vertical'
-                                    });
-                                }
-                                app.popup.show('pop');
-                            }
-                        }]
-                    }],
+                            ]
+                        }
+                    ],
                     items: [
                         {
                             xtype: "component",
@@ -124,7 +144,7 @@
                             monitorResize: true,
                             id: "map",
                             listeners: {
-                                render: init,
+                                render: instantiateMap,
                                 resize: function() {
                                     if (window.map) {
                                         map.updateSize();
@@ -136,15 +156,50 @@
                 });
             }
         });
-        </script>
-    </head>
-    <body>
-        <h1 id="title">OpenLayers with Sencha Touch</h1>
-        <div id="tags">
-            mobile, sencha touch
-        </div>
-        <p id="shortdesc">
-            Using Sencha Touch to display an OpenLayers map.
-        </p>
-    </body>
+        var instantiateMap = function() {
+            init();
+            var selectControl = new OpenLayers.Control.SelectFeature(map.getLayersByName("Sprinters")[0], {
+                onSelect: function(feature) {
+                    var htmlContent = "";
+                    for (var property in feature.data) {
+                        if (feature.data[property] != 'undefined') {
+                            htmlContent = htmlContent + feature.data[property] + "<br>";
+                        }
+                    }
+                    if (featurePopup) {
+                        featurePopup.destroy();
+                    }
+                    featurePopup = new Ext.Panel({
+                        floating: true,
+                        modal: true,
+                        centered: true,
+                        hideOnMaskTap: true,
+                        width: 240,
+                        html: htmlContent,
+                        scroll: 'vertical'
+                    });
+                    featurePopup.show();
+
+                },
+                clickout: false,
+                toggle: false,
+                multiple: false,
+                hover: false,
+                box: true
+            });
+            map.addControl(selectControl);
+            selectControl.activate();
+        }
+    </script>
+</head>
+<body>
+<h1 id="title">OpenLayers with Sencha Touch</h1>
+
+<div id="tags">
+    mobile, sencha touch
+</div>
+<p id="shortdesc">
+    Using Sencha Touch to display an OpenLayers map.
+</p>
+</body>
 </html>

Modified: sandbox/cmoullet/openlayers/lib/OpenLayers/Handler/Feature.js
===================================================================
--- sandbox/cmoullet/openlayers/lib/OpenLayers/Handler/Feature.js	2011-03-31 09:52:33 UTC (rev 11831)
+++ sandbox/cmoullet/openlayers/lib/OpenLayers/Handler/Feature.js	2011-03-31 11:22:15 UTC (rev 11832)
@@ -56,6 +56,13 @@
      * {<OpenLayers.Pixel>} The location of the last mouseup.
      */
     up: null,
+
+    /**
+     * Property: touch
+     * {Boolean} When a touchstart event is fired, touch will be true and all
+     *     mouse related listeners will do nothing.
+     */
+    touch: false,
     
     /**
      * Property: clickTolerance
@@ -129,10 +136,34 @@
      * {Boolean} Let the event propagate.
      */
     touchstart: function(evt) {
+        if(!this.touch) {
+            this.touch =  true;
+            this.map.events.un({
+                mousedown: this.mousedown,
+                mouseup: this.mouseup,
+                mousemove: this.mousemove,
+                click: this.click,
+                dblclick: this.dblclick,
+                scope: this
+            });
+        }
         return this.mousedown(evt);
     },
 
     /**
+     * Method: touchmove
+     * Handle touchmove events. We just prevent the browser default behavior,
+     *    for Android Safari not to select text when moving the finger after
+     *    selecting a feature.
+     *
+     * Parameters:
+     * evt - {Event}
+     */
+    touchmove: function(evt) {
+        OpenLayers.Event.stop(evt);
+    },
+
+    /**
      * Method: mousedown
      * Handle mouse down.  Stop propagation if a feature is targeted by this
      *     event (stops map dragging during feature selection).
@@ -251,6 +282,11 @@
             this.lastFeature = null;
         }
         if(this.feature) {
+            if(evt.type === "touchstart") {
+                // stop the event to prevent Android Safari from
+                // "flashing" the map div
+                OpenLayers.Event.stop(evt);
+            }
             var inNew = (this.feature != this.lastFeature);
             if(this.geometryTypeMatches(this.feature)) {
                 // in to a feature
@@ -349,6 +385,7 @@
             this.lastFeature = null;
             this.down = null;
             this.up = null;
+            this.touch = false;
             this.map.events.un({
                 "removelayer": this.handleMapEvents,
                 "changelayer": this.handleMapEvents,

Modified: sandbox/cmoullet/openlayers/lib/OpenLayers/Handler/Point.js
===================================================================
--- sandbox/cmoullet/openlayers/lib/OpenLayers/Handler/Point.js	2011-03-31 09:52:33 UTC (rev 11831)
+++ sandbox/cmoullet/openlayers/lib/OpenLayers/Handler/Point.js	2011-03-31 11:22:15 UTC (rev 11832)
@@ -219,6 +219,7 @@
             this.layer.destroy(false);
         }
         this.layer = null;
+        this.touch = false;
         return true;
     },
     
@@ -385,9 +386,6 @@
      * {Boolean} Allow event propagation
      */
     mousedown: function(evt) {
-        if (this.touch) {
-            return;
-        }
         return this.down(evt);
     },
 
@@ -402,7 +400,18 @@
      * {Boolean} Allow event propagation
      */
     touchstart: function(evt) {
-        this.touch = true;
+        if (!this.touch) {
+            this.touch = true;
+            // unregister mouse listeners
+            this.map.events.un({
+                mousedown: this.mousedown,
+                mouseup: this.mouseup,
+                mousemove: this.mousemove,
+                click: this.click,
+                dblclick: this.dblclick,
+                scope: this
+            });
+        }
         this.lastTouchPx = evt.xy;
         return this.down(evt);
     },
@@ -418,9 +427,6 @@
      * {Boolean} Allow event propagation
      */
     mousemove: function(evt) {
-        if (this.touch) {
-            return;
-        }
         return this.move(evt);
     },
 
@@ -450,9 +456,6 @@
      * {Boolean} Allow event propagation
      */
     mouseup: function(evt) {
-        if (this.touch) {
-            return;
-        }
         return this.up(evt);
     },
 

Modified: sandbox/cmoullet/openlayers/lib/OpenLayers/Util.js
===================================================================
--- sandbox/cmoullet/openlayers/lib/OpenLayers/Util.js	2011-03-31 09:52:33 UTC (rev 11831)
+++ sandbox/cmoullet/openlayers/lib/OpenLayers/Util.js	2011-03-31 11:22:15 UTC (rev 11832)
@@ -1614,7 +1614,7 @@
  *     * "opera" -- Opera
  *     * "msie"  -- Internet Explorer
  *     * "safari" -- Safari
- *     * "firefox" -- FireFox
+ *     * "firefox" -- Firefox
  *     * "mozilla" -- Mozilla
  */
 OpenLayers.BROWSER_NAME = (function() {
@@ -1647,7 +1647,7 @@
  *           * 'opera' -- Opera
  *           * 'msie'  -- Internet Explorer
  *           * 'safari' -- Safari
- *           * 'firefox' -- FireFox
+ *           * 'firefox' -- Firefox
  *           * 'mozilla' -- Mozilla
  * 
  *          If we are unable to property identify the browser, we 

Modified: sandbox/cmoullet/openlayers/tests/Handler/Feature.html
===================================================================
--- sandbox/cmoullet/openlayers/tests/Handler/Feature.html	2011-03-31 09:52:33 UTC (rev 11831)
+++ sandbox/cmoullet/openlayers/tests/Handler/Feature.html	2011-03-31 11:22:15 UTC (rev 11832)
@@ -53,7 +53,7 @@
         
     }
     function test_events(t) {
-        t.plan(30);
+        t.plan(35);
         
         var map = new OpenLayers.Map('map');
         var control = new OpenLayers.Control();
@@ -64,8 +64,8 @@
  
         // list below events that should be handled (events) and those
         // that should not be handled (nonevents) by the handler
-        var events = ["mousedown", "mouseup", "mousemove", "click", "dblclick", "touchstart"];
-        var nonevents = ["mouseout", "resize", "focus", "blur"];
+        var events = ["mousedown", "mouseup", "mousemove", "click", "dblclick", "touchstart", "touchmove"];
+        var nonevents = ["mouseout", "resize", "focus", "blur", "touchend"];
         map.events.registerPriority = function(type, obj, func) {
             var output = func();
             // Don't listen for setEvent handlers (#902)
@@ -255,6 +255,82 @@
         map.events.triggerEvent('touchstart', evtPx);
     }
 
+    function test_touchstart(t) {
+        // a test to verify that the touchstart function does
+        // unregister the mouse listeners when it's called the
+        // first time
+
+        t.plan(4);
+
+        // set up
+
+        var map = new OpenLayers.Map('map', {controls: []});
+        var control = new OpenLayers.Control();
+        map.addControl(control);
+        var layer = new OpenLayers.Layer();
+        map.addLayer(layer);
+
+        var handler = new OpenLayers.Handler.Feature(control, layer, {});
+        handler.mousedown = function() {}; // mock mousedown
+        handler.activate();
+
+        function allRegistered() {
+            var eventTypes = ['mousedown', 'mouseup', 'mousemove', 'click', 'dblclick'],
+                eventType,
+                listeners,
+                listener,
+                flag;
+            for(var i=0, ilen=eventTypes.length; i<ilen; i++) {
+                flag =  false;
+                eventType = eventTypes[i];
+                listeners = map.events.listeners[eventType];
+                for(var j=0, jlen=listeners.length; j<jlen; j++) {
+                    listener = listeners[j];
+                    if(listener.func === handler[eventType] && listener.obj === handler) {
+                        flag = true;
+                        break;
+                    }
+                }
+                if(!flag) {
+                    return false;
+                }
+            }
+            return true;
+        }
+
+        function noneRegistered() {
+            var eventTypes = ['mousedown', 'mouseup', 'mousemove', 'click', 'dblclick'],
+                eventType,
+                listeners,
+                listener;
+            for(var i=0, ilen=eventTypes.length; i<ilen; i++) {
+                eventType = eventTypes[i];
+                listeners = map.events.listeners[eventType];
+                for(var j=0, jlen=listeners.length; j<jlen; j++) {
+                    listener = listeners[j];
+                    if(listener.func === handler[eventType] && listener.obj === handler) {
+                        return false;
+                    }
+                }
+            }
+            return true;
+        }
+
+        // test
+
+        t.ok(allRegistered(), 'mouse listeners are registered');
+        handler.touchstart({xy: new OpenLayers.Pixel(0, 0)});
+        t.ok(noneRegistered(), 'mouse listeners are unregistered');
+        t.ok(handler.touch, 'handler.touch is set');
+
+        handler.deactivate();
+        t.ok(!handler.touch, 'handler.touch is not set');
+
+        // tear down
+
+        map.destroy();
+    }
+
     function test_deactivate(t) {
         t.plan(3);
         var map = new OpenLayers.Map('map');

Modified: sandbox/cmoullet/openlayers/tests/Handler/Point.html
===================================================================
--- sandbox/cmoullet/openlayers/tests/Handler/Point.html	2011-03-31 09:52:33 UTC (rev 11831)
+++ sandbox/cmoullet/openlayers/tests/Handler/Point.html	2011-03-31 11:22:15 UTC (rev 11832)
@@ -417,6 +417,88 @@
              "handler.point is null after destroy");
     }
 
+    function test_touchstart(t) {
+        // a test to verify that the touchstart function does
+        // unregister the mouse listeners when it's called the
+        // first time
+
+        t.plan(4);
+
+        // set up
+
+        var map = new OpenLayers.Map("map", {
+            resolutions: [1]
+        });
+        var layer = new OpenLayers.Layer.Vector("foo", {
+            maxExtent: new OpenLayers.Bounds(-10, -10, 10, 10),
+            isBaseLayer: true
+        });
+        map.addLayer(layer);
+        var control = new OpenLayers.Control({});
+        var handler = new OpenLayers.Handler.Point(control, {});
+        control.handler = handler;
+        map.addControl(control);
+        map.setCenter(new OpenLayers.LonLat(0, 0), 0);
+        handler.activate();
+
+        function allRegistered() {
+            var eventTypes = ['mousedown', 'mouseup', 'mousemove', 'click', 'dblclick'],
+                eventType,
+                listeners,
+                listener,
+                flag;
+            for(var i=0, ilen=eventTypes.length; i<ilen; i++) {
+                flag =  false;
+                eventType = eventTypes[i];
+                listeners = map.events.listeners[eventType];
+                for(var j=0, jlen=listeners.length; j<jlen; j++) {
+                    listener = listeners[j];
+                    if(listener.func === handler[eventType] && listener.obj === handler) {
+                        flag = true;
+                        break;
+                    }
+                }
+                if(!flag) {
+                    return false;
+                }
+            }
+            return true;
+        }
+
+        function noneRegistered() {
+            var eventTypes = ['mousedown', 'mouseup', 'mousemove', 'click', 'dblclick'],
+                eventType,
+                listeners,
+                listener;
+            for(var i=0, ilen=eventTypes.length; i<ilen; i++) {
+                eventType = eventTypes[i];
+                listeners = map.events.listeners[eventType];
+                for(var j=0, jlen=listeners.length; j<jlen; j++) {
+                    listener = listeners[j];
+                    if(listener.func === handler[eventType] && listener.obj === handler) {
+                        return false;
+                    }
+                }
+            }
+            return true;
+        }
+
+        // test
+
+        t.ok(allRegistered(), 'mouse listeners are registered');
+        handler.touchstart({xy: new OpenLayers.Pixel(0, 0)});
+        t.ok(noneRegistered(), 'mouse listeners are unregistered');
+        t.ok(handler.touch, 'handler.touch is set');
+
+        handler.deactivate();
+        t.ok(!handler.touch, 'handler.touch is not set');
+
+        // tear down
+
+        map.destroy();
+    }
+
+
     //
     // Sequence tests
     // 



More information about the Commits mailing list