Skip to content

Commit ae9be87

Browse files
author
Hannah
authored
Merge pull request #5821 from josh-bernstein/5819_fix_for_empty_icon_tag
Fix bug where yellow icon is shown when icon tag is empty #5819
2 parents 4414fc4 + 4b0b03a commit ae9be87

File tree

7 files changed

+93
-0
lines changed

7 files changed

+93
-0
lines changed

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Change Log
1414
* Added `eyeSeparation` and `focalLength` properties to `Scene` to configure VR settings. [#5917](https://github.com/AnalyticalGraphicsInc/cesium/pull/5917)
1515
* Added `customTags` property to the UrlTemplateImageryProvider to allow custom keywords in the template URL. [#5696](https://github.com/AnalyticalGraphicsInc/cesium/pull/5696)
1616
* Improved CZML Reference Properties example [#5754](https://github.com/AnalyticalGraphicsInc/cesium/pull/5754)
17+
* Fixed bug with placemarks in imported KML: placemarks with no specified icon would be displayed with default icon. [#5819](https://github.com/AnalyticalGraphicsInc/cesium/issues/5819)
1718

1819
### 1.38 - 2017-10-02
1920

CONTRIBUTORS.md

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu
9393
* [Logilab](https://www.logilab.fr/)
9494
* [Florent Cayré](https://github.com/fcayre/)
9595
* [Novetta](http://www.novetta.com/)
96+
* [Joshua Bernstein](https://github.com/jbernstein/)
9697
* [Natanael Rivera](https://github.com/nrivera-Novetta/)
9798
* [Justin Burr](https://github.com/jburr-nc/)
9899

Source/DataSources/KmlDataSource.js

+12
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,12 @@ define([
729729

730730
var iconNode = queryFirstNode(node, 'Icon', namespaces.kml);
731731
var icon = getIconHref(iconNode, dataSource, sourceUri, uriResolver, false, query);
732+
733+
// If icon tags are present but blank, we do not want to show an icon
734+
if (defined(iconNode) && !defined(icon)) {
735+
icon = false;
736+
}
737+
732738
var x = queryNumericValue(iconNode, 'x', namespaces.gx);
733739
var y = queryNumericValue(iconNode, 'y', namespaces.gx);
734740
var w = queryNumericValue(iconNode, 'w', namespaces.gx);
@@ -1140,6 +1146,12 @@ define([
11401146

11411147
if (!defined(billboard.image)) {
11421148
billboard.image = dataSource._pinBuilder.fromColor(Color.YELLOW, 64);
1149+
1150+
// If there were empty <Icon> tags in the KML, then billboard.image was set to false above
1151+
// However, in this case, the false value would have been converted to a property afterwards
1152+
// Thus, we check if billboard.image is defined with value of false
1153+
} else if (billboard.image && !billboard.image.getValue()) {
1154+
billboard.image = undefined;
11431155
}
11441156

11451157
var scale = 1.0;
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<kml xmlns="http://www.opengis.net/kml/2.2">
3+
<Document>
4+
<Placemark>
5+
<Style>
6+
<IconStyle>
7+
</IconStyle>
8+
</Style>
9+
<description><![CDATA[image.png <a href="./image.png">image.png</a><img src="image.png"/>]]></description>
10+
<Point>
11+
<coordinates>1,2,3</coordinates>
12+
</Point>
13+
</Placemark>
14+
</Document>
15+
</kml>

Specs/Data/KML/simpleNoIcon.kml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<kml xmlns="http://www.opengis.net/kml/2.2">
3+
<Document>
4+
<Placemark>
5+
<Style>
6+
<IconStyle>
7+
<Icon>
8+
</Icon>
9+
</IconStyle>
10+
</Style>
11+
<description><![CDATA[image.png <a href="./image.png">image.png</a><img src="image.png"/>]]></description>
12+
<Point>
13+
<coordinates>1,2,3</coordinates>
14+
</Point>
15+
</Placemark>
16+
</Document>
17+
</kml>

Specs/Data/KML/simpleNoStyle.kml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<kml xmlns="http://www.opengis.net/kml/2.2">
3+
<Document>
4+
<Placemark>
5+
<description><![CDATA[image.png <a href="./image.png">image.png</a><img src="image.png"/>]]></description>
6+
<Point>
7+
<coordinates>1,2,3</coordinates>
8+
</Point>
9+
</Placemark>
10+
</Document>
11+
</kml>

Specs/DataSources/KmlDataSourceSpec.js

+36
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,42 @@ defineSuite([
271271
});
272272
});
273273

274+
it('if load contains <icon> tag with no image included, no image is added', function() {
275+
var dataSource = new KmlDataSource(options);
276+
return loadBlob('Data/KML/simpleNoIcon.kml').then(function(blob) {
277+
return dataSource.load(blob);
278+
}).then(function(source) {
279+
expect(source.entities);
280+
expect(source.entities.values.length).toEqual(1);
281+
expect(source.entities._entities._array.length).toEqual(1);
282+
expect(source.entities._entities._array[0]._billboard._image).toBeUndefined();
283+
});
284+
});
285+
286+
it('if load does not contain icon <style> tag for placemark, default yellow pin does show', function() {
287+
var dataSource = new KmlDataSource(options);
288+
return loadBlob('Data/KML/simpleNoStyle.kml').then(function(blob) {
289+
return dataSource.load(blob);
290+
}).then(function(source) {
291+
expect(source.entities);
292+
expect(source.entities.values.length).toEqual(1);
293+
expect(source.entities._entities._array.length).toEqual(1);
294+
expect(source.entities._entities._array[0]._billboard._image._value).toEqual(dataSource._pinBuilder.fromColor(Color.YELLOW, 64));
295+
});
296+
});
297+
298+
it('if load contains empty <IconStyle> tag for placemark, default yellow pin does show', function() {
299+
var dataSource = new KmlDataSource(options);
300+
return loadBlob('Data/KML/simpleEmptyIconStyle.kml').then(function(blob) {
301+
return dataSource.load(blob);
302+
}).then(function(source) {
303+
expect(source.entities);
304+
expect(source.entities.values.length).toEqual(1);
305+
expect(source.entities._entities._array.length).toEqual(1);
306+
expect(source.entities._entities._array[0]._billboard._image._value).toEqual(dataSource._pinBuilder.fromColor(Color.YELLOW, 64));
307+
});
308+
});
309+
274310
it('sets DataSource name from Document', function() {
275311
var kml = '<?xml version="1.0" encoding="UTF-8"?>\
276312
<Document>\

0 commit comments

Comments
 (0)