artmacks / google-maps-utility-library-v3

Automatically exported from code.google.com/p/google-maps-utility-library-v3
Apache License 2.0
0 stars 0 forks source link

Support polygon with inner rings. #257

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Class-googleearth

Support polygon with inner rings.

Additional comments:
I've fixed this my self, and the patch to fix it follows below:
(contributing the normal way for such a small fix seemed to much of a hurdle)

Index: googleearth.js
===================================================================
--- googleearth.js  (revisão 434)
+++ googleearth.js  (cópia de trabalho)
@@ -426,32 +426,37 @@
 /**
  * @param {google.maps.Polygon} polygon the polygon overlay.
  * @private
- */
-GoogleEarth.prototype.createPolygon_ = function(polygon) {
-  var ge = this.instance_;
-  var placemark = this.createPlacemark_(polygon);
-
-  // Create polygon
-  var poly = ge.createPolygon('');
-  placemark.setGeometry(poly);
-
-  //set the style
-  var style = this.createStyle_(polygon);
-  placemark.setStyleSelector(style);
-
-
-  //assume single linearRing
-  var outer = ge.createLinearRing('');
-  poly.setOuterBoundary(outer);
-  var coords = outer.getCoordinates();
-  var path = polygon.getPath().getArray();
-
-  //TODO(jlivni) use getPaths and multiple rings
-  for (var i = 0, latLng; latLng = path[i]; i++) {
-    coords.pushLatLngAlt(latLng.lat(), latLng.lng(), 0);
-  }
-
-  ge.getFeatures().appendChild(placemark);
+ */
+GoogleEarth.prototype.createPolygon_ = function (polygon) {
+    var ge = this.instance_;
+    var placemark = this.createPlacemark_(polygon);
+
+    // Create polygon
+    var poly = ge.createPolygon('');
+    placemark.setGeometry(poly);
+
+    //set the style
+    var style = this.createStyle_(polygon);
+    placemark.setStyleSelector(style);
+
+    
+    var paths = polygon.getPaths().getArray();
+    for (var j = 0, gmPath; gmPath = paths[j]; j++) {
+        var path = gmPath.getArray()
+        var ring = ge.createLinearRing('');
+        var coords = ring.getCoordinates();
+
+        for (var i = 0, latLng; latLng = path[i]; i++) {
+            coords.pushLatLngAlt(latLng.lat(), latLng.lng(), 0);
+        }
+
+        if (j == 0) {
+            poly.setOuterBoundary(ring);
+            continue;
+        }
+        poly.getInnerBoundaries().appendChild(ring);
+    }
+    ge.getFeatures().appendChild(placemark);
 };

*********************************************************
Tip: Star this issue (next to title) to receive notifications of status
changes against this issue, also used as a gauge for how many people are
interested in seeing it resolved.
*********************************************************

Original issue reported on code.google.com by Heitor.Z...@gmail.com on 22 May 2013 at 11:39