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)


git-svn-id: http://svn.openlayers.org/trunk/openlayers@6494 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
crschmidt
2008-03-12 12:49:47 +00:00
parent 98e7bd3db6
commit 819825d8c3

View File

@@ -343,18 +343,48 @@ OpenLayers.Format.KML = OpenLayers.Class(OpenLayers.Format.XML, {
break; break;
case "iconstyle": case "iconstyle":
// set scale
var scale = parseFloat(this.parseProperty(styleTypeNode,
"*", "scale") || 1);
// set default width and height of icon
var width = 32 * scale;
var height = 32 * scale;
var iconNode = this.getElementsByTagNameNS(styleTypeNode, var iconNode = this.getElementsByTagNameNS(styleTypeNode,
"*", "*",
"Icon")[0]; "Icon")[0];
// set default width and height of icon
style["graphicWidth"] = 32;
style["graphicHeight"] = 32;
if (iconNode) { if (iconNode) {
var href = this.parseProperty(iconNode, "*", "href"); var href = this.parseProperty(iconNode, "*", "href");
if (href) { if (href) {
var w = this.parseProperty(iconNode, "*", "w");
var h = this.parseProperty(iconNode, "*", "h");
// Settings for Google specific icons that are 64x64
// We set the width and height to 64 and halve the
// scale to prevent icons from being too big
var google = "http://maps.google.com/mapfiles/kml";
if (OpenLayers.String.startsWith(
href, google) && !w && !h) {
w = 64;
h = 64;
scale = scale / 2;
}
// if only dimension is defined, make sure the
// other one has the same value
w = w || h;
h = h || w;
if (w) {
width = parseInt(w) * scale;
}
if (h) {
height = parseInt(h) * scale;
}
// support for internal icons // support for internal icons
// (/root://icons/palette-x.png) // (/root://icons/palette-x.png)
// x and y tell the position on the palette: // x and y tell the position on the palette:
@@ -379,17 +409,6 @@ OpenLayers.Format.KML = OpenLayers.Class(OpenLayers.Format.XML, {
+ palette + "/icon" + pos + file_extension; + palette + "/icon" + pos + file_extension;
} }
var w = this.parseProperty(iconNode, "*", "w");
if (w) {
style["graphicWidth"] = parseInt(w);
}
var h = this.parseProperty(iconNode, "*", "h");
if (h) {
style["graphicHeight"] = parseInt(h);
}
style["graphicOpacity"] = 1; // fully opaque style["graphicOpacity"] = 1; // fully opaque
style["externalGraphic"] = href; style["externalGraphic"] = href;
} }
@@ -402,36 +421,36 @@ OpenLayers.Format.KML = OpenLayers.Class(OpenLayers.Format.XML, {
"*", "*",
"hotSpot")[0]; "hotSpot")[0];
if (hotSpotNode) { if (hotSpotNode) {
var x = hotSpotNode.getAttribute("x"); var x = parseFloat(hotSpotNode.getAttribute("x"));
var y = hotSpotNode.getAttribute("y"); var y = parseFloat(hotSpotNode.getAttribute("y"));
var xUnits = hotSpotNode.getAttribute("xunits"); var xUnits = hotSpotNode.getAttribute("xunits");
if (xUnits == "pixels") { if (xUnits == "pixels") {
style["graphicXOffset"] = parseInt(x); style["graphicXOffset"] = -x * scale;
} }
else if (xUnits == "insetPixels") { else if (xUnits == "insetPixels") {
style["graphicXOffset"] = style["graphicWidth"] style["graphicXOffset"] = -width + (x * scale);
- parseInt(x);
} }
else if (xUnits == "fraction") { else if (xUnits == "fraction") {
style["graphicXOffset"] = style["graphicWidth"] style["graphicXOffset"] = -width * x;
* parseFloat(x);
} }
var yUnits = hotSpotNode.getAttribute("yunits"); var yUnits = hotSpotNode.getAttribute("yunits");
if (yUnits == "pixels") { if (yUnits == "pixels") {
style["graphicYOffset"] = parseInt(y); style["graphicYOffset"] = -height + (y * scale) + 1;
} }
else if (yUnits == "insetPixels") { else if (yUnits == "insetPixels") {
style["graphicYOffset"] = style["graphicHeight"] style["graphicYOffset"] = -(y * scale) + 1;
- parseInt(y);
} }
else if (yUnits == "fraction") { else if (yUnits == "fraction") {
style["graphicYOffset"] = style["graphicHeight"] style["graphicYOffset"] = -height * (1 - y) + 1;
* parseFloat(y);
} }
} }
style["graphicWidth"] = width;
style["graphicHeight"] = height;
break; break;
case "balloonstyle": case "balloonstyle":
var balloonStyle = OpenLayers.Util.getXmlNodeValue( var balloonStyle = OpenLayers.Util.getXmlNodeValue(
styleTypeNode); styleTypeNode);
@@ -529,7 +548,7 @@ OpenLayers.Format.KML = OpenLayers.Class(OpenLayers.Format.XML, {
"*", "*",
"Style")[0]; "Style")[0];
if (inlineStyleNode) { if (inlineStyleNode) {
var inlineStyle= this.parseStyle(styleNode); var inlineStyle= this.parseStyle(inlineStyleNode);
if (inlineStyle) { if (inlineStyle) {
feature.style = OpenLayers.Util.extend({}, feature.style = OpenLayers.Util.extend({},
feature.style); feature.style);