Commits

Frank Wynants  committed 968bec8

Added convenient method to convert a POLYGON VectorFeature to a MULTIPOLYGON.

  • Participants
  • Parent commits 63688d0

Comments (0)

Files changed (1)

File gwt-openlayers-client/src/main/java/org/gwtopenmaps/openlayers/client/feature/VectorFeature.java

 import org.gwtopenmaps.openlayers.client.geometry.Geometry;
 import org.gwtopenmaps.openlayers.client.geometry.LineString;
 import org.gwtopenmaps.openlayers.client.geometry.MultiLineString;
+import org.gwtopenmaps.openlayers.client.geometry.MultiPolygon;
+import org.gwtopenmaps.openlayers.client.geometry.Polygon;
 import org.gwtopenmaps.openlayers.client.layer.VectorOptions;
 import org.gwtopenmaps.openlayers.client.util.Attributes;
 import org.gwtopenmaps.openlayers.client.util.JObjectArray;
 
     /**
      * Convenient method to convert a LINESTRING VectorFeature to a
-     * MULTILINEFEATURE. This method can be used of you are trying to save a
-     * VectorFeature using WFS-T to geoserver and you are seeing a "Error
+     * MULTILINE featureE. This method can be used of you are trying to save a
+     * VectorFeature Line using WFS-T to geoserver and you are seeing a "Error
      * performing insert: java.lang.String cannot be cast to
      * com.vividsolutions.jts.geom.Geometry".
      *
     }
 
     /**
+     * Convenient method to convert a POLYGON VectorFeature to a
+     * MULTIPOLYGON feature. This method can be used of you are trying to save a
+     * VectorFeature Polygon using WFS-T to geoserver and you are seeing a "Error
+     * performing insert: java.lang.String cannot be cast to
+     * com.vividsolutions.jts.geom.Geometry".
+     *
+     * @return true if converting succeeded (if this is not a POLYGON)
+     */
+    public boolean convertPolygonToMultiPolygon() {
+        final Geometry g = this.getGeometry();
+
+        if (g.getClassName().equals(
+                org.gwtopenmaps.openlayers.client.geometry.Geometry.POLYGON_CLASS_NAME)) {
+            final Polygon p = Polygon.narrowToPolygon(g.getJSObject());
+            final MultiPolygon mp = new MultiPolygon(new Polygon[]{p});
+            this.getJSObject().setProperty("geometry", mp.getJSObject());
+
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+
+    /**
      * Moves the feature and redraws it at its new location.
      *
      * @param lonLat the location to which to move the feature