Changeset 6492


Ignore:
Timestamp:
Mar 11, 2008 11:32:17 AM (7 years ago)
Author:
tschaub
Message:

Smooth GDragging at last. Thanks to overstdr for digging up the getDragObject method. With v2.93 and later we no longer get flickers on panning. Non-API smooth dragging is no longer supported. r=crschmidt,me (closes #1402)

Location:
trunk/openlayers
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/openlayers/examples/google.html

    r6491 r6492  
    5858    <div id="map"></div>
    5959
    60     <div id="docs"></div>
     60    <div id="docs">
     61      For best performance, you must be using a version of the Google Maps
     62      API which is v2.93 or higher. In order to use this version of the API,
     63      it is best to simply set your application to use the string "v=2" in
     64      the request, rather than tying your application to an explicit version.
     65    </div>
    6166  </body>
    6267</html>
  • trunk/openlayers/examples/spherical-mercator.html

    r6316 r6492  
    1212
    1313    <script src='http://dev.virtualearth.net/mapcontrol/v3/mapcontrol.js'></script>
    14     <script src='http://maps.google.com/maps?file=api&amp;v=2.82&amp;key=ABQIAAAAjpkAC9ePGem0lIq5XcMiuhR_wWLPFku8Ix9i2SXYRVK3e45q1BQUd_beF8dtzKET_EteAjPdGDwqpQ'></script>
     14    <script src='http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAjpkAC9ePGem0lIq5XcMiuhR_wWLPFku8Ix9i2SXYRVK3e45q1BQUd_beF8dtzKET_EteAjPdGDwqpQ'></script>
    1515    <script src="http://api.maps.yahoo.com/ajaxymap?v=3.0&appid=euzuro-openlayers"></script>
    1616
  • trunk/openlayers/lib/OpenLayers/Control/DragPan.js

    r5614 r6492  
    4747    panMap: function(xy) {
    4848        this.panned = true;
    49         var deltaX = this.handler.last.x - xy.x;
    50         var deltaY = this.handler.last.y - xy.y;
    51         var size = this.map.getSize();
    52         var newXY = new OpenLayers.Pixel(size.w / 2 + deltaX,
    53                                          size.h / 2 + deltaY);
    54         var newCenter = this.map.getLonLatFromViewPortPx( newXY );
    55         this.map.setCenter(newCenter, null, this.handler.dragging);
     49        this.map.pan(
     50            this.handler.last.x - xy.x,
     51            this.handler.last.y - xy.y,
     52            {dragging: this.handler.dragging, animate: false}
     53        );
    5654    },
    5755   
  • trunk/openlayers/lib/OpenLayers/Layer/EventPane.js

    r5627 r6492  
    242242                    if (dragging && this.dragPanMapObject &&
    243243                        this.smoothDragPan) {
    244                         var resolution = this.map.getResolution();
    245                         var dX = (newCenter.lon - oldCenter.lon) / resolution;
    246                         var dY = (newCenter.lat - oldCenter.lat) / resolution;
    247                         this.dragPanMapObject(dX, dY);
     244                        var oldPx = this.map.getViewPortPxFromLonLat(oldCenter);
     245                        var newPx = this.map.getViewPortPxFromLonLat(newCenter);
     246                        this.dragPanMapObject(newPx.x-oldPx.x, oldPx.y-newPx.y);
    248247                    } else {
    249248                        var center = this.getMapObjectLonLatFromOLLonLat(newCenter);
     
    282281            var moLonLat = this.getMapObjectLonLatFromMapObjectPixel(moPixel);
    283282            lonlat = this.getOLLonLatFromMapObjectLonLat(moLonLat);
    284             var xrem = this.map.size.w % 2;
    285             var yrem = this.map.size.h % 2;
    286             if(xrem != 0 || yrem != 0) {
    287                 // odd sized viewport
    288                 var olPx = viewPortPx.add(xrem, yrem);
    289                 var moPx = this.getMapObjectPixelFromOLPixel(olPx);
    290                 var moLoc = this.getMapObjectLonLatFromMapObjectPixel(moPx);
    291                 var olLoc = this.getOLLonLatFromMapObjectLonLat(moLoc);
    292                 // adjust by half a pixel in odd dimension(s)
    293                 lonlat.lon += (olLoc.lon - lonlat.lon) / 2;
    294                 lonlat.lat += (olLoc.lat - lonlat.lat) / 2;
    295             }
    296283        }
    297284        return lonlat;
  • trunk/openlayers/lib/OpenLayers/Layer/Google.js

    r6442 r6492  
    7676     */
    7777    sphericalMercator: false,
     78   
     79    /**
     80     * Property: dragObject
     81     * {GDraggableObject} Since 2.93, Google has exposed the ability to get
     82     *     the maps GDraggableObject. We can now use this for smooth panning
     83     */
     84    dragObject: null,
    7885
    7986    /**
     
    107114            // create GMap, hide nav controls
    108115            this.mapObject = new GMap2( this.div );
     116           
     117            //since v 2.93 getDragObject is now available.
     118            if(typeof this.mapObject.getDragObject == "function") {
     119                this.dragObject = this.mapObject.getDragObject();
     120            } else {
     121                this.dragPanMapObject = null;
     122            }
     123
    109124
    110125            // move the ToS and branding stuff up to the pane
     
    124139            termsOfUse.style.bottom = "";
    125140
    126             //can we do smooth panning? (some versions don't)
    127             if ( !this.mapObject.G || !this.mapObject.G.qb ||
    128                  (typeof this.mapObject.G.qb != "function") ) {
    129 
    130                 this.dragPanMapObject = null;
    131             }
    132 
    133141        } catch (e) {
    134             // do not crash
     142            OpenLayers.Console.error(e);
    135143        }
    136144               
     
    344352     */
    345353    dragPanMapObject: function(dX, dY) {
    346         var newX = this.mapObject.G.left - dX;
    347         var newY = this.mapObject.G.top + dY;
    348         this.mapObject.G.qb(newX, newY);
    349     },
    350    
     354        this.dragObject.moveBy(new GSize(-dX, dY));
     355    },
     356
    351357    /**
    352358     * APIMethod: getMapObjectCenter
  • trunk/openlayers/lib/OpenLayers/Map.js

    r6447 r6492  
    13181318     * dx - {Integer}
    13191319     * dy - {Integer}
    1320      * options - {Object} Only one at this time: "animate", which uses
    1321      *    panTo instead of setCenter. Default is true.
     1320     * options - {Object} Options to configure panning:
     1321     *  - *animate* {Boolean} Use panTo instead of setCenter. Default is true.
     1322     *  - *dragging* {Boolean} Call setCenter with dragging true.  Default is
     1323     *    false.
    13221324     */
    13231325    pan: function(dx, dy, options) {
    1324        
     1326        // this should be pushed to applyDefaults and extend
    13251327        if (!options) {
    1326             options = {animate: true}
    1327         }   
     1328            options = {};
     1329        }
     1330        OpenLayers.Util.applyDefaults(options, {
     1331            animate: true,
     1332            dragging: false
     1333        });
    13281334        // getCenter
    13291335        var centerPx = this.getViewPortPxFromLonLat(this.getCenter());
     
    13321338        var newCenterPx = centerPx.add(dx, dy);
    13331339       
    1334         // only call setCenter if there has been a change
    1335         if (!newCenterPx.equals(centerPx)) {
     1340        // only call setCenter if not dragging or there has been a change
     1341        if (!options.dragging || !newCenterPx.equals(centerPx)) {
    13361342            var newCenterLonLat = this.getLonLatFromViewPortPx(newCenterPx);
    13371343            if (options.animate) {
    13381344                this.panTo(newCenterLonLat);
    13391345            } else {
    1340                 this.setCenter(newCenterLonLat);
     1346                this.setCenter(newCenterLonLat, null, options.dragging);
    13411347            }   
    13421348        }
Note: See TracChangeset for help on using the changeset viewer.