From ced9b3159ac8e799543b004db08a93f5922a9e60 Mon Sep 17 00:00:00 2001
From: Matthew Amato <matt.amato@gmail.com>
Date: Wed, 15 Apr 2015 20:29:58 -0400
Subject: [PATCH] Fix KML wrapping GroundOverlays

Replace `convertLongitudeRange` with `negativePiToPi` as discussed in #2624.

Fixes #2624
---
 Source/DataSources/KmlDataSource.js    |  4 ++--
 Specs/DataSources/KmlDataSourceSpec.js | 18 ++++++++++++++++++
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/Source/DataSources/KmlDataSource.js b/Source/DataSources/KmlDataSource.js
index a4759abcc3f..b1986838948 100644
--- a/Source/DataSources/KmlDataSource.js
+++ b/Source/DataSources/KmlDataSource.js
@@ -1413,13 +1413,13 @@ define([
                 var north = queryNumericValue(latLonBox, 'north', namespaces.kml);
 
                 if (defined(west)) {
-                    west = CesiumMath.convertLongitudeRange(CesiumMath.toRadians(west));
+                    west = CesiumMath.negativePiToPi(CesiumMath.toRadians(west));
                 }
                 if (defined(south)) {
                     south = CesiumMath.negativePiToPi(CesiumMath.toRadians(south));
                 }
                 if (defined(east)) {
-                    east = CesiumMath.convertLongitudeRange(CesiumMath.toRadians(east));
+                    east = CesiumMath.negativePiToPi(CesiumMath.toRadians(east));
                 }
                 if (defined(north)) {
                     north = CesiumMath.negativePiToPi(CesiumMath.toRadians(north));
diff --git a/Specs/DataSources/KmlDataSourceSpec.js b/Specs/DataSources/KmlDataSourceSpec.js
index 7d16b0f754a..38d14242165 100644
--- a/Specs/DataSources/KmlDataSourceSpec.js
+++ b/Specs/DataSources/KmlDataSourceSpec.js
@@ -668,6 +668,24 @@ defineSuite([
         });
     });
 
+    it('GroundOverlay: Handles wrapping longitude.', function() {
+        var kml = '<?xml version="1.0" encoding="UTF-8"?>\
+        <GroundOverlay>\
+            <LatLonBox>\
+                <west>-180</west>\
+                <south>-90</south>\
+                <east>180</east>\
+                <north>90</north>\
+            </LatLonBox>\
+        </GroundOverlay>';
+
+        return KmlDataSource.load(parser.parseFromString(kml, "text/xml")).then(function(dataSource) {
+            var entity = dataSource.entities.values[0];
+            expect(entity.polygon).toBeUndefined();
+            expect(entity.rectangle.coordinates.getValue()).toEqual(Rectangle.fromDegrees(-180, -90, 180, 90));
+        });
+    });
+
     it('GroundOverlay: Sets polygon coordinates for gx:LatLonQuad', function() {
         var kml = '<?xml version="1.0" encoding="UTF-8"?>\
         <GroundOverlay xmlns="http://www.opengis.net/kml/2.2"\