OpenLayers OpenLayers

Changeset 6494

Show
Ignore:
Timestamp:
03/12/08 08:49:47 (9 months ago)
Author:
crschmidt
Message:

Apply patch from rdewit to fix parsing of hotSpot values on Icon objects
in KML styles. This fixes issues reported with the location of icons when
using KML styling. r=me (Closes #1426)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/openlayers/lib/OpenLayers/Format/KML.js

    r6313 r6494  
    344344                    break; 
    345345                case "iconstyle": 
     346                    // set scale 
     347                    var scale = parseFloat(this.parseProperty(styleTypeNode,  
     348                                                          "*", "scale") || 1); 
     349   
     350                    // set default width and height of icon 
     351                    var width = 32 * scale; 
     352                    var height = 32 * scale; 
     353 
    346354                    var iconNode = this.getElementsByTagNameNS(styleTypeNode,  
    347355                                               "*",  
    348356                                               "Icon")[0]; 
    349  
    350                     // set default width and height of icon 
    351                     style["graphicWidth"] = 32; 
    352                     style["graphicHeight"] = 32; 
    353  
    354357                    if (iconNode) { 
    355358                        var href = this.parseProperty(iconNode, "*", "href"); 
    356359                        if (href) {                                                    
     360 
     361                            var w = this.parseProperty(iconNode, "*", "w"); 
     362                            var h = this.parseProperty(iconNode, "*", "h"); 
     363 
     364                            // Settings for Google specific icons that are 64x64 
     365                            // We set the width and height to 64 and halve the 
     366                            // scale to prevent icons from being too big 
     367                            var google = "http://maps.google.com/mapfiles/kml"; 
     368                            if (OpenLayers.String.startsWith( 
     369                                                 href, google) && !w && !h) { 
     370                                w = 64; 
     371                                h = 64; 
     372                                scale = scale / 2; 
     373                            } 
     374                                 
     375                            // if only dimension is defined, make sure the 
     376                            // other one has the same value 
     377                            w = w || h; 
     378                            h = h || w; 
     379 
     380                            if (w) { 
     381                                width = parseInt(w) * scale; 
     382                            } 
     383 
     384                            if (h) { 
     385                                height = parseInt(h) * scale; 
     386                            } 
    357387 
    358388                            // support for internal icons  
     
    380410                            } 
    381411 
    382  
    383                             var w = this.parseProperty(iconNode, "*", "w"); 
    384                             if (w) { 
    385                                 style["graphicWidth"] = parseInt(w); 
    386                             } 
    387  
    388                             var h = this.parseProperty(iconNode, "*", "h"); 
    389                             if (h) { 
    390                                 style["graphicHeight"] = parseInt(h); 
    391                             } 
    392  
    393412                            style["graphicOpacity"] = 1; // fully opaque 
    394413                            style["externalGraphic"] = href; 
     
    403422                                               "hotSpot")[0]; 
    404423                    if (hotSpotNode) { 
    405                         var x = hotSpotNode.getAttribute("x"); 
    406                         var y = hotSpotNode.getAttribute("y"); 
     424                        var x = parseFloat(hotSpotNode.getAttribute("x")); 
     425                        var y = parseFloat(hotSpotNode.getAttribute("y")); 
    407426 
    408427                        var xUnits = hotSpotNode.getAttribute("xunits"); 
    409428                        if (xUnits == "pixels") { 
    410                             style["graphicXOffset"] = parseInt(x)
     429                            style["graphicXOffset"] = -x * scale
    411430                        } 
    412431                        else if (xUnits == "insetPixels") { 
    413                             style["graphicXOffset"] = style["graphicWidth"]  
    414                                                           - parseInt(x); 
     432                            style["graphicXOffset"] = -width + (x * scale); 
    415433                        } 
    416434                        else if (xUnits == "fraction") { 
    417                             style["graphicXOffset"] = style["graphicWidth"]  
    418                                                           * parseFloat(x); 
     435                            style["graphicXOffset"] = -width * x; 
    419436                        } 
    420437 
    421438                        var yUnits = hotSpotNode.getAttribute("yunits"); 
    422439                        if (yUnits == "pixels") { 
    423                             style["graphicYOffset"] = parseInt(y)
     440                            style["graphicYOffset"] = -height + (y * scale) + 1
    424441                        } 
    425442                        else if (yUnits == "insetPixels") { 
    426                             style["graphicYOffset"] = style["graphicHeight"]  
    427                                                           - parseInt(y); 
     443                            style["graphicYOffset"] = -(y * scale) + 1; 
    428444                        } 
    429445                        else if (yUnits == "fraction") { 
    430                             style["graphicYOffset"] = style["graphicHeight"]  
    431                                                           * parseFloat(y); 
     446                            style["graphicYOffset"] =  -height * (1 - y) + 1; 
    432447                        } 
    433448                    } 
     449 
     450                    style["graphicWidth"] = width; 
     451                    style["graphicHeight"] = height; 
    434452                    break; 
     453 
    435454                case "balloonstyle": 
    436455                    var balloonStyle = OpenLayers.Util.getXmlNodeValue( 
     
    530549                                                       "Style")[0]; 
    531550                if (inlineStyleNode) { 
    532                     var inlineStyle= this.parseStyle(styleNode); 
     551                    var inlineStyle= this.parseStyle(inlineStyleNode); 
    533552                    if (inlineStyle) { 
    534553                        feature.style = OpenLayers.Util.extend({},