Cope with undefined baseURI in ol.format.KML

This commit is contained in:
Tom Payne
2014-02-04 16:15:21 +01:00
parent cd1355a699
commit 17fba61bf2
+26 -16
View File
@@ -371,10 +371,10 @@ ol.format.KML.readFlatCoordinates_ = function(node) {
*/ */
ol.format.KML.readStyleUrl_ = function(node) { ol.format.KML.readStyleUrl_ = function(node) {
var s = goog.string.trim(ol.xml.getAllTextContent(node, false)); var s = goog.string.trim(ol.xml.getAllTextContent(node, false));
if (goog.isNull(node.baseURI)) { if (goog.isDefAndNotNull(node.baseURI)) {
return s;
} else {
return goog.Uri.resolve(node.baseURI, s).toString(); return goog.Uri.resolve(node.baseURI, s).toString();
} else {
return s;
} }
}; };
@@ -387,10 +387,10 @@ ol.format.KML.readStyleUrl_ = function(node) {
*/ */
ol.format.KML.readURI_ = function(node) { ol.format.KML.readURI_ = function(node) {
var s = ol.xml.getAllTextContent(node, false); var s = ol.xml.getAllTextContent(node, false);
if (goog.isNull(node.baseURI)) { if (goog.isDefAndNotNull(node.baseURI)) {
return goog.string.trim(s);
} else {
return goog.Uri.resolve(node.baseURI, goog.string.trim(s)).toString(); return goog.Uri.resolve(node.baseURI, goog.string.trim(s)).toString();
} else {
return goog.string.trim(s);
} }
}; };
@@ -1465,8 +1465,13 @@ ol.format.KML.prototype.readSharedStyle_ = function(node, objectStack) {
if (!goog.isNull(id)) { if (!goog.isNull(id)) {
var style = ol.format.KML.readStyle_(node, objectStack); var style = ol.format.KML.readStyle_(node, objectStack);
if (goog.isDef(style)) { if (goog.isDef(style)) {
var baseURI = goog.isNull(node.baseURI) ? '' : node.baseURI; var styleUri;
this.sharedStyles_[baseURI + '#' + id] = [style]; if (goog.isDefAndNotNull(node.baseURI)) {
styleUri = goog.Uri.resolve(node.baseURI, '#' + id).toString();
} else {
styleUri = '#' + id;
}
this.sharedStyles_[styleUri] = [style];
} }
} }
}; };
@@ -1487,23 +1492,28 @@ ol.format.KML.prototype.readSharedStyleMap_ = function(node, objectStack) {
if (!goog.isDef(styleObject)) { if (!goog.isDef(styleObject)) {
return; return;
} }
var baseURI = goog.isNull(node.baseURI) ? '' : node.baseURI;
var style = /** @type {ol.style.Style} */ var style = /** @type {ol.style.Style} */
(goog.object.get(styleObject, 'style', null)); (goog.object.get(styleObject, 'style', null));
var styleUri;
if (goog.isDefAndNotNull(node.baseURI)) {
styleUri = goog.Uri.resolve(node.baseURI, '#' + id).toString();
} else {
styleUri = '#' + id;
}
if (!goog.isNull(style)) { if (!goog.isNull(style)) {
this.sharedStyles_[baseURI + '#' + id] = [style]; this.sharedStyles_[styleUri] = [style];
} }
var styleUrl = /** @type {string|undefined} */ var styleUrl = /** @type {string|undefined} */
(goog.object.get(styleObject, 'styleUrl')); (goog.object.get(styleObject, 'styleUrl'));
if (goog.isDef(styleUrl)) { if (goog.isDef(styleUrl)) {
var styleUri; var styleUrlUri;
if (goog.isNull(node.baseURI)) { if (goog.isDefAndNotNull(node.baseURI)) {
styleUri = '#' + goog.string.trim(styleUrl); styleUrlUri = goog.Uri.resolve(node.baseURI, styleUrl).toString();
} else { } else {
styleUri = goog.Uri.resolve(baseURI, styleUrl).toString(); styleUrlUri = '#' + goog.string.trim(styleUrl).replace(/^#/, '');
} }
goog.asserts.assert(styleUri in this.sharedStyles_); goog.asserts.assert(styleUrlUri in this.sharedStyles_);
this.sharedStyles_[baseURI + '#' + id] = this.sharedStyles_[styleUri]; this.sharedStyles_[styleUri] = this.sharedStyles_[styleUrlUri];
} }
} }
}; };