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:
@@ -343,18 +343,48 @@ OpenLayers.Format.KML = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
|
||||
break;
|
||||
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,
|
||||
"*",
|
||||
"Icon")[0];
|
||||
|
||||
// set default width and height of icon
|
||||
style["graphicWidth"] = 32;
|
||||
style["graphicHeight"] = 32;
|
||||
|
||||
if (iconNode) {
|
||||
var href = this.parseProperty(iconNode, "*", "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
|
||||
// (/root://icons/palette-x.png)
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
||||
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["externalGraphic"] = href;
|
||||
}
|
||||
@@ -402,36 +421,36 @@ OpenLayers.Format.KML = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
"*",
|
||||
"hotSpot")[0];
|
||||
if (hotSpotNode) {
|
||||
var x = hotSpotNode.getAttribute("x");
|
||||
var y = hotSpotNode.getAttribute("y");
|
||||
var x = parseFloat(hotSpotNode.getAttribute("x"));
|
||||
var y = parseFloat(hotSpotNode.getAttribute("y"));
|
||||
|
||||
var xUnits = hotSpotNode.getAttribute("xunits");
|
||||
if (xUnits == "pixels") {
|
||||
style["graphicXOffset"] = parseInt(x);
|
||||
style["graphicXOffset"] = -x * scale;
|
||||
}
|
||||
else if (xUnits == "insetPixels") {
|
||||
style["graphicXOffset"] = style["graphicWidth"]
|
||||
- parseInt(x);
|
||||
style["graphicXOffset"] = -width + (x * scale);
|
||||
}
|
||||
else if (xUnits == "fraction") {
|
||||
style["graphicXOffset"] = style["graphicWidth"]
|
||||
* parseFloat(x);
|
||||
style["graphicXOffset"] = -width * x;
|
||||
}
|
||||
|
||||
var yUnits = hotSpotNode.getAttribute("yunits");
|
||||
if (yUnits == "pixels") {
|
||||
style["graphicYOffset"] = parseInt(y);
|
||||
style["graphicYOffset"] = -height + (y * scale) + 1;
|
||||
}
|
||||
else if (yUnits == "insetPixels") {
|
||||
style["graphicYOffset"] = style["graphicHeight"]
|
||||
- parseInt(y);
|
||||
style["graphicYOffset"] = -(y * scale) + 1;
|
||||
}
|
||||
else if (yUnits == "fraction") {
|
||||
style["graphicYOffset"] = style["graphicHeight"]
|
||||
* parseFloat(y);
|
||||
style["graphicYOffset"] = -height * (1 - y) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
style["graphicWidth"] = width;
|
||||
style["graphicHeight"] = height;
|
||||
break;
|
||||
|
||||
case "balloonstyle":
|
||||
var balloonStyle = OpenLayers.Util.getXmlNodeValue(
|
||||
styleTypeNode);
|
||||
@@ -529,7 +548,7 @@ OpenLayers.Format.KML = OpenLayers.Class(OpenLayers.Format.XML, {
|
||||
"*",
|
||||
"Style")[0];
|
||||
if (inlineStyleNode) {
|
||||
var inlineStyle= this.parseStyle(styleNode);
|
||||
var inlineStyle= this.parseStyle(inlineStyleNode);
|
||||
if (inlineStyle) {
|
||||
feature.style = OpenLayers.Util.extend({},
|
||||
feature.style);
|
||||
|
||||
Reference in New Issue
Block a user