Changeset 5795
- Timestamp:
- 01/17/08 02:20:49 (1 year ago)
- Files:
-
- sandbox/rdewit/kml/lib/OpenLayers/Format/KML.js (modified) (23 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
sandbox/rdewit/kml/lib/OpenLayers/Format/KML.js
r5794 r5795 150 150 } 151 151 152 153 // Fetch external links <NetworkLink> and <Link> 154 this.fetchLinks(data); 155 156 // Parse internal Style information 157 this.parseStyles(data); 158 159 // Parse placemarks (features) 160 this.parseFeatures(data); 161 162 // Reverse drawing order of features (this seems to be standard in KML) 163 if (!recursion && this.reverseFeatures) { 164 this.features.reverse(); 165 } 166 167 return this.features; 168 }, 169 170 fetchLinks: function(data) { 152 171 153 172 var urlNodes = this.getElementsByTagNameNS(data, 154 173 this.internalns, 155 " Url");174 "NetworkLink"); 156 175 var numurls = urlNodes.length; 157 176 var urls = new Array(numurls); … … 160 179 this.internalns, 161 180 "href")[0]; 162 //console.info(url);163 181 if(hrefNode) { 164 182 var href = OpenLayers.Util.getXmlNodeValue(hrefNode); … … 168 186 } 169 187 170 //console.info(href);171 188 if (OpenLayers.ProxyHost 172 189 && OpenLayers.String.startsWith(href, "http")) { … … 191 208 this.internalns, 192 209 "href")[0]; 193 //console.info(link);194 210 if(hrefNode) { 195 211 var href = OpenLayers.Util.getXmlNodeValue(hrefNode); … … 211 227 } 212 228 } 213 214 //215 // Parse internal Style information216 this.parseStyles(data);217 218 219 // Loop through all Placemark nodes and parse them.220 // This will create a list of features221 var featureNodes = this.getElementsByTagNameNS(data,222 this.internalns,223 "Placemark");224 var numFeatures = featureNodes.length;225 var features = new Array(numFeatures);226 //console.info("read, numfeatures: " + numFeatures);227 228 for(var i=0; i<numFeatures; i++) {229 //var feature = this.parseFeature(featureNodes[i]);230 var featureNode = featureNodes[i];231 var feature = OpenLayers.Format.GML.prototype.parseFeature.apply(232 this,[featureNode]) ;233 234 //console.info(feature);235 if(feature) {236 // give feature default style237 feature.style = OpenLayers.Util.extend({},238 OpenLayers.Feature.Vector.style["default"]);239 240 if (feature.attributes.styleUrl) {241 var newStyle = this.getStyle(feature.attributes.styleUrl);242 243 if (newStyle) {244 feature.style = OpenLayers.Util.extend(feature.style,245 newStyle);246 }247 //console.info(feature.style);248 }249 250 // Make sure that <Style> nodes within a placemark are251 // processed as well: add a styleUrl attribute to the feature.252 var styleNode = this.getElementsByTagNameNS(featureNode,253 this.internalns,254 "Style")[0];255 if (styleNode) {256 var style = this.parseStyle(styleNode);257 //console.info(style.name, style);258 if (style) {259 feature.style = OpenLayers.Util.extend(feature.style,260 style);261 }262 }263 264 // add feature to list of features265 features[i] = feature;266 } else {267 throw "Bad Placemark: " + i;268 }269 }270 271 272 // add new features to existing feature list273 this.features = this.features.concat(features);274 275 276 // Reverse drawing order of features (this seems to be standard in KML)277 if (!recursion && this.reverseFeatures) {278 this.features.reverse();279 }280 281 282 //this.applyStyles();283 284 //console.info(this.styles);285 //console.info("*** RETURN FEATURES ***");286 //console.debug(this.styles);287 return this.features;288 289 //this.timer = setTimeout(this.read(), 200);290 //return this.read();291 229 }, 292 230 … … 327 265 328 266 329 330 267 parseStyles: function(data, baseUrl) { 331 if (!data) { 332 return null; 333 } 334 335 if (!baseUrl) { 336 baseUrl = ""; 337 } 338 339 // Parse Styles 268 // Parse Style nodes first 340 269 var styleNodes = this.getElementsByTagNameNS(data, 341 270 this.internalns, … … 344 273 var numNodes = styleNodes.length; 345 274 var styles = {}; 346 //console.info("numStyles: " + numStyles);347 275 for(var i=0; i<numNodes; i++) { 348 276 var style = this.parseStyle(styleNodes[i]); … … 355 283 } 356 284 357 // Parse StyleMaps 285 // Parse StyleMaps afterwards 358 286 // Only the default or "normal" part of the StyleMap is processed now 359 287 // To do the select or "highlight" bit, we'd need to change lots more … … 371 299 var id = node.getAttribute("id"); 372 300 for (var j=0; j<pairs.length; j++) { 373 pair = pairs[j];301 var pair = pairs[j]; 374 302 375 303 // Use the shortcut in the SLD format to quickly retrieve the 376 304 // value of a node. Maybe it's good to have a method in Util 377 305 // to do this 378 key = OpenLayers.Format.SLD.prototype.parseProperty(pair,306 var key = OpenLayers.Format.SLD.prototype.parseProperty(pair, 379 307 this.internalns, "key"); 380 styleUrl = OpenLayers.Format.SLD.prototype.parseProperty(pair,308 var styleUrl = OpenLayers.Format.SLD.prototype.parseProperty(pair, 381 309 this.internalns, "styleUrl"); 382 310 … … 393 321 } 394 322 395 //console.info("before", this.styles);396 323 OpenLayers.Util.extend(this.styles, styles); 397 324 398 //console.info("after", this.styles);399 325 }, 400 326 … … 415 341 416 342 // only deal with first geometry of this type 417 //console.info(styleTypeNode);418 343 switch (type.toLowerCase()) { 419 344 case "linestyle": 420 colorNode = this.getElementsByTagNameNS(styleTypeNode,345 var colorNode = this.getElementsByTagNameNS(styleTypeNode, 421 346 this.internalns, 422 347 "color")[0]; … … 438 363 } 439 364 440 widthNode = this.getElementsByTagNameNS(styleTypeNode,365 var widthNode = this.getElementsByTagNameNS(styleTypeNode, 441 366 this.internalns, 442 367 "width")[0]; … … 447 372 448 373 case "polystyle": 449 colorNode = this.getElementsByTagNameNS(styleTypeNode,374 var colorNode = this.getElementsByTagNameNS(styleTypeNode, 450 375 this.internalns, 451 376 "color")[0]; … … 456 381 this.regExes.kmlColor); 457 382 458 console.info(matches);459 383 // transparency 460 384 var alpha = matches[1]; … … 470 394 break; 471 395 case "iconstyle": 472 iconNode = this.getElementsByTagNameNS(styleTypeNode,396 var iconNode = this.getElementsByTagNameNS(styleTypeNode, 473 397 this.internalns, 474 398 "Icon")[0]; … … 479 403 480 404 if (iconNode) { 481 hrefNode = this.getElementsByTagNameNS(iconNode,405 var hrefNode = this.getElementsByTagNameNS(iconNode, 482 406 this.internalns, 483 407 "href")[0]; … … 493 417 // list and request the appropriate icon from the 494 418 // google maps website 495 matches = href.match(this.regExes.kmlIconPalette);419 var matches = href.match(this.regExes.kmlIconPalette); 496 420 if (matches) { 497 421 var palette = matches[1]; … … 512 436 513 437 var pos = posY * 8 + posX; 514 href = "http://maps.google.com/mapfiles/kml/pal"438 var href = "http://maps.google.com/mapfiles/kml/pal" 515 439 + palette + "/icon" + pos + file_extension; 516 //console.info(x,y, pos, href);517 440 } 518 441 … … 521 444 this.internalns, 522 445 "w")[0]; 523 w = OpenLayers.Util.getXmlNodeValue(wNode);446 var w = OpenLayers.Util.getXmlNodeValue(wNode); 524 447 525 448 var hNode = this.getElementsByTagNameNS(iconNode, 526 449 this.internalns, 527 450 "h")[0]; 528 h = OpenLayers.Util.getXmlNodeValue(hNode);451 var h = OpenLayers.Util.getXmlNodeValue(hNode); 529 452 530 453 if (w) { … … 544 467 545 468 // hotSpots define the offset for an Icon 546 hotSpotNode = this.getElementsByTagNameNS(styleTypeNode,469 var hotSpotNode = this.getElementsByTagNameNS(styleTypeNode, 547 470 this.internalns, 548 471 "hotSpot")[0]; … … 576 499 * parseFloat(y); 577 500 } 578 //console.info(x, xUnits, y, yUnits, style["graphicXOffset"],579 // style["graphicYOffset"]);580 501 } 581 502 break; 582 503 case "balloonstyle": 583 balloonStyle = OpenLayers.Util.getXmlNodeValue(styleTypeNode); 504 var balloonStyle = OpenLayers.Util.getXmlNodeValue( 505 styleTypeNode); 584 506 if (balloonStyle) { 585 507 style["balloonStyle"] = balloonStyle.replace( 586 straightBracket, "${$1}"); 587 //console.info(balloonStyle); 508 this.regExes.straightBracket, "${$1}"); 588 509 } 589 510 break; … … 603 524 return style; 604 525 }, 526 527 parseFeatures: function(data) { 528 // Loop through all Placemark nodes and parse them. 529 // This will create a list of features 530 var featureNodes = this.getElementsByTagNameNS(data, 531 this.internalns, 532 "Placemark"); 533 var numFeatures = featureNodes.length; 534 var features = new Array(numFeatures); 535 536 for(var i=0; i<numFeatures; i++) { 537 //var feature = this.parseFeature(featureNodes[i]); 538 var featureNode = featureNodes[i]; 539 var feature = OpenLayers.Format.GML.prototype.parseFeature.apply( 540 this,[featureNode]) ; 541 542 if(feature) { 543 // give feature default style 544 feature.style = OpenLayers.Util.extend({}, 545 OpenLayers.Feature.Vector.style["default"]); 546 547 if (feature.attributes.styleUrl) { 548 var newStyle = this.getStyle(feature.attributes.styleUrl); 549 550 if (newStyle) { 551 feature.style = OpenLayers.Util.extend(feature.style, 552 newStyle); 553 } 554 } 555 556 // Make sure that <Style> nodes within a placemark are 557 // processed as well: add a styleUrl attribute to the feature. 558 var styleNode = this.getElementsByTagNameNS(featureNode, 559 this.internalns, 560 "Style")[0]; 561 if (styleNode) { 562 var style = this.parseStyle(styleNode); 563 if (style) { 564 feature.style = OpenLayers.Util.extend(feature.style, 565 style); 566 } 567 } 568 569 // add feature to list of features 570 features[i] = feature; 571 } else { 572 throw "Bad Placemark: " + i; 573 } 574 } 575 576 577 // add new features to existing feature list 578 this.features = this.features.concat(features); 579 }, 580 581 605 582 606 583 /** … … 622 599 if(child.nodeType == 1) { 623 600 grandchildren = child.childNodes; 624 //console.info(child, child.nodeType);625 //console.info(grandchildren.length);626 601 if(grandchildren.length == 1 || grandchildren.length == 3) { 627 602 var grandchild;
