Example #1
0
 @Override
 public KmlGeometry clone() {
   KmlGeometry kmlGeometry = null;
   try {
     kmlGeometry = (KmlGeometry) super.clone();
   } catch (CloneNotSupportedException e) {
     e.printStackTrace();
     return null;
   }
   if (mCoordinates != null) kmlGeometry.mCoordinates = cloneArrayOfGeoPoint(mCoordinates);
   return kmlGeometry;
 }
 @Override
 public Overlay buildOverlay(
     MapView map, Style defaultStyle, Styler styler, KmlDocument kmlDocument) {
   if (mGeometry != null)
     return mGeometry.buildOverlay(map, defaultStyle, styler, this, kmlDocument);
   else return null;
 }
 /** @return this as a GeoJSON object. */
 @Override
 public JsonObject asGeoJSON(boolean isRoot) {
   JsonObject json = new JsonObject();
   json.addProperty("type", "Feature");
   if (mId != null) json.addProperty("id", mId);
   json.add("geometry", mGeometry.asGeoJSON());
   json.add("properties", geoJSONProperties());
   return json;
 }
Example #4
0
 /**
  * Build an array of Positions in GeoJSON format.
  *
  * @param coordinates
  * @return the GeoJSON array of Positions.
  */
 public static JsonArray geoJSONCoordinates(ArrayList<GeoPoint> coordinates) {
   JsonArray json = new JsonArray();
   Iterator<GeoPoint> it = coordinates.iterator();
   while (it.hasNext()) {
     GeoPoint position = it.next();
     json.add(KmlGeometry.geoJSONPosition(position));
   }
   return json;
 }
Example #5
0
 /** parse a GeoJSON array of Positions: [ [lon, lat, alt],... [lon, lat, alt] ] */
 public static ArrayList<GeoPoint> parseGeoJSONPositions(JsonArray json) {
   if (json == null) return null;
   ArrayList<GeoPoint> coordinates = new ArrayList<GeoPoint>(json.size());
   for (int i = 0; i < json.size(); i++) {
     JsonArray position = json.get(i).getAsJsonArray();
     GeoPoint p = KmlGeometry.parseGeoJSONPosition(position);
     if (p != null) coordinates.add(p);
   }
   return coordinates;
 }
 /** constructs a Placemark from a Polyline overlay, as a KML LineString */
 public KmlPlacemark(Polyline polyline, KmlDocument kmlDoc) {
   this();
   mName = "LineString - " + polyline.getNumberOfPoints() + " points";
   mGeometry = new KmlLineString();
   mGeometry.mCoordinates = (ArrayList<GeoPoint>) polyline.getPoints();
   mVisibility = polyline.isEnabled();
   // Style:
   Style style = new Style();
   style.mLineStyle = new LineStyle(polyline.getColor(), polyline.getWidth());
   mStyle = kmlDoc.addStyle(style);
 }
 /** constructs a Placemark from a Polygon overlay, as a KML Polygon */
 public KmlPlacemark(Polygon polygon, KmlDocument kmlDoc) {
   this();
   mName = polygon.getTitle();
   mDescription = polygon.getSnippet();
   mGeometry = new KmlPolygon();
   mGeometry.mCoordinates = (ArrayList<GeoPoint>) polygon.getPoints();
   ((KmlPolygon) mGeometry).mHoles = (ArrayList<ArrayList<GeoPoint>>) polygon.getHoles();
   mVisibility = polygon.isEnabled();
   // Style:
   Style style = new Style();
   style.mPolyStyle = new ColorStyle(polygon.getFillColor());
   style.mLineStyle = new LineStyle(polygon.getStrokeColor(), polygon.getStrokeWidth());
   mStyle = kmlDoc.addStyle(style);
 }
 /** GeoJSON constructor */
 public KmlPlacemark(JsonObject json) {
   this();
   if (json.has("id")) mId = json.get("id").getAsString();
   JsonObject geometry = json.getAsJsonObject("geometry");
   if (geometry != null) {
     mGeometry = KmlGeometry.parseGeoJSON(geometry);
   }
   if (json.has("properties")) {
     // Parse properties:
     JsonObject properties = json.getAsJsonObject("properties");
     Set<Map.Entry<String, JsonElement>> entrySet = properties.entrySet();
     for (Map.Entry<String, JsonElement> entry : entrySet) {
       String key = entry.getKey();
       String value = entry.getValue().getAsString();
       if (key != null && value != null) setExtendedData(key, value);
     }
     // Put "name" property in standard KML format:
     if (mExtendedData != null && mExtendedData.containsKey("name")) {
       mName = mExtendedData.get("name");
       mExtendedData.remove("name");
     }
   }
 }
 @Override
 public KmlPlacemark clone() {
   KmlPlacemark kmlPlacemark = (KmlPlacemark) super.clone();
   if (mGeometry != null) kmlPlacemark.mGeometry = mGeometry.clone();
   return kmlPlacemark;
 }
 @Override
 public void writeKMLSpecifics(Writer writer) {
   if (mGeometry != null) mGeometry.saveAsKML(writer);
 }
 @Override
 public BoundingBoxE6 getBoundingBox() {
   if (mGeometry != null) return mGeometry.getBoundingBox();
   else return null;
 }