OpenLayers OpenLayers

Ticket #1004: safeGoogle.patch

File safeGoogle.patch, 4.6 kB (added by euzuro, 1 year ago)
  • lib/OpenLayers/Layer/Google.js

    old new  
    103103            // create GMap, hide nav controls 
    104104            this.mapObject = new GMap2( this.div ); 
    105105 
    106             // move the ToS and branding stuff up to the pane 
    107             // thanks a *mil* Erik for thinking of this 
    108             var poweredBy = this.div.lastChild; 
    109             this.div.removeChild(poweredBy); 
    110             this.pane.appendChild(poweredBy); 
    111             poweredBy.className = "olLayerGooglePoweredBy gmnoprint"; 
    112             poweredBy.style.left = ""; 
    113             poweredBy.style.bottom = ""; 
     106            // Move GMap's special divs to eventPane so they can be clicked. 
     107            this.moveSpecialDivsToEventPane(); 
    114108 
    115             var termsOfUse = this.div.lastChild; 
    116             this.div.removeChild(termsOfUse); 
    117             this.pane.appendChild(termsOfUse); 
    118             termsOfUse.className = "olLayerGoogleCopyright"; 
    119             termsOfUse.style.right = ""; 
    120             termsOfUse.style.bottom = ""; 
    121  
    122109        } catch (e) { 
    123110            // do not crash 
    124111        } 
     
    157144    }, 
    158145 
    159146    /** 
     147     * Method: moveSpecialDivsToEventPane 
     148     * Move the "Powered By" and "Terms of Use" divs to the eventPane so that 
     149     *     the user will still be able to click on them. 
     150     */ 
     151    moveSpecialDivsToEventPane: function() { 
     152        // move the ToS and branding stuff up to the pane 
     153        // thanks a *mil* Erik for thinking of this 
     154        var poweredBy = this.div.lastChild; 
     155        if (poweredBy) { 
     156            this.div.removeChild(poweredBy); 
     157            this.pane.appendChild(poweredBy); 
     158            poweredBy.className = "olLayerGooglePoweredBy gmnoprint"; 
     159            poweredBy.style.left = ""; 
     160            poweredBy.style.bottom = ""; 
     161        } else { 
     162            var msg = "Google Maps has changed its internal " +  
     163                "workings and has therefore caused an error in " + 
     164                "the OpenLayers.Layer.Google layer. " +  
     165                "Specifically, OL was unable to find the " + 
     166                "'Powered By' div to move it to the eventPane."; 
     167            OpenLayers.Console.warn(msg); 
     168        } 
     169         
     170        var termsOfUse = this.div.lastChild; 
     171        if (termsOfUse) { 
     172            this.div.removeChild(termsOfUse); 
     173            this.pane.appendChild(termsOfUse); 
     174            termsOfUse.className = "olLayerGoogleCopyright"; 
     175            termsOfUse.style.right = ""; 
     176            termsOfUse.style.bottom = ""; 
     177        } else { 
     178            var msg = "Google Maps has changed its internal " +  
     179                "workings and has therefore caused an error in " + 
     180                "the OpenLayers.Layer.Google layer. " +  
     181                "Specifically, OL was unable to find the " + 
     182                "'Terms of Use' div to move it to the eventPane."; 
     183            OpenLayers.Console.warn(msg); 
     184        } 
     185    }, 
     186 
     187    /** 
    160188     * APIMethod: onMapResize 
    161189     *  
    162190     * Parameters: 
     
    273301                var gPoint = this.fromLatLngToDivPixel(gLatLng); 
    274302       
    275303                // locate the sliding "Div" div 
    276                 var div = this.getContainer().firstChild.firstChild; 
     304                var container = this.getContainer(); 
     305 
     306                //it's the grandchild of the container that has the  
     307                // offset information we need. if we can't find the  
     308                // grandchild, we'll just return the divpx. not ideal, but 
     309                // yes better than a script error 
     310                if (container.firstChild && container.firstChild.firstChild) { 
     311                    var div = this.getContainer().firstChild.firstChild; 
    277312   
    278                 // adjust by the offset of "Div" and voila! 
    279                 gPoint.x += div.offsetLeft; 
    280                 gPoint.y += div.offsetTop; 
    281      
     313                    // adjust by the offset of "Div" and voila! 
     314                    gPoint.x += div.offsetLeft; 
     315                    gPoint.y += div.offsetTop; 
     316                } else { 
     317                    var msg = "Google Maps has changed its internal " +  
     318                        "workings and has therefore caused an error in " + 
     319                        "the OpenLayers.Layer.Google layer. " +  
     320                        "Specifically, OL was unable to find the proper " + 
     321                        "grandchild of the container div to translate " + 
     322                        "LatLng to ContainerPixel."; 
     323                    OpenLayers.Console.warn(msg); 
     324                } 
     325 
    282326                return gPoint; 
    283327            }; 
    284328        }