[OpenLayers-Commits] r12454 - in addins/timedpointtrack/trunk/lib/OpenLayers: Control Layer

commits-20090109 at openlayers.org commits-20090109 at openlayers.org
Thu Jan 26 09:52:52 EST 2012


Author: openlayersgit
Date: 2012-01-26 06:52:51 -0800 (Thu, 26 Jan 2012)
New Revision: 12454

Modified:
   addins/timedpointtrack/trunk/lib/OpenLayers/Control/TimeSlider.js
   addins/timedpointtrack/trunk/lib/OpenLayers/Control/TimeSliderBar.js
   addins/timedpointtrack/trunk/lib/OpenLayers/Layer/TimedPointTrack.js
Log:
Updating addin to work with latest OpenLayers from master.

Modified: addins/timedpointtrack/trunk/lib/OpenLayers/Control/TimeSlider.js
===================================================================
--- addins/timedpointtrack/trunk/lib/OpenLayers/Control/TimeSlider.js	2012-01-24 08:25:38 UTC (rev 12453)
+++ addins/timedpointtrack/trunk/lib/OpenLayers/Control/TimeSlider.js	2012-01-26 14:52:51 UTC (rev 12454)
@@ -5,6 +5,9 @@
 /**
  * Class: OpenLayers.Control.TimeSlider
  *
+ * This class is not meant to be instantiated directly. It only serves as a
+ * base class for <OpenLayers.Control.TimeSliderBar>.
+ *
  * Inherits from:
  *  - <OpenLayers.Control>
  */
@@ -45,16 +48,26 @@
      * APIMethod: destroy
      */
     destroy: function() {
-        OpenLayers.Control.prototype.destroy.apply(this, arguments);
-        while(this.buttons.length) {
-            var btn = this.buttons.shift();
-            btn.map = null;
-            OpenLayers.Event.stopObservingElement(btn);
+        if (this.map) {
+            this.map.events.unregister("buttonclick", this, this.onButtonClick);
         }
+        this.removeButtons();
         this.buttons = null;
         this.position = null;
+        OpenLayers.Control.prototype.destroy.apply(this, arguments);
     },
 
+    /** 
+     * Method: setMap
+     *
+     * Properties:
+     * map - {<OpenLayers.Map>} 
+     */
+    setMap: function(map) {
+        OpenLayers.Control.prototype.setMap.apply(this, arguments);
+        this.map.events.register("buttonclick", this, this.onButtonClick);
+    },
+
     /**
      * Method: draw
      *
@@ -83,55 +96,26 @@
     },
 
     /**
-     * Method: doubleClick
+     * Method: onButtonClick
      *
      * Parameters:
      * evt - {Event}
-     *
-     * Returns:
-     * {Boolean}
      */
-    doubleClick: function (evt) {
-        OpenLayers.Event.stop(evt);
-        return false;
-    },
-
-    /**
-     * Method: buttonDown
-     *
-     * Parameters:
-     * evt - {Event}
-     */
-    buttonDown: function (evt) {
-        if (!OpenLayers.Event.isLeftClick(evt)) {
-            return;
-        }
-
-        switch (this.btn.action) {
-            case "panup":
-                this.map.pan(0, -this.slideFactor);
-                break;
-            case "pandown":
-                this.map.pan(0, this.slideFactor);
-                break;
-            case "panleft":
-                this.map.pan(-this.slideFactor, 0);
-                break;
-            case "panright":
-                this.map.pan(this.slideFactor, 0);
-                break;
+    onButtonClick: function (evt) {
+        var btn = evt.buttonElement;
+        switch (btn.action) {
             case "timein":
-                if (this.control.now < this.control.time.length) {
-                    this.control.now++;
-                    this.control.setMapTime();
-                    this.control.moveTimeBar();
+                if (this.now < this.time.length) {
+                    this.now++;
+                    this.setMapTime();
+                    this.moveTimeBar();
                 }
                 break;
             case "timeout":
-                if (this.control.now > 0) {
-                    this.control.now--;
-                    this.control.setMapTime();
-                    this.control.moveTimeBar();
+                if (this.now > 0) {
+                    this.now--;
+                    this.setMapTime();
+                    this.moveTimeBar();
                 }
                 break;
         }

Modified: addins/timedpointtrack/trunk/lib/OpenLayers/Control/TimeSliderBar.js
===================================================================
--- addins/timedpointtrack/trunk/lib/OpenLayers/Control/TimeSliderBar.js	2012-01-24 08:25:38 UTC (rev 12453)
+++ addins/timedpointtrack/trunk/lib/OpenLayers/Control/TimeSliderBar.js	2012-01-26 14:52:51 UTC (rev 12454)
@@ -64,13 +64,6 @@
     now: 0,
 
     /**
-     * Constructor: <OpenLayers.Control.PanZoomBar>
-     */
-    initialize: function() {
-        OpenLayers.Control.TimeSlider.prototype.initialize.apply(this, arguments);
-    },
-
-    /**
      * APIMethod: destroy
      */
     destroy: function() {
@@ -93,16 +86,6 @@
     },
 
     /**
-     * Method: setMap
-     *
-     * Parameters:
-     * map - {<OpenLayers.Map>}
-     */
-    setMap: function(map) {
-        OpenLayers.Control.TimeSlider.prototype.setMap.apply(this, arguments);
-    },
-
-    /**
      * Method: redraw
      * clear the div and start over.
      */
@@ -147,14 +130,8 @@
         //we want to add the outer div
         this.div.appendChild(btn);
 
-        OpenLayers.Event.observe(btn, "mousedown",
-            OpenLayers.Function.bindAsEventListener(this.buttonDown, {btn: btn, control: this}));
-        OpenLayers.Event.observe(btn, "dblclick",
-            OpenLayers.Function.bindAsEventListener(this.doubleClick, {btn: btn, control: this}));
-        OpenLayers.Event.observe(btn, "click",
-            OpenLayers.Function.bindAsEventListener(this.doubleClick, {btn: btn, control: this}));
         btn.action = id;
-        btn.map = this.map;
+        btn.className = "olButton";
         btn.slideFactor = this.slideFactor;
 
         //we want to remember/reference the outer div
@@ -182,11 +159,16 @@
         this.slider = slider;
 
         this.sliderEvents = new OpenLayers.Events(this, slider, null, true);
-        if (this.time.length) this.sliderEvents.register("mousedown", this, this.timeBarDown);
-        if (this.time.length) this.sliderEvents.register("mousemove", this, this.timeBarDrag);
-        if (this.time.length) this.sliderEvents.register("mouseup", this, this.timeBarUp);
-        if (this.time.length) this.sliderEvents.register("dblclick", this, this.doubleClick);
-        if (this.time.length) this.sliderEvents.register("click", this, this.doubleClick);
+        if (this.time.length) {
+            this.sliderEvents.on({
+                "touchstart": this.timeBarDown,
+                "touchmove": this.timeBarDrag,
+                "touchend": this.timeBarUp,
+                "mousedown": this.timeBarDown,
+                "mousemove": this.timeBarDrag,
+                "mouseup": this.timeBarUp
+            });
+        }
 
         var sz = new OpenLayers.Size();
         sz.h = this.timeStopHeight * this.time.length+10;
@@ -210,14 +192,9 @@
                         OpenLayers.TimedPointTrackImgPath+"timebar.png");
         }
 
+        div.className = "olButton";
         this.timebarDiv = div;
 
-        this.divEvents = new OpenLayers.Events(this, div, null, true);
-        this.divEvents.register("mousedown", this, this.divClick);
-        this.divEvents.register("mousemove", this, this.passEventToSlider);
-        this.divEvents.register("dblclick", this, this.doubleClick);
-        this.divEvents.register("click", this, this.doubleClick);
-
         this.div.appendChild(div);
 
         this.startTop = parseInt(div.style.top);
@@ -228,6 +205,22 @@
         centered = centered.add(0, this.timeStopHeight * this.time.length+10);
         return centered;
     },
+    
+    /**
+     * Method: onButtonClick
+     *
+     * Parameters:
+     * evt - {Event}
+     */
+    onButtonClick: function(evt) {
+        OpenLayers.Control.TimeSlider.prototype.onButtonClick.apply(this, arguments);
+        if (evt.buttonElement === this.timebarDiv) {
+            this.now = this.timeStopHeight * this.time.length+10 - evt.buttonXY.y;
+            if (this.now < 0) this.now = 0;
+            else if (this.now > this.time.length) this.now = this.time.length;
+            this.setMapTime();
+        }
+    },
 
     /**
      * Method: passEventToSlider
@@ -242,21 +235,6 @@
     },
 
     /**
-     * Method: divClick
-     * Picks up on clicks directly on the timebar div
-     *           and sets the zoom level appropriately.
-     */
-    divClick: function (evt) {
-        if (!OpenLayers.Event.isLeftClick(evt)) {
-            return;
-        }
-        var y = evt.clientY;
-        var top = OpenLayers.Util.pagePosition(evt.object)[1];
-        var levels = Math.floor((y - top)/this.timeStopHeight);
-        OpenLayers.Event.stop(evt);
-    },
-
-    /**
      * Method: timeBarDown
      * event listener for clicks on the slider
      *
@@ -264,9 +242,10 @@
      * evt - {<OpenLayers.Event>}
      */
     timeBarDown:function(evt) {
-        if (!OpenLayers.Event.isLeftClick(evt)) {
+        if (!OpenLayers.Event.isLeftClick(evt) && !OpenLayers.Event.isSingleTouch(evt)) {
             return;
         }
+        this.map.events.register("touchmove", this, this.passEventToSlider);
         this.map.events.register("mousemove", this, this.passEventToSlider);
         this.map.events.register("mouseup", this, this.passEventToSlider);
         this.mouseDragStart = new OpenLayers.Pixel(evt.clientX, evt.clientY);
@@ -316,11 +295,12 @@
      * evt - {<OpenLayers.Event>}
      */
     timeBarUp:function(evt) {
-        if (!OpenLayers.Event.isLeftClick(evt)) {
+        if (!OpenLayers.Event.isLeftClick(evt) && evt.type !== "touchend") {
             return;
         }
         if (this.timeStart) {
             this.div.style.cursor="";
+            this.map.events.unregister("touchmove", this, this.passEventToSlider);
             this.map.events.unregister("mouseup", this, this.passEventToSlider);
             this.map.events.unregister("mousemove", this, this.passEventToSlider);
             var deltaY = (this.timeStart.y+OpenLayers.Control.TimeSlider.Y-10) - (evt.clientY+OpenLayers.Control.TimeSlider.Y-10);

Modified: addins/timedpointtrack/trunk/lib/OpenLayers/Layer/TimedPointTrack.js
===================================================================
--- addins/timedpointtrack/trunk/lib/OpenLayers/Layer/TimedPointTrack.js	2012-01-24 08:25:38 UTC (rev 12453)
+++ addins/timedpointtrack/trunk/lib/OpenLayers/Layer/TimedPointTrack.js	2012-01-26 14:52:51 UTC (rev 12454)
@@ -1,5 +1,8 @@
 /**
- * @requires OpenLayers/Layer/GML.js
+ * @requires OpenLayers/Layer/Vector.js
+ * @requires OpenLayers/Strategy/Fixed.js
+ * @requires OpenLayers/Protocol/HTTP.js
+ * @requires OpenLayers/Format/GeoRSS.js
  */
 
 /**
@@ -8,9 +11,9 @@
  * LineString feature for each pair of two points and marking positions base on time.
  *
  * Inherits from:
- *  - <OpenLayers.Layer.GML> 
+ *  - <OpenLayers.Layer.Vector> 
  */
-OpenLayers.Layer.TimedPointTrack = OpenLayers.Class(OpenLayers.Layer.GML, {
+OpenLayers.Layer.TimedPointTrack = OpenLayers.Class(OpenLayers.Layer.Vector, {
   
     /**
      * APIProperty:
@@ -82,71 +85,74 @@
         var feedCategories = this.feedCategories;
         
         var defaultOptions = {
-            format: OpenLayers.Format.GeoRSS,
-            formatOptions: {
-                georssns: "http://www.georss.org/georss/10",
-                read: function(doc) {
-                    if(typeof doc == "string") { 
-                        doc = OpenLayers.Format.XML.prototype.read.apply(
-                            this, [doc]);
-                    }
-                    
-                    var feedCats = this.getElementsByTagNameNS(doc, '*', 'category');
-                    var cat;
-                    for(var i=0; i<feedCats.length; ++i) {
-                        cat = feedCats[i];
-                        if(cat.parentNode.nodeName == "feed") {
-                            feedCategories[cat.getAttribute("scheme")] = {
-                                term: cat.getAttribute("term"),
-                                label: cat.getAttribute("label")
+            strategies: [new OpenLayers.Strategy.Fixed()],
+            protocol: new OpenLayers.Protocol.HTTP({
+                url: url,
+                format: new OpenLayers.Format.GeoRSS({
+                    georssns: "http://www.georss.org/georss/10",
+                    read: function(doc) {
+                        if(typeof doc == "string") { 
+                            doc = OpenLayers.Format.XML.prototype.read.apply(
+                                this, [doc]);
+                        }
+
+                        var feedCats = this.getElementsByTagNameNS(doc, '*', 'category');
+                        var cat;
+                        for(var i=0; i<feedCats.length; ++i) {
+                            cat = feedCats[i];
+                            if(cat.parentNode.nodeName == "feed") {
+                                feedCategories[cat.getAttribute("scheme")] = {
+                                    term: cat.getAttribute("term"),
+                                    label: cat.getAttribute("label")
+                                }
                             }
                         }
-                    }
-            
-                    var itemlist = this.getElementsByTagNameNS(doc, '*', 'item');
-                    if(itemlist.length == 0) {
-                        itemlist = this.getElementsByTagNameNS(doc, '*', 'entry');
-                    }
 
-                    // create an empty linestring geometry for the track
-                    var pointtrack = new OpenLayers.Geometry.LineString();
-                    var len = itemlist.length;
-                    pointtrack.components = new Array(len);
-                    // Create the features array with an empty feature.
-                    // This feature will get the pointtrack geometry when
-                    // we are done with parsing the rss feed. Doing it
-                    // this way will ensure that the track is on bottom of
-                    // the markers.
-                    var features = [new OpenLayers.Feature.Vector()];
-                    var feature, component, pubDate, prevDate;
-                    for(var i=0; i<len; ++i) {
-                        feature = this.createFeatureFromItem(itemlist[i]);
-                        // add the point to the track
-                        component = feature.geometry;
-                        pubDate = OpenLayers.Date.smartParse(feature.attributes["pubDate"]);
-                        component.dateTime = pubDate;
-                        pointtrack.components[i] = component;
+                        var itemlist = this.getElementsByTagNameNS(doc, '*', 'item');
+                        if(itemlist.length == 0) {
+                            itemlist = this.getElementsByTagNameNS(doc, '*', 'entry');
+                        }
 
+                        // create an empty linestring geometry for the track
+                        var pointtrack = new OpenLayers.Geometry.LineString();
+                        var len = itemlist.length;
+                        pointtrack.components = new Array(len);
+                        // Create the features array with an empty feature.
+                        // This feature will get the pointtrack geometry when
+                        // we are done with parsing the rss feed. Doing it
+                        // this way will ensure that the track is on bottom of
+                        // the markers.
+                        var features = [new OpenLayers.Feature.Vector()];
+                        var feature, component, pubDate, prevDate;
+                        for(var i=0; i<len; ++i) {
+                            feature = this.createFeatureFromItem(itemlist[i]);
+                            // add the point to the track
+                            component = feature.geometry;
+                            pubDate = OpenLayers.Date.smartParse(feature.attributes["pubDate"]);
+                            component.dateTime = pubDate;
+                            pointtrack.components[i] = component;
 
-                        if (i > 1 && feature.attributes["pubDate"]) {
-                            pointtrack.components[i-1].dateTime.duration = pubDate-prevDate;
+
+                            if (i > 1 && feature.attributes["pubDate"]) {
+                                pointtrack.components[i-1].dateTime.duration = pubDate-prevDate;
+                            }
+                            prevDate = pubDate;
+
+                            // only add marker if it has something to say.
+                            if(options.createFeatures !== false && feature.attributes.title != "Untitled") {
+                                features.push(feature);
+                            }
                         }
-                        prevDate = pubDate;
 
-                        // only add marker if it has something to say.
-                        if(options.createFeatures !== false && feature.attributes.title != "Untitled") {
-                            features.push(feature);
+                        features[0].geometry = pointtrack;
+                        features[0].attributes = {
+                            title: "The Track",
+                            description: "This track has been created by connecting the feed entries to a line."
                         }
+                        return features;
                     }
-                    
-                    features[0].geometry = pointtrack;
-                    features[0].attributes = {
-                        title: "The Track",
-                        description: "This track has been created by connecting the feed entries to a line."
-                    }
-                    return features;
-                }
-            }
+                })
+            })
         };
         
         var localOptions = OpenLayers.Util.extend({}, options);
@@ -154,8 +160,8 @@
             options.formatOptions);
         OpenLayers.Util.applyDefaults(localOptions, defaultOptions);
         
-        OpenLayers.Layer.GML.prototype.initialize.apply(this,
-            [name, url, localOptions]);
+        OpenLayers.Layer.Vector.prototype.initialize.apply(this,
+            [name, localOptions]);
 
         OpenLayers.Util.applyDefaults(this.highlightStyle , OpenLayers.Feature.Vector.style["default"]);
         OpenLayers.Util.extend(this.highlightStyle , {pointRadius: 5, graphicName: "square"} );
@@ -254,7 +260,7 @@
      * map - {<OpenLayers.Map>}
      */
     setMap: function(map) {
-        OpenLayers.Layer.GML.prototype.setMap.apply(this, arguments);
+        OpenLayers.Layer.Vector.prototype.setMap.apply(this, arguments);
         // make sure the highlights stays turned on and current with the map zoom
         map.events.register("zoomend", this, this.updateHighlight);
 



More information about the Commits mailing list