Changeset 6494
- Timestamp:
- 03/12/08 08:49:47 (9 months ago)
- Files:
-
- trunk/openlayers/lib/OpenLayers/Format/KML.js (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/openlayers/lib/OpenLayers/Format/KML.js
r6313 r6494 344 344 break; 345 345 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 346 354 var iconNode = this.getElementsByTagNameNS(styleTypeNode, 347 355 "*", 348 356 "Icon")[0]; 349 350 // set default width and height of icon351 style["graphicWidth"] = 32;352 style["graphicHeight"] = 32;353 354 357 if (iconNode) { 355 358 var href = this.parseProperty(iconNode, "*", "href"); 356 359 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 } 357 387 358 388 // support for internal icons … … 380 410 } 381 411 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 393 412 style["graphicOpacity"] = 1; // fully opaque 394 413 style["externalGraphic"] = href; … … 403 422 "hotSpot")[0]; 404 423 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")); 407 426 408 427 var xUnits = hotSpotNode.getAttribute("xunits"); 409 428 if (xUnits == "pixels") { 410 style["graphicXOffset"] = parseInt(x);429 style["graphicXOffset"] = -x * scale; 411 430 } 412 431 else if (xUnits == "insetPixels") { 413 style["graphicXOffset"] = style["graphicWidth"] 414 - parseInt(x); 432 style["graphicXOffset"] = -width + (x * scale); 415 433 } 416 434 else if (xUnits == "fraction") { 417 style["graphicXOffset"] = style["graphicWidth"] 418 * parseFloat(x); 435 style["graphicXOffset"] = -width * x; 419 436 } 420 437 421 438 var yUnits = hotSpotNode.getAttribute("yunits"); 422 439 if (yUnits == "pixels") { 423 style["graphicYOffset"] = parseInt(y);440 style["graphicYOffset"] = -height + (y * scale) + 1; 424 441 } 425 442 else if (yUnits == "insetPixels") { 426 style["graphicYOffset"] = style["graphicHeight"] 427 - parseInt(y); 443 style["graphicYOffset"] = -(y * scale) + 1; 428 444 } 429 445 else if (yUnits == "fraction") { 430 style["graphicYOffset"] = style["graphicHeight"] 431 * parseFloat(y); 446 style["graphicYOffset"] = -height * (1 - y) + 1; 432 447 } 433 448 } 449 450 style["graphicWidth"] = width; 451 style["graphicHeight"] = height; 434 452 break; 453 435 454 case "balloonstyle": 436 455 var balloonStyle = OpenLayers.Util.getXmlNodeValue( … … 530 549 "Style")[0]; 531 550 if (inlineStyleNode) { 532 var inlineStyle= this.parseStyle( styleNode);551 var inlineStyle= this.parseStyle(inlineStyleNode); 533 552 if (inlineStyle) { 534 553 feature.style = OpenLayers.Util.extend({},
