Fix styleUrl parsing
This commit is contained in:
@@ -262,14 +262,22 @@
|
|||||||
-112.2626894973474,36.10149062823369,630 </coordinates>
|
-112.2626894973474,36.10149062823369,630 </coordinates>
|
||||||
</LineString>
|
</LineString>
|
||||||
</Placemark>
|
</Placemark>
|
||||||
<Placemark>
|
<Placemark>
|
||||||
<name>Blue Icon</name>
|
<name>Blue Icon</name>
|
||||||
<description>Just another blue icon.</description>
|
<description>Just another blue icon.</description>
|
||||||
<styleUrl>data/kml/styles.kml#blueIcons</styleUrl>
|
<styleUrl>data/kml/styles.kml#blueIcons</styleUrl>
|
||||||
<Point>
|
<Point>
|
||||||
<coordinates>-112.292238941097,36.09520916122063,630</coordinates>
|
<coordinates>-112.292238941097,36.09520916122063,630</coordinates>
|
||||||
</Point>
|
</Point>
|
||||||
</Placemark>
|
</Placemark>
|
||||||
|
<Placemark>
|
||||||
|
<name>Sun Icon</name>
|
||||||
|
<description>Just another sun icon.</description>
|
||||||
|
<styleUrl>data/kml/styles.kml#sunIconMap</styleUrl>
|
||||||
|
<Point>
|
||||||
|
<coordinates>-112.292238941097,36.15520916122063,630</coordinates>
|
||||||
|
</Point>
|
||||||
|
</Placemark>
|
||||||
</Folder>
|
</Folder>
|
||||||
</Document>
|
</Document>
|
||||||
</kml>
|
</kml>
|
||||||
|
|||||||
@@ -17,5 +17,16 @@ http://kml-samples.googlecode.com/svn/trunk/kml/Style/styles.kml
|
|||||||
</IconStyle>
|
</IconStyle>
|
||||||
</Style>
|
</Style>
|
||||||
|
|
||||||
|
<StyleMap id="sunIconMap">
|
||||||
|
<Pair>
|
||||||
|
<key>normal</key>
|
||||||
|
<styleUrl>#blueIcons</styleUrl>
|
||||||
|
</Pair>
|
||||||
|
<Pair>
|
||||||
|
<key>highlight</key>
|
||||||
|
<styleUrl>#blueIcons</styleUrl>
|
||||||
|
</Pair>
|
||||||
|
</StyleMap>
|
||||||
|
|
||||||
</Document>
|
</Document>
|
||||||
</kml>
|
</kml>
|
||||||
|
|||||||
+19
-21
@@ -148,12 +148,8 @@ ol.parser.KML = function(opt_options) {
|
|||||||
obj.features.push(feature);
|
obj.features.push(feature);
|
||||||
}
|
}
|
||||||
} else if (goog.isDef(container.geometry)) {
|
} else if (goog.isDef(container.geometry)) {
|
||||||
var styleUrl = container.properties['styleUrl'];
|
this.parseStyleUrl(obj, container.properties['styleUrl']);
|
||||||
if (goog.isDef(styleUrl)) {
|
|
||||||
if (!goog.string.startsWith(styleUrl, '#')) {
|
|
||||||
obj.links.push({href: styleUrl});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
feature = new ol.Feature(container.properties);
|
feature = new ol.Feature(container.properties);
|
||||||
if (!goog.isNull(id)) {
|
if (!goog.isNull(id)) {
|
||||||
feature.setId(id);
|
feature.setId(id);
|
||||||
@@ -172,23 +168,17 @@ ol.parser.KML = function(opt_options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
var symbolizers = undefined;
|
var symbolizers = undefined;
|
||||||
if (goog.isDef(container.styleUrl)) {
|
if (goog.isDef(container.styles)) {
|
||||||
feature.set('styleUrl', container.styleUrl);
|
|
||||||
|
|
||||||
} else if (goog.isDef(container.styles)) {
|
|
||||||
symbolizers = container.styles[0].symbolizers;
|
symbolizers = container.styles[0].symbolizers;
|
||||||
|
|
||||||
} else if (goog.isDef(container.styleMaps)) {
|
} else if (goog.isDef(container.styleMaps)) {
|
||||||
var styleMap = container.styleMaps[0];
|
var styleMap = container.styleMaps[0];
|
||||||
|
|
||||||
for (var i = 0, ii = styleMap.pairs.length; i < ii; i++) {
|
for (var i = 0, ii = styleMap.pairs.length; i < ii; i++) {
|
||||||
var pair = styleMap.pairs[i];
|
var pair = styleMap.pairs[i];
|
||||||
|
|
||||||
if (pair.key === 'normal') {
|
if (pair.key === 'normal') {
|
||||||
|
|
||||||
if (goog.isDef(pair.styleUrl)) {
|
if (goog.isDef(pair.styleUrl)) {
|
||||||
|
this.parseStyleUrl(obj, pair.styleUrl);
|
||||||
feature.set('styleUrl', pair.styleUrl);
|
feature.set('styleUrl', pair.styleUrl);
|
||||||
|
|
||||||
} else if (goog.isDef(pair.styles)) {
|
} else if (goog.isDef(pair.styles)) {
|
||||||
symbolizers = pair.styles[0].symbolizers;
|
symbolizers = pair.styles[0].symbolizers;
|
||||||
}
|
}
|
||||||
@@ -377,12 +367,6 @@ ol.parser.KML = function(opt_options) {
|
|||||||
this.readChildNodes(node, pair);
|
this.readChildNodes(node, pair);
|
||||||
obj['pairs'].push(pair);
|
obj['pairs'].push(pair);
|
||||||
},
|
},
|
||||||
'key': function(node, obj) {
|
|
||||||
obj.key = this.getChildValue(node);
|
|
||||||
},
|
|
||||||
'styleUrl': function(node, obj) {
|
|
||||||
obj.styleUrl = this.getChildValue(node);
|
|
||||||
},
|
|
||||||
'Style': function(node, obj) {
|
'Style': function(node, obj) {
|
||||||
if (this.extractStyles === true) {
|
if (this.extractStyles === true) {
|
||||||
if (!obj['styles']) {
|
if (!obj['styles']) {
|
||||||
@@ -960,6 +944,20 @@ ol.parser.KML.prototype.readFeaturesFromObject =
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse the link contained in styleUrl, if it exists.
|
||||||
|
* @param {Object} obj The returned object from the parser.
|
||||||
|
* @param {String} styleUrl The style url to parse.
|
||||||
|
*/
|
||||||
|
ol.parser.KML.prototype.parseStyleUrl = function(obj, styleUrl) {
|
||||||
|
if (goog.isDef(styleUrl)) {
|
||||||
|
if (!goog.string.startsWith(styleUrl, '#')) {
|
||||||
|
obj.links.push({href: styleUrl});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Array} deferreds List of deferred instances.
|
* @param {Array} deferreds List of deferred instances.
|
||||||
* @param {Object} obj The returned object from the parser.
|
* @param {Object} obj The returned object from the parser.
|
||||||
@@ -1033,7 +1031,7 @@ ol.parser.KML.prototype.read = function(data, opt_callback) {
|
|||||||
function(datas) {
|
function(datas) {
|
||||||
for (var i = 0, ii = obj.features.length; i < ii; ++i) {
|
for (var i = 0, ii = obj.features.length; i < ii; ++i) {
|
||||||
var feature = obj.features[i];
|
var feature = obj.features[i];
|
||||||
this.applyStyle_(feature, obj['styles']);
|
this.applyStyle_(feature, obj['styles'], obj['styleMaps']);
|
||||||
}
|
}
|
||||||
opt_callback.call(null, obj);
|
opt_callback.call(null, obj);
|
||||||
}, function() {
|
}, function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user