OpenLayers OpenLayers

Ticket #1402: drag.patch

File drag.patch, 8.3 kB (added by tschaub, 10 months ago)

smooth GDragging

  • lib/OpenLayers/Map.js

    old new  
    13171317     * Parameters: 
    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()); 
    13301336 
    13311337        // adjust 
    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        } 
    13431349 
  • lib/OpenLayers/Control/DragPan.js

    old new  
    4646    */ 
    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     
    5856    /** 
  • lib/OpenLayers/Control/ModifyFeature.js

    old new  
    297297     *     selected feature. 
    298298     */ 
    299299    selectFeature: function(object) { 
    300         this.feature = object.feature; 
    301         this.resetVertices(); 
    302         this.dragControl.activate(); 
    303         this.onModificationStart(this.feature); 
    304         this.layer.events.triggerEvent("beforefeaturemodified",  
    305                                        {feature: this.feature}); 
     300        var cont = this.layer.events.triggerEvent( 
     301            "beforefeaturemodified", {feature: this.feature} 
     302        ); 
     303        if(cont !== false) { 
     304            this.feature = object.feature; 
     305            this.resetVertices(); 
     306            this.dragControl.activate(); 
     307            this.onModificationStart(this.feature); 
     308        } 
    306309    }, 
    307310 
    308311    /** 
  • lib/OpenLayers/Layer/Google.js

    old new  
    7575     *     other maps, etc.  
    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    /**  
    8087     * Constructor: OpenLayers.Layer.Google 
     
    106113        try { 
    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            } 
    109123 
     124 
    110125            // move the ToS and branding stuff up to the pane 
    111126            // thanks a *mil* Erik for thinking of this 
    112127            var poweredBy = this.div.lastChild; 
     
    123138            termsOfUse.style.right = ""; 
    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                
    137145    }, 
     
    343351     * dY - {Integer} 
    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); 
     354        this.dragObject.moveBy(new GSize(-dX, dY)); 
    349355    }, 
    350     
     356 
    351357    /** 
    352358     * APIMethod: getMapObjectCenter 
    353359     *  
  • lib/OpenLayers/Layer/EventPane.js

    old new  
    241241 
    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); 
    250249                        var zoom = this.getMapObjectZoomFromOLZoom(newZoom); 
     
    281280            var moPixel = this.getMapObjectPixelFromOLPixel(viewPortPx); 
    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; 
    298285    }, 
  • examples/spherical-mercator.html

    old new  
    1111    </style> 
    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 
    1717    <script src="../lib/OpenLayers.js"></script>