Skip to content

Commit

Permalink
Merge pull request #5821 from josh-bernstein/5819_fix_for_empty_icon_tag
Browse files Browse the repository at this point in the history
Fix bug where yellow icon is shown when icon tag is empty #5819
  • Loading branch information
Hannah authored Oct 23, 2017
2 parents 4414fc4 + 4b0b03a commit ae9be87
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Change Log
* Added `eyeSeparation` and `focalLength` properties to `Scene` to configure VR settings. [#5917](https://github.com/AnalyticalGraphicsInc/cesium/pull/5917)
* Added `customTags` property to the UrlTemplateImageryProvider to allow custom keywords in the template URL. [#5696](https://github.com/AnalyticalGraphicsInc/cesium/pull/5696)
* Improved CZML Reference Properties example [#5754](https://github.com/AnalyticalGraphicsInc/cesium/pull/5754)
* 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)

### 1.38 - 2017-10-02

Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu
* [Logilab](https://www.logilab.fr/)
* [Florent Cayré](https://github.com/fcayre/)
* [Novetta](http://www.novetta.com/)
* [Joshua Bernstein](https://github.com/jbernstein/)
* [Natanael Rivera](https://github.com/nrivera-Novetta/)
* [Justin Burr](https://github.com/jburr-nc/)

Expand Down
12 changes: 12 additions & 0 deletions Source/DataSources/KmlDataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,12 @@ define([

var iconNode = queryFirstNode(node, 'Icon', namespaces.kml);
var icon = getIconHref(iconNode, dataSource, sourceUri, uriResolver, false, query);

// If icon tags are present but blank, we do not want to show an icon
if (defined(iconNode) && !defined(icon)) {
icon = false;
}

var x = queryNumericValue(iconNode, 'x', namespaces.gx);
var y = queryNumericValue(iconNode, 'y', namespaces.gx);
var w = queryNumericValue(iconNode, 'w', namespaces.gx);
Expand Down Expand Up @@ -1140,6 +1146,12 @@ define([

if (!defined(billboard.image)) {
billboard.image = dataSource._pinBuilder.fromColor(Color.YELLOW, 64);

// If there were empty <Icon> tags in the KML, then billboard.image was set to false above
// However, in this case, the false value would have been converted to a property afterwards
// Thus, we check if billboard.image is defined with value of false
} else if (billboard.image && !billboard.image.getValue()) {
billboard.image = undefined;
}

var scale = 1.0;
Expand Down
15 changes: 15 additions & 0 deletions Specs/Data/KML/simpleEmptyIconStyle.kml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Placemark>
<Style>
<IconStyle>
</IconStyle>
</Style>
<description><![CDATA[image.png <a href="./image.png">image.png</a><img src="image.png"/>]]></description>
<Point>
<coordinates>1,2,3</coordinates>
</Point>
</Placemark>
</Document>
</kml>
17 changes: 17 additions & 0 deletions Specs/Data/KML/simpleNoIcon.kml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Placemark>
<Style>
<IconStyle>
<Icon>
</Icon>
</IconStyle>
</Style>
<description><![CDATA[image.png <a href="./image.png">image.png</a><img src="image.png"/>]]></description>
<Point>
<coordinates>1,2,3</coordinates>
</Point>
</Placemark>
</Document>
</kml>
11 changes: 11 additions & 0 deletions Specs/Data/KML/simpleNoStyle.kml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Placemark>
<description><![CDATA[image.png <a href="./image.png">image.png</a><img src="image.png"/>]]></description>
<Point>
<coordinates>1,2,3</coordinates>
</Point>
</Placemark>
</Document>
</kml>
36 changes: 36 additions & 0 deletions Specs/DataSources/KmlDataSourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,42 @@ defineSuite([
});
});

it('if load contains <icon> tag with no image included, no image is added', function() {
var dataSource = new KmlDataSource(options);
return loadBlob('Data/KML/simpleNoIcon.kml').then(function(blob) {
return dataSource.load(blob);
}).then(function(source) {
expect(source.entities);
expect(source.entities.values.length).toEqual(1);
expect(source.entities._entities._array.length).toEqual(1);
expect(source.entities._entities._array[0]._billboard._image).toBeUndefined();
});
});

it('if load does not contain icon <style> tag for placemark, default yellow pin does show', function() {
var dataSource = new KmlDataSource(options);
return loadBlob('Data/KML/simpleNoStyle.kml').then(function(blob) {
return dataSource.load(blob);
}).then(function(source) {
expect(source.entities);
expect(source.entities.values.length).toEqual(1);
expect(source.entities._entities._array.length).toEqual(1);
expect(source.entities._entities._array[0]._billboard._image._value).toEqual(dataSource._pinBuilder.fromColor(Color.YELLOW, 64));
});
});

it('if load contains empty <IconStyle> tag for placemark, default yellow pin does show', function() {
var dataSource = new KmlDataSource(options);
return loadBlob('Data/KML/simpleEmptyIconStyle.kml').then(function(blob) {
return dataSource.load(blob);
}).then(function(source) {
expect(source.entities);
expect(source.entities.values.length).toEqual(1);
expect(source.entities._entities._array.length).toEqual(1);
expect(source.entities._entities._array[0]._billboard._image._value).toEqual(dataSource._pinBuilder.fromColor(Color.YELLOW, 64));
});
});

it('sets DataSource name from Document', function() {
var kml = '<?xml version="1.0" encoding="UTF-8"?>\
<Document>\
Expand Down

0 comments on commit ae9be87

Please sign in to comment.